mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-27 05:00:48 +08:00
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:
parent
25cb8cb58c
commit
079e0e25c6
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
61
src/popconfirm/demos/enUS/actions.demo.md
Normal file
61
src/popconfirm/demos/enUS/actions.demo.md
Normal 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')
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
@ -10,6 +10,7 @@ custom-action
|
||||
custom-icon
|
||||
event
|
||||
no-icon
|
||||
actions
|
||||
```
|
||||
|
||||
## Props
|
||||
|
61
src/popconfirm/demos/zhCN/actions.demo.md
Normal file
61
src/popconfirm/demos/zhCN/actions.demo.md
Normal 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('并不')
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
@ -10,6 +10,7 @@ custom-action
|
||||
custom-icon
|
||||
event
|
||||
no-icon
|
||||
actions
|
||||
```
|
||||
|
||||
## Props
|
||||
|
@ -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>
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user