index.js 8.1 KB

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