stack.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { NotificationPlacements } from '../interface';
  2. const placementAlignProperty = {
  3. topLeft: 'left',
  4. topRight: 'right',
  5. bottomLeft: 'left',
  6. bottomRight: 'right',
  7. top: 'left',
  8. bottom: 'left'
  9. };
  10. const genPlacementStackStyle = (token, placement) => {
  11. const {
  12. componentCls
  13. } = token;
  14. return {
  15. [`${componentCls}-${placement}`]: {
  16. [`&${componentCls}-stack > ${componentCls}-notice-wrapper`]: {
  17. [placement.startsWith('top') ? 'top' : 'bottom']: 0,
  18. [placementAlignProperty[placement]]: {
  19. value: 0,
  20. _skip_check_: true
  21. }
  22. }
  23. }
  24. };
  25. };
  26. const genStackChildrenStyle = token => {
  27. const childrenStyle = {};
  28. for (let i = 1; i < token.notificationStackLayer; i++) {
  29. childrenStyle[`&:nth-last-child(${i + 1})`] = {
  30. overflow: 'hidden',
  31. [`& > ${token.componentCls}-notice`]: {
  32. opacity: 0,
  33. transition: `opacity ${token.motionDurationMid}`
  34. }
  35. };
  36. }
  37. return Object.assign({
  38. [`&:not(:nth-last-child(-n+${token.notificationStackLayer}))`]: {
  39. opacity: 0,
  40. overflow: 'hidden',
  41. color: 'transparent',
  42. pointerEvents: 'none'
  43. }
  44. }, childrenStyle);
  45. };
  46. const genStackedNoticeStyle = token => {
  47. const childrenStyle = {};
  48. for (let i = 1; i < token.notificationStackLayer; i++) {
  49. childrenStyle[`&:nth-last-child(${i + 1})`] = {
  50. background: token.colorBgBlur,
  51. backdropFilter: 'blur(10px)',
  52. '-webkit-backdrop-filter': 'blur(10px)'
  53. };
  54. }
  55. return Object.assign({}, childrenStyle);
  56. };
  57. const genStackStyle = token => {
  58. const {
  59. componentCls
  60. } = token;
  61. return Object.assign({
  62. [`${componentCls}-stack`]: {
  63. [`& > ${componentCls}-notice-wrapper`]: Object.assign({
  64. transition: `transform ${token.motionDurationSlow}, backdrop-filter 0s`,
  65. willChange: 'transform, opacity',
  66. position: 'absolute'
  67. }, genStackChildrenStyle(token))
  68. },
  69. [`${componentCls}-stack:not(${componentCls}-stack-expanded)`]: {
  70. [`& > ${componentCls}-notice-wrapper`]: Object.assign({}, genStackedNoticeStyle(token))
  71. },
  72. [`${componentCls}-stack${componentCls}-stack-expanded`]: {
  73. [`& > ${componentCls}-notice-wrapper`]: {
  74. '&:not(:nth-last-child(-n + 1))': {
  75. opacity: 1,
  76. overflow: 'unset',
  77. color: 'inherit',
  78. pointerEvents: 'auto',
  79. [`& > ${token.componentCls}-notice`]: {
  80. opacity: 1
  81. }
  82. },
  83. '&:after': {
  84. content: '""',
  85. position: 'absolute',
  86. height: token.margin,
  87. width: '100%',
  88. insetInline: 0,
  89. bottom: token.calc(token.margin).mul(-1).equal(),
  90. background: 'transparent',
  91. pointerEvents: 'auto'
  92. }
  93. }
  94. }
  95. }, NotificationPlacements.map(placement => genPlacementStackStyle(token, placement)).reduce((acc, cur) => Object.assign(Object.assign({}, acc), cur), {}));
  96. };
  97. export default genStackStyle;