index.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import { unit } from '@ant-design/cssinjs';
  2. import { genBasicInputStyle, genPlaceholderStyle, initComponentToken, initInputToken } from '../../input/style';
  3. import { genBorderlessStyle, genDisabledStyle, genFilledStyle, genOutlinedStyle, genUnderlinedStyle } from '../../input/style/variants';
  4. import { resetComponent, textEllipsis } from '../../style';
  5. import { genStyleHooks, mergeToken } from '../../theme/internal';
  6. const genMentionsStyle = token => {
  7. const {
  8. componentCls,
  9. antCls,
  10. colorTextDisabled,
  11. controlItemBgHover,
  12. controlPaddingHorizontal,
  13. colorText,
  14. motionDurationSlow,
  15. lineHeight,
  16. controlHeight,
  17. paddingInline,
  18. paddingBlock,
  19. fontSize,
  20. fontSizeIcon,
  21. colorIcon,
  22. colorTextQuaternary,
  23. colorBgElevated,
  24. paddingXXS,
  25. borderRadius,
  26. borderRadiusLG,
  27. boxShadowSecondary,
  28. itemPaddingVertical,
  29. calc
  30. } = token;
  31. return {
  32. [componentCls]: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, resetComponent(token)), genBasicInputStyle(token)), {
  33. position: 'relative',
  34. display: 'inline-block',
  35. height: 'auto',
  36. padding: `0 ${unit(token.paddingInline)}`,
  37. overflow: 'hidden',
  38. lineHeight,
  39. whiteSpace: 'pre-wrap',
  40. verticalAlign: 'bottom'
  41. }), genOutlinedStyle(token)), genFilledStyle(token)), genBorderlessStyle(token)), {
  42. '&-affix-wrapper': Object.assign(Object.assign({}, genBasicInputStyle(token)), {
  43. display: 'inline-flex',
  44. paddingBlock: 0,
  45. paddingInlineStart: 0,
  46. paddingInlineEnd: token.paddingInline,
  47. '&::before': {
  48. display: 'inline-block',
  49. width: 0,
  50. visibility: 'hidden',
  51. content: '"\\a0"'
  52. },
  53. [`${componentCls}-suffix`]: {
  54. display: 'inline-flex',
  55. alignItems: 'center',
  56. // 当页面中存在 feedback-icon 时,给 clear-icon 添加右边距
  57. [`&:has(${antCls}-form-item-feedback-icon) ${componentCls}-clear-icon`]: {
  58. marginInlineEnd: token.marginXS
  59. },
  60. [`${antCls}-form-item-feedback-icon`]: {
  61. display: 'inline-flex',
  62. alignItems: 'center',
  63. justifyContent: 'center'
  64. }
  65. },
  66. [`${componentCls}-clear-icon`]: {
  67. insetInlineEnd: 0,
  68. insetBlockStart: calc(fontSize).mul(lineHeight).mul(0.5).add(paddingBlock).equal(),
  69. padding: 0,
  70. lineHeight: 0,
  71. color: colorTextQuaternary,
  72. fontSize: fontSizeIcon,
  73. verticalAlign: -1,
  74. // https://github.com/ant-design/ant-design/pull/18151
  75. // https://codesandbox.io/s/wizardly-sun-u10br
  76. cursor: 'pointer',
  77. transition: `color ${motionDurationSlow}`,
  78. border: 'none',
  79. outline: 'none',
  80. backgroundColor: 'transparent',
  81. '&:hover': {
  82. color: colorIcon
  83. },
  84. '&:active': {
  85. color: colorText
  86. },
  87. '&-hidden': {
  88. visibility: 'hidden'
  89. }
  90. }
  91. })
  92. }), genUnderlinedStyle(token)), {
  93. '&-disabled': {
  94. '> textarea': Object.assign({}, genDisabledStyle(token))
  95. },
  96. // ================= Input Area =================
  97. [`&, &-affix-wrapper > ${componentCls}`]: {
  98. [`> textarea, ${componentCls}-measure`]: {
  99. color: colorText,
  100. boxSizing: 'border-box',
  101. minHeight: token.calc(controlHeight).sub(2).equal(),
  102. margin: 0,
  103. padding: `${unit(paddingBlock)} ${unit(paddingInline)}`,
  104. overflow: 'inherit',
  105. overflowX: 'hidden',
  106. overflowY: 'auto',
  107. fontWeight: 'inherit',
  108. fontSize: 'inherit',
  109. fontFamily: 'inherit',
  110. fontStyle: 'inherit',
  111. fontVariant: 'inherit',
  112. fontSizeAdjust: 'inherit',
  113. fontStretch: 'inherit',
  114. lineHeight: 'inherit',
  115. direction: 'inherit',
  116. letterSpacing: 'inherit',
  117. whiteSpace: 'inherit',
  118. textAlign: 'inherit',
  119. verticalAlign: 'top',
  120. wordWrap: 'break-word',
  121. wordBreak: 'inherit',
  122. tabSize: 'inherit'
  123. },
  124. '> textarea': Object.assign(Object.assign({
  125. width: '100%',
  126. border: 'none',
  127. outline: 'none',
  128. resize: 'none',
  129. backgroundColor: 'transparent'
  130. }, genPlaceholderStyle(token.colorTextPlaceholder)), {
  131. padding: `${unit(token.paddingBlock)} 0`
  132. }),
  133. [`${componentCls}-measure`]: {
  134. position: 'absolute',
  135. top: 0,
  136. insetInlineEnd: 0,
  137. bottom: 0,
  138. insetInlineStart: 0,
  139. zIndex: -1,
  140. color: 'transparent',
  141. pointerEvents: 'none',
  142. '> span': {
  143. display: 'inline-block',
  144. minHeight: '1em'
  145. }
  146. }
  147. },
  148. // ================== Dropdown ==================
  149. '&-dropdown': Object.assign(Object.assign({}, resetComponent(token)), {
  150. position: 'absolute',
  151. top: -9999,
  152. insetInlineStart: -9999,
  153. zIndex: token.zIndexPopup,
  154. boxSizing: 'border-box',
  155. fontSize,
  156. fontVariant: 'initial',
  157. padding: paddingXXS,
  158. backgroundColor: colorBgElevated,
  159. borderRadius: borderRadiusLG,
  160. outline: 'none',
  161. boxShadow: boxShadowSecondary,
  162. '&-hidden': {
  163. display: 'none'
  164. },
  165. [`${componentCls}-dropdown-menu`]: {
  166. maxHeight: token.dropdownHeight,
  167. margin: 0,
  168. paddingInlineStart: 0,
  169. // Override default ul/ol
  170. overflow: 'auto',
  171. listStyle: 'none',
  172. outline: 'none',
  173. '&-item': Object.assign(Object.assign({}, textEllipsis), {
  174. position: 'relative',
  175. display: 'block',
  176. minWidth: token.controlItemWidth,
  177. padding: `${unit(itemPaddingVertical)} ${unit(controlPaddingHorizontal)}`,
  178. color: colorText,
  179. borderRadius,
  180. fontWeight: 'normal',
  181. lineHeight,
  182. cursor: 'pointer',
  183. transition: `background ${motionDurationSlow} ease`,
  184. '&:hover': {
  185. backgroundColor: controlItemBgHover
  186. },
  187. '&-disabled': {
  188. color: colorTextDisabled,
  189. cursor: 'not-allowed',
  190. '&:hover': {
  191. color: colorTextDisabled,
  192. backgroundColor: controlItemBgHover,
  193. cursor: 'not-allowed'
  194. }
  195. },
  196. '&-selected': {
  197. color: colorText,
  198. fontWeight: token.fontWeightStrong,
  199. backgroundColor: controlItemBgHover
  200. },
  201. '&-active': {
  202. backgroundColor: controlItemBgHover
  203. }
  204. })
  205. }
  206. })
  207. })
  208. };
  209. };
  210. export const prepareComponentToken = token => Object.assign(Object.assign({}, initComponentToken(token)), {
  211. dropdownHeight: 250,
  212. controlItemWidth: 100,
  213. zIndexPopup: token.zIndexPopupBase + 50,
  214. itemPaddingVertical: (token.controlHeight - token.fontHeight) / 2
  215. });
  216. // ============================== Export ==============================
  217. export default genStyleHooks('Mentions', token => {
  218. const mentionsToken = mergeToken(token, initInputToken(token));
  219. return genMentionsStyle(mentionsToken);
  220. }, prepareComponentToken);