index.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import { unit } from '@ant-design/cssinjs';
  2. import { genPanelStyle, initPanelComponentToken, initPickerPanelToken } from '../../date-picker/style';
  3. import { resetComponent } from '../../style';
  4. import { genStyleHooks, mergeToken } from '../../theme/internal';
  5. export const genCalendarStyles = token => {
  6. const {
  7. calendarCls,
  8. componentCls,
  9. fullBg,
  10. fullPanelBg,
  11. itemActiveBg
  12. } = token;
  13. return {
  14. [calendarCls]: Object.assign(Object.assign(Object.assign({}, genPanelStyle(token)), resetComponent(token)), {
  15. background: fullBg,
  16. '&-rtl': {
  17. direction: 'rtl'
  18. },
  19. [`${calendarCls}-header`]: {
  20. display: 'flex',
  21. justifyContent: 'flex-end',
  22. padding: `${unit(token.paddingSM)} 0`,
  23. [`${calendarCls}-year-select`]: {
  24. minWidth: token.yearControlWidth
  25. },
  26. [`${calendarCls}-month-select`]: {
  27. minWidth: token.monthControlWidth,
  28. marginInlineStart: token.marginXS
  29. },
  30. [`${calendarCls}-mode-switch`]: {
  31. marginInlineStart: token.marginXS
  32. }
  33. }
  34. }),
  35. [`${calendarCls} ${componentCls}-panel`]: {
  36. background: fullPanelBg,
  37. border: 0,
  38. borderTop: `${unit(token.lineWidth)} ${token.lineType} ${token.colorSplit}`,
  39. borderRadius: 0,
  40. [`${componentCls}-month-panel, ${componentCls}-date-panel`]: {
  41. width: 'auto'
  42. },
  43. [`${componentCls}-body`]: {
  44. padding: `${unit(token.paddingXS)} 0`
  45. },
  46. [`${componentCls}-content`]: {
  47. width: '100%'
  48. }
  49. },
  50. [`${calendarCls}-mini`]: {
  51. borderRadius: token.borderRadiusLG,
  52. [`${calendarCls}-header`]: {
  53. paddingInlineEnd: token.paddingXS,
  54. paddingInlineStart: token.paddingXS
  55. },
  56. [`${componentCls}-panel`]: {
  57. borderRadius: `0 0 ${unit(token.borderRadiusLG)} ${unit(token.borderRadiusLG)}`
  58. },
  59. [`${componentCls}-content`]: {
  60. height: token.miniContentHeight,
  61. th: {
  62. height: 'auto',
  63. padding: 0,
  64. lineHeight: unit(token.weekHeight)
  65. }
  66. },
  67. [`${componentCls}-cell::before`]: {
  68. pointerEvents: 'none'
  69. }
  70. },
  71. [`${calendarCls}${calendarCls}-full`]: {
  72. [`${componentCls}-panel`]: {
  73. display: 'block',
  74. width: '100%',
  75. textAlign: 'end',
  76. background: fullBg,
  77. border: 0,
  78. [`${componentCls}-body`]: {
  79. 'th, td': {
  80. padding: 0
  81. },
  82. th: {
  83. height: 'auto',
  84. paddingInlineEnd: token.paddingSM,
  85. paddingBottom: token.paddingXXS,
  86. lineHeight: unit(token.weekHeight)
  87. }
  88. }
  89. },
  90. [`${componentCls}-cell-week ${componentCls}-cell-inner`]: {
  91. display: 'block',
  92. borderRadius: 0,
  93. borderTop: `${unit(token.lineWidthBold)} ${token.lineType} ${token.colorSplit}`,
  94. width: '100%',
  95. height: token.calc(token.dateValueHeight).add(token.dateContentHeight).add(token.calc(token.paddingXS).div(2)).add(token.lineWidthBold).equal()
  96. },
  97. [`${componentCls}-cell`]: {
  98. '&::before': {
  99. display: 'none'
  100. },
  101. '&:hover': {
  102. [`${calendarCls}-date`]: {
  103. background: token.controlItemBgHover
  104. }
  105. },
  106. [`${calendarCls}-date-today::before`]: {
  107. display: 'none'
  108. },
  109. // >>> Selected
  110. [`&-in-view${componentCls}-cell-selected`]: {
  111. [`${calendarCls}-date, ${calendarCls}-date-today`]: {
  112. background: itemActiveBg
  113. }
  114. },
  115. '&-selected, &-selected:hover': {
  116. [`${calendarCls}-date, ${calendarCls}-date-today`]: {
  117. [`${calendarCls}-date-value`]: {
  118. color: token.colorPrimary
  119. }
  120. }
  121. }
  122. },
  123. [`${calendarCls}-date`]: {
  124. display: 'block',
  125. width: 'auto',
  126. height: 'auto',
  127. margin: `0 ${unit(token.calc(token.marginXS).div(2).equal())}`,
  128. padding: `${unit(token.calc(token.paddingXS).div(2).equal())} ${unit(token.paddingXS)} 0`,
  129. border: 0,
  130. borderTop: `${unit(token.lineWidthBold)} ${token.lineType} ${token.colorSplit}`,
  131. borderRadius: 0,
  132. transition: `background ${token.motionDurationSlow}`,
  133. '&-value': {
  134. lineHeight: unit(token.dateValueHeight),
  135. transition: `color ${token.motionDurationSlow}`
  136. },
  137. '&-content': {
  138. position: 'static',
  139. width: 'auto',
  140. height: token.dateContentHeight,
  141. overflowY: 'auto',
  142. color: token.colorText,
  143. lineHeight: token.lineHeight,
  144. textAlign: 'start'
  145. },
  146. '&-today': {
  147. borderColor: token.colorPrimary,
  148. [`${calendarCls}-date-value`]: {
  149. color: token.colorText
  150. }
  151. }
  152. }
  153. },
  154. [`@media only screen and (max-width: ${unit(token.screenXS)}) `]: {
  155. [calendarCls]: {
  156. [`${calendarCls}-header`]: {
  157. display: 'block',
  158. [`${calendarCls}-year-select`]: {
  159. width: '50%'
  160. },
  161. [`${calendarCls}-month-select`]: {
  162. width: `calc(50% - ${unit(token.paddingXS)})`
  163. },
  164. [`${calendarCls}-mode-switch`]: {
  165. width: '100%',
  166. marginTop: token.marginXS,
  167. marginInlineStart: 0,
  168. '> label': {
  169. width: '50%',
  170. textAlign: 'center'
  171. }
  172. }
  173. }
  174. }
  175. }
  176. };
  177. };
  178. export const prepareComponentToken = token => Object.assign({
  179. fullBg: token.colorBgContainer,
  180. fullPanelBg: token.colorBgContainer,
  181. itemActiveBg: token.controlItemBgActive,
  182. yearControlWidth: 80,
  183. monthControlWidth: 70,
  184. miniContentHeight: 256
  185. }, initPanelComponentToken(token));
  186. export default genStyleHooks('Calendar', token => {
  187. const calendarCls = `${token.componentCls}-calendar`;
  188. const calendarToken = mergeToken(token, initPickerPanelToken(token), {
  189. calendarCls,
  190. pickerCellInnerCls: `${token.componentCls}-cell-inner`,
  191. dateValueHeight: token.controlHeightSM,
  192. weekHeight: token.calc(token.controlHeightSM).mul(0.75).equal(),
  193. dateContentHeight: token.calc(token.calc(token.fontHeightSM).add(token.marginXS)).mul(3).add(token.calc(token.lineWidth).mul(2)).equal()
  194. });
  195. return genCalendarStyles(calendarToken);
  196. }, prepareComponentToken);