variants.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import { unit } from '@ant-design/cssinjs';
  2. // =====================================================
  3. // == Outlined ==
  4. // =====================================================
  5. const genBaseOutlinedStyle = (token, options) => {
  6. const {
  7. componentCls,
  8. antCls,
  9. controlOutlineWidth
  10. } = token;
  11. return {
  12. [`&:not(${componentCls}-customize-input) ${componentCls}-selector`]: {
  13. border: `${unit(token.lineWidth)} ${token.lineType} ${options.borderColor}`,
  14. background: token.selectorBg
  15. },
  16. [`&:not(${componentCls}-disabled):not(${componentCls}-customize-input):not(${antCls}-pagination-size-changer)`]: {
  17. [`&:hover ${componentCls}-selector`]: {
  18. borderColor: options.hoverBorderHover
  19. },
  20. [`${componentCls}-focused& ${componentCls}-selector`]: {
  21. borderColor: options.activeBorderColor,
  22. boxShadow: `0 0 0 ${unit(controlOutlineWidth)} ${options.activeOutlineColor}`,
  23. outline: 0
  24. },
  25. [`${componentCls}-prefix`]: {
  26. color: options.color
  27. }
  28. }
  29. };
  30. };
  31. const genOutlinedStatusStyle = (token, options) => ({
  32. [`&${token.componentCls}-status-${options.status}`]: Object.assign({}, genBaseOutlinedStyle(token, options))
  33. });
  34. const genOutlinedStyle = token => ({
  35. '&-outlined': Object.assign(Object.assign(Object.assign(Object.assign({}, genBaseOutlinedStyle(token, {
  36. borderColor: token.colorBorder,
  37. hoverBorderHover: token.hoverBorderColor,
  38. activeBorderColor: token.activeBorderColor,
  39. activeOutlineColor: token.activeOutlineColor,
  40. color: token.colorText
  41. })), genOutlinedStatusStyle(token, {
  42. status: 'error',
  43. borderColor: token.colorError,
  44. hoverBorderHover: token.colorErrorHover,
  45. activeBorderColor: token.colorError,
  46. activeOutlineColor: token.colorErrorOutline,
  47. color: token.colorError
  48. })), genOutlinedStatusStyle(token, {
  49. status: 'warning',
  50. borderColor: token.colorWarning,
  51. hoverBorderHover: token.colorWarningHover,
  52. activeBorderColor: token.colorWarning,
  53. activeOutlineColor: token.colorWarningOutline,
  54. color: token.colorWarning
  55. })), {
  56. [`&${token.componentCls}-disabled`]: {
  57. [`&:not(${token.componentCls}-customize-input) ${token.componentCls}-selector`]: {
  58. background: token.colorBgContainerDisabled,
  59. color: token.colorTextDisabled
  60. }
  61. },
  62. [`&${token.componentCls}-multiple ${token.componentCls}-selection-item`]: {
  63. background: token.multipleItemBg,
  64. border: `${unit(token.lineWidth)} ${token.lineType} ${token.multipleItemBorderColor}`
  65. }
  66. })
  67. });
  68. // =====================================================
  69. // == Filled ==
  70. // =====================================================
  71. const genBaseFilledStyle = (token, options) => {
  72. const {
  73. componentCls,
  74. antCls
  75. } = token;
  76. return {
  77. [`&:not(${componentCls}-customize-input) ${componentCls}-selector`]: {
  78. background: options.bg,
  79. border: `${unit(token.lineWidth)} ${token.lineType} transparent`,
  80. color: options.color
  81. },
  82. [`&:not(${componentCls}-disabled):not(${componentCls}-customize-input):not(${antCls}-pagination-size-changer)`]: {
  83. [`&:hover ${componentCls}-selector`]: {
  84. background: options.hoverBg
  85. },
  86. [`${componentCls}-focused& ${componentCls}-selector`]: {
  87. background: token.selectorBg,
  88. borderColor: options.activeBorderColor,
  89. outline: 0
  90. }
  91. }
  92. };
  93. };
  94. const genFilledStatusStyle = (token, options) => ({
  95. [`&${token.componentCls}-status-${options.status}`]: Object.assign({}, genBaseFilledStyle(token, options))
  96. });
  97. const genFilledStyle = token => ({
  98. '&-filled': Object.assign(Object.assign(Object.assign(Object.assign({}, genBaseFilledStyle(token, {
  99. bg: token.colorFillTertiary,
  100. hoverBg: token.colorFillSecondary,
  101. activeBorderColor: token.activeBorderColor,
  102. color: token.colorText
  103. })), genFilledStatusStyle(token, {
  104. status: 'error',
  105. bg: token.colorErrorBg,
  106. hoverBg: token.colorErrorBgHover,
  107. activeBorderColor: token.colorError,
  108. color: token.colorError
  109. })), genFilledStatusStyle(token, {
  110. status: 'warning',
  111. bg: token.colorWarningBg,
  112. hoverBg: token.colorWarningBgHover,
  113. activeBorderColor: token.colorWarning,
  114. color: token.colorWarning
  115. })), {
  116. [`&${token.componentCls}-disabled`]: {
  117. [`&:not(${token.componentCls}-customize-input) ${token.componentCls}-selector`]: {
  118. borderColor: token.colorBorder,
  119. background: token.colorBgContainerDisabled,
  120. color: token.colorTextDisabled
  121. }
  122. },
  123. [`&${token.componentCls}-multiple ${token.componentCls}-selection-item`]: {
  124. background: token.colorBgContainer,
  125. border: `${unit(token.lineWidth)} ${token.lineType} ${token.colorSplit}`
  126. }
  127. })
  128. });
  129. // =====================================================
  130. // == Borderless ==
  131. // =====================================================
  132. const genBorderlessStyle = token => ({
  133. '&-borderless': {
  134. [`${token.componentCls}-selector`]: {
  135. background: 'transparent',
  136. border: `${unit(token.lineWidth)} ${token.lineType} transparent`
  137. },
  138. [`&${token.componentCls}-disabled`]: {
  139. [`&:not(${token.componentCls}-customize-input) ${token.componentCls}-selector`]: {
  140. color: token.colorTextDisabled
  141. }
  142. },
  143. [`&${token.componentCls}-multiple ${token.componentCls}-selection-item`]: {
  144. background: token.multipleItemBg,
  145. border: `${unit(token.lineWidth)} ${token.lineType} ${token.multipleItemBorderColor}`
  146. },
  147. // Status
  148. [`&${token.componentCls}-status-error`]: {
  149. [`${token.componentCls}-prefix, ${token.componentCls}-selection-item`]: {
  150. color: token.colorError
  151. }
  152. },
  153. [`&${token.componentCls}-status-warning`]: {
  154. [`${token.componentCls}-prefix, ${token.componentCls}-selection-item`]: {
  155. color: token.colorWarning
  156. }
  157. }
  158. }
  159. });
  160. // =====================================================
  161. // == Underlined ==
  162. // =====================================================
  163. const genBaseUnderlinedStyle = (token, options) => {
  164. const {
  165. componentCls,
  166. antCls
  167. } = token;
  168. return {
  169. [`&:not(${componentCls}-customize-input) ${componentCls}-selector`]: {
  170. borderWidth: `0 0 ${unit(token.lineWidth)} 0`,
  171. borderStyle: `none none ${token.lineType} none`,
  172. borderColor: options.borderColor,
  173. background: token.selectorBg,
  174. borderRadius: 0
  175. },
  176. [`&:not(${componentCls}-disabled):not(${componentCls}-customize-input):not(${antCls}-pagination-size-changer)`]: {
  177. [`&:hover ${componentCls}-selector`]: {
  178. borderColor: options.hoverBorderHover
  179. },
  180. [`${componentCls}-focused& ${componentCls}-selector`]: {
  181. borderColor: options.activeBorderColor,
  182. outline: 0
  183. },
  184. [`${componentCls}-prefix`]: {
  185. color: options.color
  186. }
  187. }
  188. };
  189. };
  190. const genUnderlinedStatusStyle = (token, options) => ({
  191. [`&${token.componentCls}-status-${options.status}`]: Object.assign({}, genBaseUnderlinedStyle(token, options))
  192. });
  193. const genUnderlinedStyle = token => ({
  194. '&-underlined': Object.assign(Object.assign(Object.assign(Object.assign({}, genBaseUnderlinedStyle(token, {
  195. borderColor: token.colorBorder,
  196. hoverBorderHover: token.hoverBorderColor,
  197. activeBorderColor: token.activeBorderColor,
  198. activeOutlineColor: token.activeOutlineColor,
  199. color: token.colorText
  200. })), genUnderlinedStatusStyle(token, {
  201. status: 'error',
  202. borderColor: token.colorError,
  203. hoverBorderHover: token.colorErrorHover,
  204. activeBorderColor: token.colorError,
  205. activeOutlineColor: token.colorErrorOutline,
  206. color: token.colorError
  207. })), genUnderlinedStatusStyle(token, {
  208. status: 'warning',
  209. borderColor: token.colorWarning,
  210. hoverBorderHover: token.colorWarningHover,
  211. activeBorderColor: token.colorWarning,
  212. activeOutlineColor: token.colorWarningOutline,
  213. color: token.colorWarning
  214. })), {
  215. [`&${token.componentCls}-disabled`]: {
  216. [`&:not(${token.componentCls}-customize-input) ${token.componentCls}-selector`]: {
  217. color: token.colorTextDisabled
  218. }
  219. },
  220. [`&${token.componentCls}-multiple ${token.componentCls}-selection-item`]: {
  221. background: token.multipleItemBg,
  222. border: `${unit(token.lineWidth)} ${token.lineType} ${token.multipleItemBorderColor}`
  223. }
  224. })
  225. });
  226. const genVariantsStyle = token => ({
  227. [token.componentCls]: Object.assign(Object.assign(Object.assign(Object.assign({}, genOutlinedStyle(token)), genFilledStyle(token)), genBorderlessStyle(token)), genUnderlinedStyle(token))
  228. });
  229. export default genVariantsStyle;