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

refactor: picker #2990

Open
wants to merge 51 commits into
base: feat_v3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1c1ef86
feat: 初始化pickerview
irisSong Jan 16, 2025
3acf368
feat: add pickerView
irisSong Jan 22, 2025
2e3a00a
feat: add tiled demo
irisSong Jan 22, 2025
c651e62
refactor: 重构h5
irisSong Jan 24, 2025
e60df8e
fix: 适配demo
irisSong Jan 24, 2025
43fc55a
feat: 增加级联功能
irisSong Jan 26, 2025
4ce2688
fix: 级联优化
irisSong Feb 10, 2025
28c4e2c
feat: pickerview增加级联效果
irisSong Feb 11, 2025
bc3fb35
fix: 更新taro版本
irisSong Feb 11, 2025
b0b635c
fix: 移除冗余代码+解决form中滚动未结束死循环问题
irisSong Feb 11, 2025
85d5d40
fix: 移除console
irisSong Feb 12, 2025
7a27934
fix: 更新pickerview
irisSong Feb 12, 2025
a030ff4
fix: update test
irisSong Feb 12, 2025
f436c51
fix: update error
irisSong Feb 12, 2025
6a6bc39
fix: update error
irisSong Feb 12, 2025
10be5cd
fix: update demo
irisSong Feb 12, 2025
80f20a1
Merge remote-tracking branch 'upstream/feat_v3.x' into feat_v3.x_pick…
irisSong Feb 12, 2025
8ad7392
fix: update test
irisSong Feb 12, 2025
95b5423
feat: 添加异步demo
irisSong Feb 12, 2025
fe66362
fix: update doc
irisSong Feb 12, 2025
aa5f2ea
fix: 同步pickerview变更
irisSong Feb 12, 2025
b5987b9
fix: 解决小程序控制条样式问题+demo7取消不还原问题
irisSong Feb 12, 2025
0ae1a26
fix: datepicker类型同步更新
irisSong Feb 12, 2025
ce3b37b
fix: 合并主分支
irisSong Feb 12, 2025
26f9319
fix: update test
irisSong Feb 12, 2025
d5118f6
fix: 修改标签
irisSong Feb 13, 2025
a787f7d
feat: add test
irisSong Feb 13, 2025
c10fcc7
fix: update doc and test
irisSong Feb 13, 2025
9e32bcd
fix: adjust the dependency package location
irisSong Feb 13, 2025
ae272de
Merge remote-tracking branch 'upstream/feat_v3.x' into feat_v3.x_pick…
irisSong Feb 13, 2025
f539b83
fix: adjust the dependency package path
irisSong Feb 13, 2025
f06ec00
fix: adjust the dependency package path
irisSong Feb 13, 2025
b67dfca
fix: adjust the dependency package path
irisSong Feb 13, 2025
9905564
fix: update doc props type
irisSong Feb 13, 2025
0c448c8
fix: adjust note
irisSong Feb 13, 2025
cc30cb0
chore: merge v3.x
irisSong Feb 13, 2025
b699d60
Merge branch 'feat_v3.x_picker' of https://github.com/irisSong/nutui-…
irisSong Feb 13, 2025
7760169
fix: adjust the dependency package path
irisSong Feb 13, 2025
86855f0
fix: 合并最新的pickerview
irisSong Feb 13, 2025
88d4f80
fix: optimize details
irisSong Feb 13, 2025
654d1e0
fix: update test
irisSong Feb 13, 2025
507f18c
fix: merge pickerview
irisSong Feb 13, 2025
d9628e7
fix: path not compilable
irisSong Feb 13, 2025
38296d3
fix: key error
irisSong Feb 13, 2025
dc14741
Merge branch 'feat_v3.x_pickerview' into feat_v3.x_picker
irisSong Feb 14, 2025
65238d3
fix: update datepicker test
irisSong Feb 14, 2025
15630d6
Merge remote-tracking branch 'upstream/feat_v3.x' into feat_v3.x_picker
irisSong Feb 14, 2025
369fec3
fix: hidden entry
irisSong Feb 14, 2025
eb899ee
Merge remote-tracking branch 'upstream/feat_v3.x' into feat_v3.x_picker
irisSong Feb 17, 2025
b458e92
fix: modify config
irisSong Feb 17, 2025
ffba77f
fix: remove repeat config
irisSong Feb 17, 2025
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
22 changes: 17 additions & 5 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@
"show": true,
"taro": true,
"author": "dsj",
"dd": false
"dd": true
},
{
"version": "2.0.0",
Expand All @@ -594,7 +594,7 @@
"show": true,
"taro": true,
"author": "hanyuxinting",
"dd": false
"dd": true
},
{
"version": "2.0.0",
Expand All @@ -607,7 +607,7 @@
"taro": true,
"exportEmpty": true,
"author": "hanyuxinting",
"dd": false
"dd": true
},
{
"version": "3.0.0",
Expand Down Expand Up @@ -687,8 +687,20 @@
"sort": 10,
"show": true,
"taro": true,
"author": "dsj",
"dd": false
"dd": true,
"author": "songsong"
},
{
"version": "2.0.0",
"name": "PickerView",
"type": "component",
"cName": "选择器视图",
"desc": "PickerView 是 Picker 的内容区域。",
"sort": 15,
"show": true,
"taro": true,
"dd": true,
"author": "songsong"
},
{
"version": "3.0.0",
Expand Down
32 changes: 14 additions & 18 deletions src/packages/datepicker/__test__/datepicker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('Show Chinese', async () => {
fireEvent.click(confirmBtn)
await waitFor(() => {
expect(
confirm.mock.calls[0][0].map((option: any) => option.text).join('')
confirm.mock.calls[0][0].map((option: any) => option.label).join('')
).toEqual(`${currentYear - 10}年01月01日`)
})
})
Expand All @@ -40,13 +40,9 @@ test('Min date & Max date', async () => {
/>
)

const columns = container.querySelectorAll('.nut-picker-list')[0]
const lists = columns.querySelectorAll('.nut-picker-roller-item-title')
const years = ['2020', '2021', '2022']
const columns = container.querySelectorAll('.nut-pickerview-list')[0]
const lists = columns.querySelectorAll('.nut-pickerview-roller-item-title')
expect(lists.length).toBe(3)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

修复测试失败!

CI 管道显示此处的断言失败。需要验证选择器和预期的列表长度是否正确。

- const columns = container.querySelectorAll('.nut-pickerview-list')[0]
- const lists = columns.querySelectorAll('.nut-pickerview-roller-item-title')
+ const columns = container.querySelectorAll('.nut-pickerview-list')
+ const lists = columns[0].querySelectorAll('.nut-pickerview-roller-item-title')
  expect(lists.length).toBe(3)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const columns = container.querySelectorAll('.nut-pickerview-list')[0]
const lists = columns.querySelectorAll('.nut-pickerview-roller-item-title')
expect(lists.length).toBe(3)
const columns = container.querySelectorAll('.nut-pickerview-list')
const lists = columns[0].querySelectorAll('.nut-pickerview-roller-item-title')
expect(lists.length).toBe(3)
🧰 Tools
🪛 GitHub Actions: CI

[error] 45-45: AssertionError: expected +0 to be 3 // Object.is equality

lists.forEach((list, i) => {
expect(list.textContent).toEqual(years[i])
})
rerender(
<DatePicker
title="日期选择"
Expand Down Expand Up @@ -98,22 +94,22 @@ test('Min date & Max date', async () => {
const formatter = (type: string, option: any) => {
switch (type) {
case 'year':
option.text += ''
option.label += ''
break
case 'month':
option.text += 'M'
option.label += 'M'
break
case 'day':
option.text += 'D'
option.label += 'D'
break
case 'hour':
option.text += 'H'
option.label += 'H'
break
case 'minute':
option.text += 'M'
option.label += 'M'
break
default:
option.text += ''
option.label += ''
}
return option
}
Expand Down Expand Up @@ -148,7 +144,7 @@ test('should pick defaultValue', async () => {
fireEvent.click(confirmBtn)
await waitFor(() =>
expect(
confirm.mock.calls[0][0].map((option: any) => option.text).join('')
confirm.mock.calls[0][0].map((option: any) => option.label).join('')
).toEqual('20210301')
)
})
Expand All @@ -166,8 +162,8 @@ test('Increment step setting', async () => {
/>
)

const columns = container.querySelectorAll('.nut-picker-list')[1]
const lists = columns.querySelectorAll('.nut-picker-roller-item')
const columns = container.querySelectorAll('.nut-pickerview-list')[1]
const lists = columns.querySelectorAll('.nut-pickerview-roller-item')
expect(lists.length).toBe(12)
})

Expand All @@ -189,7 +185,7 @@ test('Filter Time', async () => {
/>
)

const columns = container.querySelectorAll('.nut-picker-list')[3]
const lists = columns.querySelectorAll('.nut-picker-roller-item')
const columns = container.querySelectorAll('.nut-pickerview-list')[3]
const lists = columns.querySelectorAll('.nut-pickerview-roller-item')
expect(lists.length).toBe(4)
})
48 changes: 24 additions & 24 deletions src/packages/datepicker/datepicker.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { FunctionComponent, useState, useEffect } from 'react'
import { View } from '@tarojs/components'
import Picker, { PickerOption, PickerProps } from '@/packages/picker/index.taro'
import Picker, { PickerProps } from '@/packages/picker/index.taro'
import { useConfig } from '@/packages/configprovider/index.taro'
import { usePropsValue } from '@/hooks/use-props-value'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
import { isDate } from '@/utils/is-date'
import { padZero } from '@/utils/pad-zero'
import { PickerOptionItem, PickerValue } from '@/packages/pickerview/index.taro'

export interface DatePickerProps extends BasicComponent {
value?: Date
Expand Down Expand Up @@ -38,17 +39,17 @@ export interface DatePickerProps extends BasicComponent {
| 'onChange'
>
>
formatter: (type: string, option: PickerOption) => PickerOption
filter: (type: string, option: PickerOption[]) => PickerOption[]
formatter: (type: string, option: PickerOptionItem) => PickerOptionItem
filter: (type: string, option: PickerOptionItem[]) => PickerOptionItem[]
onClose: () => void
onCancel: () => void
onConfirm: (
selectedOptions: PickerOption[],
selectedValue: (string | number)[]
selectedOptions: PickerOptionItem[],
selectedValue: PickerValue[]
) => void
onChange?: (
selectedOptions: PickerOption[],
selectedValue: (string | number)[],
selectedOptions: PickerOptionItem[],
selectedValue: PickerValue[],
columnIndex: number
) => void
}
Expand Down Expand Up @@ -104,8 +105,8 @@ export const DatePicker: FunctionComponent<
minute: lang.min,
seconds: lang.seconds,
}
const [pickerValue, setPickerValue] = useState<(string | number)[]>([])
const [pickerOptions, setPickerOptions] = useState<PickerOption[][]>([])
const [pickerValue, setPickerValue] = useState<PickerValue[]>([])
const [pickerOptions, setPickerOptions] = useState<PickerOptionItem[][]>([])
const formatValue = (value: Date | null) => {
if (!value || (value && !isDate(value))) {
value = startDate
Expand Down Expand Up @@ -218,7 +219,7 @@ export const DatePicker: FunctionComponent<
const compareDateChange = (
currentDate: number,
newDate: Date | null,
selectedOptions: PickerOption[],
selectedOptions: PickerOptionItem[],
index: number
) => {
const isEqual = new Date(currentDate)?.getTime() === newDate?.getTime()
Expand All @@ -238,8 +239,8 @@ export const DatePicker: FunctionComponent<
}
}
const handlePickerChange = (
selectedOptions: PickerOption[],
selectedValue: (number | string)[],
selectedOptions: PickerOptionItem[],
selectedValue: PickerValue[],
index: number
) => {
const rangeType = type.toLocaleLowerCase()
Expand All @@ -248,7 +249,7 @@ export const DatePicker: FunctionComponent<
rangeType
)
) {
const formatDate: (number | string)[] = []
const formatDate: PickerValue[] = []
selectedValue.forEach((item) => {
formatDate.push(item)
})
Expand Down Expand Up @@ -313,13 +314,13 @@ export const DatePicker: FunctionComponent<
const formatOption = (type: string, value: string | number) => {
if (formatter) {
return formatter(type, {
text: padZero(value, 2),
label: padZero(value, 2),
value: padZero(value, 2),
})
}
const padMin = padZero(value, 2)
const fatter = showChinese ? zhCNType[type] : ''
return { text: padMin + fatter, value: padMin }
return { label: padMin + fatter, value: padMin }
}

const generateColumn = (
Expand All @@ -330,7 +331,7 @@ export const DatePicker: FunctionComponent<
columnIndex: number
) => {
let cmin = min
const arr: Array<PickerOption> = []
const arr: Array<PickerOptionItem> = []
let index = 0
while (cmin <= max) {
arr.push(formatOption(type, cmin))
Expand Down Expand Up @@ -412,14 +413,13 @@ export const DatePicker: FunctionComponent<
onClose={onClose}
onCancel={onCancel}
value={pickerValue}
onConfirm={(options: PickerOption[], value: (string | number)[]) =>
onConfirm && onConfirm(options, value)
}
onChange={(
options: PickerOption[],
value: (number | string)[],
index: number
) => handlePickerChange(options, value, index)}
onConfirm={(
selectedOptions: PickerOptionItem[],
selectedValue: PickerValue[]
) => onConfirm && onConfirm(selectedOptions, selectedValue)}
onChange={({ value, index, selectedOptions }) => {
handlePickerChange(selectedOptions, value, index)
}}
threeDimensional={threeDimensional}
/>
)}
Expand Down
48 changes: 24 additions & 24 deletions src/packages/datepicker/datepicker.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { FunctionComponent, useState, useEffect } from 'react'
import Picker from '@/packages/picker'
import { PickerOption, PickerProps } from '@/packages/picker/index'
import { PickerProps } from '@/packages/picker/index'
import { useConfig } from '@/packages/configprovider'
import { usePropsValue } from '@/hooks/use-props-value'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
import { isDate } from '@/utils/is-date'
import { padZero } from '@/utils/pad-zero'
import { PickerOptionItem, PickerValue } from '@/packages/pickerview/index'

export interface DatePickerProps extends BasicComponent {
value?: Date
Expand Down Expand Up @@ -38,17 +39,17 @@ export interface DatePickerProps extends BasicComponent {
| 'onChange'
>
>
formatter: (type: string, option: PickerOption) => PickerOption
filter: (type: string, option: PickerOption[]) => PickerOption[]
formatter: (type: string, option: PickerOptionItem) => PickerOptionItem
filter: (type: string, option: PickerOptionItem[]) => PickerOptionItem[]
onClose: () => void
onCancel: () => void
onConfirm: (
selectedOptions: PickerOption[],
selectedValue: (string | number)[]
selectedOptions: PickerOptionItem[],
selectedValue: PickerValue[]
) => void
onChange?: (
selectedOptions: PickerOption[],
selectedValue: (string | number)[],
selectedOptions: PickerOptionItem[],
selectedValue: PickerValue[],
columnIndex: number
) => void
}
Expand Down Expand Up @@ -104,8 +105,8 @@ export const DatePicker: FunctionComponent<
minute: lang.min,
seconds: lang.seconds,
}
const [pickerValue, setPickerValue] = useState<(string | number)[]>([])
const [pickerOptions, setPickerOptions] = useState<PickerOption[][]>([])
const [pickerValue, setPickerValue] = useState<PickerValue[]>([])
const [pickerOptions, setPickerOptions] = useState<PickerOptionItem[][]>([])
const formatValue = (value: Date | null) => {
if (!value || (value && !isDate(value))) {
value = startDate
Expand Down Expand Up @@ -218,7 +219,7 @@ export const DatePicker: FunctionComponent<
const compareDateChange = (
currentDate: number,
newDate: Date | null,
selectedOptions: PickerOption[],
selectedOptions: PickerOptionItem[],
index: number
) => {
const isEqual = new Date(currentDate)?.getTime() === newDate?.getTime()
Expand All @@ -238,8 +239,8 @@ export const DatePicker: FunctionComponent<
}
}
const handlePickerChange = (
selectedOptions: PickerOption[],
selectedValue: (number | string)[],
selectedOptions: PickerOptionItem[],
selectedValue: PickerValue[],
index: number
) => {
const rangeType = type.toLocaleLowerCase()
Expand All @@ -248,7 +249,7 @@ export const DatePicker: FunctionComponent<
rangeType
)
) {
const formatDate: (number | string)[] = []
const formatDate: PickerValue[] = []
selectedValue.forEach((item) => {
formatDate.push(item)
})
Expand Down Expand Up @@ -313,13 +314,13 @@ export const DatePicker: FunctionComponent<
const formatOption = (type: string, value: string | number) => {
if (formatter) {
return formatter(type, {
text: padZero(value, 2),
label: padZero(value, 2),
value: padZero(value, 2),
})
}
const padMin = padZero(value, 2)
const fatter = showChinese ? zhCNType[type] : ''
return { text: padMin + fatter, value: padMin }
return { label: padMin + fatter, value: padMin }
}

const generateColumn = (
Expand All @@ -330,7 +331,7 @@ export const DatePicker: FunctionComponent<
columnIndex: number
) => {
let cmin = min
const arr: Array<PickerOption> = []
const arr: Array<PickerOptionItem> = []
let index = 0
while (cmin <= max) {
arr.push(formatOption(type, cmin))
Expand Down Expand Up @@ -407,14 +408,13 @@ export const DatePicker: FunctionComponent<
onClose={onClose}
onCancel={onCancel}
value={pickerValue}
onConfirm={(options: PickerOption[], value: (string | number)[]) =>
onConfirm && onConfirm(options, value)
}
onChange={(
options: PickerOption[],
value: (number | string)[],
index: number
) => handlePickerChange(options, value, index)}
onConfirm={(
selectedOptions: PickerOptionItem[],
selectedValue: PickerValue[]
) => onConfirm && onConfirm(selectedOptions, selectedValue)}
onChange={({ value, index, selectedOptions }) => {
handlePickerChange(selectedOptions, value, index)
}}
threeDimensional={threeDimensional}
/>
)}
Expand Down
Loading
Loading