Material-ui-pickers: Overriding styles on createMuiTheme with Typescript

Created on 13 Jun 2018  ·  6Comments  ·  Source: mui-org/material-ui-pickers

Hi,

I am using material-ui-pickers on a project here, but got a problem when trying to override all MuiPicker styles like (MuiPickersToolbar, MuiPickersCalendarHeader, ...), since they are not Typed on the posible override list of Material-Ui.

Is there a way to do it?

typescript

Most helpful comment

I get the same error when using TypeScript with material-ui-pickers

One way to get around the type error is to cast the override object as ThemeOptions

const datePickerTheme = createMuiTheme(theme as ThemeOptions);

All 6 comments

Ha ha ha. That’s really interesting issue.

Hmmm... Might be possible to implement a MuiThemeExtension That you can union with the MuiTheme types to make a type that includes the typings for overriding this library's styles.

A PR is welcome 🙏

My solution here.

import { createMuiTheme, MuiThemeProvider } from "@material-ui/core";

const materialTheme = createMuiTheme({
    typography: {
        display1: {
            fontSize: 24
        }
    }
});

const SomePicker = () => (
    <MuiThemeProvider theme={materialTheme}>
        <MuiPickersUtilsProvider>
            <DateTimePicker
                value={null}
                onChange={date => console.log(date)}
                format="MMMD日 HH時mm分"
            />
        </MuiPickersUtilsProvider>
    </MuiThemeProvider>
)

Create a material theme and apply it only in that area, instead of overriding MuiPicker theme (such as MuiPickersToolbar, MuiPickersCalendarHeader, ...). This way TypeScript says nothing.

I get the same error when using TypeScript with material-ui-pickers

One way to get around the type error is to cast the override object as ThemeOptions

const datePickerTheme = createMuiTheme(theme as ThemeOptions);

By type augmentation can be removed this warning right, did someone find out how? Warning: Material-UI: you are trying to override a style that does not exist.
Fix the paper key of theme.overrides.MUIDataTable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Harasz picture Harasz  ·  3Comments

aditya81070 picture aditya81070  ·  3Comments

sakulstra picture sakulstra  ·  3Comments

mnemanja picture mnemanja  ·  3Comments

danmce picture danmce  ·  3Comments