-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: configure darkmode with props * chore: memoize context value + rename files & variablse * Rename prop to `calendarColorScheme` and avoid leaking context * Forward colorScheme to Calendar instead of using context in CalendarList * add docs and changeset --------- Co-authored-by: Marcelo T Prado <[email protected]>
- Loading branch information
1 parent
8a3d4b5
commit 6d00992
Showing
8 changed files
with
141 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@marceloterreiro/flash-calendar": patch | ||
--- | ||
|
||
- Add an optional `calendarColorScheme` prop that enables overriding the color scheme used by Flash Calendar. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/flash-calendar/src/components/CalendarThemeProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { ReactNode } from "react"; | ||
import { createContext, useContext, useMemo } from "react"; | ||
import type { ColorSchemeName } from "react-native"; | ||
|
||
export interface CalendarThemeContextType { | ||
colorScheme?: ColorSchemeName; | ||
} | ||
|
||
const CalendarThemeContext = createContext<CalendarThemeContextType>({ | ||
colorScheme: undefined, | ||
}); | ||
|
||
export const CalendarThemeProvider = ({ | ||
children, | ||
colorScheme, | ||
}: { | ||
children: ReactNode; | ||
/** | ||
* When set, Flash Calendar will use this color scheme instead of the system's | ||
* value (`light|dark`). This is useful if your app doesn't support dark-mode, | ||
* for example. | ||
* | ||
* We don't advise using this prop - ideally, your app should reflect the | ||
* user's preferences. | ||
*/ | ||
colorScheme?: ColorSchemeName; | ||
}) => { | ||
const calendarThemeContextValue = useMemo<CalendarThemeContextType>( | ||
() => ({ colorScheme }), | ||
[colorScheme] | ||
); | ||
|
||
return ( | ||
<CalendarThemeContext.Provider value={calendarThemeContextValue}> | ||
{children} | ||
</CalendarThemeContext.Provider> | ||
); | ||
}; | ||
|
||
export const useCalendarTheme = () => { | ||
const context = useContext(CalendarThemeContext); | ||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters