Skip to content

Commit

Permalink
fix: add default value for theme context
Browse files Browse the repository at this point in the history
  • Loading branch information
bpingris committed Apr 16, 2024
1 parent d43810c commit e30d38e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ export const DateRangePicker = (args: typeof KichenSink.args) => {

export const ControlledColorScheme: StoryObj<typeof Calendar> = {
args: {
colorSchemeToOverride: "dark",
colorSchemeToOverride: "light",
},
};
16 changes: 5 additions & 11 deletions packages/flash-calendar/src/hooks/useCalendarTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ export interface CalendarThemeContext {
colorScheme?: ColorSchemeName;
}

export const calendarThemeContext = createContext<
CalendarThemeContext | undefined
>(undefined);
const defaultThemeContext: CalendarThemeContext = { colorScheme: undefined };

export const useCalendarThemeContext = () => {
const context = useContext(calendarThemeContext);
export const calendarThemeContext =
createContext<CalendarThemeContext>(defaultThemeContext);

if (!context) {
throw new Error(
"useCalendarThemeContext must be called inside <calendarThemeContext.Provider>"
);
}
return context;
export const useCalendarThemeContext = () => {
return useContext(calendarThemeContext);
};

0 comments on commit e30d38e

Please sign in to comment.