feat(time-picker): add actions prop (#463)

* feat(time-picker): add actions prop

* feat(time-picker): add confirm

* fix(change-log): time-picker zh

* Update CHANGELOG.en-US.md

* Update CHANGELOG.zh-CN.md

Co-authored-by: Jiwen Bai <56228105@qq.com>
Co-authored-by: 07akioni <07akioni2@gmail.com>
This commit is contained in:
Mr.Bai 2021-07-23 23:26:55 +08:00 committed by GitHub
parent 9570c5629f
commit 036cff0c90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 83 additions and 19 deletions

View File

@ -1,5 +1,11 @@
# CHANGELOG
## Pending
### Feats
- `n-time-picker` add `actions` prop, closes [#401](https://github.com/TuSimple/naive-ui/issues/401).
## 2.15.6 (2021-07-23)
### Feats

View File

@ -1,5 +1,11 @@
# CHANGELOG
## Pending
### Feats
- `n-time-picker` 增加 `actions` 属性, 关闭 [#401](https://github.com/TuSimple/naive-ui/issues/401)
## 2.15.6 (2021-07-23)
### Feats

View File

@ -0,0 +1,19 @@
# Actions
```html
<n-space vertical>
<n-time-picker v-model:value="ts1" :actions="['now']" />
<n-time-picker v-model:value="ts2" :actions="null" />
</n-space>
```
```js
export default {
data () {
return {
ts1: null,
ts2: 861333934000
}
}
}
```

View File

@ -10,12 +10,14 @@ size
disabled-time
step-time
format
actions
```
## Props
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| actions | `Array<'now' \| 'confirm'> \| null` | `['now', 'confirm']` | Operations supported in Time Picker. |
| clearable | `boolean` | `false` | Whether the value is clearable. |
| default-value | `number \| null` | `null` | Default value in uncontrolled mode. |
| disabled | `boolean` | `false` | Whether to disable. |

View File

@ -0,0 +1,19 @@
# 操作
```html
<n-space vertical>
<n-time-picker v-model:value="ts1" :actions="['now']" />
<n-time-picker v-model:value="ts2" :actions="null" />
</n-space>
```
```js
export default {
data () {
return {
ts1: null,
ts2: 861333934000
}
}
}
```

View File

@ -10,12 +10,14 @@ size
disabled-time
step-time
format
actions
```
## Props
| 名称 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| actions | `Array<'now' \| 'confirm'> \| null` | `['now', 'confirm']` | Time Picker 中支持的操作 |
| clearable | `boolean` | `false` | 是否可清空 |
| default-value | `number \| null` | `null` | 非受控模式下的默认值 |
| disabled | `boolean` | `false` | 是否禁用 |

View File

@ -15,6 +15,10 @@ import { MaybeArray } from '../../_utils'
export default defineComponent({
name: 'TimePickerPanel',
props: {
actions: {
type: Array as PropType<Array<'now' | 'confirm'>>,
default: () => ['now', 'confirm']
},
showHour: {
type: Boolean,
default: true
@ -273,25 +277,29 @@ export default defineComponent({
) : null}
</div>,
<div class={`${mergedClsPrefix}-time-picker-actions`}>
<NButton
size="tiny"
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
onClick={this.onNowClick}
>
{{ default: () => this.nowText }}
</NButton>
<NButton
size="tiny"
type="primary"
class={`${mergedClsPrefix}-time-picker-actions__confirm`}
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
disabled={this.isValueInvalid}
onClick={this.onConfirmClick}
>
{{ default: () => this.confirmText }}
</NButton>
{this.actions?.includes('now') ? (
<NButton
size="tiny"
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
onClick={this.onNowClick}
>
{{ default: () => this.nowText }}
</NButton>
) : null}
{this.actions?.includes('confirm') ? (
<NButton
size="tiny"
type="primary"
class={`${mergedClsPrefix}-time-picker-actions__confirm`}
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
disabled={this.isValueInvalid}
onClick={this.onConfirmClick}
>
{{ default: () => this.confirmText }}
</NButton>
) : null}
</div>,
<NBaseFocusDetector onFocus={this.onFocusDetectorFocus} />
]

View File

@ -78,6 +78,7 @@ const timePickerProps = {
type: Boolean as PropType<boolean | undefined>,
default: undefined
},
actions: Array as PropType<Array<'now' | 'confirm'>>,
defaultValue: {
type: Number as PropType<number | null>,
default: null
@ -689,6 +690,7 @@ export default defineComponent({
? withDirectives(
<Panel
ref="panelInstRef"
actions={this.actions}
style={this.cssVars as CSSProperties}
seconds={this.seconds}
minutes={this.minutes}