@redis-ui/styles 21.26.3 → 21.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/breakpoints.d.ts +22 -0
- package/dist/breakpoints.js +22 -0
- package/dist/hooks/useMediaQuery.d.ts +2 -0
- package/dist/hooks/useMediaQuery.js +16 -0
- package/dist/hooks/usePrefersReducedMotion.js +2 -28
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3778 -3775
- package/dist/index.umd.cjs +14 -14
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -99,6 +99,8 @@ Use tokens instead of hard-coded values, so your UI follows both themes and both
|
|
|
99
99
|
|
|
100
100
|
- `getFocusStyle()` / `getFocusStyleProperties()`: the design system's focus ring, for custom interactive elements
|
|
101
101
|
- `usePrefersReducedMotion()`: `true` when the user asked for reduced motion
|
|
102
|
+
- `useMediaQuery(query)`: `true` while a media query matches
|
|
103
|
+
- `breakpoints` / `media`: proposed viewport breakpoints and their media queries, for `@media ${media.mobile} { ... }`. Values may change until design confirms them
|
|
102
104
|
- `useStorage()`: the persisted-value hook used by mode switching
|
|
103
105
|
- `withOpacity()` / `withContrast()`: color helpers
|
|
104
106
|
- Theme types (`Theme`, `ThemePair`, ...)
|
|
@@ -110,6 +112,7 @@ The themes live in `src/themes/<themeLight|themeDark|themeLightNext|themeDarkNex
|
|
|
110
112
|
```bash
|
|
111
113
|
npm run build -w packages/styles
|
|
112
114
|
npm run lint -w packages/styles
|
|
115
|
+
npm run test -w packages/styles
|
|
113
116
|
```
|
|
114
117
|
|
|
115
|
-
|
|
118
|
+
Its hooks have unit tests. Theme changes show up in the components' stories and visual tests. See the [root README](https://github.com/redislabsdev/redis-ui) for Storybook, visual testing and releasing.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Viewport widths, in px, where the layout changes. Each one is the first width outside its range.
|
|
3
|
+
*
|
|
4
|
+
* Proposal: the values are pending design confirmation and may change before they are final.
|
|
5
|
+
*/
|
|
6
|
+
export declare const breakpoints: {
|
|
7
|
+
readonly mobile: 600;
|
|
8
|
+
readonly tablet: 900;
|
|
9
|
+
readonly laptop: 1200;
|
|
10
|
+
readonly desktop: 1536;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Media queries for `breakpoints`, for styled-components (`@media ${media.mobile} { ... }`) and `useMediaQuery`.
|
|
14
|
+
*
|
|
15
|
+
* Proposal: see `breakpoints`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const media: {
|
|
18
|
+
readonly mobile: `(max-width: ${number}px)`;
|
|
19
|
+
readonly tablet: `(max-width: ${number}px)`;
|
|
20
|
+
readonly laptop: `(max-width: ${number}px)`;
|
|
21
|
+
readonly desktop: `(max-width: ${number}px)`;
|
|
22
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Viewport widths, in px, where the layout changes. Each one is the first width outside its range.
|
|
3
|
+
*
|
|
4
|
+
* Proposal: the values are pending design confirmation and may change before they are final.
|
|
5
|
+
*/
|
|
6
|
+
export const breakpoints = {
|
|
7
|
+
mobile: 600,
|
|
8
|
+
tablet: 900,
|
|
9
|
+
laptop: 1200,
|
|
10
|
+
desktop: 1536
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Media queries for `breakpoints`, for styled-components (`@media ${media.mobile} { ... }`) and `useMediaQuery`.
|
|
14
|
+
*
|
|
15
|
+
* Proposal: see `breakpoints`.
|
|
16
|
+
*/
|
|
17
|
+
export const media = {
|
|
18
|
+
mobile: `(max-width: ${breakpoints.mobile - 1}px)`,
|
|
19
|
+
tablet: `(max-width: ${breakpoints.tablet - 1}px)`,
|
|
20
|
+
laptop: `(max-width: ${breakpoints.laptop - 1}px)`,
|
|
21
|
+
desktop: `(max-width: ${breakpoints.desktop - 1}px)`
|
|
22
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useCallback, useSyncExternalStore } from 'react';
|
|
2
|
+
const getMediaQueryList = (query) => typeof window === 'undefined' ? null : window.matchMedia(query);
|
|
3
|
+
const getServerSnapshot = () => false;
|
|
4
|
+
/** `true` while `query` matches. Always `false` on the server. */
|
|
5
|
+
export const useMediaQuery = (query) => {
|
|
6
|
+
const subscribe = useCallback((onChange) => {
|
|
7
|
+
const mediaQueryList = getMediaQueryList(query);
|
|
8
|
+
if (typeof mediaQueryList?.addEventListener === 'function') {
|
|
9
|
+
mediaQueryList.addEventListener('change', onChange);
|
|
10
|
+
return () => mediaQueryList.removeEventListener('change', onChange);
|
|
11
|
+
}
|
|
12
|
+
mediaQueryList?.addListener?.(onChange);
|
|
13
|
+
return () => mediaQueryList?.removeListener?.(onChange);
|
|
14
|
+
}, [query]);
|
|
15
|
+
return useSyncExternalStore(subscribe, () => getMediaQueryList(query)?.matches ?? false, getServerSnapshot);
|
|
16
|
+
};
|
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
3
|
-
if (typeof window === 'undefined') {
|
|
4
|
-
return null;
|
|
5
|
-
}
|
|
6
|
-
return window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
7
|
-
};
|
|
8
|
-
export const usePrefersReducedMotion = () => {
|
|
9
|
-
const [prefersReducedMotion, setPrefersReducedMotion] = useState(() => getReducedMotionQuery()?.matches ?? false);
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
const reducedMotionQuery = getReducedMotionQuery();
|
|
12
|
-
if (!reducedMotionQuery) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
setPrefersReducedMotion(reducedMotionQuery.matches);
|
|
16
|
-
const handleChange = (event) => setPrefersReducedMotion(event.matches);
|
|
17
|
-
if (typeof reducedMotionQuery.addEventListener === 'function') {
|
|
18
|
-
reducedMotionQuery.addEventListener('change', handleChange);
|
|
19
|
-
return () => reducedMotionQuery.removeEventListener('change', handleChange);
|
|
20
|
-
}
|
|
21
|
-
if (typeof reducedMotionQuery.addListener === 'function') {
|
|
22
|
-
reducedMotionQuery.addListener(handleChange);
|
|
23
|
-
return () => reducedMotionQuery.removeListener?.(handleChange);
|
|
24
|
-
}
|
|
25
|
-
return undefined;
|
|
26
|
-
}, []);
|
|
27
|
-
return prefersReducedMotion;
|
|
28
|
-
};
|
|
1
|
+
import { useMediaQuery } from './useMediaQuery';
|
|
2
|
+
export const usePrefersReducedMotion = () => useMediaQuery('(prefers-reduced-motion: reduce)');
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export * from './themes';
|
|
2
2
|
export * from './hooks/useTheme';
|
|
3
3
|
export * from './hooks/usePrefersReducedMotion';
|
|
4
|
+
export * from './hooks/useMediaQuery';
|
|
4
5
|
export * from './hooks/useStorage';
|
|
5
6
|
export * from './utils';
|
|
6
7
|
export * from './focus-indicator';
|
|
7
8
|
export * from './hooks/ThemeModeSwitching';
|
|
8
9
|
export * from './commonStyles';
|
|
10
|
+
export * from './breakpoints';
|