Skip to content

Commit

Permalink
Merge pull request #221 from ItsJonQ/refactor/wp-data-reduced-motion
Browse files Browse the repository at this point in the history
create-styles: Use WP/data for use-reduced-motion hook
  • Loading branch information
sarayourfriend committed Jan 12, 2021
2 parents 0661e53 + 5c258ab commit 6c2a1fa
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 60 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
"keywords": [],
"license": "MIT",
"devDependencies": {
"@wordpress/i18n": "^3.16.0",
"@wordpress/icons": "^2.8.0",
"@babel/core": "^7.10.3",
"@helpscout/stats": "^0.0.5",
"@itsjonq/controls": "0.0.9",
Expand All @@ -70,6 +68,9 @@
"@types/rtlcss": "^2.4.1",
"@types/styled-components": "^5.1.4",
"@types/tinycolor2": "^1.4.2",
"@types/wordpress__data": "^4.6.9",
"@wordpress/i18n": "^3.16.0",
"@wordpress/icons": "^2.8.0",
"among": "2.0.0",
"babel-loader": "^8.1.0",
"eslint-config-prettier": "6.11.0",
Expand All @@ -86,8 +87,8 @@
"lerna": "^3.20.2",
"lodash": "^4.17.19",
"prettier": "^2.1.2",
"react": "16.13.1",
"react-dom": "16.13.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"reakit-warning": "0.4.1",
"typescript": "^4.0.5",
"yup": "0.29.3"
Expand All @@ -98,4 +99,4 @@
"workspaces": [
"packages/*"
]
}
}
4 changes: 2 additions & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"sortablejs": "^1.10.2"
},
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"gitHead": "9536f69d764f89429aa66f4368914ea7936ca4c7"
}
4 changes: 2 additions & 2 deletions packages/context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"lodash": "^4.17.19"
},
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"gitHead": "9536f69d764f89429aa66f4368914ea7936ca4c7"
}
5 changes: 3 additions & 2 deletions packages/create-styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@emotion/core": "^10.0.28",
"@emotion/is-prop-valid": "^0.8.8",
"@wordpress/data": "^4.26.1",
"@wordpress/is-shallow-equal": "^2.3.0",
"@wp-g2/substate": "^0.0.132",
"@wp-g2/utils": "^0.0.132",
Expand All @@ -30,8 +31,8 @@
"styled-griddie": "^0.1.3"
},
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"reakit-utils": "^0.15.0"
Expand Down
29 changes: 0 additions & 29 deletions packages/create-styles/src/hooks/use-reduced-motion.js

This file was deleted.

15 changes: 15 additions & 0 deletions packages/create-styles/src/hooks/use-reduced-motion/index.js
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 packages/create-styles/src/hooks/use-reduced-motion/store.js
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;
4 changes: 2 additions & 2 deletions packages/design-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"yup": "^0.29.3"
},
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
}
4 changes: 2 additions & 2 deletions packages/icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"react-icons": "^3.10.0"
},
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"gitHead": "9536f69d764f89429aa66f4368914ea7936ca4c7"
}
4 changes: 2 additions & 2 deletions packages/styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"@wp-g2/utils": "^0.0.132"
},
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"gitHead": "9536f69d764f89429aa66f4368914ea7936ca4c7"
}
4 changes: 2 additions & 2 deletions packages/substate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"author": "Jon Quach <hello@jonquach.com> (https://jonquach.com)",
"license": "MIT",
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"gitHead": "9536f69d764f89429aa66f4368914ea7936ca4c7"
}
4 changes: 2 additions & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"use-isomorphic-layout-effect": "^1.0.0"
},
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"gitHead": "9536f69d764f89429aa66f4368914ea7936ca4c7"
}
Loading

1 comment on commit 6c2a1fa

@vercel
Copy link

@vercel vercel bot commented on 6c2a1fa Jan 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.