Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inputbutton): update inputbutton styles #1486

Merged
merged 5 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cascader/demos/Cascader.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const Template: Story<CascaderProps> = (props) => {
<Cascader
options={options}
overlayStyle={{ width: 240 }}
triggerProps={{ placeholder: '请选择', hidePrefix: true, style: { width: 240, textAlign: 'left' } }}
triggerProps={{ placeholder: '请选择', style: { width: 240, textAlign: 'left' } }}
size="small"
{...props}
/>
Expand Down
2 changes: 0 additions & 2 deletions src/date-picker/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const DatePicker: React.FC<DatePickerProps> = (props: DatePickerProps) =>
format: formatString,
prefix,
suffix,
hidePrefix,
size,
...restProps
} = props;
Expand Down Expand Up @@ -64,7 +63,6 @@ export const DatePicker: React.FC<DatePickerProps> = (props: DatePickerProps) =>
value={controlledValue && formatDate(controlledValue)}
size={size}
suffix={suffix}
hidePrefix={hidePrefix}
/>
);
}
Expand Down
2 changes: 0 additions & 2 deletions src/date-range-picker/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const DateRangePicker: React.FC<DateRangePickerProps> = (props: DateRange
format: formatString,
prefix,
suffix,
hidePrefix,
size,
...restProps
} = props;
Expand Down Expand Up @@ -80,7 +79,6 @@ export const DateRangePicker: React.FC<DateRangePickerProps> = (props: DateRange
value={validValue(controlledValue) ? formatDates(controlledValue) : undefined}
size={size}
suffix={suffix}
hidePrefix={hidePrefix}
/>
);
}
Expand Down
41 changes: 12 additions & 29 deletions src/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,26 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
placeholder,
onPressEnter,
onKeyPress,
style,
...rest
} = props;

const prefixCls = usePrefixCls('input-new', customizePrefixCls);

const inputClass = useMemo(
() =>
classNames(className, prefixCls, {
[`${prefixCls}__disabled`]: disabled,
[`${prefixCls}__small`]: size === 'small',
}),
classNames(
className,
{
[`${prefixCls}__hover`]: !disabled,
[`${prefixCls}__disabled`]: disabled,
[`${prefixCls}__small`]: size === 'small',
},
prefixCls
),
[prefixCls, className, size, disabled]
);

const wrapper = useMemo(
() =>
classNames({
[`${prefixCls}__suffix-wrapper`]: !!customizeSuffix,
[`${prefixCls}__prefix-wrapper`]: !!customizePrefix,
}),
[prefixCls, customizeSuffix, customizePrefix]
);

