compact-item.js 2.0 KB

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