I have an app which can be put behind any Url β I search a list of url fragments to find the 1st one the Url, and that determines which theme the app will use
in my App.tsx
<RedwoodApolloProvider>
<ThemesFromUrlCell hrefLike={window.location.href} />
<Routes />
</RedwoodApolloProvider>
ThemesFromUrlCell.tsx comes back with a lot of theme info which gets set into a themeState
In my ThemedPageLayout.tsx I merge my custom theme with the base [mui] provided theme and wrap the page with the mui theme provider
const ThemedPageLayout = ({ children }) => {
const defaultTheme = useTheme() // get mui default theme
const themeInfo = ThemeStore.useState((s) => s) // get chosen overrides
const muiTheme = rehydrateTheme(defaultTheme, themeInfo.theme) // apply overrides
return (
<ThemeProvider theme={muiTheme}>
{children}
</ThemeProvider>
)
}
all of my components need only then use the provided theme and itβs overrides
const theme = useTheme()
return (
<FormControlLabel
sx={theme['colorControls']}
/>
)
I have a mocked return for the ThemesFromUrlCell β but I donβt want to use it in all my other stories.
I have a dropdown menu in the Storybook controls bar which I want to load with url frags to replace itβs dummy data
export const globalTypes = {
fragment: {
name: 'Url-Fragment',
description: 'href url frag',
defaultValue: 'demo',
toolbar: {
icon: 'circlehollow',
// Array of plain string values as if taken from ThemeFromUrlFrag.urlFrag column
items: ['not', 'real', 'data'],
showName: true,
dynamicTitle: true,
},
},
};
I want the selection of a fragment from that menu to be used to select which theme my components are given