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(date picker) support month type #1202

Merged
merged 100 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
ea64917
feat:n-input Support hidden password
doom-9 Jun 17, 2021
149d8e6
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 17, 2021
8664169
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 18, 2021
0627777
feat(form): support require-mark-placement(#171)
doom-9 Jun 18, 2021
f9729c8
Revert "feat(form): support require-mark-placement(#171)"
doom-9 Jun 18, 2021
2566db7
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 18, 2021
aa41027
Revert "feat:n-input Support hidden password"
doom-9 Jun 18, 2021
3f01195
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 18, 2021
076c432
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 21, 2021
2307ef8
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 21, 2021
d4f08f8
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 21, 2021
56f6d75
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 22, 2021
658835d
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 22, 2021
3d90083
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 22, 2021
1e860cc
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 23, 2021
c1c7942
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 23, 2021
0cb198e
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 24, 2021
71ad4cd
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 24, 2021
cd8476a
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 25, 2021
ac74273
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 26, 2021
e685823
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 28, 2021
2a450f1
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 28, 2021
b02f5f8
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 29, 2021
4f151e7
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 29, 2021
b8cf341
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 29, 2021
c7fa132
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 30, 2021
d7348e6
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 1, 2021
c504c72
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 1, 2021
c14f943
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 1, 2021
23da897
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 2, 2021
eb86273
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 2, 2021
ba7fdda
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 2, 2021
51430c2
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 3, 2021
f25cbf3
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 3, 2021
bfdf90f
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 3, 2021
36939e1
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 4, 2021
244ea96
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 4, 2021
a445262
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 5, 2021
43a5740
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 5, 2021
8c53a25
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 5, 2021
bdddc47
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 6, 2021
c4b7311
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 6, 2021
3ac6a8a
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 7, 2021
9c59190
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 8, 2021
988f21f
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 8, 2021
f6a3a9c
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 9, 2021
c1e42a7
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 10, 2021
4e65da9
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 11, 2021
bd7b76c
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 12, 2021
22576d3
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 13, 2021
a3e4ecb
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 15, 2021
89b4729
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 16, 2021
c603d61
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 17, 2021
4536c5a
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 22, 2021
b9b72a4
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 24, 2021
69ef0b6
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 26, 2021
2f3f242
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 27, 2021
cde10b4
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 30, 2021
3d370f7
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 2, 2021
182f166
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 3, 2021
b9ac1d9
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 8, 2021
a77df05
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 9, 2021
59de411
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 10, 2021
1d21533
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 11, 2021
ae2e706
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 12, 2021
4a93636
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 13, 2021
f5f59c5
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 16, 2021
de2aa61
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 18, 2021
e9c17d4
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 20, 2021
4b88be4
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 21, 2021
ddb72e0
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 23, 2021
2fc986b
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 25, 2021
80a016c
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 26, 2021
d2afcd9
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 30, 2021
a1ebf69
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 31, 2021
98c953c
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 1, 2021
2c759c4
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 2, 2021
ede7006
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 3, 2021
d49332c
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 4, 2021
4849399
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 6, 2021
2cab16e
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 9, 2021
2a54fd7
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 10, 2021
f302028
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 12, 2021
8ba779c
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 13, 2021
1b770b3
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 14, 2021
40395dc
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 15, 2021
74e65b8
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 16, 2021
dc31190
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 18, 2021
f23518f
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 22, 2021
1af12fb
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 23, 2021
536c07b
Merge branch 'TuSimple:main' into main
doom-9-zz Sep 24, 2021
3a3a24f
feat(date-picker): wip
doom-9 Sep 15, 2021
949a161
feat(date-picker): wip
doom-9 Sep 16, 2021
19cf669
feat(date-picker): support VirtualList
doom-9 Sep 16, 2021
350ceb3
wip
doom-9 Sep 18, 2021
7036e5f
添加 NScrollbar
doom-9 Sep 22, 2021
b1a3366
Update use-calendar.ts
doom-9 Sep 22, 2021
d89c33f
changelog
doom-9 Sep 22, 2021
9e8d7b8
抽取公共代码
doom-9 Sep 23, 2021
b2f41b5
完善代码
doom-9 Sep 24, 2021
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
3 changes: 3 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Localization

- Add ukUA locale.
### Feats

- `n-date-picker`'s `type` prop support `month` option.

### 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 @@
### Localization

- 新增 ukUA locale
### Feats

- `n-date-picker` 属性 `type` 支持 `month` 选项

### Fixes

Expand Down
3 changes: 2 additions & 1 deletion src/date-picker/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ date
datetime
daterange
datetimerange
month
size
disabled
disabled-time
Expand All @@ -32,7 +33,7 @@ update-on-close
| input-readonly | `boolean` | `false` | Set the `readonly` attribute of the input (avoids virtual keyboard on touch devices). |
| shortcuts | `Record<string, number \| [number, number]>` | `undefined` | Shortcut button customizations. |
| size | `'small' \| 'medium' \| 'large'` | `'medium'` | Date picker size. |
| type | `'date' \| 'datetime' \| 'daterange' \|'datetimerange'` | `'date'` | Date picker type. |
| type | `'date' \| 'datetime' \| 'daterange' \|'datetimerange' \|'month'` | `'date'` | Date picker type. |
| value | `number \| [number, number] \| null` | `undefined` | Value of the date picker when being manually set. |
| on-blur | `() => void` | `undefined` | On blur callback. |
| on-focus | `() => void` | `undefined` | On focus callback. |
Expand Down
18 changes: 18 additions & 0 deletions src/date-picker/demos/enUS/month.demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Month

```html
<n-date-picker v-model:value="timestamp" type="month" clearable />
<pre>{{ JSON.stringify(timestamp) }}</pre>
```

```js
import { defineComponent, ref } from 'vue'

export default defineComponent({
setup () {
return {
timestamp: ref(1183135260000)
}
}
})
```
3 changes: 2 additions & 1 deletion src/date-picker/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ date
datetime
daterange
datetimerange
month
size
disabled
disabled-time
Expand All @@ -32,7 +33,7 @@ update-on-close
| input-readonly | `boolean` | `false` | 设置输入框为只读(避免在移动设备上打开虚拟键盘) |
| shortcuts | `Record<string, number \| [number, number]>` | `undefined` | 自定义快捷按钮 |
| size | `'small' \| 'medium' \| 'large'` | `'medium'` | 尺寸 |
| type | `'date' \| 'datetime' \| 'daterange' \|'datetimerange'` | `'date'` | Date Picker 的类型 |
| type | `'date' \| 'datetime' \| 'daterange' \|'datetimerange' \|'month'` | `'date'` | Date Picker 的类型 |
| value | `number \| [number, number] \| null` | `undefined` | Date Picker 的值 |
| on-blur | `() => void` | `undefined` | 用户 blur 时执行的回调 |
| on-focus | `() => void` | `undefined` | 用户 focus 时执行的回调 |
Expand Down
18 changes: 18 additions & 0 deletions src/date-picker/demos/zhCN/month.demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 月份

```html
<n-date-picker v-model:value="timestamp" type="month" clearable />
<pre>{{ JSON.stringify(timestamp) }}</pre>
```

```js
import { defineComponent, ref } from 'vue'

export default defineComponent({
setup () {
return {
timestamp: ref(1183135260000)
}
}
})
```
38 changes: 34 additions & 4 deletions src/date-picker/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import {
CSSProperties,
toRef,
Ref,
watchEffect
watchEffect,
nextTick
} from 'vue'
import { VBinder, VTarget, VFollower, FollowerPlacement } from 'vueuc'
import { clickoutside } from 'vdirs'
import { format, getTime, isValid } from 'date-fns'
import { format, getTime, isValid, getYear } from 'date-fns'
import { useIsMounted, useMergedState } from 'vooks'
import { happensIn } from 'seemly'
import { InputInst, InputProps, NInput } from '../../input'
Expand All @@ -37,6 +38,7 @@ import DatetimePanel from './panel/datetime'
import DatetimerangePanel from './panel/datetimerange'
import DatePanel from './panel/date'
import DaterangePanel from './panel/daterange'
import MonthPanel from './panel/month'
import style from './styles/index.cssr'
import { DatePickerTheme } from '../styles/light'
import {
Expand All @@ -55,7 +57,8 @@ const DATE_FORMAT = {
date: 'yyyy-MM-dd',
datetime: 'yyyy-MM-dd HH:mm:ss',
daterange: 'yyyy-MM-dd',
datetimerange: 'yyyy-MM-dd HH:mm:ss'
datetimerange: 'yyyy-MM-dd HH:mm:ss',
month: 'yyyy-MM'
}

const datePickerProps = {
Expand Down Expand Up @@ -89,7 +92,7 @@ const datePickerProps = {
size: String as PropType<'small' | 'medium' | 'large'>,
type: {
type: String as PropType<
'date' | 'datetime' | 'daterange' | 'datetimerange'
'date' | 'datetime' | 'daterange' | 'datetimerange' | 'month'
>,
default: 'date'
},
Expand Down Expand Up @@ -307,6 +310,24 @@ export default defineComponent({
disableUpdateOnClose
})
}
function scrollTimer (): void {
if (!panelInstRef.value) return
const { monthScrollRef, yearScrollRef } = panelInstRef.value
if (monthScrollRef) {
const month = monthScrollRef.contentRef?.querySelector(
'[data-selected]'
) as HTMLElement
if (month) {
monthScrollRef.scrollTo({ top: month.offsetTop })
}
}
if (yearScrollRef) {
if (mergedValueRef.value) {
const yearIndex = getYear(mergedValueRef.value as number) - 1900
yearScrollRef.scrollTo({ top: yearIndex * 40 })
}
}
}
// --- Panel update value
function handlePanelUpdateValue (
value: Value | null,
Expand Down Expand Up @@ -448,6 +469,9 @@ export default defineComponent({
function openCalendar (): void {
if (mergedDisabledRef.value || mergedShowRef.value) return
doUpdateShow(true)
if (props.type === 'month') {
void nextTick(scrollTimer)
}
}
function closeCalendar ({
returnFocus,
Expand Down Expand Up @@ -586,6 +610,8 @@ export default defineComponent({
itemSize,
itemCellWidth,
itemCellHeight,
itemMonthCellWidth,
itemMonthCellHeight,
calendarTitlePadding,
calendarTitleHeight,
calendarDaysHeight,
Expand Down Expand Up @@ -639,6 +665,8 @@ export default defineComponent({
'--item-size': itemSize,
'--item-cell-width': itemCellWidth,
'--item-cell-height': itemCellHeight,
'--item-month-cell-width': itemMonthCellWidth,
'--item-month-cell-height': itemMonthCellHeight,
'--item-text-color': itemTextColor,
'--item-color-included': itemColorIncluded,
'--item-color-disabled': itemColorDisabled,
Expand Down Expand Up @@ -798,6 +826,8 @@ export default defineComponent({
<DaterangePanel {...commonPanelProps} />
) : this.type === 'datetimerange' ? (
<DatetimerangePanel {...commonPanelProps} />
) : this.type === 'month' ? (
<MonthPanel {...commonPanelProps} />
) : (
<DatePanel {...commonPanelProps} />
),
Expand Down
8 changes: 7 additions & 1 deletion src/date-picker/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { InjectionKey, Ref, Slots } from 'vue'
import { VirtualListInst } from 'vueuc'
import { NLocale, NDateLocale } from '../../locales'
import { ScrollbarInst } from '../../scrollbar'
import {
IsHourDisabled,
IsMinuteDisabled,
Expand All @@ -14,7 +16,9 @@ import {

export type Value = number | [number, number]

export type Shortcuts = Record<string, number> | Record<string, [number, number]>
export type Shortcuts =
| Record<string, number>
| Record<string, [number, number]>

export type OnUpdateValue = (
value: number & (number | null) & [number, number] & ([number, number] | null)
Expand All @@ -39,6 +43,8 @@ export type OnClose = (disableUpdateOnClose: boolean) => void

export interface PanelRef {
$el: HTMLElement
monthScrollRef: ScrollbarInst | null
yearScrollRef: VirtualListInst | null
}

export type DatePickerInjection = {
Expand Down
Loading