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

Simplify the use of ThemeProvider #58

Closed
stuarthendren opened this issue Oct 27, 2020 · 3 comments
Closed

Simplify the use of ThemeProvider #58

stuarthendren opened this issue Oct 27, 2020 · 3 comments

Comments

@stuarthendren
Copy link
Contributor

The props are complex and difficult to use.
The complexity should be extracted to a separate function and exported separately to the ThemeProvider, The provider should just take full themes.

The api should allow simpler overriding of elements of the theme without having to supply everything. There should be options to override in both themes and separately in the light and the dark.

Ideas

const {light, dark} = createCommittedThemes() // default committed setup
const {light, dark} = createMaterialThemes() // a way to return to near material defaults

// To simply override a single element of both themes use a `common` key - rest deep merged
const const {light, dark} = createCommittedThemes({ common: {fonts: { fontSize: 20 }}})

// To override using default styles
const const {light, dark} = createCommittedThemes({ common: {fonts: (fontDefaults) => ({ ...fontDefaults:  typography: fontDefaults.text }}})

// For different light/dark config use `light` and `dark` keys
const const {light, dark} = createCommittedThemes({light: {}, dark: {}})

e.g. Typing

export interface ThemeConfig
  fonts?: FontOptions | (fonts: FontOptions) => FontOptions
  palette?: PaletteOptions | (palette: PaletteOptions) => PaletteOptions
  createShape?: ShapeOptions | (shape: ShapeOptions) => ShapeOptions
  createSpacing?: SpacingOptions | (spacing: SpacingOptions) => SpacingOptions
  createTypography?: TypographyOptions | (typography: TypographyOptions, palette: Palette)) => TypographyOptions
  overrides?: Overrides | (overrides: Overrides, palette: Palette) => Overrides
}

export interface ThemesConfig {
  common?: ThemeConfig
  light?: ThemeConfig
  dark?: ThemeConfig
}
@stuarthendren
Copy link
Contributor Author

@jonnyelliot could you have a read of this proposal and validate it for me - or suggest further improvement. No need to do it, just check you think this would be a sensible improvement to make.

@jonnyelliot
Copy link
Contributor

This seems like a nice improvement.

I guess we will have to be clear what the behaviour is when things are omitted. If createCommittedThemes and createMaterialThemes are always able to deep merge then thats not a problem.

@stuarthendren
Copy link
Contributor Author

see 22720df

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

2 participants