single.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = genSingleStyle;
  7. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  8. var _style = require("../../style");
  9. var _internal = require("../../theme/internal");
  10. function genSizeStyle(token, suffix) {
  11. const {
  12. componentCls,
  13. inputPaddingHorizontalBase,
  14. borderRadius
  15. } = token;
  16. const selectHeightWithoutBorder = token.controlHeight - token.lineWidth * 2;
  17. const selectionItemPadding = Math.ceil(token.fontSize * 1.25);
  18. const suffixCls = suffix ? `${componentCls}-${suffix}` : '';
  19. return {
  20. [`${componentCls}-single${suffixCls}`]: {
  21. fontSize: token.fontSize,
  22. // ========================= Selector =========================
  23. [`${componentCls}-selector`]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
  24. display: 'flex',
  25. borderRadius,
  26. [`${componentCls}-selection-search`]: {
  27. position: 'absolute',
  28. top: 0,
  29. insetInlineStart: inputPaddingHorizontalBase,
  30. insetInlineEnd: inputPaddingHorizontalBase,
  31. bottom: 0,
  32. '&-input': {
  33. width: '100%'
  34. }
  35. },
  36. [`
  37. ${componentCls}-selection-item,
  38. ${componentCls}-selection-placeholder
  39. `]: {
  40. padding: 0,
  41. lineHeight: `${selectHeightWithoutBorder}px`,
  42. transition: `all ${token.motionDurationSlow}`,
  43. // Firefox inline-block position calculation is not same as Chrome & Safari. Patch this:
  44. '@supports (-moz-appearance: meterbar)': {
  45. lineHeight: `${selectHeightWithoutBorder}px`
  46. }
  47. },
  48. [`${componentCls}-selection-item`]: {
  49. position: 'relative',
  50. userSelect: 'none'
  51. },
  52. [`${componentCls}-selection-placeholder`]: {
  53. transition: 'none',
  54. pointerEvents: 'none'
  55. },
  56. // For common baseline align
  57. [['&:after', /* For '' value baseline align */
  58. `${componentCls}-selection-item:after`, /* For undefined value baseline align */
  59. `${componentCls}-selection-placeholder:after`].join(',')]: {
  60. display: 'inline-block',
  61. width: 0,
  62. visibility: 'hidden',
  63. content: '"\\a0"'
  64. }
  65. }),
  66. [`
  67. &${componentCls}-show-arrow ${componentCls}-selection-item,
  68. &${componentCls}-show-arrow ${componentCls}-selection-placeholder
  69. `]: {
  70. paddingInlineEnd: selectionItemPadding
  71. },
  72. // Opacity selection if open
  73. [`&${componentCls}-open ${componentCls}-selection-item`]: {
  74. color: token.colorTextPlaceholder
  75. },
  76. // ========================== Input ==========================
  77. // We only change the style of non-customize input which is only support by `combobox` mode.
  78. // Not customize
  79. [`&:not(${componentCls}-customize-input)`]: {
  80. [`${componentCls}-selector`]: {
  81. width: '100%',
  82. height: token.controlHeight,
  83. padding: `0 ${inputPaddingHorizontalBase}px`,
  84. [`${componentCls}-selection-search-input`]: {
  85. height: selectHeightWithoutBorder
  86. },
  87. '&:after': {
  88. lineHeight: `${selectHeightWithoutBorder}px`
  89. }
  90. }
  91. },
  92. [`&${componentCls}-customize-input`]: {
  93. [`${componentCls}-selector`]: {
  94. '&:after': {
  95. display: 'none'
  96. },
  97. [`${componentCls}-selection-search`]: {
  98. position: 'static',
  99. width: '100%'
  100. },
  101. [`${componentCls}-selection-placeholder`]: {
  102. position: 'absolute',
  103. insetInlineStart: 0,
  104. insetInlineEnd: 0,
  105. padding: `0 ${inputPaddingHorizontalBase}px`,
  106. '&:after': {
  107. display: 'none'
  108. }
  109. }
  110. }
  111. }
  112. }
  113. };
  114. }
  115. function genSingleStyle(token) {
  116. const {
  117. componentCls
  118. } = token;
  119. const inputPaddingHorizontalSM = token.controlPaddingHorizontalSM - token.lineWidth;
  120. return [genSizeStyle(token),
  121. // ======================== Small ========================
  122. // Shared
  123. genSizeStyle((0, _internal.mergeToken)(token, {
  124. controlHeight: token.controlHeightSM,
  125. borderRadius: token.borderRadiusSM
  126. }), 'sm'),
  127. // padding
  128. {
  129. [`${componentCls}-single${componentCls}-sm`]: {
  130. [`&:not(${componentCls}-customize-input)`]: {
  131. [`${componentCls}-selection-search`]: {
  132. insetInlineStart: inputPaddingHorizontalSM,
  133. insetInlineEnd: inputPaddingHorizontalSM
  134. },
  135. [`${componentCls}-selector`]: {
  136. padding: `0 ${inputPaddingHorizontalSM}px`
  137. },
  138. // With arrow should provides `padding-right` to show the arrow
  139. [`&${componentCls}-show-arrow ${componentCls}-selection-search`]: {
  140. insetInlineEnd: inputPaddingHorizontalSM + token.fontSize * 1.5
  141. },
  142. [`
  143. &${componentCls}-show-arrow ${componentCls}-selection-item,
  144. &${componentCls}-show-arrow ${componentCls}-selection-placeholder
  145. `]: {
  146. paddingInlineEnd: token.fontSize * 1.5
  147. }
  148. }
  149. }
  150. },
  151. // ======================== Large ========================
  152. // Shared
  153. genSizeStyle((0, _internal.mergeToken)(token, {
  154. controlHeight: token.controlHeightLG,
  155. fontSize: token.fontSizeLG,
  156. borderRadius: token.borderRadiusLG
  157. }), 'lg')];
  158. }