mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-18 08:00:53 +08:00

* feat[Space]:Unified use of orientation attribute * feat: use useOrientation and change doc, add test * feat: add warning * test: update snapshots * Update components/space/Compact.tsx Co-authored-by: thinkasany <480968828@qq.com> Signed-off-by: EmilyyyLiu <100924403+EmilyyyLiu@users.noreply.github.com> * test: reset snapshots,delete direction default value * feat: change demo direnction->orentation * feat: demos direction ->orientation * feat: add vertical, and change demos , doc * feat: change demo space -> flex * feat: change demo space -> flex * feat: space -> flex * Update components/space/index.tsx Signed-off-by: thinkasany <480968828@qq.com> * Update components/space/Compact.tsx Signed-off-by: thinkasany <480968828@qq.com> * add warning toHaveBeenCalledWith --------- Signed-off-by: EmilyyyLiu <100924403+EmilyyyLiu@users.noreply.github.com> Signed-off-by: thinkasany <480968828@qq.com> Co-authored-by: 刘欢 <lh01217311@antgroup.com> Co-authored-by: thinkasany <480968828@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 vertical>
|
|
<DatePicker
|
|
showNow={false}
|
|
onChange={onChange}
|
|
components={{
|
|
date: MyDatePanel,
|
|
}}
|
|
/>
|
|
</Space>
|
|
);
|
|
|
|
export default App;
|