const handleKeyPress = useCallback(
(e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
Expand Down Expand Up @@ -72,25 +69,11 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
() => (customizeSuffix ? <div className={suffixCls}>{customizeSuffix}</div> : null),
[suffixCls, customizeSuffix]
);
const input = (
<input
{...rest}
disabled={disabled}
className={inputClass}
onKeyPress={handleKeyPress}
placeholder={placeholder}
ref={ref}
/>
);

if (!suffix && !prefix) {
return input;
}

return (
<span className={wrapper}>
<span className={inputClass} {...rest} style={style}>
{prefix}
{input}
<input {...rest} disabled={disabled} onKeyPress={handleKeyPress} placeholder={placeholder} ref={ref} />
{suffix}
</span>
);
Expand Down
22 changes: 11 additions & 11 deletions src/input/InputButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CloseCircleFilled, DownFilled, EventsPresetOutlined } from '@gio-design/icons';
import { CloseCircleFilled, DownFilled } from '@gio-design/icons';
import { usePrefixCls } from '@gio-design/utils';
import classNames from 'classnames';
import React, { useCallback, useMemo } from 'react';
Expand All @@ -17,8 +17,7 @@ const InputButton = React.forwardRef<HTMLInputElement, InputButtonProps>((props,
defaultValue,
value: enterValue,
disabled,
hidePrefix = false,
allowClear,
allowClear = false,
className,
style = {},
maxWidth,
Expand Down Expand Up @@ -54,15 +53,15 @@ const InputButton = React.forwardRef<HTMLInputElement, InputButtonProps>((props,
);

const wrapperCls = useMemo(
() => classNames(className, prefixCls, { [`${prefixCls}__disabled`]: disabled, [`${prefixCls}__active`]: active }),
() =>
classNames(className, prefixCls, {
[`${prefixCls}__hover`]: !disabled,
[`${prefixCls}__disabled`]: disabled,
[`${prefixCls}__active`]: active,
}),
[className, prefixCls, disabled, active]
);

const prefix = useMemo(
() => (hidePrefix ? null : customizePrefix || <EventsPresetOutlined />),
[customizePrefix, hidePrefix]
);

const suffix = useMemo(() => {
const hideClear = allowClear === false;
const defaultSuffix = value && !hideClear && !disabled ? <CloseCircleFilled onClick={onClear} /> : <DownFilled />;
Expand All @@ -78,9 +77,10 @@ const InputButton = React.forwardRef<HTMLInputElement, InputButtonProps>((props,
style={{ ...style, ...styles }}
className={inputCls}
type="button"
value={value || placeholder}
value={value}
placeholder={placeholder}
onChange={onChange}
prefix={prefix}
prefix={customizePrefix}
suffix={suffix}
ref={ref}
size={size}
Expand Down
37 changes: 24 additions & 13 deletions src/input/demos/Input.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Story, Meta } from '@storybook/react/types-6-0';
import { action } from '@storybook/addon-actions';
import { PlusOutlined, FilterOutlined } from '@gio-design/icons';
import { PlusOutlined, FilterOutlined, EventsPresetOutlined } from '@gio-design/icons';
import { InputProps, InputButtonProps } from '../interface';
import Input from '../Input';
import '../style';
Expand Down Expand Up @@ -248,17 +248,17 @@ const InputButtonTemplate: Story<InputButtonProps> = (args) => (
<InputButton {...args} />
</td>
<td>
<InputButton {...args} hidePrefix />
<InputButton {...args} prefix="" />
</td>
</tr>
<tr>
<td>Removable</td>
<td>是否可以清除选中内容</td>
<td>
<InputButton {...args} value="浏览商品详情页" />
<InputButton {...args} value="浏览商品详情页" allowClear />
</td>
<td>
<InputButton {...args} value="浏览商品详情页" allowClear={false} />
<InputButton {...args} value="浏览商品详情页" />
</td>
</tr>
</table>
Expand All @@ -268,23 +268,18 @@ const InputButtonTemplate: Story<InputButtonProps> = (args) => (
export const InputButtonDemo = InputButtonTemplate.bind({});
InputButtonDemo.args = {
onChange: () => action('onChange'),
prefix: <EventsPresetOutlined />,
placeholder: '请选择事件',
};

const InputButtonDefaultTemplate = () => <InputButton />;
export const InputButtonDefault = InputButtonDefaultTemplate.bind({});
InputButtonDefault.args = {
allowClear: false,
prefix: <EventsPresetOutlined />,
onChange: () => action('onChange'),
};

const HidePrefixTemplate = (args: InputButtonProps) => <InputButton {...args} value="请选择事件" />;
export const InputButtonHidePrefix = HidePrefixTemplate.bind({});
InputButtonHidePrefix.args = {
hidePrefix: true,
onChange: () => action('onChange'),
placeholder: '请选择事件',
};
const customPrefixTemplate = (args: InputButtonProps) => (
<InputButton {...args} value="请选择事件" prefix={<PlusOutlined />} suffix={<FilterOutlined />} />
);
Expand All @@ -304,11 +299,27 @@ InputButtonMaxWidth.args = {};
const InputButtonActiveTemplate = (args: InputButtonProps) => <InputButton {...args} value="请选择事件" active />;

export const InputButtonActive = InputButtonActiveTemplate.bind({});
InputButtonActive.args = {};
InputButtonActive.args = {
prefix: <EventsPresetOutlined />,
allowClear: true,
};

const InputButtonCustomWidthExample = (args: InputButtonProps) => (
<InputButton {...args} value="请选择事件" style={{ width: 300 }} />
);

export const InputButtonCustomWidth = InputButtonCustomWidthExample.bind({});
InputButtonCustomWidth.args = {};
InputButtonCustomWidth.args = {
prefix: <EventsPresetOutlined />,
allowClear: true,
};

const InputButtonWidthExample = (args: InputButtonProps) => (
<InputButton {...args} value="请选择事件" style={{ width: '100%' }} />
);

export const InputButtonWidth = InputButtonWidthExample.bind({});
InputButtonWidth.args = {
prefix: <EventsPresetOutlined />,
};
InputButtonWidth.storyName = 'Input Button Width 100%';
5 changes: 1 addition & 4 deletions src/input/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,10 @@ export interface InputButtonProps

/**
* 是否可以被清空
* @default false
*/
allowClear?: boolean;

/**
* 是否隐藏前缀的icon,默认是false
*/
hidePrefix?: boolean;
/**
* 自定义前缀icon
*/
Expand Down
35 changes: 22 additions & 13 deletions src/input/style/InputButton.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
@input-btn-input-prefix-cls: ~'@{component-prefix}-input-btn-new__input';

.@{input-btn-prefix-cls} {
display: flex;
cursor: pointer;

.@{input-btn-input-prefix-cls} {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
input {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
background-color: @gray-0;
cursor: pointer;

Expand Down Expand Up @@ -52,24 +52,33 @@
}
}
&__active,
&:hover {
.@{input-btn-input-prefix-cls} {
color: @blue-3;
background-color: @gray-1;
}
.@{input-prefix-cls} {
&__prefix {
&__hover {
&:hover {
.@{input-btn-input-prefix-cls} {
background-color: @gray-1;
}
input {
color: @blue-3;
cursor: pointer;
svg {
}
.@{input-prefix-cls} {
&__prefix {
color: @blue-3;
cursor: pointer;
svg {
color: @blue-3;
cursor: pointer;
}
}
}
}
}
&__disabled {
background-color: @gray-0;

input {
color: @gray-3;
}
svg {
color: @gray-3;
cursor: not-allowed;
Expand Down
Loading