Skip to content

Commit

Permalink
[PR feedback] Clean up types in src-docs ThemeContext
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Sep 23, 2024
1 parent 918b951 commit 2cdacd7
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions packages/eui/src-docs/src/components/with_theme/theme_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,20 @@ export const theme_languages: THEME_LANGUAGES[] = [
const THEME_NAMES = EUI_THEMES.map(({ value }) => value);
const THEME_LANGS = theme_languages.map(({ id }) => id);

const defaultState = {
themeLanguage: THEME_LANGS[0],
// eslint-disable-next-line @typescript-eslint/no-unused-vars
changeThemeLanguage: (language: THEME_LANGUAGES['id']) => {},
theme: undefined as string | undefined,
changeTheme: (themeValue: EUI_THEME['value']) => {
applyTheme(themeValue);
},
};

interface State {
type ThemeContextType = {
theme?: EUI_THEME['value'];
changeTheme: (themeValue: EUI_THEME['value']) => void;
themeLanguage: THEME_LANGUAGES['id'];
}
changeThemeLanguage: (language: THEME_LANGUAGES['id']) => void;
};
export const ThemeContext = React.createContext<ThemeContextType>({
theme: undefined,
changeTheme: () => {},
themeLanguage: THEME_LANGS[0],
changeThemeLanguage: () => {},
});

export const ThemeContext = React.createContext(defaultState);
type State = Pick<ThemeContextType, 'theme' | 'themeLanguage'>;

export class ThemeProvider extends React.Component<PropsWithChildren, State> {
constructor(props: object) {
Expand Down Expand Up @@ -82,7 +80,7 @@ export class ThemeProvider extends React.Component<PropsWithChildren, State> {

// If not set by either param or storage, or an invalid value, use the default
if (!themeLanguage || !THEME_LANGS.includes(themeLanguage))
themeLanguage = defaultState.themeLanguage;
themeLanguage = THEME_LANGS[0];

return themeLanguage;
};
Expand Down

0 comments on commit 2cdacd7

Please sign in to comment.