feat: alert support cssvar
parent
3ca620a929
commit
a0c9369989
|
@ -70,7 +70,7 @@ const Alert = defineComponent({
|
||||||
props: alertProps(),
|
props: alertProps(),
|
||||||
setup(props, { slots, emit, attrs, expose }) {
|
setup(props, { slots, emit, attrs, expose }) {
|
||||||
const { prefixCls, direction } = useConfigInject('alert', props);
|
const { prefixCls, direction } = useConfigInject('alert', props);
|
||||||
const [wrapSSR, hashId] = useStyle(prefixCls);
|
const [wrapSSR, hashId, cssVarCls] = useStyle(prefixCls);
|
||||||
const closing = shallowRef(false);
|
const closing = shallowRef(false);
|
||||||
const closed = shallowRef(false);
|
const closed = shallowRef(false);
|
||||||
const alertNode = shallowRef();
|
const alertNode = shallowRef();
|
||||||
|
@ -134,6 +134,7 @@ const Alert = defineComponent({
|
||||||
[`${prefixClsValue}-closable`]: closable,
|
[`${prefixClsValue}-closable`]: closable,
|
||||||
[`${prefixClsValue}-rtl`]: direction.value === 'rtl',
|
[`${prefixClsValue}-rtl`]: direction.value === 'rtl',
|
||||||
[hashId.value]: true,
|
[hashId.value]: true,
|
||||||
|
[cssVarCls.value]: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const closeIcon = closable ? (
|
const closeIcon = closable ? (
|
||||||
|
|
|
@ -1,13 +1,29 @@
|
||||||
import type { CSSInterpolation, CSSObject } from '../../_util/cssinjs';
|
import { CSSObject, unit } from '../../_util/cssinjs';
|
||||||
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
import { FullToken, GenerateStyle, genStyleHooks, GetDefaultToken } from '../../theme/internal';
|
||||||
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
|
||||||
import { resetComponent } from '../../style';
|
import { resetComponent } from '../../style';
|
||||||
|
import { CSSProperties } from 'vue';
|
||||||
|
|
||||||
export interface ComponentToken {}
|
export interface ComponentToken {
|
||||||
|
// Component token here
|
||||||
|
/**
|
||||||
|
* @desc 默认内间距
|
||||||
|
* @descEN Default padding
|
||||||
|
*/
|
||||||
|
defaultPadding: CSSProperties['padding'];
|
||||||
|
/**
|
||||||
|
* @desc 带有描述的内间距
|
||||||
|
* @descEN Padding with description
|
||||||
|
*/
|
||||||
|
withDescriptionPadding: CSSProperties['padding'];
|
||||||
|
/**
|
||||||
|
* @desc 带有描述时的图标尺寸
|
||||||
|
* @descEN Icon size with description
|
||||||
|
*/
|
||||||
|
withDescriptionIconSize: number;
|
||||||
|
}
|
||||||
|
|
||||||
type AlertToken = FullToken<'Alert'> & {
|
type AlertToken = FullToken<'Alert'> & {
|
||||||
alertIconSizeLG: number;
|
// Custom token here
|
||||||
alertPaddingHorizontal: number;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const genAlertTypeStyle = (
|
const genAlertTypeStyle = (
|
||||||
|
@ -17,8 +33,8 @@ const genAlertTypeStyle = (
|
||||||
token: AlertToken,
|
token: AlertToken,
|
||||||
alertCls: string,
|
alertCls: string,
|
||||||
): CSSObject => ({
|
): CSSObject => ({
|
||||||
backgroundColor: bgColor,
|
background: bgColor,
|
||||||
border: `${token.lineWidth}px ${token.lineType} ${borderColor}`,
|
border: `${unit(token.lineWidth)} ${token.lineType} ${borderColor}`,
|
||||||
[`${alertCls}-icon`]: {
|
[`${alertCls}-icon`]: {
|
||||||
color: iconColor,
|
color: iconColor,
|
||||||
},
|
},
|
||||||
|
@ -35,12 +51,11 @@ export const genBaseStyle: GenerateStyle<AlertToken> = (token: AlertToken): CSSO
|
||||||
lineHeight,
|
lineHeight,
|
||||||
borderRadiusLG: borderRadius,
|
borderRadiusLG: borderRadius,
|
||||||
motionEaseInOutCirc,
|
motionEaseInOutCirc,
|
||||||
alertIconSizeLG,
|
withDescriptionIconSize,
|
||||||
colorText,
|
colorText,
|
||||||
paddingContentVerticalSM,
|
colorTextHeading,
|
||||||
alertPaddingHorizontal,
|
withDescriptionPadding,
|
||||||
paddingMD,
|
defaultPadding,
|
||||||
paddingContentHorizontalLG,
|
|
||||||
} = token;
|
} = token;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -49,7 +64,7 @@ export const genBaseStyle: GenerateStyle<AlertToken> = (token: AlertToken): CSSO
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
padding: `${paddingContentVerticalSM}px ${alertPaddingHorizontal}px`, // Fixed horizontal padding here.
|
padding: defaultPadding,
|
||||||
wordWrap: 'break-word',
|
wordWrap: 'break-word',
|
||||||
borderRadius,
|
borderRadius,
|
||||||
|
|
||||||
|
@ -67,14 +82,14 @@ export const genBaseStyle: GenerateStyle<AlertToken> = (token: AlertToken): CSSO
|
||||||
lineHeight: 0,
|
lineHeight: 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
[`&-description`]: {
|
'&-description': {
|
||||||
display: 'none',
|
display: 'none',
|
||||||
fontSize,
|
fontSize,
|
||||||
lineHeight,
|
lineHeight,
|
||||||
},
|
},
|
||||||
|
|
||||||
'&-message': {
|
'&-message': {
|
||||||
color: colorText,
|
color: colorTextHeading,
|
||||||
},
|
},
|
||||||
|
|
||||||
[`&${componentCls}-motion-leave`]: {
|
[`&${componentCls}-motion-leave`]: {
|
||||||
|
@ -96,24 +111,23 @@ export const genBaseStyle: GenerateStyle<AlertToken> = (token: AlertToken): CSSO
|
||||||
|
|
||||||
[`${componentCls}-with-description`]: {
|
[`${componentCls}-with-description`]: {
|
||||||
alignItems: 'flex-start',
|
alignItems: 'flex-start',
|
||||||
paddingInline: paddingContentHorizontalLG,
|
padding: withDescriptionPadding,
|
||||||
paddingBlock: paddingMD,
|
|
||||||
|
|
||||||
[`${componentCls}-icon`]: {
|
[`${componentCls}-icon`]: {
|
||||||
marginInlineEnd: marginSM,
|
marginInlineEnd: marginSM,
|
||||||
fontSize: alertIconSizeLG,
|
fontSize: withDescriptionIconSize,
|
||||||
lineHeight: 0,
|
lineHeight: 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
[`${componentCls}-message`]: {
|
[`${componentCls}-message`]: {
|
||||||
display: 'block',
|
display: 'block',
|
||||||
marginBottom: marginXS,
|
marginBottom: marginXS,
|
||||||
color: colorText,
|
color: colorTextHeading,
|
||||||
fontSize: fontSizeLG,
|
fontSize: fontSizeLG,
|
||||||
},
|
},
|
||||||
|
|
||||||
[`${componentCls}-description`]: {
|
[`${componentCls}-description`]: {
|
||||||
display: 'block',
|
display: 'block',
|
||||||
|
color: colorText,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -187,7 +201,7 @@ export const genActionStyle: GenerateStyle<AlertToken> = (token: AlertToken): CS
|
||||||
|
|
||||||
return {
|
return {
|
||||||
[componentCls]: {
|
[componentCls]: {
|
||||||
[`&-action`]: {
|
'&-action': {
|
||||||
marginInlineStart: marginXS,
|
marginInlineStart: marginXS,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -196,7 +210,7 @@ export const genActionStyle: GenerateStyle<AlertToken> = (token: AlertToken): CS
|
||||||
padding: 0,
|
padding: 0,
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
fontSize: fontSizeIcon,
|
fontSize: fontSizeIcon,
|
||||||
lineHeight: `${fontSizeIcon}px`,
|
lineHeight: unit(fontSizeIcon),
|
||||||
backgroundColor: 'transparent',
|
backgroundColor: 'transparent',
|
||||||
border: 'none',
|
border: 'none',
|
||||||
outline: 'none',
|
outline: 'none',
|
||||||
|
@ -222,19 +236,17 @@ export const genActionStyle: GenerateStyle<AlertToken> = (token: AlertToken): CS
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const genAlertStyle: GenerateStyle<AlertToken> = (token: AlertToken): CSSInterpolation => [
|
export const prepareComponentToken: GetDefaultToken<'Alert'> = token => {
|
||||||
genBaseStyle(token),
|
const paddingHorizontal = 12; // Fixed value here.
|
||||||
genTypeStyle(token),
|
return {
|
||||||
genActionStyle(token),
|
withDescriptionIconSize: token.fontSizeHeading3,
|
||||||
];
|
defaultPadding: `${token.paddingContentVerticalSM}px ${paddingHorizontal}px`,
|
||||||
|
withDescriptionPadding: `${token.paddingMD}px ${token.paddingContentHorizontalLG}px`,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export default genComponentStyleHook('Alert', token => {
|
export default genStyleHooks(
|
||||||
const { fontSizeHeading3 } = token;
|
'Alert',
|
||||||
|
token => [genBaseStyle(token), genTypeStyle(token), genActionStyle(token)],
|
||||||
const alertToken = mergeToken<AlertToken>(token, {
|
prepareComponentToken,
|
||||||
alertIconSizeLG: fontSizeHeading3,
|
);
|
||||||
alertPaddingHorizontal: 12, // Fixed value here.
|
|
||||||
});
|
|
||||||
|
|
||||||
return [genAlertStyle(alertToken)];
|
|
||||||
});
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import type { App } from 'vue';
|
||||||
|
|
||||||
import * as components from './components';
|
import * as components from './components';
|
||||||
import { default as version } from './version';
|
import { default as version } from './version';
|
||||||
import cssinjs from './_util/cssinjs';
|
import * as cssinjs from './_util/cssinjs';
|
||||||
export * from './components';
|
export * from './components';
|
||||||
export * from './_util/cssinjs';
|
export * from './_util/cssinjs';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue