index.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.prepareComponentToken = exports.default = void 0;
  6. var _cssinjs = require("@ant-design/cssinjs");
  7. var _style = require("../../style");
  8. var _internal = require("../../theme/internal");
  9. const genTransferCustomizeStyle = token => {
  10. const {
  11. antCls,
  12. componentCls,
  13. listHeight,
  14. controlHeightLG
  15. } = token;
  16. const tableCls = `${antCls}-table`;
  17. const inputCls = `${antCls}-input`;
  18. return {
  19. [`${componentCls}-customize-list`]: {
  20. [`${componentCls}-list`]: {
  21. flex: '1 1 50%',
  22. width: 'auto',
  23. height: 'auto',
  24. minHeight: listHeight,
  25. minWidth: 0
  26. },
  27. // =================== Hook Components ===================
  28. [`${tableCls}-wrapper`]: {
  29. [`${tableCls}-small`]: {
  30. border: 0,
  31. borderRadius: 0,
  32. [`${tableCls}-selection-column`]: {
  33. width: controlHeightLG,
  34. minWidth: controlHeightLG
  35. }
  36. },
  37. [`${tableCls}-pagination${tableCls}-pagination`]: {
  38. margin: 0,
  39. padding: token.paddingXS
  40. }
  41. },
  42. [`${inputCls}[disabled]`]: {
  43. backgroundColor: 'transparent'
  44. }
  45. }
  46. };
  47. };
  48. const genTransferStatusColor = (token, color) => {
  49. const {
  50. componentCls,
  51. colorBorder
  52. } = token;
  53. return {
  54. [`${componentCls}-list`]: {
  55. borderColor: color,
  56. '&-search:not([disabled])': {
  57. borderColor: colorBorder
  58. }
  59. }
  60. };
  61. };
  62. const genTransferStatusStyle = token => {
  63. const {
  64. componentCls
  65. } = token;
  66. return {
  67. [`${componentCls}-status-error`]: Object.assign({}, genTransferStatusColor(token, token.colorError)),
  68. [`${componentCls}-status-warning`]: Object.assign({}, genTransferStatusColor(token, token.colorWarning))
  69. };
  70. };
  71. const genTransferListStyle = token => {
  72. const {
  73. componentCls,
  74. colorBorder,
  75. colorSplit,
  76. lineWidth,
  77. itemHeight,
  78. headerHeight,
  79. transferHeaderVerticalPadding,
  80. itemPaddingBlock,
  81. controlItemBgActive,
  82. colorTextDisabled,
  83. colorTextSecondary,
  84. listHeight,
  85. listWidth,
  86. listWidthLG,
  87. fontSizeIcon,
  88. marginXS,
  89. paddingSM,
  90. lineType,
  91. antCls,
  92. iconCls,
  93. motionDurationSlow,
  94. controlItemBgHover,
  95. borderRadiusLG,
  96. colorBgContainer,
  97. colorText,
  98. controlItemBgActiveHover
  99. } = token;
  100. const contentBorderRadius = (0, _cssinjs.unit)(token.calc(borderRadiusLG).sub(lineWidth).equal());
  101. return {
  102. display: 'flex',
  103. flexDirection: 'column',
  104. width: listWidth,
  105. height: listHeight,
  106. border: `${(0, _cssinjs.unit)(lineWidth)} ${lineType} ${colorBorder}`,
  107. borderRadius: token.borderRadiusLG,
  108. '&-with-pagination': {
  109. width: listWidthLG,
  110. height: 'auto'
  111. },
  112. '&-search': {
  113. [`${iconCls}-search`]: {
  114. color: colorTextDisabled
  115. }
  116. },
  117. '&-header': {
  118. display: 'flex',
  119. flex: 'none',
  120. alignItems: 'center',
  121. height: headerHeight,
  122. // border-top is on the transfer dom. We should minus 1px for this
  123. padding: `${(0, _cssinjs.unit)(token.calc(transferHeaderVerticalPadding).sub(lineWidth).equal())} ${(0, _cssinjs.unit)(paddingSM)} ${(0, _cssinjs.unit)(transferHeaderVerticalPadding)}`,
  124. color: colorText,
  125. background: colorBgContainer,
  126. borderBottom: `${(0, _cssinjs.unit)(lineWidth)} ${lineType} ${colorSplit}`,
  127. borderRadius: `${(0, _cssinjs.unit)(borderRadiusLG)} ${(0, _cssinjs.unit)(borderRadiusLG)} 0 0`,
  128. '> *:not(:last-child)': {
  129. marginInlineEnd: 4 // This is magic and fixed number, DO NOT use token since it may change.
  130. },
  131. '> *': {
  132. flex: 'none'
  133. },
  134. '&-title': Object.assign(Object.assign({}, _style.textEllipsis), {
  135. flex: 'auto',
  136. textAlign: 'end'
  137. }),
  138. '&-dropdown': Object.assign(Object.assign({}, (0, _style.resetIcon)()), {
  139. fontSize: fontSizeIcon,
  140. transform: 'translateY(10%)',
  141. cursor: 'pointer',
  142. '&[disabled]': {
  143. cursor: 'not-allowed'
  144. }
  145. })
  146. },
  147. '&-body': {
  148. display: 'flex',
  149. flex: 'auto',
  150. flexDirection: 'column',
  151. fontSize: token.fontSize,
  152. // https://blog.csdn.net/qq449245884/article/details/107373672/
  153. minHeight: 0,
  154. '&-search-wrapper': {
  155. position: 'relative',
  156. flex: 'none',
  157. padding: paddingSM
  158. }
  159. },
  160. '&-content': {
  161. flex: 'auto',
  162. margin: 0,
  163. padding: 0,
  164. overflow: 'auto',
  165. listStyle: 'none',
  166. borderRadius: `0 0 ${contentBorderRadius} ${contentBorderRadius}`,
  167. '&-item': {
  168. display: 'flex',
  169. alignItems: 'center',
  170. minHeight: itemHeight,
  171. padding: `${(0, _cssinjs.unit)(itemPaddingBlock)} ${(0, _cssinjs.unit)(paddingSM)}`,
  172. transition: `all ${motionDurationSlow}`,
  173. '> *:not(:last-child)': {
  174. marginInlineEnd: marginXS
  175. },
  176. '> *': {
  177. flex: 'none'
  178. },
  179. '&-text': Object.assign(Object.assign({}, _style.textEllipsis), {
  180. flex: 'auto'
  181. }),
  182. '&-remove': Object.assign(Object.assign({}, (0, _style.operationUnit)(token)), {
  183. color: colorBorder,
  184. '&:hover, &:focus': {
  185. color: colorTextSecondary
  186. }
  187. }),
  188. [`&:not(${componentCls}-list-content-item-disabled)`]: {
  189. '&:hover': {
  190. backgroundColor: controlItemBgHover,
  191. cursor: 'pointer'
  192. },
  193. [`&${componentCls}-list-content-item-checked:hover`]: {
  194. backgroundColor: controlItemBgActiveHover
  195. }
  196. },
  197. '&-checked': {
  198. backgroundColor: controlItemBgActive
  199. },
  200. '&-disabled': {
  201. color: colorTextDisabled,
  202. cursor: 'not-allowed'
  203. }
  204. },
  205. // Do not change hover style when `oneWay` mode
  206. [`&-show-remove ${componentCls}-list-content-item:not(${componentCls}-list-content-item-disabled):hover`]: {
  207. background: 'transparent',
  208. cursor: 'default'
  209. }
  210. },
  211. '&-pagination': {
  212. padding: token.paddingXS,
  213. textAlign: 'end',
  214. borderTop: `${(0, _cssinjs.unit)(lineWidth)} ${lineType} ${colorSplit}`,
  215. [`${antCls}-pagination-options`]: {
  216. paddingInlineEnd: token.paddingXS
  217. }
  218. },
  219. '&-body-not-found': {
  220. flex: 'none',
  221. width: '100%',
  222. margin: 'auto 0',
  223. color: colorTextDisabled,
  224. textAlign: 'center'
  225. },
  226. '&-footer': {
  227. borderTop: `${(0, _cssinjs.unit)(lineWidth)} ${lineType} ${colorSplit}`
  228. },
  229. // fix: https://github.com/ant-design/ant-design/issues/44489
  230. '&-checkbox': {
  231. lineHeight: 1
  232. }
  233. };
  234. };
  235. const genTransferStyle = token => {
  236. const {
  237. antCls,
  238. iconCls,
  239. componentCls,
  240. marginXS,
  241. marginXXS,
  242. fontSizeIcon,
  243. colorBgContainerDisabled
  244. } = token;
  245. return {
  246. [componentCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  247. position: 'relative',
  248. display: 'flex',
  249. alignItems: 'stretch',
  250. [`${componentCls}-disabled`]: {
  251. [`${componentCls}-list`]: {
  252. background: colorBgContainerDisabled
  253. }
  254. },
  255. [`${componentCls}-list`]: genTransferListStyle(token),
  256. [`${componentCls}-operation`]: {
  257. display: 'flex',
  258. flex: 'none',
  259. flexDirection: 'column',
  260. alignSelf: 'center',
  261. margin: `0 ${(0, _cssinjs.unit)(marginXS)}`,
  262. verticalAlign: 'middle',
  263. gap: marginXXS,
  264. [`${antCls}-btn ${iconCls}`]: {
  265. fontSize: fontSizeIcon
  266. }
  267. }
  268. })
  269. };
  270. };
  271. const genTransferRTLStyle = token => {
  272. const {
  273. componentCls
  274. } = token;
  275. return {
  276. [`${componentCls}-rtl`]: {
  277. direction: 'rtl'
  278. }
  279. };
  280. };
  281. const prepareComponentToken = token => {
  282. const {
  283. fontSize,
  284. lineHeight,
  285. controlHeight,
  286. controlHeightLG,
  287. lineWidth
  288. } = token;
  289. const fontHeight = Math.round(fontSize * lineHeight);
  290. return {
  291. listWidth: 180,
  292. listHeight: 200,
  293. listWidthLG: 250,
  294. headerHeight: controlHeightLG,
  295. itemHeight: controlHeight,
  296. itemPaddingBlock: (controlHeight - fontHeight) / 2,
  297. transferHeaderVerticalPadding: Math.ceil((controlHeightLG - lineWidth - fontHeight) / 2)
  298. };
  299. };
  300. // ============================== Export ==============================
  301. exports.prepareComponentToken = prepareComponentToken;
  302. var _default = exports.default = (0, _internal.genStyleHooks)('Transfer', token => {
  303. const transferToken = (0, _internal.mergeToken)(token);
  304. return [genTransferStyle(transferToken), genTransferCustomizeStyle(transferToken), genTransferStatusStyle(transferToken), genTransferRTLStyle(transferToken)];
  305. }, prepareComponentToken);