index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.prepareComponentToken = exports.initComponentToken = exports.genTreeStyle = exports.genBaseStyle = exports.default = void 0;
  6. var _cssinjs = require("@ant-design/cssinjs");
  7. var _style = require("../../checkbox/style");
  8. var _style2 = require("../../style");
  9. var _motion = require("../../style/motion");
  10. var _internal = require("../../theme/internal");
  11. var _directory = require("./directory");
  12. // ============================ Keyframes =============================
  13. const treeNodeFX = new _cssinjs.Keyframes('ant-tree-node-fx-do-not-use', {
  14. '0%': {
  15. opacity: 0
  16. },
  17. '100%': {
  18. opacity: 1
  19. }
  20. });
  21. // ============================== Switch ==============================
  22. const getSwitchStyle = (prefixCls, token) => ({
  23. [`.${prefixCls}-switcher-icon`]: {
  24. display: 'inline-block',
  25. fontSize: 10,
  26. verticalAlign: 'baseline',
  27. svg: {
  28. transition: `transform ${token.motionDurationSlow}`
  29. }
  30. }
  31. });
  32. // =============================== Drop ===============================
  33. const getDropIndicatorStyle = (prefixCls, token) => ({
  34. [`.${prefixCls}-drop-indicator`]: {
  35. position: 'absolute',
  36. // it should displayed over the following node
  37. zIndex: 1,
  38. height: 2,
  39. backgroundColor: token.colorPrimary,
  40. borderRadius: 1,
  41. pointerEvents: 'none',
  42. '&:after': {
  43. position: 'absolute',
  44. top: -3,
  45. insetInlineStart: -6,
  46. width: 8,
  47. height: 8,
  48. backgroundColor: 'transparent',
  49. border: `${(0, _cssinjs.unit)(token.lineWidthBold)} solid ${token.colorPrimary}`,
  50. borderRadius: '50%',
  51. content: '""'
  52. }
  53. }
  54. });
  55. const genBaseStyle = (prefixCls, token) => {
  56. const {
  57. treeCls,
  58. treeNodeCls,
  59. treeNodePadding,
  60. titleHeight,
  61. indentSize,
  62. nodeSelectedBg,
  63. nodeHoverBg,
  64. colorTextQuaternary,
  65. controlItemBgActiveDisabled
  66. } = token;
  67. return {
  68. [treeCls]: Object.assign(Object.assign({}, (0, _style2.resetComponent)(token)), {
  69. // fix https://github.com/ant-design/ant-design/issues/50316
  70. ['--rc-virtual-list-scrollbar-bg']: token.colorSplit,
  71. background: token.colorBgContainer,
  72. borderRadius: token.borderRadius,
  73. transition: `background-color ${token.motionDurationSlow}`,
  74. '&-rtl': {
  75. direction: 'rtl'
  76. },
  77. [`&${treeCls}-rtl ${treeCls}-switcher_close ${treeCls}-switcher-icon svg`]: {
  78. transform: 'rotate(90deg)'
  79. },
  80. [`&-focused:not(:hover):not(${treeCls}-active-focused)`]: (0, _style2.genFocusOutline)(token),
  81. // =================== Virtual List ===================
  82. [`${treeCls}-list-holder-inner`]: {
  83. alignItems: 'flex-start'
  84. },
  85. [`&${treeCls}-block-node`]: {
  86. [`${treeCls}-list-holder-inner`]: {
  87. alignItems: 'stretch',
  88. // >>> Title
  89. [`${treeCls}-node-content-wrapper`]: {
  90. flex: 'auto'
  91. },
  92. // >>> Drag
  93. [`${treeNodeCls}.dragging:after`]: {
  94. position: 'absolute',
  95. inset: 0,
  96. border: `1px solid ${token.colorPrimary}`,
  97. opacity: 0,
  98. animationName: treeNodeFX,
  99. animationDuration: token.motionDurationSlow,
  100. animationPlayState: 'running',
  101. animationFillMode: 'forwards',
  102. content: '""',
  103. pointerEvents: 'none',
  104. borderRadius: token.borderRadius
  105. }
  106. }
  107. },
  108. // ===================== TreeNode =====================
  109. [treeNodeCls]: {
  110. display: 'flex',
  111. alignItems: 'flex-start',
  112. marginBottom: treeNodePadding,
  113. lineHeight: (0, _cssinjs.unit)(titleHeight),
  114. position: 'relative',
  115. // 非常重要,避免 drop-indicator 在拖拽过程中闪烁
  116. '&:before': {
  117. content: '""',
  118. position: 'absolute',
  119. zIndex: 1,
  120. insetInlineStart: 0,
  121. width: '100%',
  122. top: '100%',
  123. height: treeNodePadding
  124. },
  125. // Disabled
  126. [`&-disabled ${treeCls}-node-content-wrapper`]: {
  127. color: token.colorTextDisabled,
  128. cursor: 'not-allowed',
  129. '&:hover': {
  130. background: 'transparent'
  131. }
  132. },
  133. [`${treeCls}-checkbox-disabled + ${treeCls}-node-selected,&${treeNodeCls}-disabled${treeNodeCls}-selected ${treeCls}-node-content-wrapper`]: {
  134. backgroundColor: controlItemBgActiveDisabled
  135. },
  136. // we can not set pointer-events to none for checkbox in tree
  137. // ref: https://github.com/ant-design/ant-design/issues/39822#issuecomment-2605234058
  138. [`${treeCls}-checkbox-disabled`]: {
  139. pointerEvents: 'unset'
  140. },
  141. // not disable
  142. [`&:not(${treeNodeCls}-disabled)`]: {
  143. // >>> Title
  144. [`${treeCls}-node-content-wrapper`]: {
  145. '&:hover': {
  146. color: token.nodeHoverColor
  147. }
  148. }
  149. },
  150. [`&-active ${treeCls}-node-content-wrapper`]: {
  151. background: token.controlItemBgHover
  152. },
  153. [`&:not(${treeNodeCls}-disabled).filter-node ${treeCls}-title`]: {
  154. color: token.colorPrimary,
  155. fontWeight: token.fontWeightStrong
  156. },
  157. '&-draggable': {
  158. cursor: 'grab',
  159. [`${treeCls}-draggable-icon`]: {
  160. // https://github.com/ant-design/ant-design/issues/41915
  161. flexShrink: 0,
  162. width: titleHeight,
  163. textAlign: 'center',
  164. visibility: 'visible',
  165. color: colorTextQuaternary
  166. },
  167. [`&${treeNodeCls}-disabled ${treeCls}-draggable-icon`]: {
  168. visibility: 'hidden'
  169. }
  170. }
  171. },
  172. // >>> Indent
  173. [`${treeCls}-indent`]: {
  174. alignSelf: 'stretch',
  175. whiteSpace: 'nowrap',
  176. userSelect: 'none',
  177. '&-unit': {
  178. display: 'inline-block',
  179. width: indentSize
  180. }
  181. },
  182. // >>> Drag Handler
  183. [`${treeCls}-draggable-icon`]: {
  184. visibility: 'hidden'
  185. },
  186. // Switcher / Checkbox
  187. [`${treeCls}-switcher, ${treeCls}-checkbox`]: {
  188. marginInlineEnd: token.calc(token.calc(titleHeight).sub(token.controlInteractiveSize)).div(2).equal()
  189. },
  190. // >>> Switcher
  191. [`${treeCls}-switcher`]: Object.assign(Object.assign({}, getSwitchStyle(prefixCls, token)), {
  192. position: 'relative',
  193. flex: 'none',
  194. alignSelf: 'stretch',
  195. width: titleHeight,
  196. textAlign: 'center',
  197. cursor: 'pointer',
  198. userSelect: 'none',
  199. transition: `all ${token.motionDurationSlow}`,
  200. '&-noop': {
  201. cursor: 'unset'
  202. },
  203. '&:before': {
  204. pointerEvents: 'none',
  205. content: '""',
  206. width: titleHeight,
  207. height: titleHeight,
  208. position: 'absolute',
  209. left: {
  210. _skip_check_: true,
  211. value: 0
  212. },
  213. top: 0,
  214. borderRadius: token.borderRadius,
  215. transition: `all ${token.motionDurationSlow}`
  216. },
  217. [`&:not(${treeCls}-switcher-noop):hover:before`]: {
  218. backgroundColor: token.colorBgTextHover
  219. },
  220. [`&_close ${treeCls}-switcher-icon svg`]: {
  221. transform: 'rotate(-90deg)'
  222. },
  223. '&-loading-icon': {
  224. color: token.colorPrimary
  225. },
  226. '&-leaf-line': {
  227. position: 'relative',
  228. zIndex: 1,
  229. display: 'inline-block',
  230. width: '100%',
  231. height: '100%',
  232. // https://github.com/ant-design/ant-design/issues/31884
  233. '&:before': {
  234. position: 'absolute',
  235. top: 0,
  236. insetInlineEnd: token.calc(titleHeight).div(2).equal(),
  237. bottom: token.calc(treeNodePadding).mul(-1).equal(),
  238. marginInlineStart: -1,
  239. borderInlineEnd: `1px solid ${token.colorBorder}`,
  240. content: '""'
  241. },
  242. '&:after': {
  243. position: 'absolute',
  244. width: token.calc(token.calc(titleHeight).div(2).equal()).mul(0.8).equal(),
  245. height: token.calc(titleHeight).div(2).equal(),
  246. borderBottom: `1px solid ${token.colorBorder}`,
  247. content: '""'
  248. }
  249. }
  250. }),
  251. // >>> Title
  252. // add `${treeCls}-checkbox + span` to cover checkbox `${checkboxCls} + span`
  253. [`${treeCls}-node-content-wrapper`]: Object.assign(Object.assign({
  254. position: 'relative',
  255. minHeight: titleHeight,
  256. paddingBlock: 0,
  257. paddingInline: token.paddingXS,
  258. background: 'transparent',
  259. borderRadius: token.borderRadius,
  260. cursor: 'pointer',
  261. transition: `all ${token.motionDurationMid}, border 0s, line-height 0s, box-shadow 0s`
  262. }, getDropIndicatorStyle(prefixCls, token)), {
  263. '&:hover': {
  264. backgroundColor: nodeHoverBg
  265. },
  266. [`&${treeCls}-node-selected`]: {
  267. color: token.nodeSelectedColor,
  268. backgroundColor: nodeSelectedBg
  269. },
  270. // Icon
  271. [`${treeCls}-iconEle`]: {
  272. display: 'inline-block',
  273. width: titleHeight,
  274. height: titleHeight,
  275. textAlign: 'center',
  276. verticalAlign: 'top',
  277. '&:empty': {
  278. display: 'none'
  279. }
  280. }
  281. }),
  282. // https://github.com/ant-design/ant-design/issues/28217
  283. [`${treeCls}-unselectable ${treeCls}-node-content-wrapper:hover`]: {
  284. backgroundColor: 'transparent'
  285. },
  286. [`${treeNodeCls}.drop-container > [draggable]`]: {
  287. boxShadow: `0 0 0 2px ${token.colorPrimary}`
  288. },
  289. // ==================== Show Line =====================
  290. '&-show-line': {
  291. // ================ Indent lines ================
  292. [`${treeCls}-indent-unit`]: {
  293. position: 'relative',
  294. height: '100%',
  295. '&:before': {
  296. position: 'absolute',
  297. top: 0,
  298. insetInlineEnd: token.calc(titleHeight).div(2).equal(),
  299. bottom: token.calc(treeNodePadding).mul(-1).equal(),
  300. borderInlineEnd: `1px solid ${token.colorBorder}`,
  301. content: '""'
  302. },
  303. '&-end:before': {
  304. display: 'none'
  305. }
  306. },
  307. // ============== Cover Background ==============
  308. [`${treeCls}-switcher`]: {
  309. background: 'transparent',
  310. '&-line-icon': {
  311. // https://github.com/ant-design/ant-design/issues/32813
  312. verticalAlign: '-0.15em'
  313. }
  314. }
  315. },
  316. [`${treeNodeCls}-leaf-last ${treeCls}-switcher-leaf-line:before`]: {
  317. top: 'auto !important',
  318. bottom: 'auto !important',
  319. height: `${(0, _cssinjs.unit)(token.calc(titleHeight).div(2).equal())} !important`
  320. }
  321. })
  322. };
  323. };
  324. // ============================== Merged ==============================
  325. exports.genBaseStyle = genBaseStyle;
  326. const genTreeStyle = (prefixCls, token,
  327. /**
  328. * @descCN 是否启用目录树样式
  329. * @descEN Whether to enable directory style
  330. * @default true
  331. */
  332. enableDirectory = true) => {
  333. const treeCls = `.${prefixCls}`;
  334. const treeNodeCls = `${treeCls}-treenode`;
  335. const treeNodePadding = token.calc(token.paddingXS).div(2).equal();
  336. const treeToken = (0, _internal.mergeToken)(token, {
  337. treeCls,
  338. treeNodeCls,
  339. treeNodePadding
  340. });
  341. return [
  342. // Basic
  343. genBaseStyle(prefixCls, treeToken),
  344. // Directory
  345. enableDirectory && (0, _directory.genDirectoryStyle)(treeToken)].filter(Boolean);
  346. };
  347. exports.genTreeStyle = genTreeStyle;
  348. const initComponentToken = token => {
  349. const {
  350. controlHeightSM,
  351. controlItemBgHover,
  352. controlItemBgActive
  353. } = token;
  354. const titleHeight = controlHeightSM;
  355. return {
  356. titleHeight,
  357. indentSize: titleHeight,
  358. nodeHoverBg: controlItemBgHover,
  359. nodeHoverColor: token.colorText,
  360. nodeSelectedBg: controlItemBgActive,
  361. nodeSelectedColor: token.colorText
  362. };
  363. };
  364. exports.initComponentToken = initComponentToken;
  365. const prepareComponentToken = token => {
  366. const {
  367. colorTextLightSolid,
  368. colorPrimary
  369. } = token;
  370. return Object.assign(Object.assign({}, initComponentToken(token)), {
  371. directoryNodeSelectedColor: colorTextLightSolid,
  372. directoryNodeSelectedBg: colorPrimary
  373. });
  374. };
  375. exports.prepareComponentToken = prepareComponentToken;
  376. var _default = exports.default = (0, _internal.genStyleHooks)('Tree', (token, {
  377. prefixCls
  378. }) => [{
  379. [token.componentCls]: (0, _style.getStyle)(`${prefixCls}-checkbox`, token)
  380. }, genTreeStyle(prefixCls, token), (0, _motion.genCollapseMotion)(token)], prepareComponentToken);