single.js 5.3 KB

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