mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-26 01:42:30 +08:00
18e85a7b81
* chore: init * chore: link picker * chore: move files * chore: update style * chore: update types * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * test: fix test case * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * chore: clesn up useless types * chore: update types * chore: fix types * chore: fix types * chore: fix types * chore: fix types * chore: fix types * chore: fix types * chore: fix types * chore: fix types * chore: fix types * chore: update style * chore: clean up * chore: update types * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * fix: format * chore: update deps * chore: feature merge master (#46794) * fix: Fix typo s/Notificaiton/Notification/ (#46775) * docs: supplement form preserve field description (#46788) close https://github.com/ant-design/ant-design/issues/46773 * docs: tweak changelog drawer width in small screen (#46791) * docs: Update compatible-style.zh-CN.md (#46790) Signed-off-by: afc163 <afc163@gmail.com> --------- Signed-off-by: afc163 <afc163@gmail.com> Co-authored-by: hugo-syn <61210734+hugo-syn@users.noreply.github.com> Co-authored-by: Shunze Chen <qianlonwork@outlook.com> Co-authored-by: afc163 <afc163@gmail.com> * chore: update locale size * chore: lock dumi * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * chore: bump version * test: update snapshot * test: update snapshot * chore: bump version * chore: update limit * test: update snapshot * docs: update 7 days sample * chore: rm useless style * chore: clean up style * docs: add buddihist era demo * refactor: interface * chore: add multiple types * docs: add demo * chore: init style * chore: init style * chore: fill style * chore: fill style * chore: style * chore: size of it * chore: size style * docs: add align demo * docs: needConfirm * chore: fix showWeek style * test: update snapshot * chore: fix ts * chore: fix ts * chore: fix ts * chore: fix ts * fix: week style * docs: update dayjs note * fix: style missing * chore: fix footer extra style missing * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * chore: demo update * docs: update demo * docs: min & max date * test: update snapshot * docs: add order * chore: update deps * test: update snapshot * test: update snapshot * chore: adjust style * chore: clean up style * test: update snapshot * chore: fix comment * chore: update align * chore: bump rc-picker * test: update snapshot * test: update snapshot * test: update snapshot --------- Signed-off-by: afc163 <afc163@gmail.com> Signed-off-by: lijianan <574980606@qq.com> Co-authored-by: hugo-syn <61210734+hugo-syn@users.noreply.github.com> Co-authored-by: Shunze Chen <qianlonwork@outlook.com> Co-authored-by: afc163 <afc163@gmail.com> Co-authored-by: lijianan <574980606@qq.com>
77 lines
2.0 KiB
TypeScript
77 lines
2.0 KiB
TypeScript
import React from 'react';
|
|
import type { DatePickerProps } from 'antd';
|
|
import { Button, DatePicker, Flex, Slider, Space, Typography } from 'antd';
|
|
import dayjs from 'dayjs';
|
|
import type { Dayjs } from 'dayjs';
|
|
|
|
const onChange: DatePickerProps['onChange'] = (date, dateString) => {
|
|
console.log(date, dateString);
|
|
};
|
|
|
|
type DateComponent = Required<NonNullable<DatePickerProps<Dayjs>['components']>>['date'];
|
|
type GetProps<T> = T extends React.ComponentType<infer P> ? P : never;
|
|
|
|
const MyDatePanel = (props: GetProps<DateComponent>) => {
|
|
const { value, onSelect, onHover } = props;
|
|
|
|
// Value
|
|
const startDate = React.useMemo(() => dayjs().date(1).month(0), []);
|
|
const [innerValue, setInnerValue] = React.useState(value || startDate);
|
|
|
|
React.useEffect(() => {
|
|
if (value) {
|
|
setInnerValue(value);
|
|
}
|
|
}, [value]);
|
|
|
|
// Range
|
|
const dateCount = React.useMemo(() => {
|
|
const endDate = startDate.add(1, 'year').add(-1, 'day');
|
|
return endDate.diff(startDate, 'day');
|
|
}, [startDate]);
|
|
|
|
const sliderValue = Math.min(Math.max(0, innerValue.diff(startDate, 'day')), dateCount);
|
|
|
|
// Render
|
|
return (
|
|
<Flex vertical gap="small" style={{ padding: 16 }}>
|
|
<Typography.Title level={4} style={{ margin: 0 }} title="no, it's not">
|
|
The BEST Picker Panel
|
|
</Typography.Title>
|
|
<Slider
|
|
min={0}
|
|
max={dateCount}
|
|
value={sliderValue}
|
|
onChange={(nextValue) => {
|
|
const nextDate = startDate.add(nextValue, 'day');
|
|
setInnerValue(nextDate);
|
|
onHover?.(nextDate);
|
|
}}
|
|
tooltip={{
|
|
formatter: (nextValue) => startDate.add(nextValue || 0, 'day').format('YYYY-MM-DD'),
|
|
}}
|
|
/>
|
|
<Button
|
|
type="primary"
|
|
onClick={() => {
|
|
onSelect(innerValue);
|
|
}}
|
|
>{`That's It!`}</Button>
|
|
</Flex>
|
|
);
|
|
};
|
|
|
|
const App: React.FC = () => (
|
|
<Space direction="vertical">
|
|
<DatePicker
|
|
showNow={false}
|
|
onChange={onChange}
|
|
components={{
|
|
date: MyDatePanel,
|
|
}}
|
|
/>
|
|
</Space>
|
|
);
|
|
|
|
export default App;
|