compact-item.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.genCompactItemStyle = genCompactItemStyle;
  7. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  8. // handle border collapse
  9. function compactItemBorder(token, parentCls, options) {
  10. const {
  11. focusElCls,
  12. focus,
  13. borderElCls
  14. } = options;
  15. const childCombinator = borderElCls ? '> *' : '';
  16. const hoverEffects = ['hover', focus ? 'focus' : null, 'active'].filter(Boolean).map(n => `&:${n} ${childCombinator}`).join(',');
  17. return {
  18. [`&-item:not(${parentCls}-last-item)`]: {
  19. marginInlineEnd: -token.lineWidth
  20. },
  21. '&-item': (0, _extends2.default)((0, _extends2.default)({
  22. [hoverEffects]: {
  23. zIndex: 2
  24. }
  25. }, focusElCls ? {
  26. [`&${focusElCls}`]: {
  27. zIndex: 2
  28. }
  29. } : {}), {
  30. [`&[disabled] ${childCombinator}`]: {
  31. zIndex: 0
  32. }
  33. })
  34. };
  35. }
  36. // handle border-radius
  37. function compactItemBorderRadius(prefixCls, parentCls, options) {
  38. const {
  39. borderElCls
  40. } = options;
  41. const childCombinator = borderElCls ? `> ${borderElCls}` : '';
  42. return {
  43. [`&-item:not(${parentCls}-first-item):not(${parentCls}-last-item) ${childCombinator}`]: {
  44. borderRadius: 0
  45. },
  46. [`&-item:not(${parentCls}-last-item)${parentCls}-first-item`]: {
  47. [`& ${childCombinator}, &${prefixCls}-sm ${childCombinator}, &${prefixCls}-lg ${childCombinator}`]: {
  48. borderStartEndRadius: 0,
  49. borderEndEndRadius: 0
  50. }
  51. },
  52. [`&-item:not(${parentCls}-first-item)${parentCls}-last-item`]: {
  53. [`& ${childCombinator}, &${prefixCls}-sm ${childCombinator}, &${prefixCls}-lg ${childCombinator}`]: {
  54. borderStartStartRadius: 0,
  55. borderEndStartRadius: 0
  56. }
  57. }
  58. };
  59. }
  60. function genCompactItemStyle(token) {
  61. let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  62. focus: true
  63. };
  64. const {
  65. componentCls
  66. } = token;
  67. const compactCls = `${componentCls}-compact`;
  68. return {
  69. [compactCls]: (0, _extends2.default)((0, _extends2.default)({}, compactItemBorder(token, compactCls, options)), compactItemBorderRadius(componentCls, compactCls, options))
  70. };
  71. }