index.js 13 KB

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