Skip to content

Commit e2c507f

Browse files
committed
chore: update def
1 parent 0c38fa8 commit e2c507f

File tree

4 files changed

+78
-17
lines changed

4 files changed

+78
-17
lines changed

src/PickerInput/RangePicker.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import useRangeValue, { useInnerValue } from './hooks/useRangeValue';
3535
import useShowNow from './hooks/useShowNow';
3636
import Popup, { type PopupShowTimeConfig } from './Popup';
3737
import RangeSelector, { type SelectorIdType } from './Selector/RangeSelector';
38+
import useSemantic from '../hooks/useSemantic';
3839

3940
function separateConfig<T>(config: T | [T, T] | null | undefined, defaultConfig: T): [T, T] {
4041
const singleConfig = config ?? defaultConfig;
@@ -158,8 +159,8 @@ function RangePicker<DateType extends object = any>(
158159
const {
159160
// Style
160161
prefixCls,
161-
styles,
162-
classNames,
162+
styles: propStyles,
163+
classNames: propClassNames,
163164

164165
// Value
165166
defaultValue,
@@ -224,6 +225,9 @@ function RangePicker<DateType extends object = any>(
224225
// ========================= Refs =========================
225226
const selectorRef = usePickerRef(ref);
226227

228+
// ======================= Semantic =======================
229+
const [mergedClassNames, mergedStyles] = useSemantic(propClassNames, propStyles);
230+
227231
// ========================= Open =========================
228232
const [mergedOpen, setMergeOpen] = useOpen(open, defaultOpen, disabled, onOpenChange);
229233

@@ -562,6 +566,8 @@ function RangePicker<DateType extends object = any>(
562566
'className',
563567
'onPanelChange',
564568
'disabledTime',
569+
'classNames',
570+
'styles',
565571
]);
566572
return restProps;
567573
}, [filledProps]);
@@ -693,10 +699,18 @@ function RangePicker<DateType extends object = any>(
693699
generateConfig,
694700
button: components.button,
695701
input: components.input,
696-
styles,
697-
classNames,
702+
classNames: mergedClassNames,
703+
styles: mergedStyles,
698704
}),
699-
[prefixCls, locale, generateConfig, components.button, components.input, classNames, styles],
705+
[
706+
prefixCls,
707+
locale,
708+
generateConfig,
709+
components.button,
710+
components.input,
711+
mergedClassNames,
712+
mergedStyles,
713+
],
700714
);
701715

702716
// ======================== Effect ========================
@@ -755,8 +769,8 @@ function RangePicker<DateType extends object = any>(
755769
<PickerTrigger
756770
{...pickTriggerProps(filledProps)}
757771
popupElement={panel}
758-
popupStyle={styles.popup}
759-
popupClassName={classNames.popup}
772+
popupStyle={mergedStyles.popup.root}
773+
popupClassName={mergedClassNames.popup.root}
760774
// Visible
761775
visible={mergedOpen}
762776
onClose={onPopupClose}

src/PickerInput/SinglePicker.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import useRangeValue, { useInnerValue } from './hooks/useRangeValue';
3131
import useShowNow from './hooks/useShowNow';
3232
import Popup from './Popup';
3333
import SingleSelector from './Selector/SingleSelector';
34+
import useSemantic from '../hooks/useSemantic';
3435

3536
// TODO: isInvalidateDate with showTime.disabledTime should not provide `range` prop
3637

@@ -122,8 +123,8 @@ function Picker<DateType extends object = any>(
122123
const {
123124
// Style
124125
prefixCls,
125-
styles,
126-
classNames,
126+
styles: propStyles,
127+
classNames: propClassNames,
127128

128129
// Value
129130
order,
@@ -202,6 +203,9 @@ function Picker<DateType extends object = any>(
202203

203204
const toggleDates = useToggleDates(generateConfig, locale, internalPicker);
204205

206+
// ======================= Semantic =======================
207+
const [mergedClassNames, mergedStyles] = useSemantic(propClassNames, propStyles);
208+
205209
// ========================= Open =========================
206210
const [mergedOpen, triggerOpen] = useOpen(open, defaultOpen, [disabled], onOpenChange);
207211

@@ -478,6 +482,8 @@ function Picker<DateType extends object = any>(
478482
'style',
479483
'className',
480484
'onPanelChange',
485+
'classNames',
486+
'styles',
481487
]);
482488
return {
483489
...restProps,
@@ -577,10 +583,18 @@ function Picker<DateType extends object = any>(
577583
generateConfig,
578584
button: components.button,
579585
input: components.input,
580-
styles,
581-
classNames,
586+
classNames: mergedClassNames,
587+
styles: mergedStyles,
582588
}),
583-
[prefixCls, locale, generateConfig, components.button, components.input, styles, classNames],
589+
[
590+
prefixCls,
591+
locale,
592+
generateConfig,
593+
components.button,
594+
components.input,
595+
mergedClassNames,
596+
mergedStyles,
597+
],
584598
);
585599

586600
// ======================== Effect ========================
@@ -615,8 +629,8 @@ function Picker<DateType extends object = any>(
615629
<PickerTrigger
616630
{...pickTriggerProps(filledProps)}
617631
popupElement={panel}
618-
popupStyle={styles.popup}
619-
popupClassName={classNames.popup}
632+
popupStyle={mergedStyles.popup.root}
633+
popupClassName={mergedClassNames.popup.root}
620634
// Visible
621635
visible={mergedOpen}
622636
onClose={onPopupClose}

src/PickerInput/context.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import type { GenerateConfig } from '../generate';
3-
import type { Components, Locale, SemanticStructure } from '../interface';
3+
import type { Components, Locale } from '../interface';
4+
import type { FilledClassNames, FilledStyles } from '../hooks/useSemantic';
45

56
export interface PickerContextProps<DateType = any> {
67
prefixCls: string;
@@ -9,8 +10,8 @@ export interface PickerContextProps<DateType = any> {
910
/** Customize button component */
1011
button?: Components['button'];
1112
input?: Components['input'];
12-
styles?: Partial<Record<SemanticStructure, React.CSSProperties>>;
13-
classNames?: Partial<Record<SemanticStructure, string>>;
13+
classNames: FilledClassNames;
14+
styles: FilledStyles;
1415
}
1516

1617
const PickerContext = React.createContext<PickerContextProps>(null!);

src/hooks/useSemantic.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useMemo } from 'react';
2+
import type { SharedPickerProps } from '../interface';
3+
4+
export type FilledClassNames = NonNullable<SharedPickerProps['classNames']> & {
5+
popup: NonNullable<SharedPickerProps['classNames']>['popup'];
6+
};
7+
8+
export type FilledStyles = NonNullable<SharedPickerProps['styles']> & {
9+
popup: NonNullable<SharedPickerProps['styles']>['popup'];
10+
};
11+
12+
/**
13+
* Convert `classNames` & `styles` to a fully filled object
14+
*/
15+
export default function useSemantic(
16+
classNames?: SharedPickerProps['classNames'],
17+
styles?: SharedPickerProps['styles'],
18+
) {
19+
return useMemo(() => {
20+
const mergedClassNames: FilledClassNames = {
21+
...classNames,
22+
popup: classNames?.popup || {},
23+
};
24+
25+
const mergedStyles: FilledStyles = {
26+
...styles,
27+
popup: styles?.popup || {},
28+
};
29+
30+
return [mergedClassNames, mergedStyles] as const;
31+
}, [classNames, styles]);
32+
}

0 commit comments

Comments
 (0)