Skip to content

Commit

Permalink
feat(date-picker): onSelect 回调中增加 panelIndex 参数 (#2980)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyprepare committed Aug 28, 2024
1 parent 8d4571c commit 6aaa095
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-donuts-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

feat(date-picker): onSelect 回调中增加 panelIndex 参数
5 changes: 5 additions & 0 deletions .changeset/tall-walls-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/date-picker": minor
---

feat: onSelect 回调中增加 panelIndex 参数
4 changes: 2 additions & 2 deletions packages/ui/date-picker/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ export const DatePicker = forwardRef<HTMLDivElement | null, DatePickerProps>(
}, [propType])

const propsOnSelect = useCallback(
(data: moment.Moment, isCompleted: boolean) => {
propsOnSelectOriginal && propsOnSelectOriginal(moment(data).toDate(), isCompleted)
(data: moment.Moment, isCompleted: boolean, panelIndex?: number) => {
propsOnSelectOriginal?.(moment(data).toDate(), isCompleted, panelIndex)
},
[propsOnSelectOriginal]
)
Expand Down
10 changes: 5 additions & 5 deletions packages/ui/date-picker/src/components/range-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const RangePanel = () => {
[type]
)

const setRanges = (date: moment.Moment) => {
const setRanges = (date: moment.Moment, panelIndex: number = 0) => {
const newRange = { ...range }

if (newRange.start && (range.selecting || !calendarClickIsEnd.current)) {
Expand All @@ -101,7 +101,7 @@ const RangePanel = () => {

// 此处是明显的语法错误,故而注释修改
// onSelect(date, calendarClickIsEnd)
onSelect(date as any, !calendarClickIsEnd.current)
onSelect(date as any, !calendarClickIsEnd.current, panelIndex)

if (type === 'weekrange') {
// 固定模式下,即使跨月选择了日期,仍然显示当前月的日期选择面板
Expand Down Expand Up @@ -143,7 +143,7 @@ const RangePanel = () => {
newRange.selecting = true
newRange.start = date
newRange.end = null
onSelect(date as any, false)
onSelect(date as any, false, panelIndex)
}
setRange(newRange)
}
Expand All @@ -157,12 +157,12 @@ const RangePanel = () => {

if (type === 'timeperiod' && views[uIndex] === 'date') {
onPick([date, moment(date).hour(date.hour() + timeInterval / 60)], true)
onSelect(date as any, true)
onSelect(date as any, true, uIndex)
return
}
// V4修改:type === 'weekrange' -> views[uIndex] === 'date' (修正,周模式下,无法使用年份月份快捷切换面板BUG)
if (type.includes(views[uIndex]) || (type === 'weekrange' && views[uIndex] === 'date')) {
setRanges(date)
setRanges(date, uIndex)
} else {
const _innerDates = genNewDates(calRenderDates, date, uIndex)
setCalRenderDates(_innerDates)
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/date-picker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ export interface DatePickerProps extends Omit<HiBaseHTMLProps<'div'>, 'placehold
| ((selectedHour: number, selectedMinute: number, panel: TimePickerPanelType) => number[])
| number[]
/**
* 选择日期的回调函数,(data: 选中的 moment 日期对象, sCompleted: 是否选择完成,仅在范围选择下有效) => void
* 选择日期的回调函数,(data: 选中的 moment 日期对象, isCompleted: 是否选择完成,仅在范围选择下有效,panelIndex: 当前操作面板索引) => void
*/
onSelect?: (data: Date, isCompleted: boolean) => void
onSelect?: (data: Date, isCompleted: boolean, panelIndex?: number) => void
/**
* 选择后的回调,(date: 选中的日期,dateStr: 选中的日期字符串) => void
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/ui/date-picker/stories/range.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const Range = () => {
onChange={(date, dateStr) => {
console.log('onChange', date, dateStr)
}}
onSelect={console.log}
/>

<h2>季度</h2>
Expand All @@ -55,6 +56,7 @@ export const Range = () => {
onChange={(date, dateStr) => {
console.log('onChange', date, dateStr)
}}
onSelect={console.log}
/>

<h2>月份</h2>
Expand All @@ -65,6 +67,7 @@ export const Range = () => {
onChange={(date, dateStr) => {
console.log('onChange', date, dateStr)
}}
onSelect={console.log}
/>

<h2></h2>
Expand All @@ -75,6 +78,7 @@ export const Range = () => {
onChange={(date, dateStr) => {
console.log('onChange', date, dateStr)
}}
onSelect={console.log}
/>

<h2>日期时间范围</h2>
Expand All @@ -85,6 +89,7 @@ export const Range = () => {
onChange={(date, dateStr) => {
console.log('onChange', date, dateStr)
}}
onSelect={console.log}
/>

<h2>时间段快速选择</h2>
Expand Down

0 comments on commit 6aaa095

Please sign in to comment.