Skip to content

Commit 9688104

Browse files
committed
fix: ts类型和单测修正
1 parent f6edf91 commit 9688104

41 files changed

Lines changed: 164 additions & 132 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/packages/datepicker/__test__/datepicker.spec.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ test('Min date & Max date', async () => {
4040
/>
4141
)
4242

43-
const columns = container.querySelectorAll('.nut-pickerview-list')[0]
44-
const lists = columns.querySelectorAll('.nut-pickerview-roller-item-tiled')
43+
const columns = container.querySelectorAll('.nut-pickerview-list')
44+
const lists = columns[0].querySelectorAll('.nut-pickerview-roller-item-tiled')
4545
expect(lists.length).toBe(3)
4646
rerender(
4747
<DatePicker
@@ -162,8 +162,8 @@ test('Increment step setting', async () => {
162162
/>
163163
)
164164

165-
const columns = container.querySelectorAll('.nut-pickerview-list')[1]
166-
const lists = columns.querySelectorAll('.nut-pickerview-roller-item')
165+
const columns = container.querySelectorAll('.nut-pickerview-list')
166+
const lists = columns[1].querySelectorAll('.nut-pickerview-roller-item')
167167
expect(lists.length).toBe(12)
168168
})
169169

@@ -185,7 +185,7 @@ test('Filter Time', async () => {
185185
/>
186186
)
187187

188-
const columns = container.querySelectorAll('.nut-pickerview-list')[3]
189-
const lists = columns.querySelectorAll('.nut-pickerview-roller-item')
188+
const columns = container.querySelectorAll('.nut-pickerview-list')
189+
const lists = columns[3].querySelectorAll('.nut-pickerview-roller-item')
190190
expect(lists.length).toBe(4)
191191
})

src/packages/datepicker/datepicker.taro.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { usePropsValue } from '@/hooks/use-props-value'
66
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
77
import { isDate } from '@/utils/is-date'
88
import { padZero } from '@/utils/pad-zero'
9-
import { PickerOptionItem, PickerValue } from '@/packages/pickerview/index.taro'
9+
import {
10+
PickerOption,
11+
PickerOptions,
12+
PickerValue,
13+
} from '@/packages/pickerview/types'
1014

