ant-design/components/date-picker/hooks/useMergedPickerSemantic.ts
thinkasany c90e7705f7
feat: ConfigProvider support classNames and styles for TimePicker / DatePicker (#53489)
* feat: ConfigProvider support classNames and styles for timepicker

* save

* empty

* add test

* bump

* fix

* fix

* improve type

* chore: refactor

* chore: clean up

* chore: memo

* docs: fix ts

* chore: update demo

* chore: all semantic

* chore: fix types

* chore: update demo

* test: update test case

* chore: fix ts

* test: fix test case

* test: fix test case

* chore: rm console

---------

Co-authored-by: 二货机器人 <smith3816@gmail.com>
2025-04-22 11:31:56 +08:00

56 lines
1.5 KiB
TypeScript

import * as React from 'react';
import type { PickerProps } from '@rc-component/picker';
import cls from 'classnames';
import useMergeSemantic from '../../_util/hooks/useMergeSemantic';
import { useComponentConfig } from '../../config-provider/context';
import type { PickerClassNames } from '../generatePicker/interface';
const useMergedPickerSemantic = (
pickerType: 'timePicker' | 'datePicker',
classNames?: PickerClassNames,
styles?: PickerProps['styles'],
popupClassName?: string,
popupStyle?: React.CSSProperties,
) => {
const { classNames: contextClassNames, styles: contextStyles } = useComponentConfig(pickerType);
const [mergedClassNames, mergedStyles] = useMergeSemantic(
[contextClassNames as PickerProps['classNames'], classNames as PickerProps['classNames']],
[contextStyles as PickerProps['styles'], styles],
{
popup: {
_default: 'root',
},
},
);
return React.useMemo(() => {
// ClassNames
const filledClassNames = {
...mergedClassNames,
popup: {
...mergedClassNames.popup,
root: cls(mergedClassNames.popup?.root, popupClassName),
},
};
// Styles
const filledStyles = {
...mergedStyles,
popup: {
...mergedStyles.popup,
root: {
...mergedStyles.popup?.root,
...popupStyle,
},
},
};
// Return
return [filledClassNames, filledStyles] as const;
}, [mergedClassNames, mergedStyles, popupClassName, popupStyle]);
};
export default useMergedPickerSemantic;