Skip to content

Commit

Permalink
feat(date-picker): adds default-calendar-start-time prop when type …
Browse files Browse the repository at this point in the history
…is `date\datetime\week`, closes tusen-ai#4493
  • Loading branch information
jizai1125 committed Feb 23, 2024
1 parent 82fccfb commit 335fc67
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## NEXT_VERSION

### Features

- `n-date-picker` adds `default-calendar-start-time` props when `type` is `date\datetime\week`, closes [#4493](https://github.com/tusen-ai/naive-ui/issues/4493).

## 2.38.0

`2024-02-22`
Expand Down Expand Up @@ -27,6 +33,8 @@
- `n-split` adds `size` prop and `on-update:size` prop.
- `n-split` adds `watch-props` prop, closes [#5526](https://github.com/tusen-ai/naive-ui/issues/5526).
- `n-drawer` adds `borderRadius` theme variable.
- adds `n-float-button` component.
- Provides ES module bundle.

### i18n

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## NEXT_VERSION

### Features

- `n-date-picker``type``date\datetime\week` 时新增 `default-calendar-start-time` 属性,关闭 [#4493](https://github.com/tusen-ai/naive-ui/issues/4493)

## 2.38.0

`2024-02-22`
Expand Down Expand Up @@ -27,6 +33,8 @@
- `n-split` 新增 `size``on-update:size` 属性
- `n-split` 新增 `watch-props` 属性,关闭 [#5526](https://github.com/tusen-ai/naive-ui/issues/5526)
- `n-drawer` 新增 `borderRadius` 主题变量
- 新增 `n-float-button` 组件
- 提供 ES module 打包

### i18n

Expand Down
3 changes: 3 additions & 0 deletions src/date-picker/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ panel.vue
| Name | Type | Default | Description | Version |
| --- | --- | --- | --- | --- |
| actions | `Array<'clear' \| 'now'> \| null` | `['clear', 'now']` | Operations supported for the `date` type date picker. | |
| default-calendar-start-time | `number` | `undefined` | Default panel calendar start month timestamp. | NEXT_VERSION |
| format | `string` | `'yyyy-MM-dd'` | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | |
| is-date-disabled | `(current: number, detail: { type: 'date', year: number, month: number, date: number } \| { type: 'month', year: number, month: number } \| { type: 'year', year: number } \| { type: 'quarter', year: number, quarter: number } \| { type: 'input' }) => boolean` | `() => false` | Validator of the date. | `detail` 2.37.1 |
| placeholder | `string` | `'Select Date'` | Placeholder. | |
Expand All @@ -84,6 +85,7 @@ panel.vue
| Name | Type | Default | Description | Version |
| --- | --- | --- | --- | --- |
| actions | `Array<'clear' \| 'now' \| 'confirm'> \| null` | `['clear', 'now', 'confirm']` | Operations supported for the `datetime` type date picker. | |
| default-calendar-start-time | `number` | `undefined` | Default panel calendar start month timestamp. | NEXT_VERSION |
| default-time | `string` | `undefined` | Default time of the selected date. It's format is `HH:mm:ss`. | 2.22.0 |
| format | `string` | `'yyyy-MM-dd HH:mm:ss'` | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | |
| is-date-disabled | `(current: number, detail: { type: 'date', year: number, month: number, date: number } \| { type: 'month', year: number, month: number } \| { type: 'year', year: number } \| { type: 'quarter', year: number, quarter: number } \| { type: 'input' }) => boolean` | `() => false` | Validator of the date. | `detail` 2.37.1 |
Expand Down Expand Up @@ -174,6 +176,7 @@ panel.vue
| Name | Type | Default | Description | Version |
| --- | --- | --- | --- | --- |
| actions | `Array<'clear' \| 'now'> \| null` | `['clear', 'now']` | Operations supported for the `week` type date picker. | 2.37.0 |
| default-calendar-start-time | `number` | `undefined` | Default panel calendar start month timestamp. | NEXT_VERSION |
| format | `string` | `'yyyy-w'` for en-US, Locale specific. | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | 2.37.0 |
| placeholder | `string` | `'Select Week'` for en-US, Locale specific. | Placeholder. | 2.37.0 |
| on-update:formatted-value | `(value: string \| null, timestampValue: number \| null) => void` | `undefined` | Formatted value changed callback. | 2.37.0 |
Expand Down
3 changes: 3 additions & 0 deletions src/date-picker/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ form-debug.vue
| 名称 | 类型 | 默认值 | 说明 | 版本 |
| --- | --- | --- | --- | --- |
| actions | `Array<'clear' \| 'now'> \| null` | `['clear', 'now']` | Date 类型的 Date Picker 中支持的操作 | |
| default-calendar-start-time | `number` | `undefined` | 面板日历默认开始的月份时间戳 | NEXT_VERSION |
| format | `string` | `'yyyy-MM-dd'` | 时间格式化字符串,详情见 [format](https://date-fns.org/v2.23.0/docs/format) | |
| is-date-disabled | `(current: number, detail: { type: 'date', year: number, month: number, date: number } \| { type: 'month', year: number, month: number } \| { type: 'year', year: number } \| { type: 'quarter', year: number, quarter: number } \| { type: 'input' }) => boolean` | `undefined` | 日期禁用的校验函数 | `detail` 2.37.1 |
| placeholder | `string` | `'选择日期'` | 没有值时的占位信息 | |
Expand All @@ -85,6 +86,7 @@ form-debug.vue
| 名称 | 类型 | 默认值 | 说明 | 版本 |
| --- | --- | --- | --- | --- |
| actions | `Array<'clear' \| 'now' \| 'confirm'> \| null` | `['clear', 'now', 'confirm']` | DateTime 类型的 Date Picker 中支持的操作 | |
| default-calendar-start-time | `number` | `undefined` | 面板日历默认开始的月份时间戳 | NEXT_VERSION |
| default-time | `string` | `undefined` | 默认时间,格式为 `HH:mm:ss` | 2.22.0 |
| format | `string` | `'yyyy-MM-dd HH:mm:ss'` | 时间格式化字符串,详情见 [format](https://date-fns.org/v2.23.0/docs/format) | |
| is-date-disabled | `(current: number, detail: { type: 'date', year: number, month: number, date: number } \| { type: 'month', year: number, month: number } \| { type: 'year', year: number } \| { type: 'quarter', year: number, quarter: number } \| { type: 'input' }) => boolean` | `undefined` | 日期禁用的校验函数 | `detail` 2.37.1 |
Expand Down Expand Up @@ -174,6 +176,7 @@ form-debug.vue
| 名称 | 类型 | 默认值 | 说明 | 版本 |
| --- | --- | --- | --- | --- |
| actions | `Array<'clear' \| 'now'> \| null` | `['clear', 'now']` | Week 类型的 Date Picker 中支持的操作 | 2.37.0 |
| default-calendar-start-time | `number` | `undefined` | 面板日历默认开始的月份时间戳 | NEXT_VERSION |
| format | `string` | 中文为 `'yyyy-w'`,随语言变化 | 时间格式化字符串,详情见 [format](https://date-fns.org/v2.23.0/docs/format) | 2.37.0 |
| placeholder | `string` | 中文为 `'选择周'`,随语言变化 | 没有值时的占位信息 | 2.37.0 |
| on-update:formatted-value | `(value: string \| null, timestampValue: number \| null) => void` | `undefined` | 受控数据更新时触发的回调函数 | 2.37.0 |
Expand Down
13 changes: 11 additions & 2 deletions src/date-picker/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,12 @@ export default defineComponent({
const renderPanel = (): VNode => {
const { type } = this
return type === 'datetime' ? (
<DatetimePanel {...commonPanelProps}>{$slots}</DatetimePanel>
<DatetimePanel
{...commonPanelProps}
defaultCalendarStartTime={this.defaultCalendarStartTime}
>
{$slots}
</DatetimePanel>
) : type === 'daterange' ? (
<DaterangePanel
{...commonPanelProps}
Expand All @@ -1053,7 +1058,11 @@ export default defineComponent({
type === 'quarterrange' ? (
<MonthRangePanel {...commonPanelProps} type={type} />
) : (
<DatePanel {...commonPanelProps} type={type}>
<DatePanel
{...commonPanelProps}
type={type}
defaultCalendarStartTime={this.defaultCalendarStartTime}
>
{$slots}
</DatePanel>
)
Expand Down
3 changes: 2 additions & 1 deletion src/date-picker/src/panel/use-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { MONTH_ITEM_HEIGHT, START_YEAR } from '../config'

const useCalendarProps = {
...usePanelCommonProps,
defaultCalendarStartTime: Number,
actions: {
type: Array as PropType<string[]>,
default: () => ['now', 'clear', 'confirm']
Expand Down Expand Up @@ -100,7 +101,7 @@ function useCalendar (
)
const calendarValueRef = ref(
props.value === null || Array.isArray(props.value)
? Date.now()
? props.defaultCalendarStartTime ?? Date.now()
: props.value
)
const yearVlRef = ref<VirtualListInst | null>(null)
Expand Down

0 comments on commit 335fc67

Please sign in to comment.