index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { unit } from '@ant-design/cssinjs';
  2. import { genStyleHooks, mergeToken } from '../../theme/internal';
  3. // ============================== Styles ==============================
  4. const genBaseStyle = token => {
  5. const {
  6. componentCls,
  7. lineHeightHeading3,
  8. iconCls,
  9. padding,
  10. paddingXL,
  11. paddingXS,
  12. paddingLG,
  13. marginXS,
  14. lineHeight
  15. } = token;
  16. return {
  17. // Result
  18. [componentCls]: {
  19. padding: `${unit(token.calc(paddingLG).mul(2).equal())} ${unit(paddingXL)}`,
  20. // RTL
  21. '&-rtl': {
  22. direction: 'rtl'
  23. }
  24. },
  25. // Exception Status image
  26. [`${componentCls} ${componentCls}-image`]: {
  27. width: token.imageWidth,
  28. height: token.imageHeight,
  29. margin: 'auto'
  30. },
  31. [`${componentCls} ${componentCls}-icon`]: {
  32. marginBottom: paddingLG,
  33. textAlign: 'center',
  34. [`& > ${iconCls}`]: {
  35. fontSize: token.iconFontSize
  36. }
  37. },
  38. [`${componentCls} ${componentCls}-title`]: {
  39. color: token.colorTextHeading,
  40. fontSize: token.titleFontSize,
  41. lineHeight: lineHeightHeading3,
  42. marginBlock: marginXS,
  43. textAlign: 'center'
  44. },
  45. [`${componentCls} ${componentCls}-subtitle`]: {
  46. color: token.colorTextDescription,
  47. fontSize: token.subtitleFontSize,
  48. lineHeight,
  49. textAlign: 'center'
  50. },
  51. [`${componentCls} ${componentCls}-content`]: {
  52. marginTop: paddingLG,
  53. padding: `${unit(paddingLG)} ${unit(token.calc(padding).mul(2.5).equal())}`,
  54. backgroundColor: token.colorFillAlter
  55. },
  56. [`${componentCls} ${componentCls}-extra`]: {
  57. margin: token.extraMargin,
  58. textAlign: 'center',
  59. '& > *': {
  60. marginInlineEnd: paddingXS,
  61. '&:last-child': {
  62. marginInlineEnd: 0
  63. }
  64. }
  65. }
  66. };
  67. };
  68. const genStatusIconStyle = token => {
  69. const {
  70. componentCls,
  71. iconCls
  72. } = token;
  73. return {
  74. [`${componentCls}-success ${componentCls}-icon > ${iconCls}`]: {
  75. color: token.resultSuccessIconColor
  76. },
  77. [`${componentCls}-error ${componentCls}-icon > ${iconCls}`]: {
  78. color: token.resultErrorIconColor
  79. },
  80. [`${componentCls}-info ${componentCls}-icon > ${iconCls}`]: {
  81. color: token.resultInfoIconColor
  82. },
  83. [`${componentCls}-warning ${componentCls}-icon > ${iconCls}`]: {
  84. color: token.resultWarningIconColor
  85. }
  86. };
  87. };
  88. const genResultStyle = token => [genBaseStyle(token), genStatusIconStyle(token)];
  89. const getStyle = token => genResultStyle(token);
  90. // ============================== Export ==============================
  91. export const prepareComponentToken = token => ({
  92. titleFontSize: token.fontSizeHeading3,
  93. subtitleFontSize: token.fontSize,
  94. iconFontSize: token.fontSizeHeading3 * 3,
  95. extraMargin: `${token.paddingLG}px 0 0 0`
  96. });
  97. export default genStyleHooks('Result', token => {
  98. const resultInfoIconColor = token.colorInfo;
  99. const resultErrorIconColor = token.colorError;
  100. const resultSuccessIconColor = token.colorSuccess;
  101. const resultWarningIconColor = token.colorWarning;
  102. const resultToken = mergeToken(token, {
  103. resultInfoIconColor,
  104. resultErrorIconColor,
  105. resultSuccessIconColor,
  106. resultWarningIconColor,
  107. imageWidth: 250,
  108. imageHeight: 295
  109. });
  110. return [getStyle(resultToken)];
  111. }, prepareComponentToken);