-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scaffold TableOfContents compact view
- Loading branch information
1 parent
f0d4821
commit e56b5b9
Showing
67 changed files
with
986 additions
and
375 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
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
53 changes: 53 additions & 0 deletions
53
packages/embla-carousel-docs/src/components/KeyNavigating/Context.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,53 @@ | ||
import React, { | ||
useState, | ||
createContext, | ||
PropsWithChildren, | ||
useCallback, | ||
useMemo, | ||
} from 'react' | ||
import { useEventListener } from 'hooks/useEventListener' | ||
|
||
export type KeyNavigatingContextType = { | ||
isKeyNavigating: boolean | ||
setIsKeyNavigating: React.Dispatch<React.SetStateAction<boolean>> | ||
} | ||
|
||
export const KeyNavigatingContext = createContext<KeyNavigatingContextType>({ | ||
isKeyNavigating: false, | ||
setIsKeyNavigating: () => undefined, | ||
}) | ||
|
||
type PropType = PropsWithChildren<{}> | ||
|
||
export const KeyNavigatingProvider = (props: PropType) => { | ||
const { children } = props | ||
const [isKeyNavigating, setIsKeyNavigating] = useState(false) | ||
|
||
const onMouseDown = useCallback(() => { | ||
if (isKeyNavigating) setIsKeyNavigating(false) | ||
}, [isKeyNavigating, setIsKeyNavigating]) | ||
|
||
const onKeyDown = useCallback( | ||
({ key }: KeyboardEvent) => { | ||
if (key === 'Tab' && !isKeyNavigating) setIsKeyNavigating(true) | ||
}, | ||
[isKeyNavigating, setIsKeyNavigating], | ||
) | ||
|
||
const value = useMemo( | ||
() => ({ | ||
isKeyNavigating, | ||
setIsKeyNavigating, | ||
}), | ||
[isKeyNavigating, setIsKeyNavigating], | ||
) | ||
|
||
useEventListener('keydown', onKeyDown) | ||
useEventListener('mousedown', onMouseDown) | ||
|
||
return ( | ||
<KeyNavigatingContext.Provider value={value}> | ||
{children} | ||
</KeyNavigatingContext.Provider> | ||
) | ||
} |
Oops, something went wrong.