-
Notifications
You must be signed in to change notification settings - Fork 119
Fix dark mode flicker docs #4250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
67b66e1
Revert "Fix theme flash on paste website (#4025)"
PixeledCode b27d1ee
fix(docs): build failure for changing to ssr
krisantrobus 27b1546
fix(docs): build failure for changing to ssr
krisantrobus 95a21bf
fix(theme-flicker): use cookies to get and set a default theme
krisantrobus 49d320b
fix(docs): update keyboard shortcut default
krisantrobus 61772bc
fix(docs): add in better type check
krisantrobus 936d03c
fix(docs-theme): remove local storage
krisantrobus ff6a92d
fix(ci): lint
krisantrobus 0d609b2
fix(test): fix broken link
krisantrobus 34d32e4
chore(docs): debug ssr app cookie capture
krisantrobus 3526bf8
chore(docs): debug ssr app cookie capture
krisantrobus b55612c
chore(docs): debug ssr app cookie capture
krisantrobus 35e52a4
chore(docs): debug ssr app cookie capture
krisantrobus 7af23e2
chore(docs): debug ssr app cookie capture
krisantrobus 9260386
chore(docs): debug ssr app cookie capture
krisantrobus 927dece
chore(docs): debug ssr app cookie capture
krisantrobus 4cb9ff7
chore(docs): debug ssr app cookie capture
krisantrobus 1760cd0
chore(docs): debug ssr app cookie capture
krisantrobus 19e0232
chore(docs): debug ssr app cookie capture
krisantrobus 26c18ec
chore(docs): debug ssr app cookie capture
krisantrobus 2ea9427
chore(docs): debug ssr app cookie capture
krisantrobus 196faf0
chore(docs): debug ssr app cookie capture
krisantrobus 0d5fe90
chore(docs): debug ssr app cookie capture
krisantrobus 801a9ed
chore(docs): debug ssr app cookie capture
krisantrobus 3aaa322
chore(docs): debug ssr app cookie capture
krisantrobus 4eb27ee
chore(docs): test dark by default
krisantrobus 752dd2d
chore(docs): test cookie theme only
krisantrobus 8079b9f
chore(pr): cleanup
krisantrobus 73e7cd1
fix(tests): incorrect page link
krisantrobus 07a5a8f
fix(tests): incorrect page link
krisantrobus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -5,6 +5,16 @@ | |
|
||
export type UseDarkModeReturn = [ValidThemeName, () => void, boolean]; | ||
|
||
const setCookie = (name: string, value: any, days: number): void => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot use the NextJS cookies tool are this does not run client side and I couldn't get it to work except this way or we add a new cookie dependency |
||
let expires = ""; | ||
if (days) { | ||
const date = new Date(); | ||
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); | ||
expires = `; expires=${date.toUTCString()}`; | ||
} | ||
document.cookie = `${name}=${value || ""}${expires}; path=/`; | ||
}; | ||
|
||
const ValidThemes = { | ||
DEFAULT: "twilio", | ||
DARK: "twilio-dark", | ||
|
@@ -13,16 +23,17 @@ | |
type ValidThemeName = ValueOf<typeof ValidThemes>; | ||
|
||
const isValidTheme = (themeName: ValidThemeName): boolean => { | ||
return Object.values(ValidThemes).includes(themeName); | ||
return themeName === ValidThemes.DEFAULT || themeName === ValidThemes.DARK; | ||
}; | ||
|
||
export const useDarkMode = (): UseDarkModeReturn => { | ||
const [theme, setTheme] = React.useState<ValidThemeName>(ValidThemes.DEFAULT); | ||
export const useDarkMode = (defaultValue: ValidThemeName = ValidThemes.DEFAULT): UseDarkModeReturn => { | ||
const [theme, setTheme] = React.useState<ValidThemeName>(defaultValue); | ||
const [componentMounted, setComponentMounted] = React.useState(false); | ||
|
||
const setMode = (mode: ValidThemeName): void => { | ||
SimpleStorage.set("theme", mode); | ||
setTheme(mode); | ||
setCookie("paste-docs-theme", mode, 365); | ||
}; | ||
|
||
const toggleTheme = (): void => { | ||
|
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An error came up after removing the delayed rendering as navigator is only available running client side.