Skip to content

Commit

Permalink
feat(input-button): support loading prop (#2023)
Browse files Browse the repository at this point in the history
* feat(input-button): support loading prop

* test(input-button): add case

Co-authored-by: maxin <maxin@growingio.com>
  • Loading branch information
nnmax and maxin committed May 20, 2022
1 parent e7341a5 commit 579bd07
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/input/InputButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorFilled, DownFilled } from '@gio-design/icons';
import { ErrorFilled, DownFilled, LoadingTwoTone } from '@gio-design/icons';
import { usePrefixCls } from '@gio-design/utils';
import classNames from 'classnames';
import React, { useCallback, useMemo } from 'react';
Expand All @@ -24,6 +24,7 @@ const InputButton = React.forwardRef<HTMLInputElement, InputButtonProps>((props,
maxWidth,
active = false,
onClear: handleOnClear,
loading,
...rest
} = props;

Expand Down Expand Up @@ -55,17 +56,21 @@ const InputButton = React.forwardRef<HTMLInputElement, InputButtonProps>((props,
classNames(className, prefixCls, {
[`${prefixCls}__disabled`]: disabled,
[`${prefixCls}__active`]: active,
[`${prefixCls}__loading`]: loading,
}),
[className, prefixCls, disabled, active]
[className, prefixCls, disabled, active, loading]
);

const suffix = useMemo(() => {
const hideClear = allowClear === false;
const { onClick } = rest;
if (loading) {
return customizeSuffix || <LoadingTwoTone rotating />;
}
const defaultSuffix =
value && !hideClear && !disabled ? <ErrorFilled onClick={onClear} /> : <DownFilled onClick={onClick} />;
return customizeSuffix || defaultSuffix;
}, [customizeSuffix, value, onClear, allowClear, disabled, rest]);
}, [customizeSuffix, value, onClear, allowClear, disabled, rest, loading]);

const styles = maxWidth ? { maxWidth } : {};

Expand Down
2 changes: 2 additions & 0 deletions src/input/demos/input-button/InputButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ export const Size = () => (
);

export const Active = () => <Input.Button placeholder="Active" active />;

export const Loading = () => <Input.Button placeholder="Loading" loading />;
9 changes: 9 additions & 0 deletions src/input/demos/input-button/InputButtonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ export default function InputButtonPage() {
<Story id="upgraded-input-input-button--active" />
</Canvas>

<Subheading>Loading</Subheading>
<Description>
Input Button 支持 loading 属性。如果 loading 为 true,则其 suffix icon 将显示一个 Loading
Icon,并且为不可点击状态
</Description>
<Canvas>
<Story id="upgraded-input-input-button--loading" />
</Canvas>

<Heading>参数说明</Heading>
<ArgsTable of={Input.Button} />
</>
Expand Down
5 changes: 5 additions & 0 deletions src/input/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export interface InputButtonProps
*/
disabled?: boolean;

/**
* 加载状态
*/
loading?: boolean;

/**
* 是否可以被清空
* @default false
Expand Down
4 changes: 4 additions & 0 deletions src/input/style/InputButton.less
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@
}
}
}

&__loading {
pointer-events: none;
}
}
10 changes: 10 additions & 0 deletions src/input/test/InputButton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { render } from '@testing-library/react';
import InputButton from '../InputButton';

describe('InputButton', () => {
test('should have loading class', () => {
const { container } = render(<InputButton loading />);
expect(container.querySelector('.gio-input-btn__loading')).not.toBeNull();
});
});

1 comment on commit 579bd07

@vercel
Copy link

@vercel vercel bot commented on 579bd07 May 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

gio-design – ./

gio-design-growingio.vercel.app
gio-design-git-master-growingio.vercel.app
gio-design.vercel.app

Please sign in to comment.