Skip to content

Commit

Permalink
feat: support classNames and styles (#518)
Browse files Browse the repository at this point in the history
* feat: add innserStyle

* test: add test case

* feat: support classNames and styles

* Revert "test: add test case"

This reverts commit dca7a95.

* test: add test case

* chore: update

* chore: update case

* chore: update

* chore: update

Co-authored-by: zombieJ <[email protected]>

* chore: update case

* chore: revert

---------

Co-authored-by: zombieJ <[email protected]>
  • Loading branch information
Wxh16144 and zombieJ authored Oct 18, 2023
1 parent 6e24053 commit 3dacfff
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/AjaxUploader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint react/no-is-mounted:0,react/sort-comp:0,react/prop-types:0 */
import type { ReactElement } from 'react';
import React, { Component } from 'react';
import classNames from 'classnames';
import clsx from 'classnames';
import pickAttrs from 'rc-util/lib/pickAttrs';
import defaultRequest from './request';
import getUid from './uid';
Expand Down Expand Up @@ -264,9 +264,11 @@ class AjaxUploader extends Component<UploadProps> {
component: Tag,
prefixCls,
className,
classNames = {},
disabled,
id,
style,
styles = {},
multiple,
accept,
capture,
Expand All @@ -277,7 +279,7 @@ class AjaxUploader extends Component<UploadProps> {
onMouseLeave,
...otherProps
} = this.props;
const cls = classNames({
const cls = clsx({
[prefixCls]: true,
[`${prefixCls}-disabled`]: disabled,
[className]: className,
Expand Down Expand Up @@ -307,7 +309,8 @@ class AjaxUploader extends Component<UploadProps> {
ref={this.saveFileInput}
onClick={e => e.stopPropagation()} // https://github.com/ant-design/ant-design/issues/19948
key={this.state.uid}
style={{ display: 'none' }}
style={{ display: 'none', ...styles.input }}
className={classNames.input}
accept={accept}
{...dirProps}
multiple={multiple}
Expand Down
6 changes: 6 additions & 0 deletions src/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export interface UploadProps
onMouseEnter?: (e: React.MouseEvent<HTMLDivElement>) => void;
onMouseLeave?: (e: React.MouseEvent<HTMLDivElement>) => void;
onClick?: (e: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
classNames?: {
input?: string;
};
styles?: {
input?: React.CSSProperties;
};
}

export interface UploadProgressEvent extends Partial<ProgressEvent> {
Expand Down
15 changes: 15 additions & 0 deletions tests/uploader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,4 +850,19 @@ describe('uploader', () => {

expect(requests[0].url).toEqual('bamboo');
});

it('input style defaults to display none', () => {
const wrapper = mount(<Uploader />);
expect(wrapper.find('input').props().style.display).toBe('none');
});

it('classNames and styles should work', () => {
const wrapper = mount(
<Uploader classNames={{ input: 'bamboo-input' }} styles={{ input: { color: 'red' } }} />,
);
expect(wrapper.find('.bamboo-input').length).toBeTruthy();

expect(wrapper.find('.bamboo-input').props().style.color).toEqual('red');
expect(wrapper.find('input').props().style.display).toBe('none');
});
});

0 comments on commit 3dacfff

Please sign in to comment.