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(DatePicker): support multiple api #1978

Merged
merged 4 commits into from
Nov 10, 2024
Merged
Changes from all commits
Commits
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
32 changes: 29 additions & 3 deletions js/date-picker/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,42 @@ export interface DateTime {
value: Date;
}

export function flagActive(data: any[], { ...args }: any) {
const { start, end, hoverStart, hoverEnd, type = 'date', isRange = false } = args;
interface FlagActiveOptions {
start: Date;
end: Date;
hoverStart: Date;
hoverEnd: Date;
type: any;
isRange: boolean;
value: DateValue | DateValue[];
multiple: boolean;
}

export function flagActive(data: any[], { ...args }: FlagActiveOptions) {
const {
start,
end,
hoverStart,
hoverEnd,
type = 'date',
isRange = false,
value,
multiple = false,
} = args;

// 周选择器不更改 cell 样式
if (type === 'week') return data;

if (!isRange) {
return data.map((row: any[]) => row.map((item: DateTime) => {
const _item = item;
_item.active = start && isSame(item.value, start, type) && !_item.additional;

if (multiple) {
_item.active = (value as DateValue[]).some((val) => isSame(dayjs(val).toDate(), _item.value));
} else {
_item.active = start && isSame(item.value, start, type) && !_item.additional;
}

return _item;
}));
}
Expand Down