Skip to content

Commit

Permalink
test adding new theme toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanie56 committed Apr 19, 2024
1 parent c3d3b33 commit 03d3dd0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 29 deletions.
18 changes: 18 additions & 0 deletions apps/demo/app/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ import { useIsScrolled } from '../../hooks/use-is-scrolled';
type IconType = React.ComponentType<React.SVGProps<SVGSVGElement>>;

const modes = ['dark-mode', 'light-mode'];
const themes = ['saddles', 'photostop'];
/** This should be integrated into a Page layout component, currently a WIP in design */
const pageMaxWidth = 1280;

export default function Index() {
const [mode, setMode] = useState(1);
const [theme, setTheme] = useState(1);
const isScrolled = useIsScrolled();

const toggleMode = () => {
Expand All @@ -44,6 +46,13 @@ export default function Index() {
setMode(mode ^ 1);
};

const toggleTheme = () => {
const themeElement = document.querySelector(`.${themes[theme]}`);
themeElement?.classList.remove(themes[theme]);
themeElement?.classList.add(themes[theme ^ 1]);
setTheme(theme ^ 1);
};

return (
<RadiusAutoLayout
direction="vertical"
Expand Down Expand Up @@ -91,6 +100,15 @@ export default function Index() {
onClick: toggleMode,
icon: (mode ? DarkMode : LightMode) as IconType,
},
{
'aria-label': theme
? 'Switch to New Theme'
: 'Switch to Default Theme',
title: theme ? 'Switch to New Theme' : 'Switch to Default Theme',
as: 'button',
onClick: toggleTheme,
icon: (theme ? DarkMode : LightMode) as IconType,
},
]}
logos={
<>
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/app/utils/demo.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const voidCallback = () => {};
*/
const brandOrEventToken = '{--brandOrEvent}';
/** Event tokens to look for to identify if an event is active */
const events = ['--halloweenevent'];
const events = [''];

export const useMutationObserver = () => {
useEffect(() => {
Expand Down
73 changes: 45 additions & 28 deletions libs/foundations/scripts/generate-storybook-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,34 +307,51 @@ readTokenData(tokenFileName).then(tokenFile => {
let fileCount = 4;
writeLayerDefinitions(`${STORYBOOK_DOCS_PATH}/${fileIndex(fileCount++)}-token-layer-definitions.mdx`, 'Layer Definition', order, layers, layerMap);

[ "core", "brand--photostop", "brand--saddles", "halloweenevent--saddles"].map((layerName) => {
const { name, variables }: TokenLayer = layerMap[layerName];
const basetokenDefinitions = renderLayerVariables(name, variables);
const valueMap = variables.reduce((map, obj) => {
map[obj.key] = obj.value;
return map;
}, {});

const modeDefinitions = ['mode--light', 'mode--dark', "breakpoint--desktop", "breakpoint--tablet",
"breakpoint--mobile", "components--components"].map((mode) => {
const modeVariables: TokenOutput[] = layerMap[mode].variables;
const layerVariables = modeVariables.reduce(function(acc, variable){
if (variable.value) {
const value = variable.value.replace(/[{}]/g, "");
const newValue = valueMap[value];
if (newValue) {
acc.push({
...variable,
value: newValue
})
}
}
return acc;
}, []);
return (layerVariables.length > 0) ? renderLayerVariables(`${name} ${mode}`, layerVariables) : '';
}).join('\n');

writeTokenDefinitions(name, basetokenDefinitions, modeDefinitions, `${STORYBOOK_DOCS_PATH}/${fileIndex(fileCount++)}-${layerName}-token-definitions.mdx`);
['core', 'brand--photostop', 'brand--saddles'].map((layerName) => {
const { name, variables }: TokenLayer = layerMap[layerName];
const basetokenDefinitions = renderLayerVariables(name, variables);
const valueMap = variables.reduce((map, obj) => {
map[obj.key] = obj.value;
return map;
}, {});

const modeDefinitions = [
'mode--light',
'mode--dark',
'breakpoint--desktop',
'breakpoint--tablet',
'breakpoint--mobile',
'components--components',
]
.map((mode) => {
const modeVariables: TokenOutput[] = layerMap[mode].variables;
const layerVariables = modeVariables.reduce(function (acc, variable) {
if (variable.value) {
const value = variable.value.replace(/[{}]/g, '');
const newValue = valueMap[value];
if (newValue) {
acc.push({
...variable,
value: newValue,
});
}
}
return acc;
}, []);
return layerVariables.length > 0
? renderLayerVariables(`${name} ${mode}`, layerVariables)
: '';
})
.join('\n');

writeTokenDefinitions(
name,
basetokenDefinitions,
modeDefinitions,
`${STORYBOOK_DOCS_PATH}/${fileIndex(
fileCount++
)}-${layerName}-token-definitions.mdx`
);
});
});

0 comments on commit 03d3dd0

Please sign in to comment.