expandUtil.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  2. import * as React from 'react';
  3. import classNames from 'classnames';
  4. export function renderExpandIcon(_ref) {
  5. var prefixCls = _ref.prefixCls,
  6. record = _ref.record,
  7. onExpand = _ref.onExpand,
  8. expanded = _ref.expanded,
  9. expandable = _ref.expandable;
  10. var expandClassName = "".concat(prefixCls, "-row-expand-icon");
  11. if (!expandable) {
  12. return /*#__PURE__*/React.createElement("span", {
  13. className: classNames(expandClassName, "".concat(prefixCls, "-row-spaced"))
  14. });
  15. }
  16. var onClick = function onClick(event) {
  17. onExpand(record, event);
  18. event.stopPropagation();
  19. };
  20. return /*#__PURE__*/React.createElement("span", {
  21. className: classNames(expandClassName, _defineProperty(_defineProperty({}, "".concat(prefixCls, "-row-expanded"), expanded), "".concat(prefixCls, "-row-collapsed"), !expanded)),
  22. onClick: onClick
  23. });
  24. }
  25. export function findAllChildrenKeys(data, getRowKey, childrenColumnName) {
  26. var keys = [];
  27. function dig(list) {
  28. (list || []).forEach(function (item, index) {
  29. keys.push(getRowKey(item, index));
  30. dig(item[childrenColumnName]);
  31. });
  32. }
  33. dig(data);
  34. return keys;
  35. }
  36. export function computedExpandedClassName(cls, record, index, indent) {
  37. if (typeof cls === 'string') {
  38. return cls;
  39. }
  40. if (typeof cls === 'function') {
  41. return cls(record, index, indent);
  42. }
  43. return '';
  44. }