-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
562d662
commit 5d4b7b6
Showing
32 changed files
with
656 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import { DefaultTheme } from '@mui/system'; | ||
import ThemeProviderNoVars from './ThemeProviderNoVars'; | ||
import { CssThemeVariables } from './createThemeNoVars'; | ||
import { CssVarsProvider } from './ThemeProviderWithVars'; | ||
import { CssVarsTheme } from './createThemeWithVars'; | ||
import THEME_ID from './identifier'; | ||
|
||
type ThemeProviderCssVariablesProps = CssThemeVariables extends { enabled: true } | ||
? { | ||
/** | ||
* The node for attaching the `theme.colorSchemeSelector`. | ||
* @default document | ||
*/ | ||
colorSchemeNode?: Element | null; | ||
/** | ||
* If `true`, the provider creates its own context and generate stylesheet as if it is a root `ThemeProvider`. | ||
*/ | ||
disableNestedContext?: boolean; | ||
/** | ||
* If `true`, the style sheet for CSS theme variables won't be generated. | ||
* | ||
* This is useful for controlling nested ThemeProvider behavior. | ||
* @default false | ||
*/ | ||
disableStyleSheetGeneration?: boolean; | ||
} | ||
: {}; | ||
|
||
export interface ThemeProviderProps<Theme = DefaultTheme> extends ThemeProviderCssVariablesProps { | ||
children?: React.ReactNode; | ||
theme: Partial<Theme> | ((outerTheme: Theme) => Theme); | ||
/** | ||
* The document used to perform `disableTransitionOnChange` feature | ||
* @default document | ||
*/ | ||
documentNode?: Document | null; | ||
/** | ||
* The window that attaches the 'storage' event listener | ||
* @default window | ||
*/ | ||
storageWindow?: Window | null; | ||
/** | ||
* localStorage key used to store application `mode` | ||
* @default 'mui-mode' | ||
*/ | ||
modeStorageKey?: string; | ||
/** | ||
* localStorage key used to store `colorScheme` | ||
* @default 'mui-color-scheme' | ||
*/ | ||
colorSchemeStorageKey?: string; | ||
/** | ||
* Disable CSS transitions when switching between modes or color schemes | ||
* @default false | ||
*/ | ||
disableTransitionOnChange?: boolean; | ||
} | ||
|
||
export default function ThemeProvider<Theme = DefaultTheme>({ | ||
theme, | ||
...props | ||
}: ThemeProviderProps<Theme>) { | ||
if (typeof theme === 'function') { | ||
return <ThemeProviderNoVars theme={theme} {...props} />; | ||
} | ||
const muiTheme = (THEME_ID in theme ? theme[THEME_ID] : theme) as ThemeProviderProps['theme']; | ||
if (!('colorSchemes' in muiTheme)) { | ||
return <ThemeProviderNoVars theme={theme} {...props} />; | ||
} | ||
return <CssVarsProvider theme={theme as unknown as CssVarsTheme} {...props} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import { ThemeProvider as SystemThemeProvider, DefaultTheme } from '@mui/system'; | ||
import THEME_ID from './identifier'; | ||
|
||
export interface ThemeProviderNoVarsProps<Theme = DefaultTheme> { | ||
children?: React.ReactNode; | ||
theme: Partial<Theme> | ((outerTheme: Theme) => Theme); | ||
} | ||
|
||
export default function ThemeProviderNoVars<Theme = DefaultTheme>({ | ||
theme: themeInput, | ||
...props | ||
}: ThemeProviderNoVarsProps<Theme>): React.ReactElement<ThemeProviderNoVarsProps<Theme>> { | ||
const scopedTheme = THEME_ID in themeInput ? themeInput[THEME_ID] : undefined; | ||
return ( | ||
<SystemThemeProvider | ||
{...props} | ||
themeId={scopedTheme ? THEME_ID : undefined} | ||
theme={scopedTheme || themeInput} | ||
/> | ||
); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...i-material/src/styles/CssVarsProvider.tsx → ...rial/src/styles/ThemeProviderWithVars.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { ColorSystemOptions } from './createThemeWithVars'; | ||
import createPalette, { PaletteOptions } from './createPalette'; | ||
import getOverlayAlpha from './getOverlayAlpha'; | ||
|
||
const defaultDarkOverlays = [...Array(25)].map((_, index) => { | ||
if (index === 0) { | ||
return undefined; | ||
} | ||
const overlay = getOverlayAlpha(index); | ||
return `linear-gradient(rgba(255 255 255 / ${overlay}), rgba(255 255 255 / ${overlay}))`; | ||
}); | ||
|
||
export function getOpacity(mode: 'light' | 'dark') { | ||
return { | ||
inputPlaceholder: mode === 'dark' ? 0.5 : 0.42, | ||
inputUnderline: mode === 'dark' ? 0.7 : 0.42, | ||
switchTrackDisabled: mode === 'dark' ? 0.2 : 0.12, | ||
switchTrack: mode === 'dark' ? 0.3 : 0.38, | ||
}; | ||
} | ||
export function getOverlays(mode: 'light' | 'dark') { | ||
return mode === 'dark' ? defaultDarkOverlays : []; | ||
} | ||
|
||
export default function createColorScheme(options: ColorSystemOptions) { | ||
const { | ||
palette: paletteInput = { mode: 'light' } as PaletteOptions, // need to cast to avoid module augmentation test | ||
opacity, | ||
overlays, | ||
...rest | ||
} = options; | ||
const palette = createPalette(paletteInput); | ||
return { | ||
palette, | ||
opacity: { ...getOpacity(palette.mode), ...opacity }, | ||
overlays: overlays || getOverlays(palette.mode), | ||
...rest, | ||
} as unknown as ColorSystemOptions; | ||
} |
Oops, something went wrong.