Column.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.FIX_LABEL = void 0;
  7. exports.default = Column;
  8. var _vue = require("vue");
  9. var _commonUtil = require("../utils/commonUtil");
  10. var _Checkbox = _interopRequireDefault(require("./Checkbox"));
  11. var _useSearchOptions = require("../hooks/useSearchOptions");
  12. var _context = require("../context");
  13. var _vnode = require("../../_util/vnode");
  14. const FIX_LABEL = exports.FIX_LABEL = '__cascader_fix_label__';
  15. function Column(_ref) {
  16. let {
  17. prefixCls,
  18. multiple,
  19. options,
  20. activeValue,
  21. prevValuePath,
  22. onToggleOpen,
  23. onSelect,
  24. onActive,
  25. checkedSet,
  26. halfCheckedSet,
  27. loadingKeys,
  28. isSelectable
  29. } = _ref;
  30. var _a, _b, _c, _d, _e, _f;
  31. const menuPrefixCls = `${prefixCls}-menu`;
  32. const menuItemPrefixCls = `${prefixCls}-menu-item`;
  33. const {
  34. fieldNames,
  35. changeOnSelect,
  36. expandTrigger,
  37. expandIcon: expandIconRef,
  38. loadingIcon: loadingIconRef,
  39. dropdownMenuColumnStyle,
  40. customSlots
  41. } = (0, _context.useInjectCascader)();
  42. const expandIcon = (_a = expandIconRef.value) !== null && _a !== void 0 ? _a : (_c = (_b = customSlots.value).expandIcon) === null || _c === void 0 ? void 0 : _c.call(_b);
  43. const loadingIcon = (_d = loadingIconRef.value) !== null && _d !== void 0 ? _d : (_f = (_e = customSlots.value).loadingIcon) === null || _f === void 0 ? void 0 : _f.call(_e);
  44. const hoverOpen = expandTrigger.value === 'hover';
  45. // ============================ Render ============================
  46. return (0, _vue.createVNode)("ul", {
  47. "class": menuPrefixCls,
  48. "role": "menu"
  49. }, [options.map(option => {
  50. var _a;
  51. const {
  52. disabled
  53. } = option;
  54. const searchOptions = option[_useSearchOptions.SEARCH_MARK];
  55. const label = (_a = option[FIX_LABEL]) !== null && _a !== void 0 ? _a : option[fieldNames.value.label];
  56. const value = option[fieldNames.value.value];
  57. const isMergedLeaf = (0, _commonUtil.isLeaf)(option, fieldNames.value);
  58. // Get real value of option. Search option is different way.
  59. const fullPath = searchOptions ? searchOptions.map(opt => opt[fieldNames.value.value]) : [...prevValuePath, value];
  60. const fullPathKey = (0, _commonUtil.toPathKey)(fullPath);
  61. const isLoading = loadingKeys.includes(fullPathKey);
  62. // >>>>> checked
  63. const checked = checkedSet.has(fullPathKey);
  64. // >>>>> halfChecked
  65. const halfChecked = halfCheckedSet.has(fullPathKey);
  66. // >>>>> Open
  67. const triggerOpenPath = () => {
  68. if (!disabled && (!hoverOpen || !isMergedLeaf)) {
  69. onActive(fullPath);
  70. }
  71. };
  72. // >>>>> Selection
  73. const triggerSelect = () => {
  74. if (isSelectable(option)) {
  75. onSelect(fullPath, isMergedLeaf);
  76. }
  77. };
  78. // >>>>> Title
  79. let title;
  80. if (typeof option.title === 'string') {
  81. title = option.title;
  82. } else if (typeof label === 'string') {
  83. title = label;
  84. }
  85. // >>>>> Render
  86. return (0, _vue.createVNode)("li", {
  87. "key": fullPathKey,
  88. "class": [menuItemPrefixCls, {
  89. [`${menuItemPrefixCls}-expand`]: !isMergedLeaf,
  90. [`${menuItemPrefixCls}-active`]: activeValue === value,
  91. [`${menuItemPrefixCls}-disabled`]: disabled,
  92. [`${menuItemPrefixCls}-loading`]: isLoading
  93. }],
  94. "style": dropdownMenuColumnStyle.value,
  95. "role": "menuitemcheckbox",
  96. "title": title,
  97. "aria-checked": checked,
  98. "data-path-key": fullPathKey,
  99. "onClick": () => {
  100. triggerOpenPath();
  101. if (!multiple || isMergedLeaf) {
  102. triggerSelect();
  103. }
  104. },
  105. "onDblclick": () => {
  106. if (changeOnSelect.value) {
  107. onToggleOpen(false);
  108. }
  109. },
  110. "onMouseenter": () => {
  111. if (hoverOpen) {
  112. triggerOpenPath();
  113. }
  114. },
  115. "onMousedown": e => {
  116. // Prevent selector from blurring
  117. e.preventDefault();
  118. }
  119. }, [multiple && (0, _vue.createVNode)(_Checkbox.default, {
  120. "prefixCls": `${prefixCls}-checkbox`,
  121. "checked": checked,
  122. "halfChecked": halfChecked,
  123. "disabled": disabled,
  124. "onClick": e => {
  125. e.stopPropagation();
  126. triggerSelect();
  127. }
  128. }, null), (0, _vue.createVNode)("div", {
  129. "class": `${menuItemPrefixCls}-content`
  130. }, [label]), !isLoading && expandIcon && !isMergedLeaf && (0, _vue.createVNode)("div", {
  131. "class": `${menuItemPrefixCls}-expand-icon`
  132. }, [(0, _vnode.cloneElement)(expandIcon)]), isLoading && loadingIcon && (0, _vue.createVNode)("div", {
  133. "class": `${menuItemPrefixCls}-loading-icon`
  134. }, [(0, _vnode.cloneElement)(loadingIcon)])]);
  135. })]);
  136. }
  137. Column.props = ['prefixCls', 'multiple', 'options', 'activeValue', 'prevValuePath', 'onToggleOpen', 'onSelect', 'onActive', 'checkedSet', 'halfCheckedSet', 'loadingKeys', 'isSelectable'];
  138. Column.displayName = 'Column';
  139. Column.inheritAttrs = false;