Skip to content

Commit

Permalink
fix(storybook): fix theme picker current selection (#25533)
Browse files Browse the repository at this point in the history
  • Loading branch information
tudorpopams authored Nov 9, 2022
1 parent 87859b0 commit 891868c
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ const useStyles = makeStyles({
*/
export const ThemePicker: React.FC<{ selectedThemeId?: string }> = ({ selectedThemeId }) => {
const styles = useStyles();
const [currentThemeId, setCurrentThemeId] = React.useState(selectedThemeId ?? null);

const setGlobalTheme = (themeId: ThemeIds): void => {
addons.getChannel().emit('updateGlobals', { globals: { [THEME_ID]: themeId } });
};
const onCheckedValueChange: MenuProps['onCheckedValueChange'] = (e, data) => {
setGlobalTheme(data.checkedItems[0] as ThemeIds);
const newThemeId = data.checkedItems[0] as ThemeIds;
setGlobalTheme(newThemeId);
setCurrentThemeId(newThemeId);
};

const selectedTheme = themes.find(theme => theme.id === selectedThemeId);
const selectedTheme = themes.find(theme => theme.id === currentThemeId);

return (
<Menu
Expand Down

0 comments on commit 891868c

Please sign in to comment.