refactor(input): update input style (#2876)
* refactor(input): update input style * refactor(form): update form style about input component * refactor(input): update clearable icon style Modify the clearable icon style to prevent the width of the input box from changing due to the insertion of the iconpull/2927/head
parent
51fb7cd888
commit
ca2c77e4bd
|
@ -136,23 +136,11 @@
|
||||||
|
|
||||||
form {
|
form {
|
||||||
.has-feedback {
|
.has-feedback {
|
||||||
.@{ant-prefix}-input {
|
|
||||||
padding-right: @input-padding-horizontal-base + @input-affix-width;
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/ant-design/ant-design/issues/19884
|
// https://github.com/ant-design/ant-design/issues/19884
|
||||||
.@{ant-prefix}-input-affix-wrapper {
|
.@{ant-prefix}-input-affix-wrapper {
|
||||||
.@{ant-prefix}-input-suffix {
|
.@{ant-prefix}-input-suffix {
|
||||||
padding-right: 18px;
|
padding-right: 18px;
|
||||||
}
|
}
|
||||||
.@{ant-prefix}-input {
|
|
||||||
padding-right: @input-padding-horizontal-base + @input-affix-width * 2;
|
|
||||||
}
|
|
||||||
&.@{ant-prefix}-input-affix-wrapper-input-with-clear-btn {
|
|
||||||
.@{ant-prefix}-input {
|
|
||||||
padding-right: @input-padding-horizontal-base + @input-affix-width * 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix overlapping between feedback icon and <Select>'s arrow.
|
// Fix overlapping between feedback icon and <Select>'s arrow.
|
||||||
|
|
|
@ -33,25 +33,30 @@ const ClearableLabeledInput = {
|
||||||
addonBefore: PropTypes.any,
|
addonBefore: PropTypes.any,
|
||||||
addonAfter: PropTypes.any,
|
addonAfter: PropTypes.any,
|
||||||
readonly: PropTypes.bool,
|
readonly: PropTypes.bool,
|
||||||
|
isFocused: PropTypes.bool,
|
||||||
|
style: PropTypes.object,
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
renderClearIcon(prefixCls) {
|
renderClearIcon(prefixCls) {
|
||||||
const { allowClear, value, disabled, readonly, inputType, handleReset } = this.$props;
|
const { allowClear, value, disabled, readonly, inputType, handleReset } = this.$props;
|
||||||
if (
|
if (!allowClear) {
|
||||||
!allowClear ||
|
|
||||||
disabled ||
|
|
||||||
readonly ||
|
|
||||||
value === undefined ||
|
|
||||||
value === null ||
|
|
||||||
value === ''
|
|
||||||
) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
const showClearIcon =
|
||||||
|
!disabled && !readonly && value !== undefined && value !== null && value !== '';
|
||||||
const className =
|
const className =
|
||||||
inputType === ClearableInputType[0]
|
inputType === ClearableInputType[0]
|
||||||
? `${prefixCls}-textarea-clear-icon`
|
? `${prefixCls}-textarea-clear-icon`
|
||||||
: `${prefixCls}-clear-icon`;
|
: `${prefixCls}-clear-icon`;
|
||||||
return <CloseCircleFilled onClick={handleReset} class={className} role="button" />;
|
return (
|
||||||
|
<CloseCircleFilled
|
||||||
|
onClick={handleReset}
|
||||||
|
class={classNames(className, {
|
||||||
|
[`${className}-hidden`]: !showClearIcon,
|
||||||
|
})}
|
||||||
|
role="button"
|
||||||
|
/>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
renderSuffix(prefixCls) {
|
renderSuffix(prefixCls) {
|
||||||
|
@ -81,12 +86,13 @@ const ClearableLabeledInput = {
|
||||||
) : null;
|
) : null;
|
||||||
|
|
||||||
const affixWrapperCls = classNames(this.$attrs?.class, `${prefixCls}-affix-wrapper`, {
|
const affixWrapperCls = classNames(this.$attrs?.class, `${prefixCls}-affix-wrapper`, {
|
||||||
|
[`${prefixCls}-affix-wrapper-focused`]: props.isFocused,
|
||||||
|
[`${prefixCls}-affix-wrapper-disabled`]: props.disabled,
|
||||||
[`${prefixCls}-affix-wrapper-sm`]: props.size === 'small',
|
[`${prefixCls}-affix-wrapper-sm`]: props.size === 'small',
|
||||||
[`${prefixCls}-affix-wrapper-lg`]: props.size === 'large',
|
[`${prefixCls}-affix-wrapper-lg`]: props.size === 'large',
|
||||||
[`${prefixCls}-affix-wrapper-input-with-clear-btn`]:
|
[`${prefixCls}-affix-wrapper-input-with-clear-btn`]:
|
||||||
props.suffix && props.allowClear && this.$props.value,
|
props.suffix && props.allowClear && this.$props.value,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span class={affixWrapperCls} style={props.style}>
|
<span class={affixWrapperCls} style={props.style}>
|
||||||
{prefix}
|
{prefix}
|
||||||
|
|
|
@ -64,6 +64,7 @@ export default {
|
||||||
const value = typeof props.value === 'undefined' ? props.defaultValue : props.value;
|
const value = typeof props.value === 'undefined' ? props.defaultValue : props.value;
|
||||||
return {
|
return {
|
||||||
stateValue: typeof value === 'undefined' ? '' : value,
|
stateValue: typeof value === 'undefined' ? '' : value,
|
||||||
|
isFocused: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -87,6 +88,16 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
handleInputFocus(e) {
|
||||||
|
this.isFocused = true;
|
||||||
|
this.onFocus && this.onFocus(e);
|
||||||
|
},
|
||||||
|
|
||||||
|
handleInputBlur(e) {
|
||||||
|
this.isFocused = false;
|
||||||
|
this.onBlur && this.onBlur(e);
|
||||||
|
},
|
||||||
|
|
||||||
focus() {
|
focus() {
|
||||||
this.input.focus();
|
this.input.focus();
|
||||||
},
|
},
|
||||||
|
@ -147,7 +158,15 @@ export default {
|
||||||
'inputPrefixCls',
|
'inputPrefixCls',
|
||||||
'loading',
|
'loading',
|
||||||
]);
|
]);
|
||||||
const { handleKeyDown, handleChange, size, disabled, $attrs } = this;
|
const {
|
||||||
|
handleKeyDown,
|
||||||
|
handleChange,
|
||||||
|
handleInputFocus,
|
||||||
|
handleInputBlur,
|
||||||
|
size,
|
||||||
|
disabled,
|
||||||
|
$attrs,
|
||||||
|
} = this;
|
||||||
|
|
||||||
const inputProps = {
|
const inputProps = {
|
||||||
...otherProps,
|
...otherProps,
|
||||||
|
@ -160,6 +179,8 @@ export default {
|
||||||
key: 'ant-input',
|
key: 'ant-input',
|
||||||
onInput: handleChange,
|
onInput: handleChange,
|
||||||
onChange: handleChange,
|
onChange: handleChange,
|
||||||
|
onFocus: handleInputFocus,
|
||||||
|
onBlur: handleInputBlur,
|
||||||
};
|
};
|
||||||
if (!inputProps.autofocus) {
|
if (!inputProps.autofocus) {
|
||||||
delete inputProps.autofocus;
|
delete inputProps.autofocus;
|
||||||
|
@ -205,7 +226,7 @@ export default {
|
||||||
// return <TextArea {...textareaProps} ref="input" />;
|
// return <TextArea {...textareaProps} ref="input" />;
|
||||||
// }
|
// }
|
||||||
const { prefixCls: customizePrefixCls } = this.$props;
|
const { prefixCls: customizePrefixCls } = this.$props;
|
||||||
const { stateValue } = this.$data;
|
const { stateValue, isFocused } = this.$data;
|
||||||
const getPrefixCls = this.configProvider.getPrefixCls;
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||||
const prefixCls = getPrefixCls('input', customizePrefixCls);
|
const prefixCls = getPrefixCls('input', customizePrefixCls);
|
||||||
const addonAfter = getComponent(this, 'addonAfter');
|
const addonAfter = getComponent(this, 'addonAfter');
|
||||||
|
@ -224,6 +245,7 @@ export default {
|
||||||
addonBefore,
|
addonBefore,
|
||||||
suffix,
|
suffix,
|
||||||
prefix,
|
prefix,
|
||||||
|
isFocused,
|
||||||
};
|
};
|
||||||
return <ClearableLabeledInput {...props} ref={this.saveClearableInput} />;
|
return <ClearableLabeledInput {...props} ref={this.saveClearableInput} />;
|
||||||
},
|
},
|
||||||
|
|
|
@ -41,6 +41,14 @@
|
||||||
vertical-align: 0;
|
vertical-align: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-input-clear-icon-hidden {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-input-textarea-clear-icon-hidden {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
.@{ant-prefix}-input-textarea-clear-icon {
|
.@{ant-prefix}-input-textarea-clear-icon {
|
||||||
.clear-icon;
|
.clear-icon;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
@import '../../style/themes/index';
|
@import '../../style/themes/index';
|
||||||
@import '../../style/mixins/index';
|
@import '../../style/mixins/index';
|
||||||
|
|
||||||
|
@input-affix-margin: 4px;
|
||||||
@input-affix-width: 19px;
|
@input-affix-width: 19px;
|
||||||
@input-affix-with-clear-btn-width: 38px;
|
@input-affix-with-clear-btn-width: 38px;
|
||||||
|
|
||||||
// size mixins for input
|
// size mixins for input
|
||||||
.input-lg() {
|
.input-lg() {
|
||||||
height: @input-height-lg;
|
|
||||||
padding: @input-padding-vertical-lg @input-padding-horizontal-lg;
|
padding: @input-padding-vertical-lg @input-padding-horizontal-lg;
|
||||||
font-size: @font-size-lg;
|
font-size: @font-size-lg;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-sm() {
|
.input-sm() {
|
||||||
height: @input-height-sm;
|
|
||||||
padding: @input-padding-vertical-sm @input-padding-horizontal-sm;
|
padding: @input-padding-vertical-sm @input-padding-horizontal-sm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +46,6 @@
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: @input-height-base;
|
|
||||||
padding: @input-padding-vertical-base @input-padding-horizontal-base;
|
padding: @input-padding-vertical-base @input-padding-horizontal-base;
|
||||||
color: @input-color;
|
color: @input-color;
|
||||||
font-size: @font-size-base;
|
font-size: @font-size-base;
|
||||||
|
@ -264,12 +262,6 @@
|
||||||
height: @input-height-sm;
|
height: @input-height-sm;
|
||||||
}
|
}
|
||||||
|
|
||||||
.@{inputClass}-affix-wrapper {
|
|
||||||
display: table-cell;
|
|
||||||
float: left;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
&&-compact {
|
&&-compact {
|
||||||
display: block;
|
display: block;
|
||||||
.clearfix;
|
.clearfix;
|
||||||
|
@ -297,6 +289,10 @@
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
& > .@{inputClass}-affix-wrapper {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
|
|
||||||
& > *:not(:last-child) {
|
& > *:not(:last-child) {
|
||||||
margin-right: -@border-width-base;
|
margin-right: -@border-width-base;
|
||||||
border-right-width: @border-width-base;
|
border-right-width: @border-width-base;
|
||||||
|
@ -364,17 +360,44 @@
|
||||||
|
|
||||||
.input-affix-wrapper(@inputClass) {
|
.input-affix-wrapper(@inputClass) {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-flex;
|
||||||
|
border: @border-width-base @border-style-base @input-border-color;
|
||||||
|
border-radius: @border-radius-base;
|
||||||
|
padding: @input-padding-vertical-base @input-padding-horizontal-base;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
text-align: start;
|
text-align: start;
|
||||||
|
|
||||||
&:hover .@{inputClass}:not(.@{inputClass}-disabled) {
|
&:hover {
|
||||||
.hover();
|
.hover();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&-disabled {
|
||||||
|
.disabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
&-focused {
|
||||||
|
.active();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size
|
||||||
|
&-lg {
|
||||||
|
.input-lg();
|
||||||
|
}
|
||||||
|
|
||||||
|
&-sm {
|
||||||
|
.input-sm();
|
||||||
|
}
|
||||||
|
|
||||||
.@{inputClass} {
|
.@{inputClass} {
|
||||||
position: relative;
|
position: relative;
|
||||||
text-align: inherit;
|
text-align: inherit;
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
&:focus {
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should not break align of icon & text
|
// Should not break align of icon & text
|
||||||
|
@ -385,14 +408,10 @@
|
||||||
// https://codesandbox.io/embed/nifty-benz-gb7ml
|
// https://codesandbox.io/embed/nifty-benz-gb7ml
|
||||||
.@{inputClass}-prefix,
|
.@{inputClass}-prefix,
|
||||||
.@{inputClass}-suffix {
|
.@{inputClass}-suffix {
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
z-index: 2;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
color: @input-color;
|
color: @input-color;
|
||||||
line-height: 0;
|
white-space: nowrap;
|
||||||
transform: translateY(-50%);
|
|
||||||
|
|
||||||
:not(.anticon) {
|
:not(.anticon) {
|
||||||
line-height: @line-height-base;
|
line-height: @line-height-base;
|
||||||
|
@ -407,27 +426,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.@{inputClass}-prefix {
|
.@{inputClass}-prefix {
|
||||||
left: @input-padding-horizontal-base + 1px;
|
margin-right: @input-affix-margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
.@{inputClass}-suffix {
|
.@{inputClass}-suffix {
|
||||||
right: @input-padding-horizontal-base + 1px;
|
margin-left: @input-affix-margin;
|
||||||
}
|
|
||||||
|
|
||||||
.@{inputClass}:not(:first-child) {
|
|
||||||
padding-left: @input-padding-horizontal-base + @input-affix-width;
|
|
||||||
}
|
|
||||||
|
|
||||||
.@{inputClass}:not(:last-child) {
|
|
||||||
padding-right: @input-padding-horizontal-base + @input-affix-width;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.@{inputClass}-affix-wrapper-input-with-clear-btn .@{inputClass}:not(:last-child) {
|
|
||||||
padding-right: @input-padding-horizontal-base + @input-affix-with-clear-btn-width;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.@{inputClass}-affix-wrapper-textarea-with-clear-btn .@{inputClass} {
|
|
||||||
padding-right: 22px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,7 +441,7 @@
|
||||||
// https://codesandbox.io/s/wizardly-sun-u10br
|
// https://codesandbox.io/s/wizardly-sun-u10br
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: color 0.3s;
|
transition: color 0.3s;
|
||||||
|
margin: 0 @input-affix-margin;
|
||||||
&:hover {
|
&:hover {
|
||||||
color: @text-color-secondary;
|
color: @text-color-secondary;
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,7 +318,7 @@
|
||||||
@input-padding-horizontal-lg: @input-padding-horizontal;
|
@input-padding-horizontal-lg: @input-padding-horizontal;
|
||||||
@input-padding-vertical-base: 4px;
|
@input-padding-vertical-base: 4px;
|
||||||
@input-padding-vertical-sm: 1px;
|
@input-padding-vertical-sm: 1px;
|
||||||
@input-padding-vertical-lg: 6px;
|
@input-padding-vertical-lg: 6.5px;
|
||||||
@input-placeholder-color: hsv(0, 0, 75%);
|
@input-placeholder-color: hsv(0, 0, 75%);
|
||||||
@input-color: @text-color;
|
@input-color: @text-color;
|
||||||
@input-border-color: @border-color-base;
|
@input-border-color: @border-color-base;
|
||||||
|
|
Loading…
Reference in New Issue