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(ui/uploader): support remove button slot #1835

Merged
merged 3 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 13 additions & 3 deletions packages/varlet-ui/src/uploader/Uploader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@
@click="preview(f)"
>
<div :class="n('file-name')">{{ f.name || f.url }}</div>
<div :class="n('file-close')" v-if="removable" @click.stop="handleRemove(f)">
<var-icon :class="n('file-close-icon')" var-uploader-cover name="delete" />
</div>
<slot
name="remove-button"
v-if="removable"
:remove="

Check warning on line 15 in packages/varlet-ui/src/uploader/Uploader.vue

View check run for this annotation

Codecov / codecov/patch

packages/varlet-ui/src/uploader/Uploader.vue#L15

Added line #L15 was not covered by tests
() => {
handleRemove(f)
}
"
>
<div :class="n('file-close')" @click.stop="handleRemove(f)">
<var-icon :class="n('file-close-icon')" var-uploader-cover name="delete" />
</div>
</slot>
<img
role="img"
:class="n('file-cover')"
Expand Down
39 changes: 39 additions & 0 deletions packages/varlet-ui/src/uploader/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,44 @@ const files = ref([
</style>
```

### Custom Remove Button

```html
<script setup>
import { ref } from 'vue'

const files = ref([
{
url: 'https://varletjs.org/cat.jpg',
cover: 'https://varletjs.org/cat.jpg'
},
{
url: 'https://www.runoob.com/try/demo_source/mov_bbb.mp4',
cover: 'https://varletjs.org/cover.jpg'
}
])
</script>

<template>
<var-uploader v-model="files">
<template #remove-button="{ remove }">
<div class="custom-remove-button">
<var-icon color="#fff" name="window-close" @click.stop="remove"></var-icon>
</div>
</template>
</var-uploader>
</template>

<style>
.custom-remove-button {
position: absolute;
top: 0;
right: 0;
z-index: 3;
}
</style>
```

## API

### Props
Expand Down Expand Up @@ -511,6 +549,7 @@ const files = ref([
| --- | --- | --- |
| `default` | Upload action content | `-` |
| `extra-message` | Extra message | `-` |
| `remove-button` ***3.8.0*** | Remove button | `remove: () => void` |

### Style Variables

Expand Down
39 changes: 39 additions & 0 deletions packages/varlet-ui/src/uploader/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,44 @@ const files = ref([
</style>
```

### 自定义删除按钮

```html
<script setup>
import { ref } from 'vue'

const files = ref([
{
url: 'https://varletjs.org/cat.jpg',
cover: 'https://varletjs.org/cat.jpg'
},
{
url: 'https://www.runoob.com/try/demo_source/mov_bbb.mp4',
cover: 'https://varletjs.org/cover.jpg'
}
])
</script>

<template>
<var-uploader v-model="files">
<template #remove-button="{ remove }">
<div class="custom-remove-button">
<var-icon color="#fff" name="window-close" @click.stop="remove"></var-icon>
</div>
</template>
</var-uploader>
</template>

<style>
.custom-remove-button {
position: absolute;
top: 0;
right: 0;
z-index: 3;
}
</style>
```

## API

### 属性
Expand Down Expand Up @@ -510,6 +548,7 @@ const files = ref([
| --- | --- | --- |
| `default` | 上传按钮内容 | `-` |
| `extra-message` | 附加信息 | `-` |
| `remove-button` ***3.8.0*** | 删除按钮 | `remove: () => void` |

### 样式变量

Expand Down
16 changes: 15 additions & 1 deletion packages/varlet-ui/src/uploader/example/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,14 @@ function handleActionClick(chooseFile) {
</var-uploader>
</var-space>

<var-space></var-space>
<app-type>{{ t('removeButtonSlot') }}</app-type>
<var-uploader v-model="values.files2">
<template #remove-button="{ remove }">
<div class="custom-remove-button">
<var-icon color="#fff" name="window-close" @click.stop="remove"></var-icon>
</div>
</template>
</var-uploader>
</template>

<style scoped lang="less">
Expand All @@ -235,4 +242,11 @@ function handleActionClick(chooseFile) {
font-size: 12px;
object-fit: cover;
}

.custom-remove-button {
position: absolute;
top: 0;
right: 0;
z-index: 3;
}
</style>
1 change: 1 addition & 0 deletions packages/varlet-ui/src/uploader/example/locale/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export default {
useProgress: 'Use Progress',
beforeFilter: 'File List Filter',
clickAction: 'Upload Button Click Event',
removeButtonSlot: 'Custom Remove Button',
}
1 change: 1 addition & 0 deletions packages/varlet-ui/src/uploader/example/locale/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export default {
useProgress: '使用进度条',
beforeFilter: '文件列表过滤',
clickAction: '上传按钮点击事件',
removeButtonSlot: '自定义删除按钮',
}
1 change: 1 addition & 0 deletions packages/varlet-ui/types/uploader.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class Uploader extends VarComponent {
$slots: {
default(): VNode[]
'extra-message'(): VNode[]
'remove-button'(remove: () => void): VNode[]
}

getLoading(): VarFile[]
Expand Down
Loading