mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-19 00:41:03 +08:00

* 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>
56 lines
1.5 KiB
TypeScript
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;
|