variants.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. import { unit } from '@ant-design/cssinjs';
  2. import { mergeToken } from '../../theme/internal';
  3. export const genHoverStyle = token => ({
  4. borderColor: token.hoverBorderColor,
  5. backgroundColor: token.hoverBg
  6. });
  7. export const genDisabledStyle = token => ({
  8. color: token.colorTextDisabled,
  9. backgroundColor: token.colorBgContainerDisabled,
  10. borderColor: token.colorBorder,
  11. boxShadow: 'none',
  12. cursor: 'not-allowed',
  13. opacity: 1,
  14. 'input[disabled], textarea[disabled]': {
  15. cursor: 'not-allowed'
  16. },
  17. '&:hover:not([disabled])': Object.assign({}, genHoverStyle(mergeToken(token, {
  18. hoverBorderColor: token.colorBorder,
  19. hoverBg: token.colorBgContainerDisabled
  20. })))
  21. });
  22. /* ============== Outlined ============== */
  23. export const genBaseOutlinedStyle = (token, options) => ({
  24. background: token.colorBgContainer,
  25. borderWidth: token.lineWidth,
  26. borderStyle: token.lineType,
  27. borderColor: options.borderColor,
  28. '&:hover': {
  29. borderColor: options.hoverBorderColor,
  30. backgroundColor: token.hoverBg
  31. },
  32. '&:focus, &:focus-within': {
  33. borderColor: options.activeBorderColor,
  34. boxShadow: options.activeShadow,
  35. outline: 0,
  36. backgroundColor: token.activeBg
  37. }
  38. });
  39. const genOutlinedStatusStyle = (token, options) => ({
  40. [`&${token.componentCls}-status-${options.status}:not(${token.componentCls}-disabled)`]: Object.assign(Object.assign({}, genBaseOutlinedStyle(token, options)), {
  41. [`${token.componentCls}-prefix, ${token.componentCls}-suffix`]: {
  42. color: options.affixColor
  43. }
  44. }),
  45. [`&${token.componentCls}-status-${options.status}${token.componentCls}-disabled`]: {
  46. borderColor: options.borderColor
  47. }
  48. });
  49. export const genOutlinedStyle = (token, extraStyles) => ({
  50. '&-outlined': Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, genBaseOutlinedStyle(token, {
  51. borderColor: token.colorBorder,
  52. hoverBorderColor: token.hoverBorderColor,
  53. activeBorderColor: token.activeBorderColor,
  54. activeShadow: token.activeShadow
  55. })), {
  56. [`&${token.componentCls}-disabled, &[disabled]`]: Object.assign({}, genDisabledStyle(token))
  57. }), genOutlinedStatusStyle(token, {
  58. status: 'error',
  59. borderColor: token.colorError,
  60. hoverBorderColor: token.colorErrorBorderHover,
  61. activeBorderColor: token.colorError,
  62. activeShadow: token.errorActiveShadow,
  63. affixColor: token.colorError
  64. })), genOutlinedStatusStyle(token, {
  65. status: 'warning',
  66. borderColor: token.colorWarning,
  67. hoverBorderColor: token.colorWarningBorderHover,
  68. activeBorderColor: token.colorWarning,
  69. activeShadow: token.warningActiveShadow,
  70. affixColor: token.colorWarning
  71. })), extraStyles)
  72. });
  73. const genOutlinedGroupStatusStyle = (token, options) => ({
  74. [`&${token.componentCls}-group-wrapper-status-${options.status}`]: {
  75. [`${token.componentCls}-group-addon`]: {
  76. borderColor: options.addonBorderColor,
  77. color: options.addonColor
  78. }
  79. }
  80. });
  81. export const genOutlinedGroupStyle = token => ({
  82. '&-outlined': Object.assign(Object.assign(Object.assign({
  83. [`${token.componentCls}-group`]: {
  84. '&-addon': {
  85. background: token.addonBg,
  86. border: `${unit(token.lineWidth)} ${token.lineType} ${token.colorBorder}`
  87. },
  88. '&-addon:first-child': {
  89. borderInlineEnd: 0
  90. },
  91. '&-addon:last-child': {
  92. borderInlineStart: 0
  93. }
  94. }
  95. }, genOutlinedGroupStatusStyle(token, {
  96. status: 'error',
  97. addonBorderColor: token.colorError,
  98. addonColor: token.colorErrorText
  99. })), genOutlinedGroupStatusStyle(token, {
  100. status: 'warning',
  101. addonBorderColor: token.colorWarning,
  102. addonColor: token.colorWarningText
  103. })), {
  104. [`&${token.componentCls}-group-wrapper-disabled`]: {
  105. [`${token.componentCls}-group-addon`]: Object.assign({}, genDisabledStyle(token))
  106. }
  107. })
  108. });
  109. /* ============ Borderless ============ */
  110. export const genBorderlessStyle = (token, extraStyles) => {
  111. const {
  112. componentCls
  113. } = token;
  114. return {
  115. '&-borderless': Object.assign({
  116. background: 'transparent',
  117. border: 'none',
  118. '&:focus, &:focus-within': {
  119. outline: 'none'
  120. },
  121. // >>>>> Disabled
  122. [`&${componentCls}-disabled, &[disabled]`]: {
  123. color: token.colorTextDisabled,
  124. cursor: 'not-allowed'
  125. },
  126. // >>>>> Status
  127. [`&${componentCls}-status-error`]: {
  128. '&, & input, & textarea': {
  129. color: token.colorError
  130. }
  131. },
  132. [`&${componentCls}-status-warning`]: {
  133. '&, & input, & textarea': {
  134. color: token.colorWarning
  135. }
  136. }
  137. }, extraStyles)
  138. };
  139. };
  140. /* ============== Filled ============== */
  141. const genBaseFilledStyle = (token, options) => {
  142. var _a;
  143. return {
  144. background: options.bg,
  145. borderWidth: token.lineWidth,
  146. borderStyle: token.lineType,
  147. borderColor: 'transparent',
  148. 'input&, & input, textarea&, & textarea': {
  149. color: (_a = options === null || options === void 0 ? void 0 : options.inputColor) !== null && _a !== void 0 ? _a : 'unset'
  150. },
  151. '&:hover': {
  152. background: options.hoverBg
  153. },
  154. '&:focus, &:focus-within': {
  155. outline: 0,
  156. borderColor: options.activeBorderColor,
  157. backgroundColor: token.activeBg
  158. }
  159. };
  160. };
  161. const genFilledStatusStyle = (token, options) => ({
  162. [`&${token.componentCls}-status-${options.status}:not(${token.componentCls}-disabled)`]: Object.assign(Object.assign({}, genBaseFilledStyle(token, options)), {
  163. [`${token.componentCls}-prefix, ${token.componentCls}-suffix`]: {
  164. color: options.affixColor
  165. }
  166. })
  167. });
  168. export const genFilledStyle = (token, extraStyles) => ({
  169. '&-filled': Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, genBaseFilledStyle(token, {
  170. bg: token.colorFillTertiary,
  171. hoverBg: token.colorFillSecondary,
  172. activeBorderColor: token.activeBorderColor
  173. })), {
  174. [`&${token.componentCls}-disabled, &[disabled]`]: Object.assign({}, genDisabledStyle(token))
  175. }), genFilledStatusStyle(token, {
  176. status: 'error',
  177. bg: token.colorErrorBg,
  178. hoverBg: token.colorErrorBgHover,
  179. activeBorderColor: token.colorError,
  180. inputColor: token.colorErrorText,
  181. affixColor: token.colorError
  182. })), genFilledStatusStyle(token, {
  183. status: 'warning',
  184. bg: token.colorWarningBg,
  185. hoverBg: token.colorWarningBgHover,
  186. activeBorderColor: token.colorWarning,
  187. inputColor: token.colorWarningText,
  188. affixColor: token.colorWarning
  189. })), extraStyles)
  190. });
  191. const genFilledGroupStatusStyle = (token, options) => ({
  192. [`&${token.componentCls}-group-wrapper-status-${options.status}`]: {
  193. [`${token.componentCls}-group-addon`]: {
  194. background: options.addonBg,
  195. color: options.addonColor
  196. }
  197. }
  198. });
  199. export const genFilledGroupStyle = token => ({
  200. '&-filled': Object.assign(Object.assign(Object.assign({
  201. [`${token.componentCls}-group-addon`]: {
  202. background: token.colorFillTertiary,
  203. '&:last-child': {
  204. position: 'static'
  205. }
  206. }
  207. }, genFilledGroupStatusStyle(token, {
  208. status: 'error',
  209. addonBg: token.colorErrorBg,
  210. addonColor: token.colorErrorText
  211. })), genFilledGroupStatusStyle(token, {
  212. status: 'warning',
  213. addonBg: token.colorWarningBg,
  214. addonColor: token.colorWarningText
  215. })), {
  216. [`&${token.componentCls}-group-wrapper-disabled`]: {
  217. [`${token.componentCls}-group`]: {
  218. '&-addon': {
  219. background: token.colorFillTertiary,
  220. color: token.colorTextDisabled
  221. },
  222. '&-addon:first-child': {
  223. borderInlineStart: `${unit(token.lineWidth)} ${token.lineType} ${token.colorBorder}`,
  224. borderTop: `${unit(token.lineWidth)} ${token.lineType} ${token.colorBorder}`,
  225. borderBottom: `${unit(token.lineWidth)} ${token.lineType} ${token.colorBorder}`
  226. },
  227. '&-addon:last-child': {
  228. borderInlineEnd: `${unit(token.lineWidth)} ${token.lineType} ${token.colorBorder}`,
  229. borderTop: `${unit(token.lineWidth)} ${token.lineType} ${token.colorBorder}`,
  230. borderBottom: `${unit(token.lineWidth)} ${token.lineType} ${token.colorBorder}`
  231. }
  232. }
  233. }
  234. })
  235. });
  236. /* ============== Underlined ============== */
  237. // https://github.com/ant-design/ant-design/issues/51379
  238. export const genBaseUnderlinedStyle = (token, options) => ({
  239. background: token.colorBgContainer,
  240. borderWidth: `${unit(token.lineWidth)} 0`,
  241. borderStyle: `${token.lineType} none`,
  242. borderColor: `transparent transparent ${options.borderColor} transparent`,
  243. borderRadius: 0,
  244. '&:hover': {
  245. borderColor: `transparent transparent ${options.borderColor} transparent`,
  246. backgroundColor: token.hoverBg
  247. },
  248. '&:focus, &:focus-within': {
  249. borderColor: `transparent transparent ${options.activeBorderColor} transparent`,
  250. outline: 0,
  251. backgroundColor: token.activeBg
  252. }
  253. });
  254. const genUnderlinedStatusStyle = (token, options) => ({
  255. [`&${token.componentCls}-status-${options.status}:not(${token.componentCls}-disabled)`]: Object.assign(Object.assign({}, genBaseUnderlinedStyle(token, options)), {
  256. [`${token.componentCls}-prefix, ${token.componentCls}-suffix`]: {
  257. color: options.affixColor
  258. }
  259. }),
  260. [`&${token.componentCls}-status-${options.status}${token.componentCls}-disabled`]: {
  261. borderColor: `transparent transparent ${options.borderColor} transparent`
  262. }
  263. });
  264. export const genUnderlinedStyle = (token, extraStyles) => ({
  265. '&-underlined': Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, genBaseUnderlinedStyle(token, {
  266. borderColor: token.colorBorder,
  267. hoverBorderColor: token.hoverBorderColor,
  268. activeBorderColor: token.activeBorderColor,
  269. activeShadow: token.activeShadow
  270. })), {
  271. // >>>>> Disabled
  272. [`&${token.componentCls}-disabled, &[disabled]`]: {
  273. color: token.colorTextDisabled,
  274. boxShadow: 'none',
  275. cursor: 'not-allowed',
  276. '&:hover': {
  277. borderColor: `transparent transparent ${token.colorBorder} transparent`
  278. }
  279. },
  280. 'input[disabled], textarea[disabled]': {
  281. cursor: 'not-allowed'
  282. }
  283. }), genUnderlinedStatusStyle(token, {
  284. status: 'error',
  285. borderColor: token.colorError,
  286. hoverBorderColor: token.colorErrorBorderHover,
  287. activeBorderColor: token.colorError,
  288. activeShadow: token.errorActiveShadow,
  289. affixColor: token.colorError
  290. })), genUnderlinedStatusStyle(token, {
  291. status: 'warning',
  292. borderColor: token.colorWarning,
  293. hoverBorderColor: token.colorWarningBorderHover,
  294. activeBorderColor: token.colorWarning,
  295. activeShadow: token.warningActiveShadow,
  296. affixColor: token.colorWarning
  297. })), extraStyles)
  298. });