Skip to content

Commit

Permalink
fix(datepicker): refactor date-picker (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn authored Jun 6, 2022
1 parent a45dfc6 commit 611c212
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/components/DatePicker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React from 'react';
import { DatePicker } from 'tdesign-react';
import type { DateValue } from 'tdesign-react/es/date-picker';
import dayjs, { Dayjs } from 'dayjs';
import { DateRangePicker, DateRangeValue } from 'tdesign-react';
import dayjs from 'dayjs';

const RECENT_7_DAYS: [Dayjs, Dayjs] = [dayjs().subtract(7, 'day'), dayjs().subtract(1, 'day')];
const RECENT_7_DAYS: DateRangeValue = [
dayjs().subtract(7, 'day').format('YYYY-MM-DD'),
dayjs().subtract(1, 'day').format('YYYY-MM-DD'),
];

const LastWeekDatePicker = (onChange: (value: Array<string>) => void) => (
<DatePicker
style={{ width: 240 }}
const LastWeekDatePicker = (onChange: (value: DateRangeValue) => void) => (
<DateRangePicker
mode='date'
range
placeholder="['开始时间', '结束时间']"
defaultValue={RECENT_7_DAYS.map((item) => item.toDate())}
onChange={(value: DateValue) => onChange(value as string[])}
placeholder={['开始时间', '结束时间']}
value={RECENT_7_DAYS}
format='YYYY-MM-DD'
onChange={(value) => onChange(value)}
/>
);

Expand Down

0 comments on commit 611c212

Please sign in to comment.