@automattic/jetpack-components 1.12.11 → 1.12.13
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/CHANGELOG.md +10 -0
- package/build/components/action-popover/index.js +2 -2
- package/build/components/dialog/index.js +3 -2
- package/build/components/icon-tooltip/types.d.ts +3 -3
- package/build/components/pricing-table/index.js +3 -3
- package/build/index.d.ts +0 -1
- package/build/index.js +0 -1
- package/components/action-popover/index.tsx +2 -2
- package/components/dialog/index.tsx +3 -2
- package/components/icon-tooltip/types.ts +3 -3
- package/components/pricing-table/index.tsx +3 -3
- package/index.ts +0 -1
- package/package.json +3 -4
- package/build/components/layout/use-breakpoint-match/index.d.ts +0 -17
- package/build/components/layout/use-breakpoint-match/index.js +0 -50
- package/components/layout/use-breakpoint-match/README.md +0 -43
- package/components/layout/use-breakpoint-match/declaration.d.ts +0 -9
- package/components/layout/use-breakpoint-match/index.ts +0 -79
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
### This is a list detailing changes for the Jetpack RNA Components package releases.
|
|
4
4
|
|
|
5
|
+
## [1.12.13] - 2026-06-26
|
|
6
|
+
### Changed
|
|
7
|
+
- Internal updates.
|
|
8
|
+
|
|
9
|
+
## [1.12.12] - 2026-06-25
|
|
10
|
+
### Fixed
|
|
11
|
+
- Icon tooltip: Type `iconCode` as `ReactElement` so it matches the `@wordpress/icons` Icon and `@wordpress/ui` 0.15 type definitions. [#49795]
|
|
12
|
+
|
|
5
13
|
## [1.12.11] - 2026-06-24
|
|
6
14
|
### Removed
|
|
7
15
|
- Remove deprecated Spinner component. Use Spinner from @wordpress/components instead. [#49856]
|
|
@@ -1856,6 +1864,8 @@
|
|
|
1856
1864
|
### Changed
|
|
1857
1865
|
- Update node version requirement to 14.16.1
|
|
1858
1866
|
|
|
1867
|
+
[1.12.13]: https://github.com/Automattic/jetpack-components/compare/1.12.12...1.12.13
|
|
1868
|
+
[1.12.12]: https://github.com/Automattic/jetpack-components/compare/1.12.11...1.12.12
|
|
1859
1869
|
[1.12.11]: https://github.com/Automattic/jetpack-components/compare/1.12.10...1.12.11
|
|
1860
1870
|
[1.12.10]: https://github.com/Automattic/jetpack-components/compare/1.12.9...1.12.10
|
|
1861
1871
|
[1.12.9]: https://github.com/Automattic/jetpack-components/compare/1.12.8...1.12.9
|
|
@@ -3,10 +3,10 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
3
3
|
* External dependencies
|
|
4
4
|
*/
|
|
5
5
|
import { Popover } from '@wordpress/components';
|
|
6
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
6
7
|
import { __, sprintf } from '@wordpress/i18n';
|
|
7
8
|
import { close } from '@wordpress/icons';
|
|
8
9
|
import Button from '../button/index.js';
|
|
9
|
-
import useBreakpointMatch from '../layout/use-breakpoint-match/index.js';
|
|
10
10
|
import Text from '../text/index.js';
|
|
11
11
|
/**
|
|
12
12
|
* Internal dependencies
|
|
@@ -14,7 +14,7 @@ import Text from '../text/index.js';
|
|
|
14
14
|
import ThemeProvider from '../theme-provider/index.js';
|
|
15
15
|
import styles from './styles.module.scss';
|
|
16
16
|
const ActionPopover = ({ hideCloseButton = false, title, children, step = null, totalSteps = null, buttonContent = null, buttonDisabled = false, buttonHref = null, buttonExternalLink = false, offset = 32, onClose, onClick, ...otherPopoverProps }) => {
|
|
17
|
-
const
|
|
17
|
+
const isSm = useViewportMatch('small', '<');
|
|
18
18
|
if (!title || !children || !buttonContent) {
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
2
3
|
import clsx from 'clsx';
|
|
3
4
|
import Col from '../layout/col/index.js';
|
|
4
5
|
import Container from '../layout/container/index.js';
|
|
5
|
-
import useBreakpointMatch from '../layout/use-breakpoint-match/index.js';
|
|
6
6
|
import styles from './style.module.scss';
|
|
7
7
|
/**
|
|
8
8
|
* Dialog component.
|
|
@@ -15,7 +15,8 @@ import styles from './style.module.scss';
|
|
|
15
15
|
* @return {ReactNode} Rendered dialog
|
|
16
16
|
*/
|
|
17
17
|
const Dialog = ({ primary, secondary, isTwoSections = false, ...containerProps }) => {
|
|
18
|
-
const
|
|
18
|
+
const isSmall = useViewportMatch('small', '<');
|
|
19
|
+
const isLowerThanLarge = useViewportMatch('large', '<');
|
|
19
20
|
/*
|
|
20
21
|
* By convention, secondary section is not shown when:
|
|
21
22
|
* - layout is a two-sections setup
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
1
|
+
import type { Icon } from '@wordpress/icons';
|
|
2
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
3
3
|
export type Placement = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end';
|
|
4
4
|
export type Position = 'top left' | 'top center' | 'top right' | 'bottom left' | 'bottom center' | 'bottom right';
|
|
5
5
|
export type IconTooltipProps = {
|
|
@@ -26,7 +26,7 @@ export type IconTooltipProps = {
|
|
|
26
26
|
/**
|
|
27
27
|
* The icon to display. Accepts icon components from `@wordpress/icons`.
|
|
28
28
|
*/
|
|
29
|
-
iconCode?:
|
|
29
|
+
iconCode?: ComponentProps<typeof Icon>['icon'];
|
|
30
30
|
/**
|
|
31
31
|
* The title of Popover.
|
|
32
32
|
*/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
2
3
|
import { __, sprintf } from '@wordpress/i18n';
|
|
3
4
|
import { Icon, check, closeSmall } from '@wordpress/icons';
|
|
4
5
|
import clsx from 'clsx';
|
|
5
6
|
import { createContext, useContext, Children, cloneElement, } from 'react';
|
|
6
7
|
import IconTooltip from '../icon-tooltip/index.js';
|
|
7
|
-
import useBreakpointMatch from '../layout/use-breakpoint-match/index.js';
|
|
8
8
|
import TermsOfService from '../terms-of-service/index.js';
|
|
9
9
|
import Text from '../text/index.js';
|
|
10
10
|
import styles from './styles.module.scss';
|
|
@@ -30,7 +30,7 @@ const getItemLabels = (isComingSoon, isIncluded, featureNameLabel) => {
|
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
32
|
export const PricingTableItem = ({ isIncluded = false, isComingSoon = false, index = 0, label = null, tooltipInfo, tooltipTitle, tooltipClassName = '', }) => {
|
|
33
|
-
const
|
|
33
|
+
const isLg = useViewportMatch('large');
|
|
34
34
|
const item = useContext(PricingTableContext)[index];
|
|
35
35
|
const isExplicitlyEmpty = label === '';
|
|
36
36
|
const showTick = isComingSoon || isIncluded;
|
|
@@ -61,7 +61,7 @@ export const PricingTableColumn = ({ primary = false, children, className, }) =>
|
|
|
61
61
|
}) }));
|
|
62
62
|
};
|
|
63
63
|
const PricingTable = ({ title, headerLogo, items, children, showIntroOfferDisclaimer = false, }) => {
|
|
64
|
-
const
|
|
64
|
+
const isLg = useViewportMatch('large');
|
|
65
65
|
return (_jsxs(PricingTableContext.Provider, { value: items, children: [
|
|
66
66
|
_jsx("div", { className: clsx(styles.container, { [styles['is-viewport-large']]: isLg }), style: {
|
|
67
67
|
'--rows': items.length + 1,
|
package/build/index.d.ts
CHANGED
|
@@ -23,7 +23,6 @@ export { default as DecorativeCard } from './components/decorative-card/index.ts
|
|
|
23
23
|
export { default as Col } from './components/layout/col/index.tsx';
|
|
24
24
|
export { default as Testimonials } from './components/testimonials/index.tsx';
|
|
25
25
|
export { default as Container } from './components/layout/container/index.tsx';
|
|
26
|
-
export { default as useBreakpointMatch } from './components/layout/use-breakpoint-match/index.ts';
|
|
27
26
|
export { default as CopyToClipboard } from './components/copy-to-clipboard/index.tsx';
|
|
28
27
|
export * from './components/icons/index.tsx';
|
|
29
28
|
export { default as SplitButton } from './components/split-button/index.tsx';
|
package/build/index.js
CHANGED
|
@@ -36,7 +36,6 @@ export { default as DecorativeCard } from './components/decorative-card/index.js
|
|
|
36
36
|
export { default as Col } from './components/layout/col/index.js';
|
|
37
37
|
export { default as Testimonials } from './components/testimonials/index.js';
|
|
38
38
|
export { default as Container } from './components/layout/container/index.js';
|
|
39
|
-
export { default as useBreakpointMatch } from './components/layout/use-breakpoint-match/index.js';
|
|
40
39
|
export { default as CopyToClipboard } from './components/copy-to-clipboard/index.js';
|
|
41
40
|
export * from './components/icons/index.js';
|
|
42
41
|
export { default as SplitButton } from './components/split-button/index.js';
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { Popover } from '@wordpress/components';
|
|
5
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
5
6
|
import { __, sprintf } from '@wordpress/i18n';
|
|
6
7
|
import { close } from '@wordpress/icons';
|
|
7
8
|
import Button from '../button/index.tsx';
|
|
8
|
-
import useBreakpointMatch from '../layout/use-breakpoint-match/index.ts';
|
|
9
9
|
import Text from '../text/index.tsx';
|
|
10
10
|
/**
|
|
11
11
|
* Internal dependencies
|
|
@@ -32,7 +32,7 @@ const ActionPopover = ( {
|
|
|
32
32
|
onClick,
|
|
33
33
|
...otherPopoverProps
|
|
34
34
|
}: ActionPopoverProps ) => {
|
|
35
|
-
const
|
|
35
|
+
const isSm = useViewportMatch( 'small', '<' );
|
|
36
36
|
|
|
37
37
|
if ( ! title || ! children || ! buttonContent ) {
|
|
38
38
|
return null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
1
2
|
import clsx from 'clsx';
|
|
2
3
|
import Col from '../layout/col/index.tsx';
|
|
3
4
|
import Container from '../layout/container/index.tsx';
|
|
4
|
-
import useBreakpointMatch from '../layout/use-breakpoint-match/index.ts';
|
|
5
5
|
import styles from './style.module.scss';
|
|
6
6
|
import type { ReactNode, FC } from 'react';
|
|
7
7
|
|
|
@@ -29,7 +29,8 @@ const Dialog: FC< DialogProps > = ( {
|
|
|
29
29
|
isTwoSections = false,
|
|
30
30
|
...containerProps
|
|
31
31
|
} ) => {
|
|
32
|
-
const
|
|
32
|
+
const isSmall = useViewportMatch( 'small', '<' );
|
|
33
|
+
const isLowerThanLarge = useViewportMatch( 'large', '<' );
|
|
33
34
|
|
|
34
35
|
/*
|
|
35
36
|
* By convention, secondary section is not shown when:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
1
|
+
import type { Icon } from '@wordpress/icons';
|
|
2
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
export type Placement = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end';
|
|
5
5
|
|
|
@@ -40,7 +40,7 @@ export type IconTooltipProps = {
|
|
|
40
40
|
/**
|
|
41
41
|
* The icon to display. Accepts icon components from `@wordpress/icons`.
|
|
42
42
|
*/
|
|
43
|
-
iconCode?:
|
|
43
|
+
iconCode?: ComponentProps< typeof Icon >[ 'icon' ];
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* The title of Popover.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
1
2
|
import { __, sprintf } from '@wordpress/i18n';
|
|
2
3
|
import { Icon, check, closeSmall } from '@wordpress/icons';
|
|
3
4
|
import clsx from 'clsx';
|
|
@@ -11,7 +12,6 @@ import {
|
|
|
11
12
|
CSSProperties,
|
|
12
13
|
} from 'react';
|
|
13
14
|
import IconTooltip from '../icon-tooltip/index.tsx';
|
|
14
|
-
import useBreakpointMatch from '../layout/use-breakpoint-match/index.ts';
|
|
15
15
|
import TermsOfService from '../terms-of-service/index.tsx';
|
|
16
16
|
import Text from '../text/index.tsx';
|
|
17
17
|
import styles from './styles.module.scss';
|
|
@@ -59,7 +59,7 @@ export const PricingTableItem: FC< PricingTableItemProps > = ( {
|
|
|
59
59
|
tooltipTitle,
|
|
60
60
|
tooltipClassName = '',
|
|
61
61
|
} ) => {
|
|
62
|
-
const
|
|
62
|
+
const isLg = useViewportMatch( 'large' );
|
|
63
63
|
const item = useContext( PricingTableContext )[ index ];
|
|
64
64
|
const isExplicitlyEmpty = label === '';
|
|
65
65
|
const showTick = isComingSoon || isIncluded;
|
|
@@ -158,7 +158,7 @@ const PricingTable: FC< PricingTableProps > = ( {
|
|
|
158
158
|
children,
|
|
159
159
|
showIntroOfferDisclaimer = false,
|
|
160
160
|
} ) => {
|
|
161
|
-
const
|
|
161
|
+
const isLg = useViewportMatch( 'large' );
|
|
162
162
|
|
|
163
163
|
return (
|
|
164
164
|
<PricingTableContext.Provider value={ items }>
|
package/index.ts
CHANGED
|
@@ -38,7 +38,6 @@ export { default as DecorativeCard } from './components/decorative-card/index.ts
|
|
|
38
38
|
export { default as Col } from './components/layout/col/index.tsx';
|
|
39
39
|
export { default as Testimonials } from './components/testimonials/index.tsx';
|
|
40
40
|
export { default as Container } from './components/layout/container/index.tsx';
|
|
41
|
-
export { default as useBreakpointMatch } from './components/layout/use-breakpoint-match/index.ts';
|
|
42
41
|
export { default as CopyToClipboard } from './components/copy-to-clipboard/index.tsx';
|
|
43
42
|
export * from './components/icons/index.tsx';
|
|
44
43
|
export { default as SplitButton } from './components/split-button/index.tsx';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/jetpack-components",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.13",
|
|
4
4
|
"description": "Jetpack Components Package",
|
|
5
5
|
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/components/#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"@automattic/format-currency": "1.0.1",
|
|
76
76
|
"@automattic/jetpack-api": "^1.0.30",
|
|
77
|
-
"@automattic/jetpack-boost-score-api": "^1.0.
|
|
77
|
+
"@automattic/jetpack-boost-score-api": "^1.0.51",
|
|
78
78
|
"@automattic/jetpack-script-data": "^0.6.4",
|
|
79
|
-
"@automattic/number-formatters": "^1.2.
|
|
79
|
+
"@automattic/number-formatters": "^1.2.5",
|
|
80
80
|
"@babel/runtime": "^7",
|
|
81
81
|
"@gravatar-com/hovercards": "0.16.0",
|
|
82
82
|
"@wordpress/admin-ui": "2.1.0",
|
|
@@ -103,7 +103,6 @@
|
|
|
103
103
|
"devDependencies": {
|
|
104
104
|
"@automattic/jetpack-base-styles": "^1.2.7",
|
|
105
105
|
"@babel/core": "7.29.7",
|
|
106
|
-
"@babel/preset-react": "7.29.7",
|
|
107
106
|
"@jest/globals": "30.4.1",
|
|
108
107
|
"@storybook/addon-docs": "10.3.6",
|
|
109
108
|
"@storybook/react": "10.3.6",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
type Operators = '<' | '<=' | '>' | '>=';
|
|
2
|
-
/**
|
|
3
|
-
* Hook to match if current viewport is equal, greater or less than expected breakpoint
|
|
4
|
-
*
|
|
5
|
-
* @param {(Breakpoints | Array< Breakpoints >)} breakpointToMatch - An single breakpoint or list of breakpoints to match.
|
|
6
|
-
* @param {(Operators | Array< Operators >)} operatorToMatch - An single operator or list of them. It should follow the same sequence than breakpoints.
|
|
7
|
-
* @return {Array<boolean>} - List of matches, following breakpoints sequence.
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```es6
|
|
11
|
-
* useBreakpointMatch('sm')
|
|
12
|
-
* useBreakpointMatch('lg', '<')
|
|
13
|
-
* useBreakpointMatch([ 'lg', 'sm' ], [ '<', null ])
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
declare const useBreakpointMatch: (breakpointToMatch: "lg" | "md" | "sm" | ("lg" | "md" | "sm")[], operatorToMatch?: Operators[] | Operators) => boolean[];
|
|
17
|
-
export default useBreakpointMatch;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { useMediaQuery } from '@wordpress/compose';
|
|
2
|
-
import breakpointsValues from '../breakpoints.module.scss';
|
|
3
|
-
const BREAKPOINTS = ['sm', 'md', 'lg'];
|
|
4
|
-
const getMediaByOperator = (breakpoint, operator, matches) => {
|
|
5
|
-
const breakpointIndex = BREAKPOINTS.indexOf(breakpoint);
|
|
6
|
-
const breakpointIndexPlusOne = breakpointIndex + 1;
|
|
7
|
-
const isEqual = operator.includes('=');
|
|
8
|
-
let allNeededBreakpoints = [];
|
|
9
|
-
if (operator.startsWith('<')) {
|
|
10
|
-
allNeededBreakpoints = BREAKPOINTS.slice(0, isEqual ? breakpointIndexPlusOne : breakpointIndex);
|
|
11
|
-
}
|
|
12
|
-
if (operator.startsWith('>')) {
|
|
13
|
-
allNeededBreakpoints = BREAKPOINTS.slice(isEqual ? breakpointIndex : breakpointIndexPlusOne);
|
|
14
|
-
}
|
|
15
|
-
return allNeededBreakpoints?.length
|
|
16
|
-
? allNeededBreakpoints.some(brk => matches[brk])
|
|
17
|
-
: matches[breakpoint];
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Hook to match if current viewport is equal, greater or less than expected breakpoint
|
|
21
|
-
*
|
|
22
|
-
* @param {(Breakpoints | Array< Breakpoints >)} breakpointToMatch - An single breakpoint or list of breakpoints to match.
|
|
23
|
-
* @param {(Operators | Array< Operators >)} operatorToMatch - An single operator or list of them. It should follow the same sequence than breakpoints.
|
|
24
|
-
* @return {Array<boolean>} - List of matches, following breakpoints sequence.
|
|
25
|
-
* @example
|
|
26
|
-
*
|
|
27
|
-
* ```es6
|
|
28
|
-
* useBreakpointMatch('sm')
|
|
29
|
-
* useBreakpointMatch('lg', '<')
|
|
30
|
-
* useBreakpointMatch([ 'lg', 'sm' ], [ '<', null ])
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
const useBreakpointMatch = (breakpointToMatch, operatorToMatch) => {
|
|
34
|
-
const breakpoints = Array.isArray(breakpointToMatch)
|
|
35
|
-
? breakpointToMatch
|
|
36
|
-
: [breakpointToMatch];
|
|
37
|
-
const operators = Array.isArray(operatorToMatch)
|
|
38
|
-
? operatorToMatch
|
|
39
|
-
: [operatorToMatch];
|
|
40
|
-
const [smKey, mdKey, lgKey] = BREAKPOINTS;
|
|
41
|
-
const sm = useMediaQuery(breakpointsValues[smKey]);
|
|
42
|
-
const md = useMediaQuery(breakpointsValues[mdKey]);
|
|
43
|
-
const lg = useMediaQuery(breakpointsValues[lgKey]);
|
|
44
|
-
const matches = { sm, md, lg };
|
|
45
|
-
return breakpoints.map((breakpoint, idx) => {
|
|
46
|
-
const operator = operators[idx];
|
|
47
|
-
return operator ? getMediaByOperator(breakpoint, operator, matches) : matches[breakpoint];
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
export default useBreakpointMatch;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# useBreakpointMatch
|
|
2
|
-
|
|
3
|
-
Utility to match against breakpoints.
|
|
4
|
-
|
|
5
|
-
[ Storybook Reference ](https://automattic.github.io/jetpack-storybook/?path=/story/js-packages-components-layout--breakpoint-match)
|
|
6
|
-
|
|
7
|
-
## Usage
|
|
8
|
-
|
|
9
|
-
```jsx
|
|
10
|
-
import { useBreakpointMatch } from '@automattic/jetpack-components';
|
|
11
|
-
const [ isLg ] = useBreakpointMatch('lg')
|
|
12
|
-
return isLg && <Component />
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Parameters
|
|
16
|
-
|
|
17
|
-
### breakpointToMatch
|
|
18
|
-
|
|
19
|
-
Single or Array of breakpoints to match against.
|
|
20
|
-
|
|
21
|
-
- Type: `String`|`Array<String>`
|
|
22
|
-
- Required: `true`
|
|
23
|
-
|
|
24
|
-
```javascript
|
|
25
|
-
useBreakpointMatch('lg');
|
|
26
|
-
useBreakpointMatch([ 'lg', 'sm' ]);
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### operator
|
|
30
|
-
|
|
31
|
-
A Single or Array of operators to match less, equal, or greater than the breakpoint.
|
|
32
|
-
|
|
33
|
-
In Array, it matches against the same index from breakpoint.
|
|
34
|
-
|
|
35
|
-
- Type: `String`|`Array<String>`
|
|
36
|
-
- Required: `false`
|
|
37
|
-
|
|
38
|
-
#### Example
|
|
39
|
-
|
|
40
|
-
```javascript
|
|
41
|
-
useBreakpointMatch('md', '<=');
|
|
42
|
-
useBreakpointMatch([ 'lg', 'sm' ], ['<', '>']);
|
|
43
|
-
```
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { useMediaQuery } from '@wordpress/compose';
|
|
2
|
-
import breakpointsValues from '../breakpoints.module.scss';
|
|
3
|
-
|
|
4
|
-
const BREAKPOINTS = [ 'sm', 'md', 'lg' ] as const;
|
|
5
|
-
|
|
6
|
-
type Breakpoints = ( typeof BREAKPOINTS )[ number ];
|
|
7
|
-
|
|
8
|
-
type Operators = '<' | '<=' | '>' | '>=';
|
|
9
|
-
|
|
10
|
-
type Matches = { sm: boolean; md: boolean; lg: boolean };
|
|
11
|
-
|
|
12
|
-
const getMediaByOperator = (
|
|
13
|
-
breakpoint: Breakpoints,
|
|
14
|
-
operator: Operators,
|
|
15
|
-
matches: Matches
|
|
16
|
-
): boolean => {
|
|
17
|
-
const breakpointIndex = BREAKPOINTS.indexOf( breakpoint );
|
|
18
|
-
const breakpointIndexPlusOne = breakpointIndex + 1;
|
|
19
|
-
const isEqual = operator.includes( '=' );
|
|
20
|
-
|
|
21
|
-
let allNeededBreakpoints = [];
|
|
22
|
-
|
|
23
|
-
if ( operator.startsWith( '<' ) ) {
|
|
24
|
-
allNeededBreakpoints = BREAKPOINTS.slice(
|
|
25
|
-
0,
|
|
26
|
-
isEqual ? breakpointIndexPlusOne : breakpointIndex
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if ( operator.startsWith( '>' ) ) {
|
|
31
|
-
allNeededBreakpoints = BREAKPOINTS.slice( isEqual ? breakpointIndex : breakpointIndexPlusOne );
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return allNeededBreakpoints?.length
|
|
35
|
-
? allNeededBreakpoints.some( brk => matches[ brk ] )
|
|
36
|
-
: matches[ breakpoint ];
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Hook to match if current viewport is equal, greater or less than expected breakpoint
|
|
41
|
-
*
|
|
42
|
-
* @param {(Breakpoints | Array< Breakpoints >)} breakpointToMatch - An single breakpoint or list of breakpoints to match.
|
|
43
|
-
* @param {(Operators | Array< Operators >)} operatorToMatch - An single operator or list of them. It should follow the same sequence than breakpoints.
|
|
44
|
-
* @return {Array<boolean>} - List of matches, following breakpoints sequence.
|
|
45
|
-
* @example
|
|
46
|
-
*
|
|
47
|
-
* ```es6
|
|
48
|
-
* useBreakpointMatch('sm')
|
|
49
|
-
* useBreakpointMatch('lg', '<')
|
|
50
|
-
* useBreakpointMatch([ 'lg', 'sm' ], [ '<', null ])
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
const useBreakpointMatch = (
|
|
54
|
-
breakpointToMatch: Breakpoints | Array< Breakpoints >,
|
|
55
|
-
operatorToMatch?: Operators | Array< Operators >
|
|
56
|
-
) => {
|
|
57
|
-
const breakpoints: Array< Breakpoints > = Array.isArray( breakpointToMatch )
|
|
58
|
-
? breakpointToMatch
|
|
59
|
-
: [ breakpointToMatch ];
|
|
60
|
-
|
|
61
|
-
const operators: Array< Operators > = Array.isArray( operatorToMatch )
|
|
62
|
-
? operatorToMatch
|
|
63
|
-
: [ operatorToMatch ];
|
|
64
|
-
|
|
65
|
-
const [ smKey, mdKey, lgKey ] = BREAKPOINTS;
|
|
66
|
-
|
|
67
|
-
const sm = useMediaQuery( breakpointsValues[ smKey ] );
|
|
68
|
-
const md = useMediaQuery( breakpointsValues[ mdKey ] );
|
|
69
|
-
const lg = useMediaQuery( breakpointsValues[ lgKey ] );
|
|
70
|
-
|
|
71
|
-
const matches: Matches = { sm, md, lg };
|
|
72
|
-
|
|
73
|
-
return breakpoints.map( ( breakpoint, idx ) => {
|
|
74
|
-
const operator = operators[ idx ];
|
|
75
|
-
return operator ? getMediaByOperator( breakpoint, operator, matches ) : matches[ breakpoint ];
|
|
76
|
-
} );
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export default useBreakpointMatch;
|