Skip to content

Commit f594bc9

Browse files
authored
feat(uploader): add listUploadRender prop for custom list mode upload… (#3198)
* feat(uploader): add listUploadRender prop for custom list mode upload area * fix: 移除文本
1 parent 4e8f3c9 commit f594bc9

File tree

7 files changed

+79
-67
lines changed

7 files changed

+79
-67
lines changed

src/packages/uploader/doc.en-US.md

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -91,59 +91,61 @@ import { Uploader } from '@nutui/nutui-react'
9191
### Props
9292

9393
| Property | Description | Type | Default |
94-
| --- | --- | --- | --- | autoUpload | Whether to upload the file immediately after selecting it.
95-
| autoUpload | If or not the upload will be done immediately after the file is selected, if false, you need to manually execute the ref submit method to upload | `boolean` | `true` | upload | The upload method, the input parameter is the file to be uploaded.
96-
| upload | Upload method, input is the file object to be uploaded, after asynchronous processing, return the upload result | `(file: File) => Promise<FileItem>` | `-` |
97-
| name | The name of the `input` tag `name`, the name of the file parameter sent to the backend | `string` | `file` |
98-
| defaultValue | Default list of files already uploaded | `FileItem[]` | `[]` |
99-
| value | List of files that have been uploaded | `FileItem[]` | `-` |
100-
| preview | Whether or not to show the preview image after a successful upload | `boolean` | `true` |
101-
| previewUrl | Default image address when uploading non-image ('image') formats | `string` | `-` |
102-
| deletable | Whether or not to show the delete button | `boolean` | `true` |
103-
| method | The http method for the upload request | `string` | `post` | | previewType
104-
| previewType | The built-in style of the uploaded list, two basic styles are supported picture, list | `string`
105-
| capture | Picture [selection mode](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input#htmlattrdefcapture), directly bring up the camera | `string` | `false` | maxFileSize
106-
| maxFileSize | You can set the maximum file size (in bytes) for uploading | `number` \| `string` | `Number.MAX_VALUE` |
107-
| maxCount | File upload count limit | `number` \| `string` | `1` |
108-
| fit | Picture fill mode | `contain` \| `cover` \| `fill` \| `none` \| `scale-down` | `cover` |
109-
| clearInput | If or not you want to clear the `input` content, set it to `true` to support selecting the same file to upload over and over again | `boolean` | `true` |
110-
| accept | Allowed file types to be uploaded, [Details] (https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/Input/file#%E9%99%90%E5%88%B6%E5%85%81%E8%AE%B8%E7%9A%84%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B) | `string` | `*` |
111-
| uploadIcon | uploadRegion <a href="#/en-US/component/icon">Icon Name</a> | `React.ReactNode` | `-` |
112-
| deleteIcon | Delete the icon name of the region | `React.ReactNode` | `-` |
113-
| uploadLabel | Text below the image in the upload area | `React.
114-
| multiple | Whether to support file multi-selection |`boolean`|`false`|
115-
| disabled | Whether to disable file uploading |`boolean`|`false`|
116-
| beforeUpload | The beforeUpload function needs to return a`Promise`object |```(file: File[]) => Promise<File[] \| boolean>```|`-`|
117-
| beforeDelete | Callback when deleting a file, does not remove it if the return value is false. Supports returning a`Promise`object, which is not removed when resolve(false) or reject |```(file: FileItem, files: FileItem[]) => boolean```|`-`|
118-
| onOversize | Triggered when file size exceeds limit |```(file: File[]) => void```|`-`|
119-
| onOverCount | Triggered when the number of files exceeds the limit |`(count: number) => void`|`-`|
120-
| onChange | Triggered when the list of uploaded files changes |```(files: FileItem[]) => void```|`-`|
121-
| onDelete | Triggered when clicked to delete a file |```(file: FileItem, files: FileItem[]) => void```|`-`|
122-
| onFileItemClick | Triggered when a file is uploaded successfully |```(file: FileItem, index: number) => void```|`-`|
123-
| onUploadQueueChange | Triggered when the image upload queue changes |```(tasks: FileItem[]) => void```|`-` |
124-
125-
> Note: accept, capture and multiple are the native attributes of the browser input tag, the support for these attributes varies among mobile models, so there may be some compatibility issues under different models and WebViews.
94+
| --- | --- | --- | --- |
95+
| autoUpload | Whether to upload immediately after selecting the file, when false, you need to manually execute the ref submit method to upload | `boolean` | `true` |
96+
| upload | Upload method, the input parameter is the file object to be uploaded, returns the upload result after asynchronous processing | `(file: File) => Promise<FileItem>` | `-` |
97+
| name | The name of the `input` tag, the file parameter name sent to the backend | `string` | `file` |
98+
| defaultValue | Default uploaded file list | `FileItem[]` | `[]` |
99+
| value | Uploaded file list | `FileItem[]` | `-` |
100+
| preview | Whether to display preview image after successful upload | `boolean` | `true` |
101+
| previewUrl | Default image address when uploading non-image('image') format | `string` | `-` |
102+
| deletable | Whether to display delete button | `boolean` | `true` |
103+
| method | Upload request http method | `string` | `post` |
104+
| previewType | Built-in style of upload list, supports two basic styles: picture、list | `string` | `picture` |
105+
| capture | Image [selection mode](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input#htmlattrdefcapture), directly launch camera | `string` | `false` |
106+
| maxFileSize | Maximum uploadable file size (bytes) | `number` \| `string` | `Number.MAX_VALUE` |
107+
| maxCount | File upload quantity limit | `number` \| `string` | `1` |
108+
| fit | Image fill mode | `contain` \| `cover` \| `fill` \| `none` \| `scale-down` | `cover` |
109+
| clearInput | Whether to clear `input` content, set to `true` to support repeatedly selecting and uploading the same file | `boolean` | `true` |
110+
| accept | Allowed upload file types, [detailed explanation](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/Input/file#%E9%99%90%E5%88%B6%E5%85%81%E8%AE%B8%E7%9A%84%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B) | `string` | `*` |
111+
| uploadIcon | Upload area <a href="#/zh-CN/component/icon">icon name</a> | `React.ReactNode` | `-` |
112+
| deleteIcon | Delete area icon name | `React.ReactNode` | `-` |
113+
| uploadLabel | Text below the upload area image | `React.ReactNode` | `-` |
114+
| listUploadRender | Custom upload area in list mode | `React.ReactNode` | `-` |
115+
| multiple | Whether to support multiple file selection | `boolean` | `false` |
116+
| disabled | Whether to disable file upload | `boolean` | `false` |
117+
| beforeUpload | The function before upload needs to return a `Promise` object | `(file: File[]) => Promise<File[] \| boolean>` | `-` |
118+
| beforeDelete | Callback when deleting files, no removal when return value is false. Supports returning a `Promise` object, no removal when `Promise` object resolve(false) or reject | `(file: FileItem, files: FileItem[]) => boolean` | `-` |
119+
| onOversize | Triggered when file size exceeds limit | `(file: File[]) => void` | `-` |
120+
| onOverCount | Triggered when the number of files exceeds the limit | `(count: number) => void` | `-` |
121+
| onChange | Triggered when the uploaded file list changes | `(files: FileItem[]) => void` | `-` |
122+
| onDelete | Triggered when clicking to delete file | `(file: FileItem, files: FileItem[]) => void` | `-` |
123+
| onFileItemClick | Triggered when clicking after file upload success | `(file: FileItem, index: number) => void` | `-` |
124+
| onUploadQueueChange | Triggered when the image upload queue changes | `(tasks: FileItem[]) => void` | `-` |
125+
126+
> Note: accept, capture and multiple are native attributes of browser input tags. Mobile devices have different levels of support for these attributes, so compatibility issues may occur on different models and WebViews.
126127
127128
### FileItem
128129

129-
| Name | Description | Default Value |
130-
| --- | --- | --- | status | File status value.
131-
| status | File status value, optionally 'ready,uploading,success,error' | `ready` |
132-
| uid | Unique identifier of the file | `-` | name | File name.
133-
| name | File name | `-` | url | Path to file
134-
| url | file path | `-` | uid | unique identifier for the file | `-` | name | file name | `-` | url | file path | `-` | type | file type
135-
| type | file type | `image` |
136-
| loadingIcon | Loading Icon | `-` |
137-
| failIcon | failureIcon | `-` |
138-
| percentage | upload prgress percent | `-` |
130+
| Name | Description | Default |
131+
| --- | --- | --- |
132+
| status | File status value, optional 'ready,uploading,success,error' | `ready` |
133+
| uid | Unique identifier of the file | `-` |
134+
| name | File name | `-` |
135+
| url | File path | `-` |
136+
| type | File type | `image` |
137+
| loadingIcon | Loading icon | `-` |
138+
| failIcon | Failed loading icon | `-` |
139+
| percentage | Upload progress bar percentage | `-` |
139140

140141
### Methods
141142

142-
The Uploader instance can be retrieved by ref and the instance methods called.
143-
| MethodName | Description | Parameters | ReturnValues |
144-
| --- | --- | --- | --- | --- | submit | Manual upload mode
145-
| submit | Manual upload mode, performs the upload operation | `-` | `-` |
146-
| clear | Clear the queue of selected files (this method is usually used when uploading in manual mode) | `index` | `-` |
143+
You can get the Uploader instance through ref and call instance methods
144+
145+
| Method | Description | Parameters | Return |
146+
| --- | --- | --- | --- |
147+
| submit | Manual upload mode, execute upload operation | `-` | `-` |
148+
| clear | Clear the selected file queue (this method is generally used in conjunction with manual mode upload) | `index` | `-` |
147149

148150
## Theme customization
149151

src/packages/uploader/doc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import { Uploader } from '@nutui/nutui-react'
115115
| uploadIcon | 上传区域<a href="#/zh-CN/component/icon">图标名称</a> | `React.ReactNode` | `-` |
116116
| deleteIcon | 删除区域的图标名称 | `React.ReactNode` | `-` |
117117
| uploadLabel | 上传区域图片下方文字 | `React.ReactNode` | `-` |
118+
| listUploadRender | 自定义列表模式的上传区域 | `React.ReactNode` | `-` |
118119
| multiple | 是否支持文件多选 | `boolean` | `false` |
119120
| disabled | 是否禁用文件上传 | `boolean` | `false` |
120121
| beforeUpload | 上传前的函数需要返回一个`Promise`对象 | `(file: File[]) => Promise<File[] \| boolean>` | `-` |

src/packages/uploader/doc.taro.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ import { Uploader } from '@nutui/nutui-react-taro'
105105
| uploadIcon | 上传区域<a href="#/zh-CN/component/icon">图标名称</a> | `React.ReactNode` | `-` |
106106
| deleteIcon | 删除区域的图标名称 | `React.ReactNode` | `-` |
107107
| uploadLabel | 上传区域图片下方文字 | `React.ReactNode` | `-` |
108+
| listUploadRender | 自定义列表模式的上传区域 | `React.ReactNode` | `-` |
108109
| multiple | 是否支持文件多选 | `boolean` | `false` |
109110
| disabled | 是否禁用文件上传 | `boolean` | `false` |
110111
| beforeUpload | 上传前的函数需要返回一个`Promise`对象 | `(file: File[]) => Promise<File[] \| boolean>` | `-` |

src/packages/uploader/doc.zh-TW.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import { Uploader } from '@nutui/nutui-react'
115115
| uploadIcon | 上傳區域<a href="#/zh-CN/component/icon">圖標名稱</a> | `React.ReactNode` | `-` |
116116
| deleteIcon | 刪除區域的圖標名稱 | `React.ReactNode` | `-` |
117117
| uploadLabel | 上傳區域圖片下方文字 | `React.ReactNode` | `-` |
118+
| listUploadRender | 自定義列表模式的上傳區域 | `React.ReactNode` | `-` |
118119
| multiple | 是否支持文件多選 | `boolean` | `false` |
119120
| disabled | 是否禁用文件上傳 | `boolean` | `false` |
120121
| beforeUpload | 上傳前的函數需要返回一個`Promise`對象 | `(file: File[]) => Promise<File[] \| boolean>` | `-` |

src/packages/uploader/uploader.taro.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const InternalUploader: ForwardRefRenderFunction<
6565
uploadIcon,
6666
deleteIcon,
6767
uploadLabel,
68+
listUploadRender,
6869
accept,
6970
name,
7071
camera,
@@ -328,9 +329,11 @@ const InternalUploader: ForwardRefRenderFunction<
328329
onFileItemClick?.(file, index)
329330
}
330331
const renderListUploader = () => {
332+
if (previewType !== 'list') return null
333+
331334
return (
332-
previewType === 'list' && (
333-
<View className="nut-uploader-slot">
335+
<View className="nut-uploader-slot">
336+
{listUploadRender || (
334337
<>
335338
<Button size="small" type="primary">
336339
{locale.uploader.list}
@@ -339,8 +342,8 @@ const InternalUploader: ForwardRefRenderFunction<
339342
<Button className="nut-uploader-input" onClick={_chooseImage} />
340343
)}
341344
</>
342-
</View>
343-
)
345+
)}
346+
</View>
344347
)
345348
}
346349
const renderImageUploader = () => {

src/packages/uploader/uploader.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const InternalUploader: ForwardRefRenderFunction<
7676
beforeUpload,
7777
beforeDelete,
7878
onUploadQueueChange,
79+
listUploadRender,
7980
...restProps
8081
} = mergeProps(defaultProps, props)
8182
const [fileList, setFileList] = usePropsValue({
@@ -276,26 +277,28 @@ const InternalUploader: ForwardRefRenderFunction<
276277
)
277278
}
278279
const renderListUploader = () => {
280+
if (previewType !== 'list') return null
281+
279282
return (
280-
previewType === 'list' && (
281-
<div className="nut-uploader-slot">
283+
<div className="nut-uploader-slot">
284+
{listUploadRender || (
282285
<Button size="small" type="primary">
283286
{locale.uploader.list}
284287
</Button>
285-
{Number(maxCount) > fileList.length && (
286-
<input
287-
className="nut-uploader-input"
288-
type="file"
289-
capture={capture}
290-
name={name}
291-
accept={accept}
292-
disabled={disabled}
293-
multiple={multiple}
294-
onChange={fileChange}
295-
/>
296-
)}
297-
</div>
298-
)
288+
)}
289+
{Number(maxCount) > fileList.length && (
290+
<input
291+
className="nut-uploader-input"
292+
type="file"
293+
capture={capture}
294+
name={name}
295+
accept={accept}
296+
disabled={disabled}
297+
multiple={multiple}
298+
onChange={fileChange}
299+
/>
300+
)}
301+
</div>
299302
)
300303
}
301304
return (

src/types/spec/uploader/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface BaseUploader extends BaseProps {
3030
uploadIcon?: React.ReactNode
3131
deleteIcon?: React.ReactNode
3232
uploadLabel?: React.ReactNode
33+
listUploadRender?: React.ReactNode
3334
name: string
3435
accept: string
3536
disabled: boolean

0 commit comments

Comments
 (0)