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(transfer): add back-icon and forward-icon slots #3142

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 4 additions & 1 deletion CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Fixes
- Fix `n-color-picker` can't set alpha value correctly by hand

### Feats
- `n-transfer` adds `back-icon` and `forward-icon` slots, closes [#2668](https://github.com/TuSimple/naive-ui/issues/2668).

## 2.30.5

### Fixes
Expand Down Expand Up @@ -2412,7 +2415,7 @@ Update package.json & README.md.
- `n-popover` adds `get-disabled` prop.
- adds `n-ellipsis` component.
- `n-popover`'s `width` prop adds `'trigger'` option.
- `n-data-table`'s columns's `ellipsis` prop can be set as props of `n-ellipsis`. x
- `n-data-table`'s columns's `ellipsis` prop can be set as props of `n-ellipsis`.

### Fixes

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Fixes
- 修复 `n-color-picker` 手动输入alpha值时不生效的问题

### Feats
- `n-transfer` 新增 `back-icon` and `forward-icon` 插槽, 关闭 [#2668](https://github.com/TuSimple/naive-ui/issues/2668).

## 2.30.5

### Fixes
Expand Down
42 changes: 42 additions & 0 deletions src/transfer/demos/enUS/icon.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<markdown>
# Custom Icon
</markdown>

<template>
<n-transfer ref="transfer" v-model:value="value" :options="options">
<template #forward-icon>
<n-icon :size="16" :component="ArrowForward" />
</template>
<template #back-icon>
<n-icon :size="16" :component="ArrowBack" />
</template>
</n-transfer>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { ArrowBack, ArrowForward } from '@vicons/ionicons5'

function createOptions () {
return Array.from({ length: 100 }).map((v, i) => ({
label: 'Option ' + i,
value: i,
disabled: i % 5 === 0
}))
}

function createValues () {
return Array.from({ length: 50 }).map((v, i) => i)
}

export default defineComponent({
setup () {
return {
options: createOptions(),
value: ref(createValues()),
ArrowForward,
ArrowBack
}
}
})
</script>
8 changes: 8 additions & 0 deletions src/transfer/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ basic.vue
large-data.vue
size.vue
filterable.vue
icon.vue
```

## API
Expand Down Expand Up @@ -40,3 +41,10 @@ filterable.vue
| label | `string` | The option's label to display. |
| value | `string \| number` | The option's unique value. |
| disabled | `boolean` | The option's disabled state. |

### TransferOption Slots

| Name | Parameters | Description | Version |
| ------------ | ---------- | --------------------- | ------------ |
| back-icon | `()` | icon of arrow back | NEXT_VERSION |
| forward-icon | `()` | icon of arrow forward | NEXT_VERSION |
42 changes: 42 additions & 0 deletions src/transfer/demos/zhCN/icon.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<markdown>
# 自定义图标
</markdown>

<template>
<n-transfer ref="transfer" v-model:value="value" :options="options">
<template #forward-icon>
<n-icon :size="16" :component="ArrowForward" />
</template>
<template #back-icon>
<n-icon :size="16" :component="ArrowBack" />
</template>
</n-transfer>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { ArrowBack, ArrowForward } from '@vicons/ionicons5'

function createOptions () {
return Array.from({ length: 100 }).map((v, i) => ({
label: 'Option ' + i,
value: i,
disabled: i % 5 === 0
}))
}

function createValues () {
return Array.from({ length: 50 }).map((v, i) => i)
}

export default defineComponent({
setup () {
return {
options: createOptions(),
value: ref(createValues()),
ArrowForward,
ArrowBack
}
}
})
</script>
8 changes: 8 additions & 0 deletions src/transfer/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ basic.vue
large-data.vue
size.vue
filterable.vue
icon.vue
```

## API
Expand Down Expand Up @@ -40,3 +41,10 @@ filterable.vue
| label | `string` | 选项中用以页面显示的名称 |
| value | `string \| number` | 所有选项中唯一的 `value` |
| disabled | `boolean` | 是否禁用这个选项 |

### TransferOption Slots

| 名称 | 参数 | 说明 | 版本 |
| ------------ | ---- | -------------- | ------------ |
| back-icon | `()` | 左箭头图标插槽 | NEXT_VERSION |
| forward-icon | `()` | 右箭头图标插槽 | NEXT_VERSION |
18 changes: 14 additions & 4 deletions src/transfer/src/Transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { NButton } from '../../button'
import { useLocale, useFormItem, useTheme, useConfig } from '../../_mixins'
import type { ThemeProps } from '../../_mixins'
import { createKey } from '../../_utils/cssr'
import { warn, call, ExtractPublicPropTypes } from '../../_utils'
import { warn, call, ExtractPublicPropTypes, resolveSlot } from '../../_utils'
import type { MaybeArray } from '../../_utils'
import { transferLight } from '../styles'
import type { TransferTheme } from '../styles'
Expand Down Expand Up @@ -296,7 +296,7 @@ export default defineComponent({
}
},
render () {
const { mergedClsPrefix } = this
const { mergedClsPrefix, $slots } = this
return (
<div
class={[
Expand Down Expand Up @@ -347,7 +347,12 @@ export default defineComponent({
{{
icon: () => (
<NBaseIcon clsPrefix={mergedClsPrefix}>
{{ default: () => <ChevronRightIcon /> }}
{{
default: () =>
resolveSlot($slots['forward-icon'], () => [
<ChevronRightIcon />
])
}}
</NBaseIcon>
)
}}
Expand All @@ -361,7 +366,12 @@ export default defineComponent({
{{
icon: () => (
<NBaseIcon clsPrefix={mergedClsPrefix}>
{{ default: () => <ChevronLeftIcon /> }}
{{
default: () =>
resolveSlot($slots['back-icon'], () => [
<ChevronLeftIcon />
])
}}
</NBaseIcon>
)
}}
Expand Down