You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
858 lines
22 KiB
858 lines
22 KiB
// deps-lint-skip-all
|
|
import { CSSObject } from '@ant-design/cssinjs';
|
|
import { clearFix, genComponentStyleHook, GenerateStyle, resetComponent } from '../../_util/theme';
|
|
import type { FullToken } from '../../_util/theme';
|
|
import type { GlobalToken } from '../../_util/theme/interface';
|
|
|
|
export type InputToken<T extends GlobalToken = FullToken<'Input'>> = T & {
|
|
inputAffixPadding: number;
|
|
inputPaddingVertical: number;
|
|
inputPaddingVerticalLG: number;
|
|
inputPaddingVerticalSM: number;
|
|
inputPaddingHorizontal: number;
|
|
inputPaddingHorizontalSM: number;
|
|
inputBorderHoverColor: string;
|
|
inputBorderActiveColor: string;
|
|
};
|
|
|
|
export const genPlaceholderStyle = (color: string): CSSObject => ({
|
|
// Firefox
|
|
'&::-moz-placeholder': {
|
|
opacity: 1,
|
|
},
|
|
'&::placeholder': {
|
|
color,
|
|
userSelect: 'none', // https://github.com/ant-design/ant-design/pull/32639
|
|
},
|
|
'&:placeholder-shown': {
|
|
textOverflow: 'ellipsis',
|
|
},
|
|
});
|
|
|
|
export const genHoverStyle = (token: InputToken): CSSObject => ({
|
|
borderColor: token.inputBorderHoverColor,
|
|
borderInlineEndWidth: token.controlLineWidth,
|
|
});
|
|
|
|
export const genActiveStyle = (token: InputToken) => ({
|
|
borderColor: token.inputBorderHoverColor,
|
|
boxShadow: `0 0 0 ${token.controlOutlineWidth}px ${token.colorPrimaryOutline}`,
|
|
borderInlineEndWidth: token.controlLineWidth,
|
|
outline: 0,
|
|
});
|
|
|
|
export const genDisabledStyle = (token: InputToken): CSSObject => ({
|
|
color: token.colorTextDisabled,
|
|
backgroundColor: token.colorBgComponentDisabled,
|
|
borderColor: token.colorBorder,
|
|
boxShadow: 'none',
|
|
cursor: 'not-allowed',
|
|
opacity: 1,
|
|
|
|
'&:hover': {
|
|
...genHoverStyle({ ...token, inputBorderHoverColor: token.colorBorder }),
|
|
},
|
|
});
|
|
|
|
const genInputLargeStyle = (token: InputToken): CSSObject => {
|
|
const { inputPaddingVerticalLG, inputPaddingHorizontal, fontSizeLG } = token;
|
|
|
|
return {
|
|
padding: `${inputPaddingVerticalLG}px ${inputPaddingHorizontal}px`,
|
|
fontSize: fontSizeLG,
|
|
};
|
|
};
|
|
|
|
export const genInputSmallStyle = (token: InputToken): CSSObject => ({
|
|
padding: `${token.inputPaddingVerticalSM}px ${token.controlPaddingHorizontalSM - 1}px`,
|
|
});
|
|
|
|
export const genStatusStyle = (token: InputToken): CSSObject => {
|
|
const { prefixCls, colorError, colorWarning, colorErrorOutline, colorWarningOutline } = token;
|
|
|
|
return {
|
|
'&-status-error:not(&-disabled):not(&-borderless)&': {
|
|
'&, &:hover': {
|
|
borderColor: colorError,
|
|
},
|
|
|
|
'&:focus, &-focused': {
|
|
...genActiveStyle({
|
|
...token,
|
|
inputBorderActiveColor: colorError,
|
|
inputBorderHoverColor: colorError,
|
|
colorPrimaryOutline: colorErrorOutline,
|
|
}),
|
|
},
|
|
|
|
[`.${prefixCls}-prefix`]: {
|
|
color: colorError,
|
|
},
|
|
},
|
|
'&-status-warning:not(&-disabled):not(&-borderless)&': {
|
|
'&, &:hover': {
|
|
borderColor: colorWarning,
|
|
},
|
|
|
|
'&:focus, &-focused': {
|
|
...genActiveStyle({
|
|
...token,
|
|
inputBorderActiveColor: colorWarning,
|
|
inputBorderHoverColor: colorWarning,
|
|
colorPrimaryOutline: colorWarningOutline,
|
|
}),
|
|
},
|
|
|
|
[`.${prefixCls}-prefix`]: {
|
|
color: colorWarning,
|
|
},
|
|
},
|
|
};
|
|
};
|
|
|
|
export const genBasicInputStyle = (token: InputToken): CSSObject => ({
|
|
position: 'relative',
|
|
display: 'inline-block',
|
|
width: '100%',
|
|
minWidth: 0,
|
|
padding: `${token.inputPaddingVertical}px ${token.inputPaddingHorizontal}px`,
|
|
color: token.colorText,
|
|
fontSize: token.fontSize,
|
|
lineHeight: token.lineHeight,
|
|
backgroundColor: token.colorBgComponent,
|
|
backgroundImage: 'none',
|
|
borderWidth: token.controlLineWidth,
|
|
borderStyle: token.controlLineType,
|
|
borderColor: token.colorBorder,
|
|
borderRadius: token.controlRadius,
|
|
transition: `all ${token.motionDurationSlow}`,
|
|
...genPlaceholderStyle(token.colorPlaceholder),
|
|
|
|
'&:hover': {
|
|
...genHoverStyle(token),
|
|
},
|
|
|
|
'&:focus, &-focused': {
|
|
...genActiveStyle(token),
|
|
},
|
|
|
|
'&-disabled, &[disabled]': {
|
|
...genDisabledStyle(token),
|
|
},
|
|
|
|
'&-borderless': {
|
|
'&, &:hover, &:focus, &-focused, &-disabled, &[disabled]': {
|
|
backgroundColor: 'transparent',
|
|
border: 'none',
|
|
boxShadow: 'none',
|
|
},
|
|
},
|
|
|
|
// Reset height for `textarea`s
|
|
'textarea&': {
|
|
maxWidth: '100%', // prevent textearea resize from coming out of its container
|
|
height: 'auto',
|
|
minHeight: token.controlHeight,
|
|
lineHeight: token.lineHeight,
|
|
verticalAlign: 'bottom',
|
|
transition: `all ${token.motionDurationSlow}, height 0s`,
|
|
},
|
|
|
|
'&-textarea': {
|
|
'&-rtl': {
|
|
direction: 'rtl',
|
|
},
|
|
},
|
|
|
|
// Size
|
|
'&-lg': {
|
|
...genInputLargeStyle(token),
|
|
},
|
|
'&-sm': {
|
|
...genInputSmallStyle(token),
|
|
},
|
|
|
|
'&-rtl': {
|
|
direction: 'rtl',
|
|
},
|
|
});
|
|
|
|
export const genInputGroupStyle = (token: InputToken): CSSObject => {
|
|
const { prefixCls } = token;
|
|
|
|
return {
|
|
position: 'relative',
|
|
display: 'table',
|
|
width: '100%',
|
|
borderCollapse: 'separate',
|
|
borderSpacing: 0,
|
|
|
|
// Undo padding and float of grid classes
|
|
[`&[class*='col-']`]: {
|
|
paddingInlineEnd: token.paddingXS,
|
|
|
|
'&:last-child': {
|
|
paddingInlineEnd: 0,
|
|
},
|
|
},
|
|
|
|
// Sizing options
|
|
[`&-lg .${prefixCls}, &-lg > .${prefixCls}-group-addon`]: {
|
|
...genInputLargeStyle(token),
|
|
},
|
|
|
|
[`&-sm .${prefixCls}, &-sm > .${prefixCls}-group-addon`]: {
|
|
...genInputSmallStyle(token),
|
|
},
|
|
|
|
// Fix https://github.com/ant-design/ant-design/issues/5754
|
|
'&-lg .ant-select-single .ant-select-selector': {
|
|
height: token.controlHeightLG,
|
|
},
|
|
|
|
'&-sm .ant-select-single .ant-select-selector': {
|
|
height: token.controlHeightSM,
|
|
},
|
|
|
|
[`> .${prefixCls}`]: {
|
|
display: 'table-cell',
|
|
|
|
'&:not(:first-child):not(:last-child)': {
|
|
borderRadius: 0,
|
|
},
|
|
},
|
|
|
|
[`.${prefixCls}-group`]: {
|
|
[`&-addon, &-wrap`]: {
|
|
display: 'table-cell',
|
|
width: 1,
|
|
whiteSpace: 'nowrap',
|
|
verticalAlign: 'middle',
|
|
|
|
'&:not(:first-child):not(:last-child)': {
|
|
borderRadius: 0,
|
|
},
|
|
},
|
|
|
|
'&-wrap > *': {
|
|
display: 'block !important',
|
|
},
|
|
|
|
'&-addon': {
|
|
position: 'relative',
|
|
padding: `0 ${token.inputPaddingHorizontal}px`,
|
|
color: token.colorText,
|
|
fontWeight: 'normal',
|
|
fontSize: token.fontSize,
|
|
textAlign: 'center',
|
|
backgroundColor: token.colorBgComponentSecondary,
|
|
border: `${token.controlLineWidth}px ${token.controlLineType} ${token.colorBorder}`,
|
|
borderRadius: token.controlRadius,
|
|
transition: `all ${token.motionDurationSlow}`,
|
|
|
|
// Reset Select's style in addon
|
|
'.ant-select': {
|
|
margin: `-${token.inputPaddingVertical + 1}px -${token.inputPaddingHorizontal}px`,
|
|
|
|
'&.ant-select-single:not(.ant-select-customize-input)': {
|
|
'.ant-select-selector': {
|
|
backgroundColor: 'inherit',
|
|
border: `${token.controlLineWidth}px ${token.controlLineType} transparent`,
|
|
boxShadow: 'none',
|
|
},
|
|
},
|
|
|
|
'&-open, &-focused': {
|
|
'.ant-select-selector': {
|
|
color: token.colorPrimary,
|
|
},
|
|
},
|
|
},
|
|
|
|
// https://github.com/ant-design/ant-design/issues/31333
|
|
'.ant-cascader-picker': {
|
|
margin: `-9px -${token.inputPaddingHorizontal}px`,
|
|
backgroundColor: 'transparent',
|
|
'.ant-cascader-input': {
|
|
textAlign: 'start',
|
|
border: 0,
|
|
boxShadow: 'none',
|
|
},
|
|
},
|
|
},
|
|
|
|
'&-addon:first-child': {
|
|
borderInlineEnd: 0,
|
|
},
|
|
|
|
'&-addon:last-child': {
|
|
borderInlineStart: 0,
|
|
},
|
|
},
|
|
|
|
[`.${prefixCls}`]: {
|
|
float: 'inline-start',
|
|
width: '100%',
|
|
marginBottom: 0,
|
|
textAlign: 'inherit',
|
|
|
|
'&:focus': {
|
|
zIndex: 1, // Fix https://gw.alipayobjects.com/zos/rmsportal/DHNpoqfMXSfrSnlZvhsJ.png
|
|
borderInlineEndWidth: 1,
|
|
},
|
|
|
|
'&:hover': {
|
|
zIndex: 1,
|
|
borderInlineEndWidth: 1,
|
|
|
|
[`.${prefixCls}-search-with-button &`]: {
|
|
zIndex: 0,
|
|
},
|
|
},
|
|
},
|
|
|
|
// Reset rounded corners
|
|
[`> .${prefixCls}:first-child, .${prefixCls}-group-addon:first-child`]: {
|
|
borderStartEndRadius: 0,
|
|
borderEndEndRadius: 0,
|
|
|
|
// Reset Select's style in addon
|
|
'.ant-select .ant-select-selector': {
|
|
borderStartEndRadius: 0,
|
|
borderEndEndRadius: 0,
|
|
},
|
|
},
|
|
|
|
[`> .${prefixCls}-affix-wrapper`]: {
|
|
[`&:not(:first-child) .${prefixCls}`]: {
|
|
borderStartStartRadius: 0,
|
|
borderEndStartRadius: 0,
|
|
},
|
|
|
|
[`&:not(:last-child) .${prefixCls}`]: {
|
|
borderStartEndRadius: 0,
|
|
borderEndEndRadius: 0,
|
|
},
|
|
},
|
|
|
|
[`> .${prefixCls}:last-child, .${prefixCls}-group-addon:last-child`]: {
|
|
borderStartStartRadius: 0,
|
|
borderEndStartRadius: 0,
|
|
|
|
// Reset Select's style in addon
|
|
'.ant-select .ant-select-selector': {
|
|
borderStartStartRadius: 0,
|
|
borderEndStartRadius: 0,
|
|
},
|
|
},
|
|
|
|
[`.${prefixCls}-affix-wrapper`]: {
|
|
'&:not(:last-child)': {
|
|
borderStartEndRadius: 0,
|
|
borderEndEndRadius: 0,
|
|
[`.${prefixCls}-search &`]: {
|
|
borderStartStartRadius: token.controlRadius,
|
|
borderEndStartRadius: token.controlRadius,
|
|
},
|
|
},
|
|
|
|
[`&:not(:first-child), .${prefixCls}-search &:not(:first-child)`]: {
|
|
borderStartStartRadius: 0,
|
|
borderEndStartRadius: 0,
|
|
},
|
|
},
|
|
|
|
'&&-compact': {
|
|
display: 'block',
|
|
...clearFix(),
|
|
|
|
[`.${prefixCls}-group-addon, .${prefixCls}-group-wrap, > .${prefixCls}`]: {
|
|
'&:not(:first-child):not(:last-child)': {
|
|
borderInlineEndWidth: token.controlLineWidth,
|
|
|
|
'&:hover': {
|
|
zIndex: 1,
|
|
},
|
|
|
|
'&:focus': {
|
|
zIndex: 1,
|
|
},
|
|
},
|
|
},
|
|
|
|
'& > *': {
|
|
display: 'inline-block',
|
|
float: 'none',
|
|
verticalAlign: 'top', // https://github.com/ant-design/ant-design-pro/issues/139
|
|
borderRadius: 0,
|
|
},
|
|
|
|
[`& > .${prefixCls}-affix-wrapper`]: {
|
|
display: 'inline-flex',
|
|
},
|
|
|
|
'& > .ant-picker-range': {
|
|
display: 'inline-flex',
|
|
},
|
|
|
|
'& > *:not(:last-child)': {
|
|
marginInlineEnd: -token.controlLineWidth,
|
|
borderInlineEndWidth: token.controlLineWidth,
|
|
},
|
|
|
|
// Undo float for .ant-input-group .ant-input
|
|
[`.${prefixCls}`]: {
|
|
float: 'none',
|
|
},
|
|