Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit a9067fd

Browse files
Custom toolbar component (#1182)
* Add new ToolbarComponent prop for custom toolbars * Update props docs * Run docgen on precommit hook * Run docgen on precommit hook * Run git add after precommit command * Automatically format json before prettier
1 parent 646db90 commit a9067fd

File tree

11 files changed

+1112
-376
lines changed

11 files changed

+1112
-376
lines changed

docs/prop-types.json

Lines changed: 1075 additions & 361 deletions
Large diffs are not rendered by default.

docs/scripts/docgen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ components.forEach(filePart => {
8585
});
8686
});
8787

88-
fs.writeFileSync(path.resolve(__dirname, '..', 'prop-types.json'), JSON.stringify(doc));
88+
fs.writeFileSync(path.resolve(__dirname, '..', 'prop-types.json'), JSON.stringify(doc, null, 2));

lib/src/DatePicker/DatePicker.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface BaseDatePickerProps extends OutterCalendarProps {
3838
*/
3939
disableFuture?: boolean;
4040
/**
41-
* To animate scrolling to current year (with scrollIntoView)
41+
* To animate scrolling to current year (using scrollIntoView)
4242
* @default false
4343
*/
4444
animateYearScrolling?: boolean;
@@ -76,12 +76,12 @@ function useOptions(props: DatePickerViewsProps) {
7676

7777
export const DatePicker = makePurePicker<DatePickerViewsProps>({
7878
useOptions,
79-
ToolbarComponent: DatePickerToolbar,
79+
DefaultToolbarComponent: DatePickerToolbar,
8080
});
8181

8282
export const KeyboardDatePicker = makeKeyboardPicker<DatePickerViewsProps>({
8383
useOptions,
84-
ToolbarComponent: DatePickerToolbar,
84+
DefaultToolbarComponent: DatePickerToolbar,
8585
});
8686

8787
DatePicker.defaultProps = defaultProps;

lib/src/DateTimePicker/DateTimePicker.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ function useOptions(props: DateTimePickerProps | KeyboardDateTimePickerProps) {
5454

5555
export const DateTimePicker = makePurePicker<DateTimePickerProps>({
5656
useOptions,
57-
ToolbarComponent: DateTimePickerToolbar,
57+
DefaultToolbarComponent: DateTimePickerToolbar,
5858
});
5959

6060
export const KeyboardDateTimePicker = makeKeyboardPicker<KeyboardDateTimePickerProps>({
6161
useOptions,
62-
ToolbarComponent: DateTimePickerToolbar,
62+
DefaultToolbarComponent: DateTimePickerToolbar,
6363
});
6464

6565
DateTimePicker.defaultProps = defaultProps;

lib/src/Picker/WrappedKeyboardPicker.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ export type WrappedKeyboardPickerProps = DateValidationProps &
1515

1616
export interface MakePickerOptions {
1717
useOptions: (props: any) => StateHookOptions;
18-
ToolbarComponent: React.ComponentType<ToolbarComponentProps>;
18+
DefaultToolbarComponent: React.ComponentType<ToolbarComponentProps>;
1919
}
2020

2121
// Mostly duplicate of ./WrappedPurePicker.tsx to enable tree-shaking of keyboard logic
2222
// TODO investigate how to reduce duplications
2323
export function makeKeyboardPicker<T extends any>({
2424
useOptions,
25-
ToolbarComponent,
25+
DefaultToolbarComponent,
2626
}: MakePickerOptions): React.FC<WrappedKeyboardPickerProps & T> {
2727
function WrappedKeyboardPicker(props: WrappedKeyboardPickerProps & T) {
2828
const {
@@ -67,6 +67,7 @@ export function makeKeyboardPicker<T extends any>({
6767
variant,
6868
disableToolbar,
6969
loadingIndicator,
70+
ToolbarComponent = DefaultToolbarComponent,
7071
...other
7172
} = props;
7273

lib/src/Picker/WrappedPurePicker.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type WrappedPurePickerProps = DateValidationProps &
1313

1414
export function makePurePicker<T extends any>({
1515
useOptions,
16-
ToolbarComponent,
16+
DefaultToolbarComponent,
1717
}: MakePickerOptions): React.FC<WrappedPurePickerProps & T> {
1818
function WrappedPurePicker(props: WrappedPurePickerProps & T) {
1919
const {
@@ -58,6 +58,7 @@ export function makePurePicker<T extends any>({
5858
orientation,
5959
disableToolbar,
6060
loadingIndicator,
61+
ToolbarComponent = DefaultToolbarComponent,
6162
...other
6263
} = props;
6364

lib/src/TimePicker/TimePicker.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ function useOptions(props: TimePickerProps | KeyboardTimePickerProps) {
5151

5252
export const TimePicker = makePurePicker<TimePickerViewsProps>({
5353
useOptions,
54-
ToolbarComponent: TimePickerToolbar,
54+
DefaultToolbarComponent: TimePickerToolbar,
5555
});
5656

5757
export const KeyboardTimePicker = makeKeyboardPicker<TimePickerViewsProps>({
5858
useOptions,
59-
ToolbarComponent: TimePickerToolbar,
59+
DefaultToolbarComponent: TimePickerToolbar,
6060
});
6161

6262
TimePicker.defaultProps = defaultProps;

lib/src/__tests__/e2e/DatePicker.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,16 @@ describe('e2e - DatePicker month change async', () => {
218218
).toEqual(0);
219219
});
220220
});
221+
222+
test('Custom toolbar component', () => {
223+
const component = mount(
224+
<DatePicker
225+
open
226+
value={new Date()}
227+
onChange={jest.fn()}
228+
ToolbarComponent={() => <div id="custom-toolbar" />}
229+
/>
230+
);
231+
232+
expect(component.find('#custom-toolbar').length).toBe(1);
233+
});

lib/src/typings/BasePicker.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MaterialUiPickersDate } from './date';
22
import { WrapperVariant } from '../wrappers/Wrapper';
33
import { ParsableDate } from '../constants/prop-types';
4+
import { ToolbarComponentProps } from '../Picker/Picker';
45

56
export interface BasePickerProps {
67
/** Picker value */
@@ -50,6 +51,8 @@ export interface BasePickerProps {
5051
* @default "portrait"
5152
*/
5253
orientation?: 'portrait' | 'landscape';
54+
/* Component that will replace default toolbar renderer */
55+
ToolbarComponent?: React.ComponentType<ToolbarComponentProps>;
5356
variant?: WrapperVariant;
5457
mergePreviousDateOnChange?: boolean;
5558
forwardedRef?: any;

lib/src/wrappers/ModalWrapper.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ import { DialogProps as MuiDialogProps } from '@material-ui/core/Dialog';
99
export interface ModalWrapperProps<T = {}> extends WrapperProps<T> {
1010
/**
1111
* "OK" label message
12-
* @default 'OK'
12+
* @default "OK"
1313
*/
1414
okLabel?: React.ReactNode;
1515
/**
1616
* "CANCEL" label message
17-
* @default 'CANCEL'
17+
* @default "CANCEL"
1818
*/
1919
cancelLabel?: React.ReactNode;
2020
/**
2121
* "CLEAR" label message
22-
* @default 'CLEAR'
22+
* @default "CLEAR"
2323
*/
2424
clearLabel?: React.ReactNode;
2525
/**
2626
* "TODAY" label message
27-
* @default 'TODAY'
27+
* @default "TODAY"
2828
*/
2929
todayLabel?: React.ReactNode;
3030
/**

0 commit comments

Comments
 (0)