1115
export interface DatePickerProps extends BasicComponent {
1216
value?: Date
@@ -39,16 +43,16 @@ export interface DatePickerProps extends BasicComponent {
3943
| 'onChange'
4044
>
4145
>
42-
formatter: (type: string, option: PickerOptionItem) => PickerOptionItem
43-
filter: (type: string, option: PickerOptionItem[]) => PickerOptionItem[]
46+
formatter: (type: string, option: PickerOption) => PickerOption
47+
filter: (type: string, options: PickerOptions) => PickerOptions
4448
onClose: () => void
4549
onCancel: () => void
4650
onConfirm: (
47-
selectedOptions: PickerOptionItem[],
51+
selectedOptions: PickerOptions,
4852
selectedValue: PickerValue[]
4953
) => void
5054
onChange?: (
51-
selectedOptions: PickerOptionItem[],
55+
selectedOptions: PickerOptions,
5256
selectedValue: PickerValue[],
5357
columnIndex: number
5458
) => void
@@ -106,7 +110,7 @@ export const DatePicker: FunctionComponent<
106110
seconds: lang.seconds,
107111
}
108112
const [pickerValue, setPickerValue] = useState<PickerValue[]>([])
109-
const [pickerOptions, setPickerOptions] = useState<PickerOptionItem[][]>([])
113+
const [pickerOptions, setPickerOptions] = useState<PickerOptions[]>([])
110114
const formatValue = (value: Date | null) => {
111115
if (!value || (value && !isDate(value))) {
112116
value = startDate
@@ -219,7 +223,7 @@ export const DatePicker: FunctionComponent<
219223
const compareDateChange = (
220224
currentDate: number,
221225
newDate: Date | null,
222-
selectedOptions: PickerOptionItem[],
226+
selectedOptions: PickerOptions,
223227
index: number
224228
) => {
225229
const isEqual = new Date(currentDate)?.getTime() === newDate?.getTime()
@@ -239,7 +243,7 @@ export const DatePicker: FunctionComponent<
239243
}
240244
}
241245
const handlePickerChange = (
242-
selectedOptions: PickerOptionItem[],
246+
selectedOptions: PickerOptions,
243247
selectedValue: PickerValue[],
244248
index: number
245249
) => {
@@ -331,7 +335,7 @@ export const DatePicker: FunctionComponent<
331335
columnIndex: number
332336
) => {
333337
let cmin = min
334-
const arr: Array<PickerOptionItem> = []
338+
const arr: Array<PickerOption> = []
335339
let index = 0
336340
while (cmin <= max) {
337341
arr.push(formatOption(type, cmin))
@@ -414,7 +418,7 @@ export const DatePicker: FunctionComponent<
414418
onCancel={onCancel}
415419
value={pickerValue}
416420
onConfirm={(
417-
selectedOptions: PickerOptionItem[],
421+
selectedOptions: PickerOptions,
418422
selectedValue: PickerValue[]
419423
) => onConfirm && onConfirm(selectedOptions, selectedValue)}
420424
onChange={({ value, index, selectedOptions }) => {

src/packages/datepicker/datepicker.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import React, { FunctionComponent, useState, useEffect } from 'react'
2-
import Picker from '@/packages/picker'
3-
import { PickerProps } from '@/packages/picker/index'
2+
import Picker, { PickerProps } from '@/packages/picker/index'
43
import { useConfig } from '@/packages/configprovider'
54
import { usePropsValue } from '@/hooks/use-props-value'
65
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
76
import { isDate } from '@/utils/is-date'
87
import { padZero } from '@/utils/pad-zero'
9-
import { PickerOptionItem, PickerValue } from '@/packages/pickerview/index'
8+
import {
9+
PickerOption,
10+
PickerOptions,
11+
PickerValue,
12+
} from '@/packages/pickerview/types'
1013

1114
export interface DatePickerProps extends BasicComponent {
1215
value?: Date
@@ -39,16 +42,16 @@ export interface DatePickerProps extends BasicComponent {
3942
| 'onChange'
4043
>
4144
>
42-
formatter: (type: string, option: PickerOptionItem) => PickerOptionItem
43-
filter: (type: string, option: PickerOptionItem[]) => PickerOptionItem[]
45+
formatter: (type: string, option: PickerOption) => PickerOption
46+
filter: (type: string, options: PickerOptions) => PickerOptions
4447
onClose: () => void
4548
onCancel: () => void
4649
onConfirm: (
47-
selectedOptions: PickerOptionItem[],
50+
selectedOptions: PickerOptions,
4851
selectedValue: PickerValue[]
4952
) => void
5053
onChange?: (
51-
selectedOptions: PickerOptionItem[],
54+
selectedOptions: PickerOptions,
5255
selectedValue: PickerValue[],
5356
columnIndex: number
5457
) => void
@@ -106,7 +109,7 @@ export const DatePicker: FunctionComponent<
106109
seconds: lang.seconds,
107110
}
108111
const [pickerValue, setPickerValue] = useState<PickerValue[]>([])
109-
const [pickerOptions, setPickerOptions] = useState<PickerOptionItem[][]>([])
112+
const [pickerOptions, setPickerOptions] = useState<PickerOptions[]>([])
110113
const formatValue = (value: Date | null) => {
111114
if (!value || (value && !isDate(value))) {
112115
value = startDate
@@ -219,7 +222,7 @@ export const DatePicker: FunctionComponent<
219222
const compareDateChange = (
220223
currentDate: number,
221224
newDate: Date | null,
222-
selectedOptions: PickerOptionItem[],
225+
selectedOptions: PickerOptions,
223226
index: number
224227
) => {
225228
const isEqual = new Date(currentDate)?.getTime() === newDate?.getTime()
@@ -239,7 +242,7 @@ export const DatePicker: FunctionComponent<
239242
}
240243
}
241244
const handlePickerChange = (
242-
selectedOptions: PickerOptionItem[],
245+
selectedOptions: PickerOptions,
243246
selectedValue: PickerValue[],
244247
index: number
245248
) => {
@@ -331,7 +334,7 @@ export const DatePicker: FunctionComponent<
331334
columnIndex: number
332335
) => {
333336
let cmin = min
334-
const arr: Array<PickerOptionItem> = []
337+
const arr: Array<PickerOption> = []
335338
let index = 0
336339
while (cmin <= max) {
337340
arr.push(formatOption(type, cmin))
@@ -409,7 +412,7 @@ export const DatePicker: FunctionComponent<
409412
onCancel={onCancel}
410413
value={pickerValue}
411414
onConfirm={(
412-
selectedOptions: PickerOptionItem[],
415+
selectedOptions: PickerOptions,
413416
selectedValue: PickerValue[]
414417
) => onConfirm && onConfirm(selectedOptions, selectedValue)}
415418
onChange={({ value, index, selectedOptions }) => {

src/packages/datepicker/demos/h5/demo1.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
DatePicker,
44
Cell,
55
PickerValue,
6-
PickerOptionItem,
6+
PickerOptions,
77
} from '@nutui/nutui-react'
88

99
const Demo1 = () => {
@@ -17,10 +17,10 @@ const Demo1 = () => {
1717
const [value, setValue] = useState('2023/01/01')
1818
const [show2, setShow2] = useState(false)
1919
const [desc2, setDesc2] = useState('')
20-
const confirm1 = (values: PickerValue[], options: PickerOptionItem[]) => {
20+
const confirm1 = (values: PickerValue[], options: PickerOptions) => {
2121
setDesc1(options.map((option) => option.label).join(' '))
2222
}
23-
const change = (options: PickerOptionItem[], values: PickerValue[]) => {
23+
const change = (options: PickerOptions, values: PickerValue[]) => {
2424
const v = values.join('/')
2525

2626
setValue(v)

src/packages/datepicker/demos/h5/demo2.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState } from 'react'
22
import {
33
DatePicker,
44
Cell,
5-
PickerOptionItem,
5+
PickerOptions,
66
PickerValue,
77
} from '@nutui/nutui-react'
88

@@ -13,7 +13,7 @@ const Demo2 = () => {
1313
`${defaultValue.getMonth() + 1}-${defaultValue.getDate()}`
1414
)
1515

16-
const confirm = (values: PickerValue[], options: PickerOptionItem[]) => {
16+
const confirm = (values: PickerValue[], options: PickerOptions) => {
1717
console.log('values', values, options)
1818
setDesc(options.map((option) => option.label).join('-'))
1919
}

src/packages/datepicker/demos/h5/demo3.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState } from 'react'
22
import {
33
DatePicker,
44
Cell,
5-
PickerOptionItem,
5+
PickerOptions,
66
PickerValue,
77
} from '@nutui/nutui-react'
88

@@ -16,7 +16,7 @@ const Demo3 = () => {
1616
const endDate = new Date(2025, 10, 1)
1717
const [show, setShow] = useState(false)
1818
const [desc, setDesc] = useState(`${defaultDescription} 11:08`)
19-
const confirm = (values: PickerValue[], options: PickerOptionItem[]) => {
19+
const confirm = (values: PickerValue[], options: PickerOptions) => {
2020
const date = values.slice(0, 3).join('-')
2121
const time = values.slice(3).join(':')
2222
setDesc(`${date} ${time}`)

src/packages/datepicker/demos/h5/demo4.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
DatePicker,
44
Cell,
55
PickerValue,
6-
PickerOptionItem,
6+
PickerOptions,
77
} from '@nutui/nutui-react'
88

99
const Demo4 = () => {
@@ -15,7 +15,7 @@ const Demo4 = () => {
1515
const endDate = new Date(2025, 10, 1)
1616
const [show, setShow] = useState(false)
1717
const [desc, setDesc] = useState('10:10:00')
18-
const confirm = (values: PickerValue[], options: PickerOptionItem[]) => {
18+
const confirm = (values: PickerValue[], options: PickerOptions) => {
1919
setDesc(options.map((option) => option.label).join(':'))
2020
}
2121

src/packages/datepicker/demos/h5/demo5.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState } from 'react'
22
import {
33
DatePicker,
44
Cell,
5-
PickerOptionItem,
5+
PickerOptions,
66
PickerValue,
77
} from '@nutui/nutui-react'
88

@@ -15,7 +15,7 @@ const Demo5 = () => {
1515
const endDate = new Date(2025, 10, 1)
1616
const [show, setShow] = useState(false)
1717
const [desc, setDesc] = useState('10:10')
18-
const confirm8 = (options: PickerOptionItem[], values: PickerValue[]) => {
18+
const confirm8 = (options: PickerOptions, values: PickerValue[]) => {
1919
setDesc(options.map((option) => option.label).join(':'))
2020
}
2121

src/packages/datepicker/demos/h5/demo6.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
DatePicker,
44
Cell,
55
PickerValue,
6-
PickerOptionItem,
6+
PickerOption,
7+
PickerOptions,
78
} from '@nutui/nutui-react'
89

910
const Demo6 = () => {
@@ -14,7 +15,7 @@ const Demo6 = () => {
1415
const [show, setShow] = useState(false)
1516
const [desc, setDesc] = useState(`${defaultDescription} 10:10`)
1617

17-
const confirm = (values: PickerValue[], options: PickerOptionItem[]) => {
18+
const confirm = (values: PickerValue[], options: PickerOptions) => {
1819
const date = options
1920
.slice(1, 3)
2021
.map((op) => op.label)
@@ -25,7 +26,7 @@ const Demo6 = () => {
2526
.join(':')
2627
setDesc(`${options[0].label}${date} ${time}`)
2728
}
28-
const formatter = (type: string, option: PickerOptionItem) => {
29+
const formatter = (type: string, option: PickerOption) => {
2930
switch (type) {
3031
case 'year':
3132
option.label += ''

src/packages/datepicker/demos/h5/demo7.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
DatePicker,
44
Cell,
55
PickerValue,
6-
PickerOptionItem,
6+
PickerOptions,
77
} from '@nutui/nutui-react'
88

99
const Demo7 = () => {
@@ -16,7 +16,7 @@ const Demo7 = () => {
1616
const [show, setShow] = useState(false)
1717
const [desc, setDesc] = useState('10:10:00')
1818

19-
const confirm6 = (values: PickerValue[], options: PickerOptionItem[]) => {
19+
const confirm6 = (values: PickerValue[], options: PickerOptions) => {
2020
setDesc(options.map((option) => option.label).join(':'))
2121
}
2222
return (

0 commit comments

Comments
 (0)