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

feat: support classNames and styles #518

Merged
Merged
Show file tree
Hide file tree
Changes from 8 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
11 changes: 6 additions & 5 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,
Wxh16144 marked this conversation as resolved.
Show resolved Hide resolved
disabled,
id,
style,
styles,
multiple,
accept,
capture,
Expand All @@ -277,10 +279,8 @@ class AjaxUploader extends Component<UploadProps> {
onMouseLeave,
...otherProps
} = this.props;
const cls = classNames({
[prefixCls]: true,
const cls = clsx(className, prefixCls, {
[`${prefixCls}-disabled`]: disabled,
[className]: className,
});
// because input don't have directory/webkitdirectory type declaration
const dirProps: any = directory
Expand All @@ -307,7 +307,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={styles?.input ?? { display: 'none' }}
Wxh16144 marked this conversation as resolved.
Show resolved Hide resolved
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).not.toBe('none');
});
});