expand.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { operationUnit } from '../../style';
  3. const genExpandStyle = token => {
  4. const {
  5. componentCls,
  6. antCls,
  7. controlInteractiveSize: checkboxSize,
  8. motionDurationSlow,
  9. lineWidth,
  10. paddingXS,
  11. lineType,
  12. tableBorderColor,
  13. tableExpandIconBg,
  14. tableExpandColumnWidth,
  15. borderRadius,
  16. fontSize,
  17. fontSizeSM,
  18. lineHeight,
  19. tablePaddingVertical,
  20. tablePaddingHorizontal,
  21. tableExpandedRowBg,
  22. paddingXXS
  23. } = token;
  24. const halfInnerSize = checkboxSize / 2 - lineWidth;
  25. // must be odd number, unless it cannot align center
  26. const expandIconSize = halfInnerSize * 2 + lineWidth * 3;
  27. const tableBorder = `${lineWidth}px ${lineType} ${tableBorderColor}`;
  28. const expandIconLineOffset = paddingXXS - lineWidth;
  29. return {
  30. [`${componentCls}-wrapper`]: {
  31. [`${componentCls}-expand-icon-col`]: {
  32. width: tableExpandColumnWidth
  33. },
  34. [`${componentCls}-row-expand-icon-cell`]: {
  35. textAlign: 'center',
  36. [`${componentCls}-row-expand-icon`]: {
  37. display: 'inline-flex',
  38. float: 'none',
  39. verticalAlign: 'sub'
  40. }
  41. },
  42. [`${componentCls}-row-indent`]: {
  43. height: 1,
  44. float: 'left'
  45. },
  46. [`${componentCls}-row-expand-icon`]: _extends(_extends({}, operationUnit(token)), {
  47. position: 'relative',
  48. float: 'left',
  49. boxSizing: 'border-box',
  50. width: expandIconSize,
  51. height: expandIconSize,
  52. padding: 0,
  53. color: 'inherit',
  54. lineHeight: `${expandIconSize}px`,
  55. background: tableExpandIconBg,
  56. border: tableBorder,
  57. borderRadius,
  58. transform: `scale(${checkboxSize / expandIconSize})`,
  59. transition: `all ${motionDurationSlow}`,
  60. userSelect: 'none',
  61. [`&:focus, &:hover, &:active`]: {
  62. borderColor: 'currentcolor'
  63. },
  64. [`&::before, &::after`]: {
  65. position: 'absolute',
  66. background: 'currentcolor',
  67. transition: `transform ${motionDurationSlow} ease-out`,
  68. content: '""'
  69. },
  70. '&::before': {
  71. top: halfInnerSize,
  72. insetInlineEnd: expandIconLineOffset,
  73. insetInlineStart: expandIconLineOffset,
  74. height: lineWidth
  75. },
  76. '&::after': {
  77. top: expandIconLineOffset,
  78. bottom: expandIconLineOffset,
  79. insetInlineStart: halfInnerSize,
  80. width: lineWidth,
  81. transform: 'rotate(90deg)'
  82. },
  83. // Motion effect
  84. '&-collapsed::before': {
  85. transform: 'rotate(-180deg)'
  86. },
  87. '&-collapsed::after': {
  88. transform: 'rotate(0deg)'
  89. },
  90. '&-spaced': {
  91. '&::before, &::after': {
  92. display: 'none',
  93. content: 'none'
  94. },
  95. background: 'transparent',
  96. border: 0,
  97. visibility: 'hidden'
  98. }
  99. }),
  100. [`${componentCls}-row-indent + ${componentCls}-row-expand-icon`]: {
  101. marginTop: (fontSize * lineHeight - lineWidth * 3) / 2 - Math.ceil((fontSizeSM * 1.4 - lineWidth * 3) / 2),
  102. marginInlineEnd: paddingXS
  103. },
  104. [`tr${componentCls}-expanded-row`]: {
  105. '&, &:hover': {
  106. '> td': {
  107. background: tableExpandedRowBg
  108. }
  109. },
  110. // https://github.com/ant-design/ant-design/issues/25573
  111. [`${antCls}-descriptions-view`]: {
  112. display: 'flex',
  113. table: {
  114. flex: 'auto',
  115. width: 'auto'
  116. }
  117. }
  118. },
  119. // With fixed
  120. [`${componentCls}-expanded-row-fixed`]: {
  121. position: 'relative',
  122. margin: `-${tablePaddingVertical}px -${tablePaddingHorizontal}px`,
  123. padding: `${tablePaddingVertical}px ${tablePaddingHorizontal}px`
  124. }
  125. }
  126. };
  127. };
  128. export default genExpandStyle;