index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
  3. // Utils
  4. import { createNamespace, isDef } from '../utils';
  5. import { emit, inherit } from '../utils/functional';
  6. import { routeProps, functionalRoute } from '../utils/router';
  7. import { cellProps } from './shared'; // Components
  8. import Icon from '../icon'; // Types
  9. var _createNamespace = createNamespace('cell'),
  10. createComponent = _createNamespace[0],
  11. bem = _createNamespace[1];
  12. function Cell(h, props, slots, ctx) {
  13. var _props$clickable;
  14. var icon = props.icon,
  15. size = props.size,
  16. title = props.title,
  17. label = props.label,
  18. value = props.value,
  19. isLink = props.isLink;
  20. var showTitle = slots.title || isDef(title);
  21. function Label() {
  22. var showLabel = slots.label || isDef(label);
  23. if (showLabel) {
  24. return h("div", {
  25. "class": [bem('label'), props.labelClass]
  26. }, [slots.label ? slots.label() : label]);
  27. }
  28. }
  29. function Title() {
  30. if (showTitle) {
  31. return h("div", {
  32. "class": [bem('title'), props.titleClass],
  33. "style": props.titleStyle
  34. }, [slots.title ? slots.title() : h("span", [title]), Label()]);
  35. }
  36. }
  37. function Value() {
  38. var showValue = slots.default || isDef(value);
  39. if (showValue) {
  40. return h("div", {
  41. "class": [bem('value', {
  42. alone: !showTitle
  43. }), props.valueClass]
  44. }, [slots.default ? slots.default() : h("span", [value])]);
  45. }
  46. }
  47. function LeftIcon() {
  48. if (slots.icon) {
  49. return slots.icon();
  50. }
  51. if (icon) {
  52. return h(Icon, {
  53. "class": bem('left-icon'),
  54. "attrs": {
  55. "name": icon,
  56. "classPrefix": props.iconPrefix
  57. }
  58. });
  59. }
  60. }
  61. function RightIcon() {
  62. var rightIconSlot = slots['right-icon'];
  63. if (rightIconSlot) {
  64. return rightIconSlot();
  65. }
  66. if (isLink) {
  67. var arrowDirection = props.arrowDirection;
  68. return h(Icon, {
  69. "class": bem('right-icon'),
  70. "attrs": {
  71. "name": arrowDirection ? "arrow-" + arrowDirection : 'arrow'
  72. }
  73. });
  74. }
  75. }
  76. function onClick(event) {
  77. emit(ctx, 'click', event);
  78. functionalRoute(ctx);
  79. }
  80. var clickable = (_props$clickable = props.clickable) != null ? _props$clickable : isLink;
  81. var classes = {
  82. clickable: clickable,
  83. center: props.center,
  84. required: props.required,
  85. borderless: !props.border
  86. };
  87. if (size) {
  88. classes[size] = size;
  89. }
  90. return h("div", _mergeJSXProps([{
  91. "class": bem(classes),
  92. "attrs": {
  93. "role": clickable ? 'button' : null,
  94. "tabindex": clickable ? 0 : null
  95. },
  96. "on": {
  97. "click": onClick
  98. }
  99. }, inherit(ctx)]), [LeftIcon(), Title(), Value(), RightIcon(), slots.extra == null ? void 0 : slots.extra()]);
  100. }
  101. Cell.props = _extends({}, cellProps, routeProps);
  102. export default createComponent(Cell);