index.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  8. var _internal = require("../../theme/internal");
  9. var _dropdown = _interopRequireDefault(require("./dropdown"));
  10. var _multiple = _interopRequireDefault(require("./multiple"));
  11. var _single = _interopRequireDefault(require("./single"));
  12. var _style = require("../../style");
  13. var _compactItem = require("../../style/compact-item");
  14. // ============================= Selector =============================
  15. const genSelectorStyle = token => {
  16. const {
  17. componentCls
  18. } = token;
  19. return {
  20. position: 'relative',
  21. backgroundColor: token.colorBgContainer,
  22. border: `${token.lineWidth}px ${token.lineType} ${token.colorBorder}`,
  23. transition: `all ${token.motionDurationMid} ${token.motionEaseInOut}`,
  24. input: {
  25. cursor: 'pointer'
  26. },
  27. [`${componentCls}-show-search&`]: {
  28. cursor: 'text',
  29. input: {
  30. cursor: 'auto',
  31. color: 'inherit'
  32. }
  33. },
  34. [`${componentCls}-disabled&`]: {
  35. color: token.colorTextDisabled,
  36. background: token.colorBgContainerDisabled,
  37. cursor: 'not-allowed',
  38. [`${componentCls}-multiple&`]: {
  39. background: token.colorBgContainerDisabled
  40. },
  41. input: {
  42. cursor: 'not-allowed'
  43. }
  44. }
  45. };
  46. };
  47. // ============================== Status ==============================
  48. const genStatusStyle = function (rootSelectCls, token) {
  49. let overwriteDefaultBorder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  50. const {
  51. componentCls,
  52. borderHoverColor,
  53. outlineColor,
  54. antCls
  55. } = token;
  56. const overwriteStyle = overwriteDefaultBorder ? {
  57. [`${componentCls}-selector`]: {
  58. borderColor: borderHoverColor
  59. }
  60. } : {};
  61. return {
  62. [rootSelectCls]: {
  63. [`&:not(${componentCls}-disabled):not(${componentCls}-customize-input):not(${antCls}-pagination-size-changer)`]: (0, _extends2.default)((0, _extends2.default)({}, overwriteStyle), {
  64. [`${componentCls}-focused& ${componentCls}-selector`]: {
  65. borderColor: borderHoverColor,
  66. boxShadow: `0 0 0 ${token.controlOutlineWidth}px ${outlineColor}`,
  67. borderInlineEndWidth: `${token.controlLineWidth}px !important`,
  68. outline: 0
  69. },
  70. [`&:hover ${componentCls}-selector`]: {
  71. borderColor: borderHoverColor,
  72. borderInlineEndWidth: `${token.controlLineWidth}px !important`
  73. }
  74. })
  75. }
  76. };
  77. };
  78. // ============================== Styles ==============================
  79. // /* Reset search input style */
  80. const getSearchInputWithoutBorderStyle = token => {
  81. const {
  82. componentCls
  83. } = token;
  84. return {
  85. [`${componentCls}-selection-search-input`]: {
  86. margin: 0,
  87. padding: 0,
  88. background: 'transparent',
  89. border: 'none',
  90. outline: 'none',
  91. appearance: 'none',
  92. '&::-webkit-search-cancel-button': {
  93. display: 'none',
  94. '-webkit-appearance': 'none'
  95. }
  96. }
  97. };
  98. };
  99. // =============================== Base ===============================
  100. const genBaseStyle = token => {
  101. const {
  102. componentCls,
  103. inputPaddingHorizontalBase,
  104. iconCls
  105. } = token;
  106. return {
  107. [componentCls]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
  108. position: 'relative',
  109. display: 'inline-block',
  110. cursor: 'pointer',
  111. [`&:not(${componentCls}-customize-input) ${componentCls}-selector`]: (0, _extends2.default)((0, _extends2.default)({}, genSelectorStyle(token)), getSearchInputWithoutBorderStyle(token)),
  112. // [`&:not(&-disabled):hover ${selectCls}-selector`]: {
  113. // ...genHoverStyle(token),
  114. // },
  115. // ======================== Selection ========================
  116. [`${componentCls}-selection-item`]: (0, _extends2.default)({
  117. flex: 1,
  118. fontWeight: 'normal'
  119. }, _style.textEllipsis),
  120. // ======================= Placeholder =======================
  121. [`${componentCls}-selection-placeholder`]: (0, _extends2.default)((0, _extends2.default)({}, _style.textEllipsis), {
  122. flex: 1,
  123. color: token.colorTextPlaceholder,
  124. pointerEvents: 'none'
  125. }),
  126. // ========================== Arrow ==========================
  127. [`${componentCls}-arrow`]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetIcon)()), {
  128. position: 'absolute',
  129. top: '50%',
  130. insetInlineStart: 'auto',
  131. insetInlineEnd: inputPaddingHorizontalBase,
  132. height: token.fontSizeIcon,
  133. marginTop: -token.fontSizeIcon / 2,
  134. color: token.colorTextQuaternary,
  135. fontSize: token.fontSizeIcon,
  136. lineHeight: 1,
  137. textAlign: 'center',
  138. pointerEvents: 'none',
  139. display: 'flex',
  140. alignItems: 'center',
  141. [iconCls]: {
  142. verticalAlign: 'top',
  143. transition: `transform ${token.motionDurationSlow}`,
  144. '> svg': {
  145. verticalAlign: 'top'
  146. },
  147. [`&:not(${componentCls}-suffix)`]: {
  148. pointerEvents: 'auto'
  149. }
  150. },
  151. [`${componentCls}-disabled &`]: {
  152. cursor: 'not-allowed'
  153. },
  154. '> *:not(:last-child)': {
  155. marginInlineEnd: 8 // FIXME: magic
  156. }
  157. }),
  158. // ========================== Clear ==========================
  159. [`${componentCls}-clear`]: {
  160. position: 'absolute',
  161. top: '50%',
  162. insetInlineStart: 'auto',
  163. insetInlineEnd: inputPaddingHorizontalBase,
  164. zIndex: 1,
  165. display: 'inline-block',
  166. width: token.fontSizeIcon,
  167. height: token.fontSizeIcon,
  168. marginTop: -token.fontSizeIcon / 2,
  169. color: token.colorTextQuaternary,
  170. fontSize: token.fontSizeIcon,
  171. fontStyle: 'normal',
  172. lineHeight: 1,
  173. textAlign: 'center',
  174. textTransform: 'none',
  175. background: token.colorBgContainer,
  176. cursor: 'pointer',
  177. opacity: 0,
  178. transition: `color ${token.motionDurationMid} ease, opacity ${token.motionDurationSlow} ease`,
  179. textRendering: 'auto',
  180. '&:before': {
  181. display: 'block'
  182. },
  183. '&:hover': {
  184. color: token.colorTextTertiary
  185. }
  186. },
  187. '&:hover': {
  188. [`${componentCls}-clear`]: {
  189. opacity: 1
  190. }
  191. }
  192. }),
  193. // ========================= Feedback ==========================
  194. [`${componentCls}-has-feedback`]: {
  195. [`${componentCls}-clear`]: {
  196. insetInlineEnd: inputPaddingHorizontalBase + token.fontSize + token.paddingXXS
  197. }
  198. }
  199. };
  200. };
  201. // ============================== Styles ==============================
  202. const genSelectStyle = token => {
  203. const {
  204. componentCls
  205. } = token;
  206. return [{
  207. [componentCls]: {
  208. // ==================== BorderLess ====================
  209. [`&-borderless ${componentCls}-selector`]: {
  210. backgroundColor: `transparent !important`,
  211. borderColor: `transparent !important`,
  212. boxShadow: `none !important`
  213. },
  214. // ==================== In Form ====================
  215. [`&${componentCls}-in-form-item`]: {
  216. width: '100%'
  217. }
  218. }
  219. },
  220. // =====================================================
  221. // == LTR ==
  222. // =====================================================
  223. // Base
  224. genBaseStyle(token),
  225. // Single
  226. (0, _single.default)(token),
  227. // Multiple
  228. (0, _multiple.default)(token),
  229. // Dropdown
  230. (0, _dropdown.default)(token),
  231. // =====================================================
  232. // == RTL ==
  233. // =====================================================
  234. {
  235. [`${componentCls}-rtl`]: {
  236. direction: 'rtl'
  237. }
  238. },
  239. // =====================================================
  240. // == Status ==
  241. // =====================================================
  242. genStatusStyle(componentCls, (0, _internal.mergeToken)(token, {
  243. borderHoverColor: token.colorPrimaryHover,
  244. outlineColor: token.controlOutline
  245. })), genStatusStyle(`${componentCls}-status-error`, (0, _internal.mergeToken)(token, {
  246. borderHoverColor: token.colorErrorHover,
  247. outlineColor: token.colorErrorOutline
  248. }), true), genStatusStyle(`${componentCls}-status-warning`, (0, _internal.mergeToken)(token, {
  249. borderHoverColor: token.colorWarningHover,
  250. outlineColor: token.colorWarningOutline
  251. }), true),
  252. // =====================================================
  253. // == Space Compact ==
  254. // =====================================================
  255. (0, _compactItem.genCompactItemStyle)(token, {
  256. borderElCls: `${componentCls}-selector`,
  257. focusElCls: `${componentCls}-focused`
  258. })];
  259. };
  260. // ============================== Export ==============================
  261. var _default = exports.default = (0, _internal.genComponentStyleHook)('Select', (token, _ref) => {
  262. let {
  263. rootPrefixCls
  264. } = _ref;
  265. const selectToken = (0, _internal.mergeToken)(token, {
  266. rootPrefixCls,
  267. inputPaddingHorizontalBase: token.paddingSM - 1
  268. });
  269. return [genSelectStyle(selectToken)];
  270. }, token => ({
  271. zIndexPopup: token.zIndexPopupBase + 50
  272. }));