-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add disable autoplay preference and group related settings into a ded…
…icated page (#3626) * add autoplay preference * group accessibility settings into a dedicated page * fix gray background on web * Put a11y first --------- Co-authored-by: Dan Abramov <[email protected]>
- Loading branch information
Showing
10 changed files
with
263 additions
and
82 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react' | ||
|
||
import * as persisted from '#/state/persisted' | ||
|
||
type StateContext = boolean | ||
type SetContext = (v: boolean) => void | ||
|
||
const stateContext = React.createContext<StateContext>( | ||
Boolean(persisted.defaults.disableAutoplay), | ||
) | ||
const setContext = React.createContext<SetContext>((_: boolean) => {}) | ||
|
||
export function Provider({children}: {children: React.ReactNode}) { | ||
const [state, setState] = React.useState( | ||
Boolean(persisted.get('disableAutoplay')), | ||
) | ||
|
||
const setStateWrapped = React.useCallback( | ||
(autoplayDisabled: persisted.Schema['disableAutoplay']) => { | ||
setState(Boolean(autoplayDisabled)) | ||
persisted.write('disableAutoplay', autoplayDisabled) | ||
}, | ||
[setState], | ||
) | ||
|
||
React.useEffect(() => { | ||
return persisted.onUpdate(() => { | ||
setState(Boolean(persisted.get('disableAutoplay'))) | ||
}) | ||
}, [setStateWrapped]) | ||
|
||
return ( | ||
<stateContext.Provider value={state}> | ||
<setContext.Provider value={setStateWrapped}> | ||
{children} | ||
</setContext.Provider> | ||
</stateContext.Provider> | ||
) | ||
} | ||
|
||
export const useAutoplayDisabled = () => React.useContext(stateContext) | ||
export const useSetAutoplayDisabled = () => React.useContext(setContext) |
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
Oops, something went wrong.