index.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var _style = require("../../style");
  8. var _compactItem = require("../../style/compact-item");
  9. var _internal = require("../../theme/internal");
  10. var _dropdown = _interopRequireDefault(require("./dropdown"));
  11. var _multiple = _interopRequireDefault(require("./multiple"));
  12. var _single = _interopRequireDefault(require("./single"));
  13. var _token = require("./token");
  14. var _variants = _interopRequireDefault(require("./variants"));
  15. // ============================= Selector =============================
  16. const genSelectorStyle = token => {
  17. const {
  18. componentCls
  19. } = token;
  20. return {
  21. position: 'relative',
  22. transition: `all ${token.motionDurationMid} ${token.motionEaseInOut}`,
  23. input: {
  24. cursor: 'pointer'
  25. },
  26. [`${componentCls}-show-search&`]: {
  27. cursor: 'text',
  28. input: {
  29. cursor: 'auto',
  30. color: 'inherit',
  31. height: '100%'
  32. }
  33. },
  34. [`${componentCls}-disabled&`]: {
  35. cursor: 'not-allowed',
  36. input: {
  37. cursor: 'not-allowed'
  38. }
  39. }
  40. };
  41. };
  42. // ============================== Styles ==============================
  43. // /* Reset search input style */
  44. const getSearchInputWithoutBorderStyle = token => {
  45. const {
  46. componentCls
  47. } = token;
  48. return {
  49. [`${componentCls}-selection-search-input`]: {
  50. margin: 0,
  51. padding: 0,
  52. background: 'transparent',
  53. border: 'none',
  54. outline: 'none',
  55. appearance: 'none',
  56. fontFamily: 'inherit',
  57. '&::-webkit-search-cancel-button': {
  58. display: 'none',
  59. appearance: 'none'
  60. }
  61. }
  62. };
  63. };
  64. // =============================== Base ===============================
  65. const genBaseStyle = token => {
  66. const {
  67. antCls,
  68. componentCls,
  69. inputPaddingHorizontalBase,
  70. iconCls
  71. } = token;
  72. const hoverShowClearStyle = {
  73. [`${componentCls}-clear`]: {
  74. opacity: 1,
  75. background: token.colorBgBase,
  76. borderRadius: '50%'
  77. }
  78. };
  79. return {
  80. [componentCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  81. position: 'relative',
  82. display: 'inline-flex',
  83. cursor: 'pointer',
  84. [`&:not(${componentCls}-customize-input) ${componentCls}-selector`]: Object.assign(Object.assign({}, genSelectorStyle(token)), getSearchInputWithoutBorderStyle(token)),
  85. // ======================== Selection ========================
  86. [`${componentCls}-selection-item`]: Object.assign(Object.assign({
  87. flex: 1,
  88. fontWeight: 'normal',
  89. position: 'relative',
  90. userSelect: 'none'
  91. }, _style.textEllipsis), {
  92. // https://github.com/ant-design/ant-design/issues/40421
  93. [`> ${antCls}-typography`]: {
  94. display: 'inline'
  95. }
  96. }),
  97. // ======================= Placeholder =======================
  98. [`${componentCls}-selection-placeholder`]: Object.assign(Object.assign({}, _style.textEllipsis), {
  99. flex: 1,
  100. color: token.colorTextPlaceholder,
  101. pointerEvents: 'none'
  102. }),
  103. // ========================== Arrow ==========================
  104. [`${componentCls}-arrow`]: Object.assign(Object.assign({}, (0, _style.resetIcon)()), {
  105. position: 'absolute',
  106. top: '50%',
  107. insetInlineStart: 'auto',
  108. insetInlineEnd: inputPaddingHorizontalBase,
  109. height: token.fontSizeIcon,
  110. marginTop: token.calc(token.fontSizeIcon).mul(-1).div(2).equal(),
  111. color: token.colorTextQuaternary,
  112. fontSize: token.fontSizeIcon,
  113. lineHeight: 1,
  114. textAlign: 'center',
  115. pointerEvents: 'none',
  116. display: 'flex',
  117. alignItems: 'center',
  118. transition: `opacity ${token.motionDurationSlow} ease`,
  119. [iconCls]: {
  120. verticalAlign: 'top',
  121. transition: `transform ${token.motionDurationSlow}`,
  122. '> svg': {
  123. verticalAlign: 'top'
  124. },
  125. [`&:not(${componentCls}-suffix)`]: {
  126. pointerEvents: 'auto'
  127. }
  128. },
  129. [`${componentCls}-disabled &`]: {
  130. cursor: 'not-allowed'
  131. },
  132. '> *:not(:last-child)': {
  133. marginInlineEnd: 8 // FIXME: magic
  134. }
  135. }),
  136. // ========================== Wrap ===========================
  137. [`${componentCls}-selection-wrap`]: {
  138. display: 'flex',
  139. width: '100%',
  140. position: 'relative',
  141. minWidth: 0,
  142. // https://github.com/ant-design/ant-design/issues/51669
  143. '&:after': {
  144. content: '"\\a0"',
  145. width: 0,
  146. overflow: 'hidden'
  147. }
  148. },
  149. // ========================= Prefix ==========================
  150. [`${componentCls}-prefix`]: {
  151. flex: 'none',
  152. marginInlineEnd: token.selectAffixPadding
  153. },
  154. // ========================== Clear ==========================
  155. [`${componentCls}-clear`]: {
  156. position: 'absolute',
  157. top: '50%',
  158. insetInlineStart: 'auto',
  159. insetInlineEnd: inputPaddingHorizontalBase,
  160. zIndex: 1,
  161. display: 'inline-block',
  162. width: token.fontSizeIcon,
  163. height: token.fontSizeIcon,
  164. marginTop: token.calc(token.fontSizeIcon).mul(-1).div(2).equal(),
  165. color: token.colorTextQuaternary,
  166. fontSize: token.fontSizeIcon,
  167. fontStyle: 'normal',
  168. lineHeight: 1,
  169. textAlign: 'center',
  170. textTransform: 'none',
  171. cursor: 'pointer',
  172. opacity: 0,
  173. transition: `color ${token.motionDurationMid} ease, opacity ${token.motionDurationSlow} ease`,
  174. textRendering: 'auto',
  175. // https://github.com/ant-design/ant-design/issues/54205
  176. // Force GPU compositing on Safari to prevent flickering on opacity/transform transitions
  177. transform: 'translateZ(0)',
  178. '&:before': {
  179. display: 'block'
  180. },
  181. '&:hover': {
  182. color: token.colorIcon
  183. }
  184. },
  185. '@media(hover:none)': hoverShowClearStyle,
  186. '&:hover': hoverShowClearStyle
  187. }),
  188. // ========================= Feedback ==========================
  189. [`${componentCls}-status`]: {
  190. '&-error, &-warning, &-success, &-validating': {
  191. [`&${componentCls}-has-feedback`]: {
  192. [`${componentCls}-clear`]: {
  193. insetInlineEnd: token.calc(inputPaddingHorizontalBase).add(token.fontSize).add(token.paddingXS).equal()
  194. }
  195. }
  196. }
  197. }
  198. };
  199. };
  200. // ============================== Styles ==============================
  201. const genSelectStyle = token => {
  202. const {
  203. componentCls
  204. } = token;
  205. return [{
  206. [componentCls]: {
  207. // ==================== In Form ====================
  208. [`&${componentCls}-in-form-item`]: {
  209. width: '100%'
  210. }
  211. }
  212. },
  213. // =====================================================
  214. // == LTR ==
  215. // =====================================================
  216. // Base
  217. genBaseStyle(token),
  218. // Single
  219. (0, _single.default)(token),
  220. // Multiple
  221. (0, _multiple.default)(token),
  222. // Dropdown
  223. (0, _dropdown.default)(token),
  224. // =====================================================
  225. // == RTL ==
  226. // =====================================================
  227. {
  228. [`${componentCls}-rtl`]: {
  229. direction: 'rtl'
  230. }
  231. },
  232. // =====================================================
  233. // == Space Compact ==
  234. // =====================================================
  235. (0, _compactItem.genCompactItemStyle)(token, {
  236. borderElCls: `${componentCls}-selector`,
  237. focusElCls: `${componentCls}-focused`
  238. })];
  239. };
  240. // ============================== Export ==============================
  241. var _default = exports.default = (0, _internal.genStyleHooks)('Select', (token, {
  242. rootPrefixCls
  243. }) => {
  244. const selectToken = (0, _internal.mergeToken)(token, {
  245. rootPrefixCls,
  246. inputPaddingHorizontalBase: token.calc(token.paddingSM).sub(1).equal(),
  247. multipleSelectItemHeight: token.multipleItemHeight,
  248. selectHeight: token.controlHeight
  249. });
  250. return [genSelectStyle(selectToken), (0, _variants.default)(selectToken)];
  251. }, _token.prepareComponentToken, {
  252. unitless: {
  253. optionLineHeight: true,
  254. optionSelectedFontWeight: true
  255. }
  256. });