2022-04-26 22:45:39 +08:00
|
|
|
// deps-lint-skip-all
|
2022-05-09 22:20:07 +08:00
|
|
|
import type React from 'react';
|
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2022-05-10 17:30:01 +08:00
|
|
|
import type { TokenWithCommonCls } from 'antd/es/_util/theme/util/genComponentStyleHook';
|
2022-05-09 22:20:07 +08:00
|
|
|
import { genComponentStyleHook, mergeToken, resetComponent, clearFix } from '../../_util/theme';
|
2022-05-10 17:30:01 +08:00
|
|
|
import type { FullToken, GenerateStyle, AliasToken } from '../../_util/theme';
|
2016-04-27 20:44:36 +08:00
|
|
|
|
2022-04-26 22:45:39 +08:00
|
|
|
/** Component only token. Which will handle additional calculation of alias token */
|
|
|
|
export interface ComponentToken {
|
|
|
|
// Component token here
|
|
|
|
}
|
|
|
|
|
2022-05-10 17:30:01 +08:00
|
|
|
export interface ModalToken extends FullToken<'Modal'> {
|
2022-04-26 22:45:39 +08:00
|
|
|
// Custom token here
|
|
|
|
modalBodyPadding: number;
|
|
|
|
modalHeaderBg: string;
|
|
|
|
modalHeaderPadding: string;
|
|
|
|
modalHeaderBorderWidth: number;
|
|
|
|
modalHeaderBorderStyle: string;
|
2022-05-13 14:33:50 +08:00
|
|
|
modalHeaderTitleLineHeight: number;
|
2022-04-26 22:45:39 +08:00
|
|
|
modalHeaderTitleFontSize: number;
|
|
|
|
modalHeaderBorderColorSplit: string;
|
|
|
|
modalHeaderCloseSize: number;
|
|
|
|
modalContentBg: string;
|
|
|
|
modalHeadingColor: string;
|
|
|
|
modalCloseColor: string;
|
|
|
|
modalFooterBg: string;
|
|
|
|
modalFooterBorderColorSplit: string;
|
|
|
|
modalFooterBorderStyle: string;
|
|
|
|
modalFooterPaddingVertical: number;
|
|
|
|
modalFooterPaddingHorizontal: number;
|
|
|
|
modalFooterBorderWidth: number;
|
|
|
|
modalConfirmTitleFontSize: number;
|
|
|
|
modalIconHoverColor: string;
|
2022-05-13 14:33:50 +08:00
|
|
|
modalConfirmIconSize: number;
|
2022-04-26 22:45:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function box(position: React.CSSProperties['position']): React.CSSProperties {
|
|
|
|
return {
|
|
|
|
position,
|
2022-04-27 21:04:09 +08:00
|
|
|
top: 0,
|
2022-05-02 10:46:36 +08:00
|
|
|
insetInlineEnd: 0,
|
2022-04-27 21:04:09 +08:00
|
|
|
bottom: 0,
|
2022-05-02 10:46:36 +08:00
|
|
|
insetInlineStart: 0,
|
2022-04-26 22:45:39 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-10 17:30:01 +08:00
|
|
|
export function modalMask(componentCls: string, token: TokenWithCommonCls<AliasToken>): CSSObject {
|
2022-04-26 22:45:39 +08:00
|
|
|
return {
|
|
|
|
[`${componentCls}${token.antCls}-zoom-enter, ${componentCls}${token.antCls}-zoom-appear`]: {
|
|
|
|
// reset scale avoid mousePosition bug
|
|
|
|
transform: 'none',
|
|
|
|
opacity: 0,
|
|
|
|
animationDuration: token.motionDurationSlow,
|
|
|
|
// https://github.com/ant-design/ant-design/issues/11777
|
|
|
|
userSelect: 'none',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-mask`]: {
|
|
|
|
...box('fixed'),
|
2022-05-10 17:30:01 +08:00
|
|
|
zIndex: token.zIndexPopupBase,
|
2022-04-26 22:45:39 +08:00
|
|
|
height: '100%',
|
2022-05-10 17:30:01 +08:00
|
|
|
backgroundColor: token.colorPopupBg,
|
2022-04-26 22:45:39 +08:00
|
|
|
|
|
|
|
[`${componentCls}-hidden`]: {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-wrap`]: {
|
|
|
|
...box('fixed'),
|
|
|
|
overflow: 'auto',
|
|
|
|
outline: 0,
|
|
|
|
WebkitOverflowScrolling: 'touch',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const genModalStyle: GenerateStyle<ModalToken> = token => {
|
|
|
|
const { componentCls } = token;
|
|
|
|
|
|
|
|
return {
|
|
|
|
[`${componentCls}-root`]: {
|
2022-04-28 09:45:53 +08:00
|
|
|
...modalMask(componentCls, token),
|
|
|
|
|
2022-04-26 22:45:39 +08:00
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
|
|
|
pointerEvents: 'none',
|
|
|
|
position: 'relative',
|
|
|
|
top: 100,
|
|
|
|
width: 'auto',
|
2022-05-13 14:33:50 +08:00
|
|
|
maxWidth: `calc(100vw - ${token.margin * 2}px)`,
|
2022-04-26 22:45:39 +08:00
|
|
|
margin: '0 auto',
|
|
|
|
paddingBottom: token.paddingLG,
|
|
|
|
|
|
|
|
'&-title': {
|
|
|
|
margin: 0,
|
|
|
|
color: token.modalHeadingColor,
|
2022-05-13 14:33:50 +08:00
|
|
|
fontWeight: token.fontWeightStrong,
|
|
|
|
fontSize: token.modalHeaderTitleFontSize,
|
2022-04-26 22:45:39 +08:00
|
|
|
lineHeight: token.modalHeaderTitleLineHeight,
|
|
|
|
wordWrap: 'break-word',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-content': {
|
|
|
|
position: 'relative',
|
|
|
|
backgroundColor: token.modalContentBg,
|
|
|
|
backgroundClip: 'padding-box',
|
|
|
|
border: 0,
|
|
|
|
borderRadius: token.controlRadius,
|
|
|
|
boxShadow: token.boxShadow,
|
|
|
|
pointerEvents: 'auto',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-close': {
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
2022-04-27 21:04:09 +08:00
|
|
|
insetInlineEnd: 0,
|
2022-05-13 14:33:50 +08:00
|
|
|
zIndex: token.zIndexPopupBase + 10,
|
2022-04-26 22:45:39 +08:00
|
|
|
padding: 0,
|
|
|
|
color: token.modalCloseColor,
|
2022-05-13 14:33:50 +08:00
|
|
|
fontWeight: token.fontWeightStrong,
|
2022-04-26 22:45:39 +08:00
|
|
|
lineHeight: 1,
|
|
|
|
textDecoration: 'none',
|
|
|
|
background: 'transparent',
|
|
|
|
border: 0,
|
|
|
|
outline: 0,
|
|
|
|
cursor: 'pointer',
|
|
|
|
transition: `color ${token.motionDurationSlow}`,
|
|
|
|
|
|
|
|
'&-x': {
|
|
|
|
display: 'block',
|
|
|
|
width: token.modalHeaderCloseSize,
|
|
|
|
height: token.modalHeaderCloseSize,
|
|
|
|
fontSize: token.fontSizeLG,
|
|
|
|
fontStyle: 'normal',
|
|
|
|
lineHeight: `${token.modalHeaderCloseSize}px`,
|
|
|
|
textAlign: 'center',
|
|
|
|
textTransform: 'none',
|
|
|
|
textRendering: 'auto',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&:focus, &:hover': {
|
|
|
|
color: token.modalIconHoverColor,
|
|
|
|
textDecoration: 'none',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-header': {
|
|
|
|
padding: token.modalHeaderPadding,
|
|
|
|
color: token.colorText,
|
|
|
|
background: token.modalHeaderBg,
|
|
|
|
borderBottom: `${token.modalHeaderBorderWidth}px ${token.modalHeaderBorderStyle} ${token.modalHeaderBorderColorSplit}`,
|
|
|
|
borderRadius: `${token.controlRadius}px ${token.controlRadius}px 0 0`,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-body': {
|
|
|
|
padding: token.modalBodyPadding,
|
|
|
|
fontSize: token.fontSizeBase,
|
|
|
|
lineHeight: token.lineHeight,
|
|
|
|
wordWrap: 'break-word',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-footer': {
|
|
|
|
padding: `${token.modalFooterPaddingVertical}px ${token.modalFooterPaddingHorizontal}px`,
|
2022-04-27 21:04:09 +08:00
|
|
|
textAlign: 'end',
|
2022-04-26 22:45:39 +08:00
|
|
|
background: token.modalFooterBg,
|
|
|
|
borderTop: `${token.modalFooterBorderWidth}px ${token.modalFooterBorderStyle} ${token.modalFooterBorderColorSplit}`,
|
|
|
|
borderRadius: `0 0 ${token.controlRadius}px ${token.controlRadius}px`,
|
|
|
|
|
|
|
|
[`${token.antCls}-btn + ${token.antCls}-btn:not(${token.antCls}-dropdown-trigger)`]: {
|
|
|
|
marginBottom: 0,
|
2022-04-27 21:04:09 +08:00
|
|
|
marginInlineStart: token.marginXS,
|
2022-04-26 22:45:39 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-open': {
|
|
|
|
overflow: 'hidden',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-wrap`]: {
|
2022-05-10 17:30:01 +08:00
|
|
|
zIndex: token.zIndexPopupBase,
|
2022-04-26 22:45:39 +08:00
|
|
|
position: 'fixed',
|
|
|
|
inset: 0,
|
|
|
|
overflow: 'auto',
|
|
|
|
outline: 0,
|
|
|
|
WebkitOverflowScrolling: 'touch',
|
2022-05-02 10:46:36 +08:00
|
|
|
},
|
|
|
|
[`${componentCls}-wrap-rtl`]: {
|
|
|
|
direction: 'rtl',
|
2022-04-26 22:45:39 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-centered`]: {
|
|
|
|
textAlign: 'center',
|
|
|
|
|
|
|
|
'&::before': {
|
|
|
|
display: 'inline-block',
|
|
|
|
width: 0,
|
|
|
|
height: '100%',
|
|
|
|
verticalAlign: 'middle',
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
[componentCls]: {
|
|
|
|
top: 0,
|
|
|
|
display: 'inline-block',
|
|
|
|
paddingBottom: 0,
|
2022-04-29 09:21:43 +08:00
|
|
|
textAlign: 'start',
|
2022-04-26 22:45:39 +08:00
|
|
|
verticalAlign: 'middle',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`@media (max-width: ${token.screenSMMax})`]: {
|
|
|
|
[componentCls]: {
|
|
|
|
maxWidth: 'calc(100vw - 16px)',
|
|
|
|
margin: `${token.marginXS} auto`,
|
|
|
|
},
|
|
|
|
[`${componentCls}-centered`]: {
|
|
|
|
[componentCls]: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-04-29 09:21:43 +08:00
|
|
|
const genModalConfirmStyle: GenerateStyle<ModalToken> = token => {
|
|
|
|
const { componentCls } = token;
|
|
|
|
const confirmComponentCls = `${componentCls}-confirm`;
|
|
|
|
|
|
|
|
return {
|
|
|
|
[`${componentCls}-root`]: {
|
|
|
|
[confirmComponentCls]: {
|
2022-05-02 10:46:36 +08:00
|
|
|
'&-rtl': {
|
|
|
|
direction: 'rtl',
|
|
|
|
},
|
2022-04-29 09:21:43 +08:00
|
|
|
[`${token.antCls}-modal-header`]: {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
[`${token.antCls}-modal-body`]: {
|
2022-05-05 09:20:27 +08:00
|
|
|
padding: `${token.padding * 2}px ${token.padding * 2}px ${token.paddingLG}px`,
|
2022-04-29 09:21:43 +08:00
|
|
|
},
|
|
|
|
[`${confirmComponentCls}-body-wrapper`]: {
|
|
|
|
...clearFix(),
|
|
|
|
},
|
|
|
|
[`${confirmComponentCls}-body`]: {
|
2022-05-13 14:33:50 +08:00
|
|
|
display: 'flex',
|
|
|
|
flexWrap: 'wrap',
|
|
|
|
alignItems: 'center',
|
|
|
|
|
2022-04-29 09:21:43 +08:00
|
|
|
[`${confirmComponentCls}-title`]: {
|
2022-05-13 14:33:50 +08:00
|
|
|
flex: 1,
|
2022-04-29 09:21:43 +08:00
|
|
|
display: 'block',
|
|
|
|
// create BFC to avoid
|
|
|
|
// https://user-images.githubusercontent.com/507615/37702510-ba844e06-2d2d-11e8-9b67-8e19be57f445.png
|
|
|
|
overflow: 'hidden',
|
|
|
|
color: token.colorTextHeading,
|
2022-05-13 14:33:50 +08:00
|
|
|
fontWeight: token.fontWeightStrong,
|
|
|
|
fontSize: token.modalHeaderTitleFontSize,
|
|
|
|
lineHeight: token.modalHeaderTitleLineHeight,
|
2022-04-29 09:21:43 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`${confirmComponentCls}-content`]: {
|
|
|
|
marginTop: token.marginXS,
|
|
|
|
color: token.colorText,
|
|
|
|
fontSize: token.fontSizeBase,
|
2022-05-13 14:33:50 +08:00
|
|
|
flexBasis: '100%',
|
2022-04-29 09:21:43 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`> ${token.iconCls}`]: {
|
2022-05-13 14:33:50 +08:00
|
|
|
flex: 'none',
|
2022-04-29 09:21:43 +08:00
|
|
|
marginInlineEnd: token.margin,
|
2022-05-13 14:33:50 +08:00
|
|
|
fontSize: token.modalConfirmIconSize,
|
2022-04-29 09:21:43 +08:00
|
|
|
|
|
|
|
// `content` after `icon` should set marginLeft
|
|
|
|
[`+ ${confirmComponentCls}-title + ${confirmComponentCls}-content`]: {
|
2022-05-13 14:33:50 +08:00
|
|
|
marginInlineStart: token.modalConfirmIconSize + token.margin,
|
2022-04-29 09:21:43 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[`${confirmComponentCls}-btns`]: {
|
2022-05-13 14:33:50 +08:00
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'flex-end',
|
2022-04-29 09:21:43 +08:00
|
|
|
marginTop: token.marginLG,
|
|
|
|
|
|
|
|
[`${token.antCls}-btn + ${token.antCls}-btn`]: {
|
|
|
|
marginBottom: 0,
|
|
|
|
marginInlineStart: token.marginXS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${confirmComponentCls}-error ${confirmComponentCls}-body > ${token.iconCls}`]: {
|
|
|
|
color: token.colorError,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${confirmComponentCls}-warning ${confirmComponentCls}-body > ${token.iconCls},
|
|
|
|
${confirmComponentCls}-confirm ${confirmComponentCls}-body > ${token.iconCls}`]: {
|
|
|
|
color: token.colorWarning,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${confirmComponentCls}-info ${confirmComponentCls}-body > ${token.iconCls}`]: {
|
|
|
|
color: token.colorInfo,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${confirmComponentCls}-success ${confirmComponentCls}-body > ${token.iconCls}`]: {
|
|
|
|
color: token.colorSuccess,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-05-02 10:46:36 +08:00
|
|
|
const genRTLStyle: GenerateStyle<ModalToken> = token => {
|
|
|
|
const { componentCls } = token;
|
|
|
|
return {
|
|
|
|
[`${componentCls}-root`]: {
|
|
|
|
[`${componentCls}-wrap-rtl`]: {
|
|
|
|
direction: 'rtl',
|
|
|
|
|
|
|
|
[`${componentCls}-confirm-body`]: {
|
2022-05-13 14:33:50 +08:00
|
|
|
direction: 'rtl',
|
2022-05-02 10:46:36 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-04-26 22:45:39 +08:00
|
|
|
// ============================== Export ==============================
|
|
|
|
export default genComponentStyleHook('Modal', token => {
|
2022-05-13 14:33:50 +08:00
|
|
|
const headerPaddingVertical = token.padding;
|
|
|
|
const headerFontSize = token.fontSizeHeading5;
|
|
|
|
const headerLineHeight = token.lineHeightHeading5;
|
|
|
|
|
2022-04-26 22:45:39 +08:00
|
|
|
const modalToken = mergeToken<ModalToken>(token, {
|
|
|
|
modalBodyPadding: token.paddingLG,
|
|
|
|
modalHeaderBg: token.colorBgComponent,
|
2022-05-13 14:33:50 +08:00
|
|
|
modalHeaderPadding: `${headerPaddingVertical}px ${token.paddingLG}px`,
|
2022-04-26 22:45:39 +08:00
|
|
|
modalHeaderBorderWidth: token.controlLineWidth,
|
|
|
|
modalHeaderBorderStyle: token.controlLineType,
|
2022-05-13 14:33:50 +08:00
|
|
|
modalHeaderTitleLineHeight: headerLineHeight,
|
|
|
|
modalHeaderTitleFontSize: headerFontSize,
|
2022-04-26 22:45:39 +08:00
|
|
|
modalHeaderBorderColorSplit: token.colorSplit,
|
2022-05-13 14:33:50 +08:00
|
|
|
modalHeaderCloseSize: headerLineHeight * headerFontSize + headerPaddingVertical * 2,
|
2022-04-26 22:45:39 +08:00
|
|
|
modalContentBg: token.colorBgComponent,
|
|
|
|
modalHeadingColor: token.colorTextHeading,
|
|
|
|
modalCloseColor: token.colorTextSecondary,
|
|
|
|
modalFooterBg: 'transparent',
|
|
|
|
modalFooterBorderColorSplit: token.colorSplit,
|
|
|
|
modalFooterBorderStyle: token.controlLineType,
|
2022-05-13 14:33:50 +08:00
|
|
|
modalFooterPaddingVertical: token.paddingXS,
|
2022-04-26 22:45:39 +08:00
|
|
|
modalFooterPaddingHorizontal: token.padding,
|
|
|
|
modalFooterBorderWidth: token.controlLineWidth,
|
|
|
|
modalConfirmTitleFontSize: token.fontSizeLG,
|
2022-05-13 14:33:50 +08:00
|
|
|
modalIconHoverColor: token.colorActionHover,
|
|
|
|
modalConfirmIconSize: token.fontSize * token.lineHeight,
|
2022-04-26 22:45:39 +08:00
|
|
|
});
|
2022-05-02 10:46:36 +08:00
|
|
|
return [genModalStyle(modalToken), genModalConfirmStyle(modalToken), genRTLStyle(modalToken)];
|
2022-04-26 22:45:39 +08:00
|
|
|
});
|