Skip to content

Commit 1014ff1

Browse files
committed
feat: popup header
1 parent 32e24a5 commit 1014ff1

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/PickerPanel/PanelHeader.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import classNames from 'classnames';
1+
import cls from 'classnames';
22
import * as React from 'react';
33
import { isSameOrAfter } from '../utils/dateUtil';
44
import { PickerHackContext, usePanelContext } from './context';
@@ -33,6 +33,8 @@ function PanelHeader<DateType extends object>(props: HeaderProps<DateType>) {
3333

3434
const {
3535
prefixCls,
36+
classNames,
37+
styles,
3638

3739
// Icons
3840
prevIcon = '\u2039',
@@ -118,17 +120,14 @@ function PanelHeader<DateType extends object>(props: HeaderProps<DateType>) {
118120
const superNextBtnCls = `${headerPrefixCls}-super-next-btn`;
119121

120122
return (
121-
<div className={headerPrefixCls}>
123+
<div className={cls(headerPrefixCls, classNames.header)} style={styles.header}>
122124
{superOffset && (
123125
<button
124126
type="button"
125127
aria-label={locale.previousYear}
126128
onClick={() => onSuperOffset(-1)}
127129
tabIndex={-1}
128-
className={classNames(
129-
superPrevBtnCls,
130-
disabledSuperOffsetPrev && `${superPrevBtnCls}-disabled`,
131-
)}
130+
className={cls(superPrevBtnCls, disabledSuperOffsetPrev && `${superPrevBtnCls}-disabled`)}
132131
disabled={disabledSuperOffsetPrev}
133132
style={hidePrev ? HIDDEN_STYLE : {}}
134133
>
@@ -141,7 +140,7 @@ function PanelHeader<DateType extends object>(props: HeaderProps<DateType>) {
141140
aria-label={locale.previousMonth}
142141
onClick={() => onOffset(-1)}
143142
tabIndex={-1}
144-
className={classNames(prevBtnCls, disabledOffsetPrev && `${prevBtnCls}-disabled`)}
143+
className={cls(prevBtnCls, disabledOffsetPrev && `${prevBtnCls}-disabled`)}
145144
disabled={disabledOffsetPrev}
146145
style={hidePrev ? HIDDEN_STYLE : {}}
147146
>
@@ -155,7 +154,7 @@ function PanelHeader<DateType extends object>(props: HeaderProps<DateType>) {
155154
aria-label={locale.nextMonth}
156155
onClick={() => onOffset(1)}
157156
tabIndex={-1}
158-
className={classNames(nextBtnCls, disabledOffsetNext && `${nextBtnCls}-disabled`)}
157+
className={cls(nextBtnCls, disabledOffsetNext && `${nextBtnCls}-disabled`)}
159158
disabled={disabledOffsetNext}
160159
style={hideNext ? HIDDEN_STYLE : {}}
161160
>
@@ -168,10 +167,7 @@ function PanelHeader<DateType extends object>(props: HeaderProps<DateType>) {
168167
aria-label={locale.nextYear}
169168
onClick={() => onSuperOffset(1)}
170169
tabIndex={-1}
171-
className={classNames(
172-
superNextBtnCls,
173-
disabledSuperOffsetNext && `${superNextBtnCls}-disabled`,
174-
)}
170+
className={cls(superNextBtnCls, disabledSuperOffsetNext && `${superNextBtnCls}-disabled`)}
175171
disabled={disabledSuperOffsetNext}
176172
style={hideNext ? HIDDEN_STYLE : {}}
177173
>

tests/picker.spec.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,12 +1353,14 @@ describe('Picker.Basic', () => {
13531353
it('support classNames and styles', () => {
13541354
const popupClassNames = {
13551355
root: 'custom-popup',
1356+
header: 'custom-header',
13561357
body: 'custom-body',
13571358
content: 'custom-content',
13581359
item: 'custom-item',
13591360
};
13601361
const popupStyles = {
13611362
root: { color: 'red' },
1363+
header: { color: 'purple' },
13621364
body: { color: 'green' },
13631365
content: { color: 'blue' },
13641366
item: { color: 'yellow' },
@@ -1377,13 +1379,18 @@ describe('Picker.Basic', () => {
13771379

13781380
expect(document.querySelector('.rc-picker-dropdown')).toHaveClass(popupClassNames.root);
13791381
expect(document.querySelector('.rc-picker-dropdown')).toHaveStyle(popupStyles.root);
1380-
const content = document.querySelector('.rc-picker-content');
1382+
1383+
const header = document.querySelector('.rc-picker-header');
13811384
const body = document.querySelector('.rc-picker-body');
1385+
const content = document.querySelector('.rc-picker-content');
13821386
const item = document.querySelector('.rc-picker-cell');
1383-
expect(content).toHaveClass(popupClassNames.content);
1384-
expect(content).toHaveStyle(popupStyles.content);
1387+
1388+
expect(header).toHaveClass(popupClassNames.header);
1389+
expect(header).toHaveStyle(popupStyles.header);
13851390
expect(body).toHaveClass(popupClassNames.body);
13861391
expect(body).toHaveStyle(popupStyles.body);
1392+
expect(content).toHaveClass(popupClassNames.content);
1393+
expect(content).toHaveStyle(popupStyles.content);
13871394
expect(item).toHaveClass(popupClassNames.item);
13881395
expect(item).toHaveStyle(popupStyles.item);
13891396
});

0 commit comments

Comments
 (0)