Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion src/PickerPanel/PanelHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ function PanelHeader<DateType extends object>(props: HeaderProps) {

const headerPrefixCls = `${prefixCls}-header`;

const { hidePrev, hideNext } = React.useContext(PickerHackContext);
const { hidePrev, hideNext, hideHeader } = React.useContext(PickerHackContext);

if (hideHeader) {
return null;
}

// ========================= Render =========================
return (
<div className={headerPrefixCls}>
{onSuperOffset && (
Expand Down
1 change: 1 addition & 0 deletions src/PickerPanel/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export function useInfo<DateType extends object = any>(
export interface PickerHackContextProps {
hidePrev?: boolean;
hideNext?: boolean;
hideHeader?: boolean;
onCellDblClick?: () => void;
}

Expand Down
79 changes: 47 additions & 32 deletions src/PickerPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import PickerContext from '../PickerInput/context';
import useCellRender from '../PickerInput/hooks/useCellRender';
import { isSame } from '../utils/dateUtil';
import { pickProps, toArray } from '../utils/miscUtil';
import { PickerHackContext } from './context';
import DatePanel from './DatePanel';
import DateTimePanel from './DateTimePanel';
import DecadePanel from './DecadePanel';
Expand Down Expand Up @@ -110,6 +111,9 @@ export interface BasePickerPanelProps<DateType extends object = any>

// Components
components?: Components;

/** @private This is internal usage. Do not use in your production env */
hideHeader?: boolean;
}

export interface SinglePickerPanelProps<DateType extends object = any>
Expand Down Expand Up @@ -172,6 +176,8 @@ function PickerPanel<DateType extends object = any>(

// Components
components = {},

hideHeader,
} = props;

const mergedPrefixCls = React.useContext(PickerContext)?.prefixCls || prefixCls || 'rc-picker';
Expand Down Expand Up @@ -345,6 +351,13 @@ function PickerPanel<DateType extends object = any>(
DefaultComponents[internalMode] ||
DatePanel) as typeof DatePanel;

// ======================== Context =========================
const parentHackContext = React.useContext(PickerHackContext);
const pickerPanelContext = React.useMemo(
() => ({ ...parentHackContext, hideHeader }),
[parentHackContext, hideHeader],
);

// ======================== Warnings ========================
if (process.env.NODE_ENV !== 'production') {
warning(
Expand Down Expand Up @@ -374,38 +387,40 @@ function PickerPanel<DateType extends object = any>(
]);

return (
<div
ref={rootRef}
tabIndex={tabIndex}
className={classNames(panelCls, {
[`${panelCls}-rtl`]: direction === 'rtl',
})}
>
<PanelComponent
{...panelProps}
// Time
showTime={mergedShowTime}
// MISC
prefixCls={mergedPrefixCls}
locale={filledLocale}
generateConfig={generateConfig}
// Mode
onModeChange={triggerModeChange}
// Value
pickerValue={mergedPickerValue}
onPickerValueChange={(nextPickerValue) => {
setPickerValue(nextPickerValue, true);
}}
value={mergedValue[0]}
onSelect={onPanelValueSelect}
values={mergedValue}
// Render
cellRender={onInternalCellRender}
// Hover
hoverRangeValue={hoverRangeDate}
hoverValue={hoverValue}
/>
</div>
<PickerHackContext.Provider value={pickerPanelContext}>
<div
ref={rootRef}
tabIndex={tabIndex}
className={classNames(panelCls, {
[`${panelCls}-rtl`]: direction === 'rtl',
})}
>
<PanelComponent
{...panelProps}
// Time
showTime={mergedShowTime}
// MISC
prefixCls={mergedPrefixCls}
locale={filledLocale}
generateConfig={generateConfig}
// Mode
onModeChange={triggerModeChange}
// Value
pickerValue={mergedPickerValue}
onPickerValueChange={(nextPickerValue) => {
setPickerValue(nextPickerValue, true);
}}
value={mergedValue[0]}
onSelect={onPanelValueSelect}
values={mergedValue}
// Render
cellRender={onInternalCellRender}
// Hover
hoverRangeValue={hoverRangeDate}
hoverValue={hoverValue}
/>
</div>
</PickerHackContext.Provider>
);
}

Expand Down
23 changes: 23 additions & 0 deletions tests/internal.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { render } from '@testing-library/react';
import React from 'react';
import { DayPickerPanel, getMoment } from './util/commonUtil';

// Note: Props tested in this file is safe to remove when refactor
describe('Picker.Internal', () => {
beforeEach(() => {
jest.useFakeTimers().setSystemTime(getMoment('1990-09-03 00:00:00').valueOf());
});

afterEach(() => {
jest.clearAllTimers();
jest.useRealTimers();
});

it('hideHeader', async () => {
const { container, rerender } = render(<DayPickerPanel />);
expect(container.querySelector('.rc-picker-header')).toBeTruthy();

rerender(<DayPickerPanel hideHeader />);
expect(container.querySelector('.rc-picker-header')).toBeFalsy();
});
});