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