Skip to content

Commit ec2eec4

Browse files
authored
feat(Uploader): add support for deleteIcon prop customization (#2618)
1 parent 33208c7 commit ec2eec4

File tree

12 files changed

+98
-10
lines changed

12 files changed

+98
-10
lines changed

src/packages/uploader/demo.taro.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Demo10 from './demos/taro/demo10'
1717
import Demo11 from './demos/taro/demo11'
1818
import Demo12 from './demos/taro/demo12'
1919
import Demo13 from './demos/taro/demo13'
20+
import Demo14 from './demos/taro/demo14'
2021

2122
const UploaderDemo = () => {
2223
const [translated] = useTranslate({
@@ -33,6 +34,7 @@ const UploaderDemo = () => {
3334
uploadXhrCustom: '自定义 Taro.uploadFile 上传方式(before-xhr-upload)',
3435
manualExecution: '选中文件后,通过按钮手动执行上传',
3536
disabled: '禁用状态',
37+
customDeleteIcon: '自定义删除icon',
3638
},
3739
'zh-TW': {
3840
basic: '基础用法',
@@ -47,6 +49,7 @@ const UploaderDemo = () => {
4749
uploadXhrCustom: '自定義 Taro.uploadFile 上傳方式(before-xhr-upload)',
4850
manualExecution: '選取檔後,通過按鈕手動執行上傳',
4951
disabled: '禁用狀態',
52+
customDeleteIcon: '自定義刪除icon',
5053
},
5154
'en-US': {
5255
basic: 'Basic usage',
@@ -63,6 +66,7 @@ const UploaderDemo = () => {
6366
manualExecution:
6467
'After selecting Chinese, manually perform the upload via the button',
6568
disabled: 'Disabled state',
69+
customDeleteIcon: 'Custom DeleteIcon',
6670
},
6771
})
6872

@@ -96,6 +100,8 @@ const UploaderDemo = () => {
96100
<Demo12 />
97101
<h2>{translated.disabled}</h2>
98102
<Demo13 />
103+
<h2>{translated.customDeleteIcon}</h2>
104+
<Demo14 />
99105
</div>
100106
</>
101107
)

src/packages/uploader/demo.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Demo10 from './demos/h5/demo10'
1414
import Demo11 from './demos/h5/demo11'
1515
import Demo12 from './demos/h5/demo12'
1616
import Demo13 from './demos/h5/demo13'
17+
import Demo14 from './demos/h5/demo14'
1718

1819
const UploaderDemo = () => {
1920
const [translated] = useTranslate({
@@ -30,6 +31,7 @@ const UploaderDemo = () => {
3031
uploadXhrCustom: '自定义 xhr 上传方式(before-xhr-upload)',
3132
manualExecution: '选中文件后,通过按钮手动执行上传',
3233
disabled: '禁用状态',
34+
customDeleteIcon: '自定义删除icon',
3335
},
3436
'zh-TW': {
3537
basic: '基础用法',
@@ -44,6 +46,7 @@ const UploaderDemo = () => {
4446
uploadXhrCustom: '自定義 xhr 上傳方式(before-xhr-upload)',
4547
manualExecution: '選取檔後,通過按鈕手動執行上傳',
4648
disabled: '禁用狀態',
49+
customDeleteIcon: '自定義刪除icon',
4750
},
4851
'en-US': {
4952
basic: 'Basic usage',
@@ -59,6 +62,7 @@ const UploaderDemo = () => {
5962
manualExecution:
6063
'After selecting Chinese, manually perform the upload via the button',
6164
disabled: 'Disabled state',
65+
customDeleteIcon: 'Custom DeleteIcon',
6266
},
6367
})
6468

@@ -91,6 +95,8 @@ const UploaderDemo = () => {
9195
<Demo12 />
9296
<h2>{translated.disabled}</h2>
9397
<Demo13 />
98+
<h2>{translated.customDeleteIcon}</h2>
99+
<Demo14 />
94100
</div>
95101
</>
96102
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react'
2+
import { Uploader } from '@nutui/nutui-react'
3+
import { Dongdong, Star } from '@nutui/icons-react'
4+
5+
const Demo14 = () => {
6+
const uploadUrl = 'https://my-json-server.typicode.com/linrufeng/demo/posts'
7+
const defaultFileList: any = [
8+
{
9+
name: '文件文件文件文件1文件文件文件文件1文件文件文件文件1.png',
10+
url: 'https://m.360buyimg.com/babel/jfs/t1/164410/22/25162/93384/616eac6cE6c711350/0cac53c1b82e1b05.gif',
11+
status: 'success',
12+
message: '上传成功',
13+
type: 'image',
14+
uid: '122',
15+
},
16+
]
17+
const onDelete = (file: any, fileList: any) => {
18+
console.log('delete事件触发', file, fileList)
19+
}
20+
return (
21+
<Uploader
22+
url={uploadUrl}
23+
defaultValue={defaultFileList}
24+
onDelete={onDelete}
25+
uploadIcon={<Dongdong />}
26+
deleteIcon={<Star />}
27+
/>
28+
)
29+
}
30+
export default Demo14
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react'
2+
import { Uploader } from '@nutui/nutui-react-taro'
3+
import { Dongdong, Star } from '@nutui/icons-react-taro'
4+
5+
const Demo14 = () => {
6+
const uploadUrl = 'https://my-json-server.typicode.com/linrufeng/demo/posts'
7+
const defaultFileList: any = [
8+
{
9+
name: '文件文件文件文件1文件文件文件文件1文件文件文件文件1.png',
10+
url: 'https://m.360buyimg.com/babel/jfs/t1/164410/22/25162/93384/616eac6cE6c711350/0cac53c1b82e1b05.gif',
11+
status: 'success',
12+
message: '上传成功',
13+
type: 'image',
14+
uid: '122',
15+
},
16+
]
17+
const onDelete = (file: any, fileList: any) => {
18+
console.log('delete事件触发', file, fileList)
19+
}
20+
return (
21+
<Uploader
22+
url={uploadUrl}
23+
defaultValue={defaultFileList}
24+
onDelete={onDelete}
25+
uploadIcon={<Dongdong />}
26+
deleteIcon={<Star />}
27+
/>
28+
)
29+
}
30+
export default Demo14

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ app.post('/upload', upload.single('file'), (req, res) => {
161161
| headers | Set request headers | `object` | `{}` |
162162
| data | Uploading extra params or function which can return uploading extra params formData | `object` | `{}` |
163163
| uploadIcon | Upload area<a href="#/zh-CN/icon">icon name</a> | `React.ReactNode` | `-` |
164+
| deleteIcon | Delete area icon name</a> | `React.ReactNode` | `-` |
164165
| uploadLabel | Upload area tip | `React.ReactNode` | `-` |
165166
| xhrState | The success status (status) value of the interface response | `number` | `200` |
166167
| withCredentials | Support for sending cookie credential information | `boolean` | `false` |

src/packages/uploader/doc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ app.post('/upload', upload.single('file'), (req, res) => {
162162
| headers | 设置上传的请求头部 | `object` | `{}` |
163163
| data | 附加上传的信息 formData | `object` | `{}` |
164164
| uploadIcon | 上传区域<a href="#/zh-CN/icon">图标名称</a> | `React.ReactNode` | `-` |
165+
| deleteIcon | 删除区域的图标名称 | `React.ReactNode` | `-` |
165166
| uploadLabel | 上传区域图片下方文字 | `React.ReactNode` | `-` |
166167
| xhrState | 接口响应的成功状态(status)值 | `number` | `200` |
167168
| withCredentials | 支持发送 cookie 凭证信息 | `Boolean` | `false` |

src/packages/uploader/doc.taro.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ app.post('/upload', upload.single('file'), (req, res) => {
163163
| headers | 设置上传的请求头部 | `object` | `{}` |
164164
| data | 附加上传的信息 formData | `object` | `{}` |
165165
| uploadIcon | 上传区域<a href="#/zh-CN/icon">图标名称</a> | `ReactNode` | `-` |
166+
| deleteIcon | 删除区域的图标名称 | `React.ReactNode` | `-` |
166167
| uploadLabel | 上传区域图片下方文字 | `string` | `&quot;&quot;` |
167168
| xhrState | 接口响应的成功状态(status)值 | `number` | `200` |
168169
| disabled | 是否禁用文件上传 | `boolean` | `false` |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ app.post('/upload', upload.single('file'), (req, res) => {
161161
| headers | 設置上傳的請求頭部 | `object` | `{}` |
162162
| data | 附加上傳的信息 formData | `object` | `{}` |
163163
| uploadIcon | 上傳區域<a href="#/zh-CN/icon">圖標名稱</a> | `React.ReactNode` | `-` |
164+
| deleteIcon | 刪除區域的圖標名稱 | `React.ReactNode` | `-` |
164165
| uploadLabel | 上傳區域圖片下方文字 | `React.ReactNode` | `-` |
165166
| xhrState | 接口響應的成功狀態(status)值 | `number` | `200` |
166167
| withCredentials | 支持發送 cookie 憑證信息 | `Boolean` | `false` |

src/packages/uploader/preview.taro.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Link as LinkIcon,
66
Loading,
77
} from '@nutui/icons-react-taro'
8-
import { Image } from '@tarojs/components'
8+
import { Image, View } from '@tarojs/components'
99
import Progress from '@/packages/progress/index.taro'
1010
import { FileItem } from '@/packages/uploader/file-item'
1111
import { ERROR } from '@/packages/uploader/upload'
@@ -17,6 +17,7 @@ export const Preview: React.FunctionComponent<any> = ({
1717
onDeleteItem,
1818
handleItemClick,
1919
previewUrl,
20+
deleteIcon,
2021
children,
2122
}) => {
2223
const renderIcon = (item: FileItem) => {
@@ -37,11 +38,12 @@ export const Preview: React.FunctionComponent<any> = ({
3738
key={item.uid}
3839
>
3940
{previewType === 'picture' && !children && deletable && (
40-
<Failure
41-
color="rgba(0,0,0,0.6)"
41+
<View
4242
className="close"
4343
onClick={() => onDeleteItem(item, index)}
44-
/>
44+
>
45+
{deleteIcon}
46+
</View>
4547
)}
4648
{previewType === 'picture' && !children && (
4749
<div className="nut-uploader-preview-img">

src/packages/uploader/preview.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const Preview: React.FunctionComponent<any> = ({
1313
onDeleteItem,
1414
handleItemClick,
1515
previewUrl,
16+
deleteIcon,
1617
children,
1718
}) => {
1819
const renderIcon = (item: FileItem) => {
@@ -33,11 +34,12 @@ export const Preview: React.FunctionComponent<any> = ({
3334
key={item.uid}
3435
>
3536
{previewType === 'picture' && !children && deletable && (
36-
<Failure
37-
color="rgba(0,0,0,0.6)"
38-
className="close"
37+
<div
3938
onClick={() => onDeleteItem(item, index)}
40-
/>
39+
className="close"
40+
>
41+
{deleteIcon}
42+
</div>
4143
)}
4244
{previewType === 'picture' && !children && (
4345
<div className="nut-uploader-preview-img">

0 commit comments

Comments
 (0)