File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 11/* eslint react/no-is-mounted:0,react/sort-comp:0,react/prop-types:0 */
2- import { clsx } from 'clsx' ;
32import pickAttrs from '@rc-component/util/lib/pickAttrs' ;
3+ import { clsx } from 'clsx' ;
44import React , { Component } from 'react' ;
55import attrAccept from './attr-accept' ;
66import type {
7+ AcceptConfig ,
78 BeforeUploadFileType ,
89 RcFile ,
910 UploadProgressEvent ,
@@ -30,6 +31,28 @@ class AjaxUploader extends Component<UploadProps> {
3031
3132 private _isMounted : boolean ;
3233
34+ private getFilterFn = ( ) => {
35+ const { accept, directory } = this . props ;
36+
37+ let filterFn : AcceptConfig [ 'filter' ] ;
38+ let acceptFormat : string | undefined ;
39+
40+ if ( typeof accept === 'string' ) {
41+ acceptFormat = accept ;
42+ } else {
43+ const { filter, format } = accept || { } ;
44+
45+ acceptFormat = format ;
46+ if ( filter === 'native' ) {
47+ filterFn = ( ) => true ;
48+ } else {
49+ filterFn = filter ;
50+ }
51+ }
52+
53+ return filterFn || ( directory ? ( file : RcFile ) => attrAccept ( file , acceptFormat ) : ( ) => true ) ;
54+ } ;
55+
3356 onChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
3457 const { accept, directory } = this . props ;
3558 const { files } = e . target ;
Original file line number Diff line number Diff line change @@ -4,6 +4,11 @@ export type BeforeUploadFileType = File | Blob | boolean | string;
44
55export type Action = string | ( ( file : RcFile ) => string | PromiseLike < string > ) ;
66
7+ export type AcceptConfig = {
8+ format : string ;
9+ filter ?: 'native' | ( ( file : RcFile ) => boolean ) ;
10+ } ;
11+
712export interface UploadProps
813 extends Omit < React . InputHTMLAttributes < HTMLInputElement > , 'onError' | 'onProgress' > {
914 name ?: string ;
@@ -16,7 +21,7 @@ export interface UploadProps
1621 directory ?: boolean ;
1722 data ?: Record < string , unknown > | ( ( file : RcFile | string | Blob ) => Record < string , unknown > ) ;
1823 headers ?: UploadRequestHeader ;
19- accept ?: string ;
24+ accept ?: string | AcceptConfig ;
2025 multiple ?: boolean ;
2126 onBatchStart ?: (
2227 fileList : { file : RcFile ; parsedFile : Exclude < BeforeUploadFileType , boolean > } [ ] ,
You can’t perform that action at this time.
0 commit comments