index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
  3. import { use, isDef } from '../utils';
  4. import { cellProps } from './shared';
  5. import { emit, inherit } from '../utils/functional';
  6. import { routeProps, functionalRoute } from '../utils/router';
  7. import Icon from '../icon'; // Types
  8. var _use = use('cell'),
  9. sfc = _use[0],
  10. bem = _use[1];
  11. function Cell(h, props, slots, ctx) {
  12. var icon = props.icon,
  13. size = props.size,
  14. title = props.title,
  15. label = props.label,
  16. value = props.value,
  17. isLink = props.isLink,
  18. arrowDirection = props.arrowDirection;
  19. var showTitle = slots.title || isDef(title);
  20. var showValue = slots["default"] || isDef(value);
  21. var showLabel = slots.label || isDef(label);
  22. var Label = showLabel && h("div", {
  23. "class": [bem('label'), props.labelClass]
  24. }, [slots.label ? slots.label() : label]);
  25. var Title = showTitle && h("div", {
  26. "class": [bem('title'), props.titleClass],
  27. "style": props.titleStyle
  28. }, [slots.title ? slots.title() : h("span", [title]), Label]);
  29. var Value = showValue && h("div", {
  30. "class": [bem('value', {
  31. alone: !slots.title && !title
  32. }), props.valueClass]
  33. }, [slots["default"] ? slots["default"]() : h("span", [value])]);
  34. var LeftIcon = slots.icon ? slots.icon() : icon && h(Icon, {
  35. "class": bem('left-icon'),
  36. "attrs": {
  37. "name": icon
  38. }
  39. });
  40. var rightIconSlot = slots['right-icon'];
  41. var RightIcon = rightIconSlot ? rightIconSlot() : isLink && h(Icon, {
  42. "class": bem('right-icon'),
  43. "attrs": {
  44. "name": arrowDirection ? "arrow-" + arrowDirection : 'arrow'
  45. }
  46. });
  47. var onClick = function onClick(event) {
  48. emit(ctx, 'click', event);
  49. functionalRoute(ctx);
  50. };
  51. var classes = {
  52. center: props.center,
  53. required: props.required,
  54. borderless: !props.border,
  55. clickable: isLink || props.clickable
  56. };
  57. if (size) {
  58. classes[size] = size;
  59. }
  60. return h("div", _mergeJSXProps([{
  61. "class": bem(classes),
  62. "on": {
  63. "click": onClick
  64. }
  65. }, inherit(ctx)]), [LeftIcon, Title, Value, RightIcon, slots.extra && slots.extra()]);
  66. }
  67. Cell.props = _extends({}, cellProps, routeProps, {
  68. clickable: Boolean,
  69. arrowDirection: String
  70. });
  71. export default sfc(Cell);