Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MuiPickersBasePicker styles to the ts overrides definitions #1414

Closed
unutoiul opened this issue Dec 5, 2019 · 10 comments
Closed

Add MuiPickersBasePicker styles to the ts overrides definitions #1414

unutoiul opened this issue Dec 5, 2019 · 10 comments

Comments

@unutoiul
Copy link

unutoiul commented Dec 5, 2019

I would like to remove the max-width: 325px to make center the calendar....but I can't find any of the following overrides.

any ideas:

export interface MuiPickersOverrides {
    MuiPickersDay?: Classes<typeof DayStyles>;
    MuiPickerDTHeader?: Classes<typeof DTHeaderStyles>;
    MuiPickerDTTabs?: Classes<typeof DTTabsStyles>;
    MuiPickersCalendar?: Classes<typeof CalendarStyles>;
    MuiPickersCalendarHeader?: Classes<typeof CalendarHeaderStyles>;
    MuiPickersSlideTransition?: Classes<typeof SlideTransitionStyles>;
    MuiPickersYearSelectionStyles?: Classes<typeof MuiPickersYearSelectionStyles>;
    MuiPickersYear?: Classes<typeof MuiPickersYearStyles>;
    MuiPickersMonthSelection?: Classes<typeof MuiPickersMonthSelectionStyles>;
    MuiPickersMonth?: Classes<typeof MuiPickersMonthStyles>;
    MuiPickersTimePickerToolbar?: Classes<typeof TimePickerToolbarStyles>;
    MuiPickersClock?: Classes<typeof ClockStyles>;
    MuiPickersClockNumber?: Classes<typeof ClockNumberStyles>;
    MuiPickersClockPointer?: Classes<typeof ClockPointerStyles>;
    MuiPickersModal?: Classes<typeof ModalDialogStyles>;
    MuiPickersToolbar?: Classes<typeof PickerToolbarStyles>;
    MuiPickersToolbarButton?: Classes<typeof ToolbarButtonStyles>;
    MuiPickersDatePickerRoot?: Classes<typeof DatePickerRootStyles>;
    MuiPickerDTToolbar?: Classes<typeof MuiPickerDTToolbarStyles>;
}

which one to use?
@MrBlue9
Copy link

MrBlue9 commented Dec 5, 2019

having the same question. the standalone "calendar" component resizes according to the container width. the static datepicker does not. i'd use the calendar component but it doesn't have the ability to pick a year.

@dmtrKovalenko
Copy link
Member

dmtrKovalenko commented Dec 5, 2019

MuiPickersBasePicker: {
  pickerView: {
    maxWidth: 400
  },
}

This should work
UPD: Ohh it is missing in typings, but code should work

@dmtrKovalenko dmtrKovalenko changed the title how to remove the max-width: 325px using inline styling... Add MuiPickersBasePicker styles to the ts overrides definitions Dec 5, 2019
@dmtrKovalenko
Copy link
Member

Lifehack you can just check the generated classnames to understand the component name
image

@MrBlue9
Copy link

MrBlue9 commented Dec 5, 2019

works like a charm! i suppose the spacing between the numbers in the calendar is fixed width, right?

@dmtrKovalenko
Copy link
Member

Yes, I think

@unutoiul
Copy link
Author

unutoiul commented Dec 5, 2019

Screenshot 2019-12-05 at 10 54 40

how come is working for you guys, is not working for me the

   overrides: {
        MuiPickerBasePicker: {
            pickerView: {
                maxWidth: '500px',
            },
        },

can't be find

@MrBlue9
Copy link

MrBlue9 commented Dec 5, 2019

it should work regardless of the error message. at least for me it worked nonetheless.

adding the following got rid of the error message for me. though i'm just starting to experiment with typescript and am not sure if this is the proper and "best" way to do so.

import { MuiPickersOverrides } from '@material-ui/pickers/typings/overrides';

type overridesNameToClassKey = {
  [P in keyof MuiPickersOverrides]: keyof MuiPickersOverrides[P];
};

type CustomType = {
  MuiPickersBasePicker: {
    pickerView: {
      maxWidth?: string;
    };
  };
};

declare module '@material-ui/core/styles/overrides' {
  interface ComponentNameToClassKey extends overridesNameToClassKey {}
  export interface ComponentNameToClassKey extends CustomType {}
}

@unutoiul
Copy link
Author

unutoiul commented Dec 5, 2019

works perfect now, thank you so much...

@AbdullahElrubi
Copy link

@dmtrKovalenko Are there any updates on the PR ?

@damir-sirola
Copy link
Contributor

If somebody else encounters a TypeScript error in material-ui type definitions after using declare module from above, this small change fixed it for me

import { MuiPickersOverrides } from '@material-ui/pickers/typings/overrides';

type OverridesNameToClassKey = {
-    [P in keyof MuiPickersOverrides]: keyof MuiPickersOverrides[P];
+    [P in keyof Required<MuiPickersOverrides>]: keyof MuiPickersOverrides[P];
};

declare module '@material-ui/core/styles/overrides' {
    export interface ComponentNameToClassKey extends OverridesNameToClassKey {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants