feat: apply new input component border style (#45009)

* feat: apply new input component border style

* feat: ColorPicker & DatePicker

* chore: fix lint
This commit is contained in:
MadCcc 2023-09-22 13:55:54 +08:00 committed by GitHub
parent 081b33d7b8
commit 431e00b1d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 77 deletions

View File

@ -20,9 +20,9 @@ export interface ColorPickerToken extends FullToken<'ColorPicker'> {
colorPickerPresetColorSize: number; colorPickerPresetColorSize: number;
} }
export const genActiveStyle = (token: ColorPickerToken) => ({ export const genActiveStyle = (token: ColorPickerToken, borderColor: string) => ({
boxShadow: `0 0 0 ${token.controlOutlineWidth}px ${token.controlOutline}`,
borderInlineEndWidth: token.lineWidth, borderInlineEndWidth: token.lineWidth,
borderColor,
outline: 0, outline: 0,
}); });
@ -78,40 +78,24 @@ const genClearStyle = (
}; };
const genStatusStyle = (token: ColorPickerToken): CSSObject => { const genStatusStyle = (token: ColorPickerToken): CSSObject => {
const { const { componentCls, colorError, colorWarning, colorErrorHover, colorWarningHover } = token;
componentCls,
colorError,
colorWarning,
colorErrorBorderHover,
colorWarningBorderHover,
colorErrorOutline,
colorWarningOutline,
} = token;
return { return {
[`&${componentCls}-status-error`]: { [`&${componentCls}-status-error`]: {
borderColor: colorError, borderColor: colorError,
'&:hover': { '&:hover': {
borderColor: colorErrorBorderHover, borderColor: colorErrorHover,
}, },
[`&${componentCls}-trigger-active`]: { [`&${componentCls}-trigger-active`]: {
...genActiveStyle( ...genActiveStyle(token, colorError),
mergeToken<ColorPickerToken>(token, {
controlOutline: colorErrorOutline,
}),
),
}, },
}, },
[`&${componentCls}-status-warning`]: { [`&${componentCls}-status-warning`]: {
borderColor: colorWarning, borderColor: colorWarning,
'&:hover': { '&:hover': {
borderColor: colorWarningBorderHover, borderColor: colorWarningHover,
}, },
[`&${componentCls}-trigger-active`]: { [`&${componentCls}-trigger-active`]: {
...genActiveStyle( ...genActiveStyle(token, colorWarning),
mergeToken<ColorPickerToken>(token, {
controlOutline: colorWarningOutline,
}),
),
}, },
}, },
}; };
@ -178,6 +162,7 @@ const genColorPickerStyle: GenerateStyle<ColorPickerToken> = (token) => {
colorBorder, colorBorder,
paddingXXS, paddingXXS,
fontSize, fontSize,
colorPrimaryHover,
} = token; } = token;
return [ return [
@ -221,12 +206,11 @@ const genColorPickerStyle: GenerateStyle<ColorPickerToken> = (token) => {
fontSize, fontSize,
color: colorText, color: colorText,
}, },
'&-active': {
...genActiveStyle(token),
borderColor: colorPrimary,
},
'&:hover': { '&:hover': {
borderColor: colorPrimary, borderColor: colorPrimaryHover,
},
[`&${componentCls}-trigger-active`]: {
...genActiveStyle(token, colorPrimary),
}, },
'&-disabled': { '&-disabled': {
color: colorTextDisabled, color: colorTextDisabled,

View File

@ -996,14 +996,18 @@ const genPickerStatusStyle: GenerateStyle<PickerToken> = (token) => {
errorActiveShadow, errorActiveShadow,
colorWarning, colorWarning,
warningActiveShadow, warningActiveShadow,
colorErrorHover,
colorWarningHover,
} = token; } = token;
return { return {
[`${componentCls}:not(${componentCls}-disabled)`]: { [`${componentCls}:not(${componentCls}-disabled):not([disabled])`]: {
[`&${componentCls}-status-error`]: { [`&${componentCls}-status-error`]: {
'&, &:not([disabled]):hover': { backgroundColor: colorBgContainer,
backgroundColor: colorBgContainer, borderColor: colorError,
borderColor: colorError,
'&:hover': {
borderColor: colorErrorHover,
}, },
[`&${componentCls}-focused, &:focus`]: { [`&${componentCls}-focused, &:focus`]: {
@ -1021,9 +1025,11 @@ const genPickerStatusStyle: GenerateStyle<PickerToken> = (token) => {
}, },
[`&${componentCls}-status-warning`]: { [`&${componentCls}-status-warning`]: {
'&, &:not([disabled]):hover': { backgroundColor: colorBgContainer,
backgroundColor: colorBgContainer, borderColor: colorWarning,
borderColor: colorWarning,
'&:hover': {
borderColor: colorWarningHover,
}, },
[`&${componentCls}-focused, &:focus`]: { [`&${componentCls}-focused, &:focus`]: {
@ -1105,11 +1111,11 @@ const genPickerStyle: GenerateStyle<PickerToken> = (token) => {
borderRadius, borderRadius,
transition: `border ${motionDurationMid}, box-shadow ${motionDurationMid}`, transition: `border ${motionDurationMid}, box-shadow ${motionDurationMid}`,
'&:hover, &-focused': { '&:hover': {
...genHoverStyle(token), ...genHoverStyle(token),
}, },
'&-focused': { [`&-focused${componentCls}`]: {
...genActiveStyle(token), ...genActiveStyle(token),
}, },

View File

@ -1,14 +1,12 @@
import type { SharedInputToken, SharedComponentToken } from '../../input/style'; import type { SharedComponentToken, SharedInputToken } from '../../input/style';
import { import {
initComponentToken,
initInputToken,
genActiveStyle,
genBasicInputStyle, genBasicInputStyle,
genDisabledStyle, genDisabledStyle,
genHoverStyle,
genInputGroupStyle, genInputGroupStyle,
genPlaceholderStyle, genPlaceholderStyle,
genStatusStyle, genStatusStyle,
initComponentToken,
initInputToken,
} from '../../input/style'; } from '../../input/style';
import { resetComponent, resetIcon } from '../../style'; import { resetComponent, resetIcon } from '../../style';
import { genCompactItemStyle } from '../../style/compact-item'; import { genCompactItemStyle } from '../../style/compact-item';
@ -151,14 +149,6 @@ const genInputNumberStyles: GenerateStyle<InputNumberToken> = (token: InputNumbe
}, },
}, },
'&:hover': {
...genHoverStyle(token),
},
'&-focused': {
...genActiveStyle(token),
},
// ===================== Out Of Range ===================== // ===================== Out Of Range =====================
'&-out-of-range': { '&-out-of-range': {
[`${componentCls}-input-wrap`]: { [`${componentCls}-input-wrap`]: {
@ -395,7 +385,6 @@ const genAffixWrapperStyles: GenerateStyle<InputNumberToken> = (token: InputNumb
}, },
[`&:not(${componentCls}-affix-wrapper-disabled):hover`]: { [`&:not(${componentCls}-affix-wrapper-disabled):hover`]: {
...genHoverStyle(token),
zIndex: 1, zIndex: 1,
}, },

View File

@ -121,7 +121,12 @@ export const genDisabledStyle = (token: InputToken): CSSObject => ({
opacity: 1, opacity: 1,
'&:hover': { '&:hover': {
...genHoverStyle(mergeToken<InputToken>(token, { hoverBorderColor: token.colorBorder })), ...genHoverStyle(
mergeToken<InputToken>(token, {
hoverBorderColor: token.colorBorder,
hoverBg: token.colorBgContainerDisabled,
}),
),
}, },
}); });
@ -160,7 +165,7 @@ export const genStatusStyle = (token: InputToken, parentCls: string): CSSObject
borderColor: colorErrorBorderHover, borderColor: colorErrorBorderHover,
}, },
'&:focus, &-focused': { '&:focus, &:focus-within': {
...genActiveStyle( ...genActiveStyle(
mergeToken<InputToken>(token, { mergeToken<InputToken>(token, {
activeBorderColor: colorError, activeBorderColor: colorError,
@ -180,7 +185,7 @@ export const genStatusStyle = (token: InputToken, parentCls: string): CSSObject
borderColor: colorWarningBorderHover, borderColor: colorWarningBorderHover,
}, },
'&:focus, &-focused': { '&:focus, &:focus-within': {
...genActiveStyle( ...genActiveStyle(
mergeToken<InputToken>(token, { mergeToken<InputToken>(token, {
activeBorderColor: colorWarning, activeBorderColor: colorWarning,
@ -217,7 +222,7 @@ export const genBasicInputStyle = (token: InputToken): CSSObject => ({
...genHoverStyle(token), ...genHoverStyle(token),
}, },
'&:focus, &-focused': { '&:focus, &:focus-within': {
...genActiveStyle(token), ...genActiveStyle(token),
}, },
@ -647,7 +652,6 @@ const genAffixStyle: GenerateStyle<InputToken> = (token: InputToken) => {
display: 'inline-flex', display: 'inline-flex',
[`&:not(${componentCls}-affix-wrapper-disabled):hover`]: { [`&:not(${componentCls}-affix-wrapper-disabled):hover`]: {
...genHoverStyle(token),
zIndex: 1, zIndex: 1,
[`${componentCls}-search-with-button &`]: { [`${componentCls}-search-with-button &`]: {
zIndex: 0, zIndex: 0,
@ -1034,10 +1038,7 @@ export const initComponentToken = (token: GlobalToken): SharedComponentToken =>
controlPaddingHorizontal, controlPaddingHorizontal,
colorFillAlter, colorFillAlter,
colorPrimaryHover, colorPrimaryHover,
controlOutlineWidth, colorPrimary,
controlOutline,
colorErrorOutline,
colorWarningOutline,
} = token; } = token;
return { return {
@ -1055,11 +1056,11 @@ export const initComponentToken = (token: GlobalToken): SharedComponentToken =>
paddingInlineSM: controlPaddingHorizontalSM - lineWidth, paddingInlineSM: controlPaddingHorizontalSM - lineWidth,
paddingInlineLG: controlPaddingHorizontal - lineWidth, paddingInlineLG: controlPaddingHorizontal - lineWidth,
addonBg: colorFillAlter, addonBg: colorFillAlter,
activeBorderColor: colorPrimaryHover, activeBorderColor: colorPrimary,
hoverBorderColor: colorPrimaryHover, hoverBorderColor: colorPrimaryHover,
activeShadow: `0 0 0 ${controlOutlineWidth}px ${controlOutline}`, activeShadow: `none`,
errorActiveShadow: `0 0 0 ${controlOutlineWidth}px ${colorErrorOutline}`, errorActiveShadow: `none`,
warningActiveShadow: `0 0 0 ${controlOutlineWidth}px ${colorWarningOutline}`, warningActiveShadow: `none`,
hoverBg: 'transparent', hoverBg: 'transparent',
activeBg: 'transparent', activeBg: 'transparent',
}; };

View File

@ -160,17 +160,16 @@ const genStatusStyle = (
componentCls: string; componentCls: string;
antCls: string; antCls: string;
borderHoverColor: string; borderHoverColor: string;
outlineColor: string; borderActiveColor: string;
controlOutlineWidth: number;
}, },
overwriteDefaultBorder: boolean = false, overwriteDefaultBorder: boolean = false,
): CSSObject => { ): CSSObject => {
const { componentCls, borderHoverColor, outlineColor, antCls } = token; const { componentCls, borderHoverColor, antCls, borderActiveColor } = token;
const overwriteStyle: CSSObject = overwriteDefaultBorder const overwriteStyle: CSSObject = overwriteDefaultBorder
? { ? {
[`${componentCls}-selector`]: { [`${componentCls}-selector`]: {
borderColor: borderHoverColor, borderColor: borderActiveColor,
}, },
} }
: {}; : {};
@ -181,15 +180,14 @@ const genStatusStyle = (
{ {
...overwriteStyle, ...overwriteStyle,
[`${componentCls}-focused& ${componentCls}-selector`]: {
borderColor: borderHoverColor,
boxShadow: `0 0 0 ${token.controlOutlineWidth}px ${outlineColor}`,
outline: 0,
},
[`&:hover ${componentCls}-selector`]: { [`&:hover ${componentCls}-selector`]: {
borderColor: borderHoverColor, borderColor: borderHoverColor,
}, },
[`${componentCls}-focused& ${componentCls}-selector`]: {
borderColor: borderActiveColor,
outline: 0,
},
}, },
}, },
}; };
@ -398,14 +396,14 @@ const genSelectStyle: GenerateStyle<SelectToken> = (token) => {
componentCls, componentCls,
mergeToken<any>(token, { mergeToken<any>(token, {
borderHoverColor: token.colorPrimaryHover, borderHoverColor: token.colorPrimaryHover,
outlineColor: token.controlOutline, borderActiveColor: token.colorPrimary,
}), }),
), ),
genStatusStyle( genStatusStyle(
`${componentCls}-status-error`, `${componentCls}-status-error`,
mergeToken<any>(token, { mergeToken<any>(token, {
borderHoverColor: token.colorErrorHover, borderHoverColor: token.colorErrorHover,
outlineColor: token.colorErrorOutline, borderActiveColor: token.colorError,
}), }),
true, true,
), ),
@ -413,7 +411,7 @@ const genSelectStyle: GenerateStyle<SelectToken> = (token) => {
`${componentCls}-status-warning`, `${componentCls}-status-warning`,
mergeToken<any>(token, { mergeToken<any>(token, {
borderHoverColor: token.colorWarningHover, borderHoverColor: token.colorWarningHover,
outlineColor: token.colorWarningOutline, borderActiveColor: token.colorWarning,
}), }),
true, true,
), ),