feat(popconfirm): support no actions (#782)

* feat(popconfirm): add actions prop

* docs(popconfirm): remove useless props

* refactor(popconfirm): display actions  by judging positiveTest and negetiveTest
This commit is contained in:
jesi 2021-08-06 23:22:29 +08:00 committed by GitHub
parent 25cb8cb58c
commit 079e0e25c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 152 additions and 12 deletions

View File

@ -15,6 +15,7 @@
- `n-loading-bar` add `loading-bar-style` props, closes [#457](https://github.com/TuSimple/naive-ui/issues/457).
- `n-button` add `text-color` prop.
- `n-form` export `FormValidationError` type.
- `n-popconfirm` support not show action components, closes [#770](https://github.com/TuSimple/naive-ui/issues/770).
### Fixes

View File

@ -15,6 +15,7 @@
- `n-loading-bar` 新增 `loading-bar-style` 属性,关闭 [#457](https://github.com/TuSimple/naive-ui/issues/457)
- `n-button` 新增 `text-color` 属性
- `n-form` 导出 `FormValidationError` 类型
- `n-popconfirm` 支持不显示操作组件,关闭 [#770](https://github.com/TuSimple/naive-ui/issues/770)
### Fixes

View File

@ -0,0 +1,61 @@
# Actions
```html
<n-space>
<n-popconfirm
@positive-click="handlePositiveClick"
@negative-click="handleNegativeClick"
>
<template #trigger>
<n-button>Quote</n-button>
</template>
Things pass us by. Nobody can catch them. That's the way we live our lives.
</n-popconfirm>
<n-popconfirm :negative-text="null" @positive-click="handlePositiveClick">
<template #trigger>
<n-button>Only confirm</n-button>
</template>
Things pass us by. Nobody can catch them. That's the way we live our lives.
</n-popconfirm>
<n-popconfirm :positive-text="null" @negative-click="handleNegativeClick">
<template #trigger>
<n-button>Only cancel</n-button>
</template>
Things pass us by. Nobody can catch them. That's the way we live our lives.
</n-popconfirm>
<n-popconfirm :positive-text="null" :negative-text="null">
<template #trigger>
<n-button>Nothing</n-button>
</template>
Things pass us by. Nobody can catch them. That's the way we live our lives.
</n-popconfirm>
<n-popconfirm>
<template #trigger>
<n-button>Custom action</n-button>
</template>
<template #action>
<n-tag type="primary">Yes</n-tag>
</template>
Things pass us by. Nobody can catch them. That's the way we live our lives.
</n-popconfirm>
</n-space>
```
```js
import { defineComponent } from 'vue'
import { useMessage } from 'naive-ui'
export default defineComponent({
setup () {
const message = useMessage()
return {
handlePositiveClick () {
message.info('Yes')
},
handleNegativeClick () {
message.info('No')
}
}
}
})
```

View File

@ -10,6 +10,7 @@ custom-action
custom-icon
event
no-icon
actions
```
## Props

View File

@ -0,0 +1,61 @@
# 操作
```html
<n-space>
<n-popconfirm
@positive-click="handlePositiveClick"
@negative-click="handleNegativeClick"
>
<template #trigger>
<n-button>引用</n-button>
</template>
一切都将一去杳然,任何人都无法将其捕获。
</n-popconfirm>
<n-popconfirm :negative-text="null" @positive-click="handlePositiveClick">
<template #trigger>
<n-button>只有确定</n-button>
</template>
一切都将一去杳然,任何人都无法将其捕获。
</n-popconfirm>
<n-popconfirm :positive-text="null" @negative-click="handleNegativeClick">
<template #trigger>
<n-button>只有取消</n-button>
</template>
一切都将一去杳然,任何人都无法将其捕获。
</n-popconfirm>
<n-popconfirm :positive-text="null" :negative-text="null">
<template #trigger>
<n-button>什么也没有</n-button>
</template>
一切都将一去杳然,任何人都无法将其捕获。
</n-popconfirm>
<n-popconfirm>
<template #trigger>
<n-button>自定义 action</n-button>
</template>
<template #action>
<n-tag type="primary">好的</n-tag>
</template>
一切都将一去杳然,任何人都无法将其捕获。
</n-popconfirm>
</n-space>
```
```js
import { defineComponent } from 'vue'
import { useMessage } from 'naive-ui'
export default defineComponent({
setup () {
const message = useMessage()
return {
handlePositiveClick () {
message.info('是的')
},
handleNegativeClick () {
message.info('并不')
}
}
}
})
```

View File

@ -10,6 +10,7 @@ custom-action
custom-icon
event
no-icon
actions
```
## Props

View File

@ -63,6 +63,9 @@ export default defineComponent({
localizedNegativeText: computed(() => {
return props.negativeText || localeRef.value.negativeText
}),
hasNeitherText: computed(() => {
return props.positiveText === null && props.negativeText === null
}),
handlePositiveClick (e: MouseEvent) {
props.onPositiveClick(e)
},
@ -88,18 +91,29 @@ export default defineComponent({
{renderSlot($slots, 'default')}
</div>
<div class={`${mergedClsPrefix}-popconfirm__action`}>
{renderSlot($slots, 'action', undefined, () => [
<NButton size="small" onClick={this.handleNegativeClick}>
{{ default: () => this.localizedNegativeText }}
</NButton>,
<NButton
size="small"
type="primary"
onClick={this.handlePositiveClick}
>
{{ default: () => this.localizedPositiveText }}
</NButton>
])}
{renderSlot(
$slots,
'action',
undefined,
() =>
((!this.hasNeitherText || $slots.action) && [
this.negativeText !== null && (
<NButton size="small" onClick={this.handleNegativeClick}>
{{ default: () => this.localizedNegativeText }}
</NButton>
),
this.positiveText !== null && (
<NButton
size="small"
type="primary"
onClick={this.handlePositiveClick}
>
{{ default: () => this.localizedPositiveText }}
</NButton>
)
]) ||
[]
)}
</div>
</div>
)