|
| 1 | +// deps-lint-skip-all |
| 2 | +import { Keyframes } from '../../_util/cssinjs'; |
| 3 | +import type { FullToken, GenerateStyle } from '../../theme/internal'; |
| 4 | +import { genComponentStyleHook, mergeToken } from '../../theme/internal'; |
| 5 | +import { resetComponent } from '../../_style'; |
| 6 | + |
| 7 | +/** Component only token. Which will handle additional calculation of alias token */ |
| 8 | +export interface ComponentToken { |
| 9 | + // Component token here |
| 10 | + height: number; |
| 11 | + zIndexPopup: number; |
| 12 | +} |
| 13 | + |
| 14 | +interface MessageToken extends FullToken<'Message'> { |
| 15 | + // Custom token here |
| 16 | + messageNoticeContentPadding: string; |
| 17 | +} |
| 18 | + |
| 19 | +const genMessageStyle: GenerateStyle<MessageToken> = token => { |
| 20 | + const { |
| 21 | + componentCls, |
| 22 | + iconCls, |
| 23 | + boxShadowSecondary, |
| 24 | + colorBgElevated, |
| 25 | + colorSuccess, |
| 26 | + colorError, |
| 27 | + colorWarning, |
| 28 | + colorInfo, |
| 29 | + fontSizeLG, |
| 30 | + motionEaseInOutCirc, |
| 31 | + motionDurationSlow, |
| 32 | + marginXS, |
| 33 | + paddingXS, |
| 34 | + borderRadiusLG, |
| 35 | + zIndexPopup, |
| 36 | + // Custom token |
| 37 | + messageNoticeContentPadding, |
| 38 | + } = token; |
| 39 | + |
| 40 | + const messageMoveIn = new Keyframes('MessageMoveIn', { |
| 41 | + '0%': { |
| 42 | + padding: 0, |
| 43 | + transform: 'translateY(-100%)', |
| 44 | + opacity: 0, |
| 45 | + }, |
| 46 | + |
| 47 | + '100%': { |
| 48 | + padding: paddingXS, |
| 49 | + transform: 'translateY(0)', |
| 50 | + opacity: 1, |
| 51 | + }, |
| 52 | + }); |
| 53 | + |
| 54 | + const messageMoveOut = new Keyframes('MessageMoveOut', { |
| 55 | + '0%': { |
| 56 | + maxHeight: token.height, |
| 57 | + padding: paddingXS, |
| 58 | + opacity: 1, |
| 59 | + }, |
| 60 | + '100%': { |
| 61 | + maxHeight: 0, |
| 62 | + padding: 0, |
| 63 | + opacity: 0, |
| 64 | + }, |
| 65 | + }); |
| 66 | + |
| 67 | + return [ |
| 68 | + // ============================ Holder ============================ |
| 69 | + { |
| 70 | + [componentCls]: { |
| 71 | + ...resetComponent(token), |
| 72 | + position: 'fixed', |
| 73 | + top: marginXS, |
| 74 | + width: '100%', |
| 75 | + pointerEvents: 'none', |
| 76 | + zIndex: zIndexPopup, |
| 77 | + |
| 78 | + [`${componentCls}-move-up`]: { |
| 79 | + animationFillMode: 'forwards', |
| 80 | + }, |
| 81 | + [` |
| 82 | + ${componentCls}-move-up-appear, |
| 83 | + ${componentCls}-move-up-enter |
| 84 | + `]: { |
| 85 | + animationName: messageMoveIn, |
| 86 | + animationDuration: motionDurationSlow, |
| 87 | + animationPlayState: 'paused', |
| 88 | + animationTimingFunction: motionEaseInOutCirc, |
| 89 | + }, |
| 90 | + [` |
| 91 | + ${componentCls}-move-up-appear${componentCls}-move-up-appear-active, |
| 92 | + ${componentCls}-move-up-enter${componentCls}-move-up-enter-active |
| 93 | + `]: { |
| 94 | + animationPlayState: 'running', |
| 95 | + }, |
| 96 | + [`${componentCls}-move-up-leave`]: { |
| 97 | + animationName: messageMoveOut, |
| 98 | + animationDuration: motionDurationSlow, |
| 99 | + animationPlayState: 'paused', |
| 100 | + animationTimingFunction: motionEaseInOutCirc, |
| 101 | + }, |
| 102 | + [`${componentCls}-move-up-leave${componentCls}-move-up-leave-active`]: { |
| 103 | + animationPlayState: 'running', |
| 104 | + }, |
| 105 | + '&-rtl': { |
| 106 | + direction: 'rtl', |
| 107 | + span: { |
| 108 | + direction: 'rtl', |
| 109 | + }, |
| 110 | + }, |
| 111 | + }, |
| 112 | + }, |
| 113 | + |
| 114 | + // ============================ Notice ============================ |
| 115 | + { |
| 116 | + [`${componentCls}-notice`]: { |
| 117 | + padding: paddingXS, |
| 118 | + textAlign: 'center', |
| 119 | + |
| 120 | + [iconCls]: { |
| 121 | + verticalAlign: 'text-bottom', |
| 122 | + marginInlineEnd: marginXS, // affected by ltr or rtl |
| 123 | + fontSize: fontSizeLG, |
| 124 | + }, |
| 125 | + |
| 126 | + [`${componentCls}-notice-content`]: { |
| 127 | + display: 'inline-block', |
| 128 | + padding: messageNoticeContentPadding, |
| 129 | + background: colorBgElevated, |
| 130 | + borderRadius: borderRadiusLG, |
| 131 | + boxShadow: boxShadowSecondary, |
| 132 | + pointerEvents: 'all', |
| 133 | + }, |
| 134 | + |
| 135 | + [`${componentCls}-success ${iconCls}`]: { |
| 136 | + color: colorSuccess, |
| 137 | + }, |
| 138 | + [`${componentCls}-error ${iconCls}`]: { |
| 139 | + color: colorError, |
| 140 | + }, |
| 141 | + [`${componentCls}-warning ${iconCls}`]: { |
| 142 | + color: colorWarning, |
| 143 | + }, |
| 144 | + [` |
| 145 | + ${componentCls}-info ${iconCls}, |
| 146 | + ${componentCls}-loading ${iconCls}`]: { |
| 147 | + color: colorInfo, |
| 148 | + }, |
| 149 | + }, |
| 150 | + }, |
| 151 | + |
| 152 | + // ============================= Pure ============================= |
| 153 | + { |
| 154 | + [`${componentCls}-notice-pure-panel`]: { |
| 155 | + padding: 0, |
| 156 | + textAlign: 'start', |
| 157 | + }, |
| 158 | + }, |
| 159 | + ]; |
| 160 | +}; |
| 161 | + |
| 162 | +// ============================== Export ============================== |
| 163 | +export default genComponentStyleHook( |
| 164 | + 'Message', |
| 165 | + token => { |
| 166 | + // Gen-style functions here |
| 167 | + const combinedToken = mergeToken<MessageToken>(token, { |
| 168 | + messageNoticeContentPadding: `${ |
| 169 | + (token.controlHeightLG - token.fontSize * token.lineHeight) / 2 |
| 170 | + }px ${token.paddingSM}px`, |
| 171 | + }); |
| 172 | + return [genMessageStyle(combinedToken)]; |
| 173 | + }, |
| 174 | + token => ({ |
| 175 | + height: 150, |
| 176 | + zIndexPopup: token.zIndexPopupBase + 10, |
| 177 | + }), |
| 178 | +); |
0 commit comments