Skip to content

Commit

Permalink
fix: Export css vars (#184)
Browse files Browse the repository at this point in the history
* fix: Add missing getColorSchemeSelector method

* fix: Export css --mui vars

* fix: Export css variables using a custom provider
  • Loading branch information
cyaiox authored Sep 5, 2024
1 parent 9c8e91a commit f9e57fe
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ In your main ReactDOM renderer import Theme Provider and the theme you want to u
```tsx
// ./src/index.ts
...
import { ThemeProvider } from '@mui/material/styles'
import { dark } from 'decentraland-ui2/lib/themes/theme'
import { dark, ThemeProvider } from 'decentraland-ui2/dist/theme';
...

<ThemeProvider theme={dark}>
Expand Down Expand Up @@ -50,6 +49,6 @@ Install dependencies and start Storybook:

```
$ npm install
$ npm run generate:storybooks // This will regenerate @MUI components
$ npm run generate:storybooks //This will regenerate @MUI components
$ npm run start
```
2 changes: 2 additions & 0 deletions src/theme/colorSchemes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const colorSchemas = {
light: {
palette: {
mode: "light",
colorScheme: "light",
text: {
primary: "rgba(22, 21, 24, 0.9)",
secondary: "rgba(22, 21, 24, 0.6)",
Expand Down Expand Up @@ -175,6 +176,7 @@ const colorSchemas = {
dark: {
palette: {
mode: "dark",
colorScheme: "dark",
text: {
primary: "rgba(240,240,240, 1)",
secondary: "rgba(240,240,240, 0.7)",
Expand Down
24 changes: 10 additions & 14 deletions src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@ import {
import createPalette, { Palette } from "@mui/material/styles/createPalette"
import { colorSchemas } from "./colorSchemes"
import { components } from "./components"
import { ThemeProvider } from "./provider"
import { typography } from "./typography"

function theme(type: "light" | "dark"): ThemeOptions {
const palette = createPalette(colorSchemas[type].palette)

return {
...extendTheme({
palette,
typography: typography,
shape: {
borderRadius: 6,
},
components: components(colorSchemas[type].palette as Palette),
} as ThemeOptions),
palette,
palette: createPalette(colorSchemas[type].palette),
typography: typography,
shape: {
borderRadius: 6,
},
components: components(colorSchemas[type].palette as Palette),
}
}

const light = theme("light")
const dark = theme("dark")
const light = extendTheme(theme("light"))
const dark = extendTheme(theme("dark"))

export { light, dark }
export { light, dark, ThemeProvider }
17 changes: 17 additions & 0 deletions src/theme/provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { ReactNode } from "react"
import { Experimental_CssVarsProvider as CssVarsProvider } from "@mui/material/styles"
import { CssBaseline } from "@mui/material"
import type { Theme } from "./types"

export type ThemeProviderProps = {
theme: Theme
children: ReactNode
}

export const ThemeProvider = React.memo((props: ThemeProviderProps) => (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
<CssVarsProvider theme={props.theme as any}>
<CssBaseline />
{props.children}
</CssVarsProvider>
))
3 changes: 3 additions & 0 deletions src/theme/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { CssVarsTheme, ThemeOptions } from "@mui/material"

export type Theme = ThemeOptions & Partial<CssVarsTheme>

0 comments on commit f9e57fe

Please sign in to comment.