-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat]: Introduce Redux to docs
- Loading branch information
Showing
99 changed files
with
2,163 additions
and
1,437 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
28 changes: 28 additions & 0 deletions
28
packages/embla-carousel-docs/src/components/KeyEvents/KeyEventsInit.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,28 @@ | ||
import { useCallback } from 'react' | ||
import { useEventListener } from 'hooks/useEventListener' | ||
import { useAppDispatch, useAppSelector } from 'hooks/useRedux' | ||
import { | ||
selectKeyNavigating, | ||
setIsKeyNavigating | ||
} from 'components/KeyEvents/keyEventsReducer' | ||
|
||
export const KeyEventsInit = () => { | ||
const dispatch = useAppDispatch() | ||
const isKeyNavigating = useAppSelector(selectKeyNavigating) | ||
|
||
const onMouseDown = useCallback(() => { | ||
if (isKeyNavigating) dispatch(setIsKeyNavigating(false)) | ||
}, [dispatch, isKeyNavigating]) | ||
|
||
const onKeyDown = useCallback( | ||
({ key }: KeyboardEvent) => { | ||
if (key === 'Tab' && !isKeyNavigating) dispatch(setIsKeyNavigating(true)) | ||
}, | ||
[dispatch, isKeyNavigating] | ||
) | ||
|
||
useEventListener('keydown', onKeyDown) | ||
useEventListener('mousedown', onMouseDown) | ||
|
||
return null | ||
} |
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
31 changes: 31 additions & 0 deletions
31
packages/embla-carousel-docs/src/components/KeyEvents/keyEventsReducer.ts
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,31 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit' | ||
import { AppStateType } from 'consts/redux' | ||
|
||
export type KeyEventsStateType = { | ||
isKeyNavigating: boolean | ||
} | ||
|
||
const initialState: KeyEventsStateType = { | ||
isKeyNavigating: false | ||
} | ||
|
||
const keyEventsSlice = createSlice({ | ||
name: 'keyEvents', | ||
initialState, | ||
reducers: { | ||
setIsKeyNavigating: ( | ||
state, | ||
action: PayloadAction<KeyEventsStateType['isKeyNavigating']> | ||
): void => { | ||
state.isKeyNavigating = action.payload | ||
} | ||
} | ||
}) | ||
|
||
const { name, reducer } = keyEventsSlice | ||
export { name as keyEventsName, reducer as keyEventsReducer } | ||
|
||
export const { setIsKeyNavigating } = keyEventsSlice.actions | ||
|
||
export const selectKeyNavigating = (state: AppStateType): boolean => | ||
state.keyEvents.isKeyNavigating |
Oops, something went wrong.