index.js 3.3 KB

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