index.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. import { resetComponent } from '../../style';
  2. import { genStyleHooks } from '../../theme/internal';
  3. const genRtlStyle = token => {
  4. const {
  5. componentCls
  6. } = token;
  7. return {
  8. [`&-rtl${componentCls}-horizontal`]: {
  9. [`> ${componentCls}-bar`]: {
  10. [`${componentCls}-bar-collapse-previous`]: {
  11. insetInlineEnd: 0,
  12. insetInlineStart: 'unset'
  13. },
  14. [`${componentCls}-bar-collapse-next`]: {
  15. insetInlineEnd: 'unset',
  16. insetInlineStart: 0
  17. }
  18. }
  19. },
  20. [`&-rtl${componentCls}-vertical`]: {
  21. [`> ${componentCls}-bar`]: {
  22. [`${componentCls}-bar-collapse-previous`]: {
  23. insetInlineEnd: '50%',
  24. insetInlineStart: 'unset'
  25. },
  26. [`${componentCls}-bar-collapse-next`]: {
  27. insetInlineEnd: '50%',
  28. insetInlineStart: 'unset'
  29. }
  30. }
  31. }
  32. };
  33. };
  34. const centerStyle = {
  35. position: 'absolute',
  36. top: '50%',
  37. left: {
  38. _skip_check_: true,
  39. value: '50%'
  40. },
  41. transform: 'translate(-50%, -50%)'
  42. };
  43. const genSplitterStyle = token => {
  44. const {
  45. componentCls,
  46. colorFill,
  47. splitBarDraggableSize,
  48. splitBarSize,
  49. splitTriggerSize,
  50. controlItemBgHover,
  51. controlItemBgActive,
  52. controlItemBgActiveHover,
  53. prefixCls
  54. } = token;
  55. const splitBarCls = `${componentCls}-bar`;
  56. const splitMaskCls = `${componentCls}-mask`;
  57. const splitPanelCls = `${componentCls}-panel`;
  58. const halfTriggerSize = token.calc(splitTriggerSize).div(2).equal();
  59. const splitterBarPreviewOffsetVar = `${prefixCls}-bar-preview-offset`;
  60. const splitterBarPreviewStyle = {
  61. position: 'absolute',
  62. background: token.colorPrimary,
  63. opacity: 0.2,
  64. pointerEvents: 'none',
  65. transition: 'none',
  66. zIndex: 1,
  67. display: 'none'
  68. };
  69. return {
  70. [componentCls]: Object.assign(Object.assign(Object.assign({}, resetComponent(token)), {
  71. display: 'flex',
  72. width: '100%',
  73. height: '100%',
  74. alignItems: 'stretch',
  75. // ======================== SplitBar ========================
  76. // Use `>` to avoid conflict with mix layout
  77. [`> ${splitBarCls}`]: {
  78. flex: 'none',
  79. position: 'relative',
  80. userSelect: 'none',
  81. // ======================= Dragger =======================
  82. [`${splitBarCls}-dragger`]: Object.assign(Object.assign({}, centerStyle), {
  83. zIndex: 1,
  84. // Hover background
  85. '&::before': Object.assign({
  86. content: '""',
  87. background: controlItemBgHover
  88. }, centerStyle),
  89. // Spinner
  90. '&::after': Object.assign({
  91. content: '""',
  92. background: colorFill
  93. }, centerStyle),
  94. // Hover
  95. [`&:hover:not(${splitBarCls}-dragger-active)`]: {
  96. '&::before': {
  97. background: controlItemBgActive
  98. }
  99. },
  100. // Active
  101. '&-active': {
  102. zIndex: 2,
  103. '&::before': {
  104. background: controlItemBgActiveHover
  105. }
  106. },
  107. // Disabled, not use `pointer-events: none` since still need trigger collapse
  108. [`&-disabled${splitBarCls}-dragger`]: {
  109. zIndex: 0,
  110. '&, &:hover, &-active': {
  111. cursor: 'default',
  112. '&::before': {
  113. background: controlItemBgHover
  114. }
  115. },
  116. '&::after': {
  117. display: 'none'
  118. }
  119. }
  120. }),
  121. // ======================= Collapse =======================
  122. [`${splitBarCls}-collapse-bar`]: Object.assign(Object.assign({}, centerStyle), {
  123. zIndex: token.zIndexPopupBase,
  124. background: controlItemBgHover,
  125. fontSize: token.fontSizeSM,
  126. borderRadius: token.borderRadiusXS,
  127. color: token.colorText,
  128. cursor: 'pointer',
  129. opacity: 0,
  130. display: 'flex',
  131. alignItems: 'center',
  132. justifyContent: 'center',
  133. // Hover
  134. '&:hover': {
  135. background: controlItemBgActive
  136. },
  137. // Active
  138. '&:active': {
  139. background: controlItemBgActiveHover
  140. }
  141. }),
  142. '&:hover, &:active': {
  143. [`${splitBarCls}-collapse-bar-hover-only`]: {
  144. opacity: 1
  145. }
  146. },
  147. [`${splitBarCls}-collapse-bar-hover-only`]: {
  148. '@media(hover:none)': {
  149. opacity: 1
  150. }
  151. },
  152. [`${splitBarCls}-collapse-bar-always-hidden`]: {
  153. display: 'none'
  154. },
  155. [`${splitBarCls}-collapse-bar-always-visible`]: {
  156. opacity: 1
  157. }
  158. },
  159. // =========================== Mask =========================
  160. // Util dom for handle cursor
  161. [splitMaskCls]: {
  162. position: 'fixed',
  163. zIndex: token.zIndexPopupBase,
  164. inset: 0,
  165. '&-horizontal': {
  166. cursor: 'col-resize'
  167. },
  168. '&-vertical': {
  169. cursor: 'row-resize'
  170. }
  171. },
  172. // ==========================================================
  173. // == Layout ==
  174. // ==========================================================
  175. '&-horizontal': {
  176. flexDirection: 'row',
  177. [`> ${splitBarCls}`]: {
  178. width: 0,
  179. // ======================= Preview =======================
  180. [`${splitBarCls}-preview`]: Object.assign(Object.assign({
  181. height: '100%',
  182. width: splitBarSize
  183. }, splitterBarPreviewStyle), {
  184. [`&${splitBarCls}-preview-active`]: {
  185. display: 'block',
  186. transform: `translateX(var(--${splitterBarPreviewOffsetVar}))`
  187. }
  188. }),
  189. // ======================= Dragger =======================
  190. [`${splitBarCls}-dragger`]: {
  191. cursor: 'col-resize',
  192. height: '100%',
  193. width: splitTriggerSize,
  194. '&::before': {
  195. height: '100%',
  196. width: splitBarSize
  197. },
  198. '&::after': {
  199. height: splitBarDraggableSize,
  200. width: splitBarSize
  201. }
  202. },
  203. // ======================= Collapse =======================
  204. [`${splitBarCls}-collapse-bar`]: {
  205. width: token.fontSizeSM,
  206. height: token.controlHeightSM,
  207. '&-start': {
  208. left: {
  209. _skip_check_: true,
  210. value: 'auto'
  211. },
  212. right: {
  213. _skip_check_: true,
  214. value: halfTriggerSize
  215. },
  216. transform: 'translateY(-50%)'
  217. },
  218. '&-end': {
  219. left: {
  220. _skip_check_: true,
  221. value: halfTriggerSize
  222. },
  223. right: {
  224. _skip_check_: true,
  225. value: 'auto'
  226. },
  227. transform: 'translateY(-50%)'
  228. }
  229. }
  230. }
  231. },
  232. '&-vertical': {
  233. flexDirection: 'column',
  234. [`> ${splitBarCls}`]: {
  235. height: 0,
  236. // ======================= Preview =======================
  237. [`${splitBarCls}-preview`]: Object.assign(Object.assign({
  238. height: splitBarSize,
  239. width: '100%'
  240. }, splitterBarPreviewStyle), {
  241. [`&${splitBarCls}-preview-active`]: {
  242. display: 'block',
  243. transform: `translateY(var(--${splitterBarPreviewOffsetVar}))`
  244. }
  245. }),
  246. // ======================= Dragger =======================
  247. [`${splitBarCls}-dragger`]: {
  248. cursor: 'row-resize',
  249. width: '100%',
  250. height: splitTriggerSize,
  251. '&::before': {
  252. width: '100%',
  253. height: splitBarSize
  254. },
  255. '&::after': {
  256. width: splitBarDraggableSize,
  257. height: splitBarSize
  258. }
  259. },
  260. // ======================= Collapse =======================
  261. [`${splitBarCls}-collapse-bar`]: {
  262. height: token.fontSizeSM,
  263. width: token.controlHeightSM,
  264. '&-start': {
  265. top: 'auto',
  266. bottom: halfTriggerSize,
  267. transform: 'translateX(-50%)'
  268. },
  269. '&-end': {
  270. top: halfTriggerSize,
  271. bottom: 'auto',
  272. transform: 'translateX(-50%)'
  273. }
  274. }
  275. }
  276. },
  277. // ========================= Panels =========================
  278. [splitPanelCls]: {
  279. overflow: 'auto',
  280. padding: '0 1px',
  281. scrollbarWidth: 'thin',
  282. boxSizing: 'border-box',
  283. '&-hidden': {
  284. padding: 0,
  285. overflow: 'hidden'
  286. },
  287. [`&:has(${componentCls}:only-child)`]: {
  288. overflow: 'hidden'
  289. }
  290. }
  291. }), genRtlStyle(token))
  292. };
  293. };
  294. export const prepareComponentToken = token => {
  295. var _a;
  296. const splitBarSize = token.splitBarSize || 2;
  297. const splitTriggerSize = token.splitTriggerSize || 6;
  298. // https://github.com/ant-design/ant-design/pull/51223
  299. const resizeSpinnerSize = token.resizeSpinnerSize || 20;
  300. const splitBarDraggableSize = (_a = token.splitBarDraggableSize) !== null && _a !== void 0 ? _a : resizeSpinnerSize;
  301. return {
  302. splitBarSize,
  303. splitTriggerSize,
  304. splitBarDraggableSize,
  305. resizeSpinnerSize
  306. };
  307. };
  308. // ============================== Export ==============================
  309. export default genStyleHooks('Splitter', genSplitterStyle, prepareComponentToken);