Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/PickerInput/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,10 @@ function RangePicker<DateType extends object = any>(
generateConfig,
button: components.button,
input: components.input,
styles,
classNames,
}),
[prefixCls, locale, generateConfig, components.button, components.input],
[prefixCls, locale, generateConfig, components.button, components.input, classNames, styles],
);

// ======================== Effect ========================
Expand Down
4 changes: 3 additions & 1 deletion src/PickerInput/SinglePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,10 @@ function Picker<DateType extends object = any>(
generateConfig,
button: components.button,
input: components.input,
styles,
classNames,
}),
[prefixCls, locale, generateConfig, components.button, components.input],
[prefixCls, locale, generateConfig, components.button, components.input, styles, classNames],
);

// ======================== Effect ========================
Expand Down
5 changes: 3 additions & 2 deletions src/PickerInput/context.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import type { GenerateConfig } from '../generate';
import type { Components, Locale } from '../interface';
import type { Components, Locale, SemanticStructure } from '../interface';

export interface PickerContextProps<DateType = any> {
prefixCls: string;
Expand All @@ -9,7 +9,8 @@ export interface PickerContextProps<DateType = any> {
/** Customize button component */
button?: Components['button'];
input?: Components['input'];

styles?: Partial<Record<SemanticStructure, React.CSSProperties>>;
classNames?: Partial<Record<SemanticStructure, string>>;
}

const PickerContext = React.createContext<PickerContextProps>(null!);
Expand Down
13 changes: 10 additions & 3 deletions src/PickerPanel/PanelBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export default function PanelBody<DateType extends object = any>(props: PanelBod
const cellPrefixCls = `${prefixCls}-cell`;

// ============================= Context ==============================
const { onCellDblClick } = React.useContext(PickerHackContext);
const {
onCellDblClick,
classNames: pickerClassNames,
styles,
} = React.useContext(PickerHackContext);

// ============================== Value ===============================
const matchValues = (date: DateType) =>
Expand Down Expand Up @@ -181,8 +185,11 @@ export default function PanelBody<DateType extends object = any>(props: PanelBod

// ============================== Render ==============================
return (
<div className={`${prefixCls}-body`}>
<table className={`${prefixCls}-content`}>
<div className={classNames(`${prefixCls}-body`, pickerClassNames?.body)} style={styles?.body}>
<table
className={classNames(`${prefixCls}-content`, pickerClassNames?.content)}
style={styles?.content}
>
{headerCells && (
<thead>
<tr>{headerCells}</tr>
Expand Down
4 changes: 3 additions & 1 deletion src/PickerPanel/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import type { PanelMode, SharedPanelProps } from '../interface';
import type { PanelMode, SemanticStructure, SharedPanelProps } from '../interface';

export interface PanelContextProps<DateType extends object = any>
extends Pick<
Expand Down Expand Up @@ -106,6 +106,8 @@ export interface PickerHackContextProps {
hideNext?: boolean;
hideHeader?: boolean;
onCellDblClick?: () => void;
styles?: Partial<Record<SemanticStructure, React.CSSProperties>>;
classNames?: Partial<Record<SemanticStructure, string>>;
}

/**
Expand Down
14 changes: 11 additions & 3 deletions src/PickerPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,15 @@ function PickerPanel<DateType extends object = any>(
hideHeader,
} = props;

const mergedPrefixCls = React.useContext(PickerContext)?.prefixCls || prefixCls || 'rc-picker';
// ======================== Context ========================
const {
prefixCls: contextPrefixCls,
classNames: pickerClassNames,
styles,
} = React.useContext(PickerContext) || {};

// ======================== prefixCls ========================
const mergedPrefixCls = contextPrefixCls || prefixCls || 'rc-picker';

// ========================== Refs ==========================
const rootRef = React.useRef<HTMLDivElement>();
Expand Down Expand Up @@ -366,8 +374,8 @@ function PickerPanel<DateType extends object = any>(
// ======================== Context =========================
const parentHackContext = React.useContext(PickerHackContext);
const pickerPanelContext = React.useMemo(
() => ({ ...parentHackContext, hideHeader }),
[parentHackContext, hideHeader],
() => ({ ...parentHackContext, hideHeader, classNames: pickerClassNames, styles }),
[parentHackContext, hideHeader, pickerClassNames, styles],
);

// ======================== Warnings ========================
Expand Down
2 changes: 1 addition & 1 deletion src/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export type Components<DateType extends object = any> = Partial<
>;

// ========================= Picker =========================
export type SemanticStructure = 'popup';
export type SemanticStructure = 'popup' | 'body' | 'content';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

popupBody & popupContent?


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

Expand Down
32 changes: 21 additions & 11 deletions tests/picker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1349,17 +1349,27 @@ describe('Picker.Basic', () => {
);
});

it('classNames.popup', () => {
render(
<DayPicker
classNames={{
popup: 'bamboo',
}}
open
/>,
);

expect(document.querySelector('.rc-picker-dropdown')).toHaveClass('bamboo');
it('support classNames and styles', () => {
const customClassNames = {
popup: 'custom-popup',
body: 'custom-body',
content: 'custom-content',
};
const customStyles = {
popup: { color: 'red' },
body: { color: 'green' },
content: { color: 'blue' },
};
render(<DayPicker classNames={customClassNames} styles={customStyles} open />);

expect(document.querySelector('.rc-picker-dropdown')).toHaveClass(customClassNames.popup);
expect(document.querySelector('.rc-picker-dropdown')).toHaveStyle(customStyles.popup);
const content = document.querySelector('.rc-picker-content');
const body = document.querySelector('.rc-picker-body');
expect(content).toHaveClass(customClassNames.content);
expect(content).toHaveStyle(customStyles.content);
expect(body).toHaveClass(customClassNames.body);
expect(body).toHaveStyle(customStyles.body);
});

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