-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #221 from ItsJonQ/refactor/wp-data-reduced-motion
create-styles: Use WP/data for use-reduced-motion hook
- Loading branch information
Showing
13 changed files
with
255 additions
and
60 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 was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
packages/create-styles/src/hooks/use-reduced-motion/index.js
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,15 @@ | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
|
||
import IS_REDUCED_MOTION_STORE from './store'; | ||
|
||
/** | ||
* @return {[boolean, (isReducedMotion: boolean) => void]} | ||
*/ | ||
export const useReducedMotion = () => { | ||
const isReducedMotion = useSelect((select) => { | ||
return select(IS_REDUCED_MOTION_STORE).getIsReducedMotion(); | ||
}); | ||
const { setIsReducedMotion } = useDispatch(IS_REDUCED_MOTION_STORE); | ||
|
||
return [/** @type {boolean} */ (isReducedMotion), setIsReducedMotion]; | ||
}; |
51 changes: 51 additions & 0 deletions
51
packages/create-styles/src/hooks/use-reduced-motion/store.js
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,51 @@ | ||
import { registerStore } from '@wordpress/data'; | ||
|
||
const IS_REDUCED_MOTION_STORE = 'g2/is-reduced-motion'; | ||
|
||
const DEFAULT_STATE = { | ||
isReducedMotion: false, | ||
}; | ||
|
||
/** @typedef {{ type: 'SET_IS_REDUCED_MOTION', isReducedMotion: boolean }} SetIsReducedMotion */ | ||
|
||
const actions = { | ||
/** | ||
* @param {boolean} isReducedMotion | ||
* @return {SetIsReducedMotion} | ||
*/ | ||
setIsReducedMotion: (/** @type {boolean} */ isReducedMotion) => ({ | ||
type: 'SET_IS_REDUCED_MOTION', | ||
isReducedMotion, | ||
}), | ||
}; | ||
|
||
/** | ||
* @type {import('@wordpress/data').Store<typeof DEFAULT_STATE>} | ||
*/ | ||
(registerStore(IS_REDUCED_MOTION_STORE, { | ||
/** | ||
* @param {typeof DEFAULT_STATE} state | ||
* @param {SetIsReducedMotion | import('@wordpress/data').Action} action | ||
*/ | ||
reducer(state = DEFAULT_STATE, action) { | ||
switch (action.type) { | ||
case 'SET_IS_REDUCED_MOTION': | ||
return { | ||
...state, | ||
isReducedMotion: action.isReducedMotion, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}, | ||
|
||
actions, | ||
|
||
selectors: { | ||
getIsReducedMotion(state) { | ||
return state.isReducedMotion; | ||
}, | ||
}, | ||
})); | ||
|
||
export default IS_REDUCED_MOTION_STORE; |
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
Oops, something went wrong.
6c2a1fa
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.
Successfully deployed to the following URLs: