Skip to content

Commit 74b0494

Browse files
authored
feat: semantic support content、body (#922)
* feat: semantic support content、body * update name
1 parent 4f14121 commit 74b0494

File tree

8 files changed

+58
-23
lines changed

8 files changed

+58
-23
lines changed

src/PickerInput/RangePicker.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,10 @@ function RangePicker<DateType extends object = any>(
693693
generateConfig,
694694
button: components.button,
695695
input: components.input,
696+
styles,
697+
classNames,
696698
}),
697-
[prefixCls, locale, generateConfig, components.button, components.input],
699+
[prefixCls, locale, generateConfig, components.button, components.input, classNames, styles],
698700
);
699701

700702
// ======================== Effect ========================

src/PickerInput/SinglePicker.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,10 @@ function Picker<DateType extends object = any>(
577577
generateConfig,
578578
button: components.button,
579579
input: components.input,
580+
styles,
581+
classNames,
580582
}),
581-
[prefixCls, locale, generateConfig, components.button, components.input],
583+
[prefixCls, locale, generateConfig, components.button, components.input, styles, classNames],
582584
);
583585

584586
// ======================== Effect ========================

src/PickerInput/context.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import type { GenerateConfig } from '../generate';
3-
import type { Components, Locale } from '../interface';
3+
import type { Components, Locale, SemanticStructure } from '../interface';
44

55
export interface PickerContextProps<DateType = any> {
66
prefixCls: string;
@@ -9,7 +9,8 @@ export interface PickerContextProps<DateType = any> {
99
/** Customize button component */
1010
button?: Components['button'];
1111
input?: Components['input'];
12-
12+
styles?: Partial<Record<SemanticStructure, React.CSSProperties>>;
13+
classNames?: Partial<Record<SemanticStructure, string>>;
1314
}
1415

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

src/PickerPanel/PanelBody.tsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export default function PanelBody<DateType extends object = any>(props: PanelBod
6363
const cellPrefixCls = `${prefixCls}-cell`;
6464

6565
// ============================= Context ==============================
66-
const { onCellDblClick } = React.useContext(PickerHackContext);
66+
const {
67+
onCellDblClick,
68+
classNames: pickerClassNames,
69+
styles,
70+
} = React.useContext(PickerHackContext);
6771

6872
// ============================== Value ===============================
6973
const matchValues = (date: DateType) =>
@@ -181,8 +185,14 @@ export default function PanelBody<DateType extends object = any>(props: PanelBod
181185

182186
// ============================== Render ==============================
183187
return (
184-
<div className={`${prefixCls}-body`}>
185-
<table className={`${prefixCls}-content`}>
188+
<div
189+
className={classNames(`${prefixCls}-body`, pickerClassNames?.popupBody)}
190+
style={styles?.popupBody}
191+
>
192+
<table
193+
className={classNames(`${prefixCls}-content`, pickerClassNames?.popupContent)}
194+
style={styles?.popupContent}
195+
>
186196
{headerCells && (
187197
<thead>
188198
<tr>{headerCells}</tr>

src/PickerPanel/context.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import type { PanelMode, SharedPanelProps } from '../interface';
2+
import type { PanelMode, SemanticStructure, SharedPanelProps } from '../interface';
33

44
export interface PanelContextProps<DateType extends object = any>
55
extends Pick<
@@ -106,6 +106,8 @@ export interface PickerHackContextProps {
106106
hideNext?: boolean;
107107
hideHeader?: boolean;
108108
onCellDblClick?: () => void;
109+
styles?: Partial<Record<SemanticStructure, React.CSSProperties>>;
110+
classNames?: Partial<Record<SemanticStructure, string>>;
109111
}
110112

111113
/**

src/PickerPanel/index.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,15 @@ function PickerPanel<DateType extends object = any>(
183183
hideHeader,
184184
} = props;
185185

186-
const mergedPrefixCls = React.useContext(PickerContext)?.prefixCls || prefixCls || 'rc-picker';
186+
// ======================== Context ========================
187+
const {
188+
prefixCls: contextPrefixCls,
189+
classNames: pickerClassNames,
190+
styles,
191+
} = React.useContext(PickerContext) || {};
192+
193+
// ======================== prefixCls ========================
194+
const mergedPrefixCls = contextPrefixCls || prefixCls || 'rc-picker';
187195

188196
// ========================== Refs ==========================
189197
const rootRef = React.useRef<HTMLDivElement>();
@@ -366,8 +374,8 @@ function PickerPanel<DateType extends object = any>(
366374
// ======================== Context =========================
367375
const parentHackContext = React.useContext(PickerHackContext);
368376
const pickerPanelContext = React.useMemo(
369-
() => ({ ...parentHackContext, hideHeader }),
370-
[parentHackContext, hideHeader],
377+
() => ({ ...parentHackContext, hideHeader, classNames: pickerClassNames, styles }),
378+
[parentHackContext, hideHeader, pickerClassNames, styles],
371379
);
372380

373381
// ======================== Warnings ========================

src/interface.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export type Components<DateType extends object = any> = Partial<
281281
>;
282282

283283
// ========================= Picker =========================
284-
export type SemanticStructure = 'popup';
284+
export type SemanticStructure = 'popup' | 'popupBody' | 'popupContent';
285285

286286
export type CustomFormat<DateType> = (value: DateType) => string;
287287

tests/picker.spec.tsx

+21-11
Original file line numberDiff line numberDiff line change
@@ -1349,17 +1349,27 @@ describe('Picker.Basic', () => {
13491349
);
13501350
});
13511351

1352-
it('classNames.popup', () => {
1353-
render(
1354-
<DayPicker
1355-
classNames={{
1356-
popup: 'bamboo',
1357-
}}
1358-
open
1359-
/>,
1360-
);
1361-
1362-
expect(document.querySelector('.rc-picker-dropdown')).toHaveClass('bamboo');
1352+
it('support classNames and styles', () => {
1353+
const customClassNames = {
1354+
popup: 'custom-popup',
1355+
popupBody: 'custom-body',
1356+
popupContent: 'custom-content',
1357+
};
1358+
const customStyles = {
1359+
popup: { color: 'red' },
1360+
popupBody: { color: 'green' },
1361+
popupContent: { color: 'blue' },
1362+
};
1363+
render(<DayPicker classNames={customClassNames} styles={customStyles} open />);
1364+
1365+
expect(document.querySelector('.rc-picker-dropdown')).toHaveClass(customClassNames.popup);
1366+
expect(document.querySelector('.rc-picker-dropdown')).toHaveStyle(customStyles.popup);
1367+
const content = document.querySelector('.rc-picker-content');
1368+
const body = document.querySelector('.rc-picker-body');
1369+
expect(content).toHaveClass(customClassNames.popupContent);
1370+
expect(content).toHaveStyle(customStyles.popupContent);
1371+
expect(body).toHaveClass(customClassNames.popupBody);
1372+
expect(body).toHaveStyle(customStyles.popupBody);
13631373
});
13641374

13651375
it('showTime config should have format', () => {

0 commit comments

Comments
 (0)