react-responsive-tools 2.6.0 → 2.6.2
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 +59 -65
- package/dist/breakpoints.config.d.ts +18 -2
- package/dist/breakpoints.config.js +33 -17
- package/dist/components/horizontal.d.ts +25 -0
- package/dist/components/horizontal.js +26 -1
- package/dist/default.config.d.ts +2 -2
- package/dist/default.config.js +17 -17
- package/dist/hooks/useBreakpoint.d.ts +50 -1
- package/dist/hooks/useBreakpoint.js +54 -7
- package/dist/hooks/useBreakpoint.test.js +25 -104
- package/dist/hooks/useVBreakpoint.js +6 -5
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/interfaces/TBreakpoint.d.ts +3 -2
- package/dist/scripts/createConfig.mjs +1 -1
- package/dist/scripts/generateCustomBreakpointsSCSS.mjs +1 -1
- package/package.json +1 -1
- package/reinit.sh +9 -9
- package/dist/functions/getBreakpoint.d.ts +0 -3
- package/dist/functions/getBreakpoint.js +0 -7
- package/dist/hooks/useVariant.d.ts +0 -2
- package/dist/hooks/useVariant.js +0 -3
- package/dist/scripts/generateTBreakpoint.mjs +0 -1
package/README.MD
CHANGED
|
@@ -8,10 +8,6 @@ The package is based on [react-responsive](https://www.npmjs.com/package/react-r
|
|
|
8
8
|
|
|
9
9
|
To install the project, run the following command:
|
|
10
10
|
|
|
11
|
-
### Установка
|
|
12
|
-
|
|
13
|
-
Пожалуйста, убедитесь, что вы установили следующие зависимости:
|
|
14
|
-
|
|
15
11
|
```sh
|
|
16
12
|
yarn add react-responsive
|
|
17
13
|
```
|
|
@@ -58,6 +54,16 @@ This command will run the `reinit.sh` script, which will recreate the necessary
|
|
|
58
54
|
|
|
59
55
|
The following horizontal and vertical breakpoints are provided by default:
|
|
60
56
|
|
|
57
|
+
### Preferred Adaptive Variant (`PREFERRED_VARIANT`)
|
|
58
|
+
|
|
59
|
+
By default, the library uses the following preferred adaptive variant:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
// DESKTOP_TO_FIRST or MOBILE_TO_FIRST
|
|
63
|
+
// TAdaptiveVariant = Dtf | MtF
|
|
64
|
+
export const PREFERRED_VARIANT: TAdaptiveVariant = 'DtF';
|
|
65
|
+
```
|
|
66
|
+
|
|
61
67
|
#### Horizontal Breakpoints
|
|
62
68
|
|
|
63
69
|
```typescript
|
|
@@ -107,38 +113,29 @@ const MyComponent = () => {
|
|
|
107
113
|
};
|
|
108
114
|
```
|
|
109
115
|
|
|
110
|
-
#### Hook `
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
import { useBreakpointMF } from 'react-responsive-tools';
|
|
116
|
+
#### Hook `useBreakpointBetween`
|
|
114
117
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const isMedium = useBreakpointMF('md');
|
|
118
|
+
`useBreakpointBetween` is an optimized hook for checking whether the current
|
|
119
|
+
viewport is between two breakpoints (`min` and `max`).
|
|
118
120
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
);
|
|
124
|
-
};
|
|
125
|
-
```
|
|
121
|
+
It is especially useful as a safe replacement for combining `useBreakpoint`
|
|
122
|
+
with both mobile-first (`For`) and desktop-first (`Before`) logic, where
|
|
123
|
+
their ranges would otherwise overlap at the same pixel (for example,
|
|
124
|
+
`min-width: 300px` and `max-width: 300px` both including 300px).
|
|
126
125
|
|
|
127
|
-
|
|
126
|
+
Internally the hook adjusts one of the boundaries by `1px` based on
|
|
127
|
+
the preferred adaptive variant (`PREFERRED_VARIANT`) to ensure that
|
|
128
|
+
a particular pixel falls into only one range.
|
|
128
129
|
|
|
129
130
|
```typescript
|
|
130
|
-
import {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
{isLarge && <p>Current breakpoint: Large (lg) for Desktop First</p>}
|
|
139
|
-
</div>
|
|
140
|
-
);
|
|
141
|
-
};
|
|
131
|
+
import { useBreakpointBetween } from 'react-responsive-tools';
|
|
132
|
+
|
|
133
|
+
const MyComponent = () => {
|
|
134
|
+
const isVisible = useBreakpointBetween('sm', 'lg');
|
|
135
|
+
return (
|
|
136
|
+
{isVisible && Visible only between "sm" and "lg" breakpoints}
|
|
137
|
+
);
|
|
138
|
+
};
|
|
142
139
|
```
|
|
143
140
|
|
|
144
141
|
#### Hook `useVBreakpoint`
|
|
@@ -158,40 +155,6 @@ const MyComponent = () => {
|
|
|
158
155
|
};
|
|
159
156
|
```
|
|
160
157
|
|
|
161
|
-
#### Hook `useVBreakpointMF`
|
|
162
|
-
|
|
163
|
-
```typescript
|
|
164
|
-
import { useVBreakpointMF } from 'react-responsive-tools';
|
|
165
|
-
|
|
166
|
-
// Usage Example
|
|
167
|
-
const MyComponent = () => {
|
|
168
|
-
const isMedium = useVBreakpointMF('md');
|
|
169
|
-
|
|
170
|
-
return (
|
|
171
|
-
<div>
|
|
172
|
-
{isMedium && <p>Current vertical breakpoint: Medium (md) for Mobile First</p>}
|
|
173
|
-
</div>
|
|
174
|
-
);
|
|
175
|
-
};
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
#### Hook `useVBreakpointDF`
|
|
179
|
-
|
|
180
|
-
```typescript
|
|
181
|
-
import { useVBreakpointDF } from 'react-responsive-tools';
|
|
182
|
-
|
|
183
|
-
// Usage Example
|
|
184
|
-
const MyComponent = () => {
|
|
185
|
-
const isLarge = useVBreakpointDF('lg');
|
|
186
|
-
|
|
187
|
-
return (
|
|
188
|
-
<div>
|
|
189
|
-
{isLarge && <p>Current vertical breakpoint: Large (lg) for Desktop First</p>}
|
|
190
|
-
</div>
|
|
191
|
-
);
|
|
192
|
-
};
|
|
193
|
-
```
|
|
194
|
-
|
|
195
158
|
### Using Components
|
|
196
159
|
|
|
197
160
|
#### Component `For`
|
|
@@ -232,6 +195,37 @@ const CustomSizeComponent = () => (
|
|
|
232
195
|
);
|
|
233
196
|
```
|
|
234
197
|
|
|
198
|
+
#### Component `Between`
|
|
199
|
+
|
|
200
|
+
`Between` is a convenience component built on top of `useBreakpointBetween`.
|
|
201
|
+
It renders its children only when the viewport width is between `min` and `max`.
|
|
202
|
+
|
|
203
|
+
Compared to combining `For` and `Before`, `Between` automatically applies the
|
|
204
|
+
1px shift logic to avoid overlapping ranges.
|
|
205
|
+
|
|
206
|
+
```tsx
|
|
207
|
+
import React from 'react';
|
|
208
|
+
|
|
209
|
+
import { Between } from 'react-responsive-tools';
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Visible only on tablet widths: from "sm" (576px) up to "lg" (992px)
|
|
213
|
+
* with a safe 1px gap between adjacent ranges.
|
|
214
|
+
*/
|
|
215
|
+
export function TabletOnlyBanner() {
|
|
216
|
+
return (
|
|
217
|
+
<Between min="sm" max="lg">
|
|
218
|
+
<section className="tablet-banner">
|
|
219
|
+
<h2>Tablet-only promo</h2>
|
|
220
|
+
<p>
|
|
221
|
+
This banner is visible only between the <code>sm</code> and <code>lg</code> breakpoints.
|
|
222
|
+
</p>
|
|
223
|
+
</section>
|
|
224
|
+
</Between>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
235
229
|
### Breakpoint Types
|
|
236
230
|
|
|
237
231
|
```typescript
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { TAdaptiveVariant } from "./interfaces/TAdaptiveVariant";
|
|
2
|
+
/**
|
|
3
|
+
* Preferred adaptive layout variant.
|
|
4
|
+
*
|
|
5
|
+
* 'DtF' stands for "Desktop To First" and is used as the default strategy
|
|
6
|
+
* for resolving overlaps between "mobile-first" (`min-width`) and
|
|
7
|
+
* "desktop-first" (`max-width`) breakpoints.
|
|
8
|
+
*
|
|
9
|
+
* When switching between these variants we shift the opposite boundary
|
|
10
|
+
* by 1px to avoid cases when two ranges overlap at the exact same pixel.
|
|
11
|
+
*
|
|
12
|
+
* For example:
|
|
13
|
+
* - `min-width: 300px` includes 300px,
|
|
14
|
+
* - `max-width: 300px` also includes 300px,
|
|
15
|
+
* which causes an overlap. By shifting one of them by 1px we guarantee
|
|
16
|
+
* that a given pixel belongs to only one range.
|
|
17
|
+
*/
|
|
2
18
|
export declare const PREFERRED_VARIANT: TAdaptiveVariant;
|
|
3
|
-
declare const HORIZONTAL_BREAKPOINTS: Record<string,
|
|
4
|
-
declare const VERTICAL_BREAKPOINTS: Record<string,
|
|
19
|
+
declare const HORIZONTAL_BREAKPOINTS: Record<string, number>;
|
|
20
|
+
declare const VERTICAL_BREAKPOINTS: Record<string, number>;
|
|
5
21
|
export { HORIZONTAL_BREAKPOINTS, VERTICAL_BREAKPOINTS };
|
|
@@ -1,23 +1,39 @@
|
|
|
1
1
|
// src/breakpoints.config.ts
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Preferred adaptive layout variant.
|
|
4
|
+
*
|
|
5
|
+
* 'DtF' stands for "Desktop To First" and is used as the default strategy
|
|
6
|
+
* for resolving overlaps between "mobile-first" (`min-width`) and
|
|
7
|
+
* "desktop-first" (`max-width`) breakpoints.
|
|
8
|
+
*
|
|
9
|
+
* When switching between these variants we shift the opposite boundary
|
|
10
|
+
* by 1px to avoid cases when two ranges overlap at the exact same pixel.
|
|
11
|
+
*
|
|
12
|
+
* For example:
|
|
13
|
+
* - `min-width: 300px` includes 300px,
|
|
14
|
+
* - `max-width: 300px` also includes 300px,
|
|
15
|
+
* which causes an overlap. By shifting one of them by 1px we guarantee
|
|
16
|
+
* that a given pixel belongs to only one range.
|
|
17
|
+
*/
|
|
18
|
+
export const PREFERRED_VARIANT = 'MtF'; // DESKTOP_TO_FIRST
|
|
3
19
|
const HORIZONTAL_BREAKPOINTS = {
|
|
4
|
-
"xs":
|
|
5
|
-
"sm":
|
|
6
|
-
"md":
|
|
7
|
-
"lg":
|
|
8
|
-
"lt":
|
|
9
|
-
"ltm":
|
|
10
|
-
"ltl":
|
|
11
|
-
"xl":
|
|
12
|
-
"xxl":
|
|
13
|
-
"qxl":
|
|
20
|
+
"xs": 320,
|
|
21
|
+
"sm": 576,
|
|
22
|
+
"md": 768,
|
|
23
|
+
"lg": 992,
|
|
24
|
+
"lt": 1024,
|
|
25
|
+
"ltm": 1200,
|
|
26
|
+
"ltl": 1440,
|
|
27
|
+
"xl": 1920,
|
|
28
|
+
"xxl": 2560,
|
|
29
|
+
"qxl": 384,
|
|
14
30
|
};
|
|
15
31
|
const VERTICAL_BREAKPOINTS = {
|
|
16
|
-
"xs":
|
|
17
|
-
"sm":
|
|
18
|
-
"md":
|
|
19
|
-
"lg":
|
|
20
|
-
"xl":
|
|
21
|
-
"xxl":
|
|
32
|
+
"xs": 600,
|
|
33
|
+
"sm": 800,
|
|
34
|
+
"md": 1000,
|
|
35
|
+
"lg": 1200,
|
|
36
|
+
"xl": 1600,
|
|
37
|
+
"xxl": 160,
|
|
22
38
|
};
|
|
23
39
|
export { HORIZONTAL_BREAKPOINTS, VERTICAL_BREAKPOINTS };
|
|
@@ -12,7 +12,32 @@ interface BetweenProps {
|
|
|
12
12
|
max: TBreakpoint | number;
|
|
13
13
|
min: TBreakpoint | number;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Renders children only when the current viewport matches
|
|
17
|
+
* the given breakpoint using the mobile-first ("MtF") strategy.
|
|
18
|
+
*
|
|
19
|
+
* Internally it uses {@link useBreakpoint} with variant "MtF".
|
|
20
|
+
*/
|
|
15
21
|
export declare function For({ children, p }: Props): import("react/jsx-runtime").JSX.Element | null;
|
|
22
|
+
/**
|
|
23
|
+
* Renders children only when the current viewport matches
|
|
24
|
+
* the given breakpoint using the desktop-first ("DtF") strategy.
|
|
25
|
+
*
|
|
26
|
+
* Internally it uses {@link useBreakpoint} with variant "DtF".
|
|
27
|
+
*/
|
|
16
28
|
export declare function Before({ children, p }: Props): import("react/jsx-runtime").JSX.Element | null;
|
|
29
|
+
/**
|
|
30
|
+
* Renders children only when the current viewport is between
|
|
31
|
+
* two breakpoints (`min` and `max`).
|
|
32
|
+
*
|
|
33
|
+
* This component is an optimized alternative to combining `For`
|
|
34
|
+
* and `Before` when their ranges would overlap at the same pixel
|
|
35
|
+
* (e.g. `min-width: 300px` and `max-width: 300px` both including 300px).
|
|
36
|
+
*
|
|
37
|
+
* Under the hood it uses {@link useBreakpointBetween}, which shifts
|
|
38
|
+
* one of the boundaries by 1px depending on the preferred adaptive
|
|
39
|
+
* variant (see {@link PREFERRED_VARIANT}) to guarantee that a given
|
|
40
|
+
* pixel belongs to only one logical range.
|
|
41
|
+
*/
|
|
17
42
|
export declare function Between({ children, min, max }: BetweenProps): import("react/jsx-runtime").JSX.Element | null;
|
|
18
43
|
export {};
|
|
@@ -3,19 +3,44 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
* Created by westp on 15.05.2023
|
|
4
4
|
*/
|
|
5
5
|
import { Fragment } from "react";
|
|
6
|
-
import { useBreakpoint, useBreakpointBetween } from '../hooks/useBreakpoint
|
|
6
|
+
import { useBreakpoint, useBreakpointBetween } from '../hooks/useBreakpoint';
|
|
7
|
+
/**
|
|
8
|
+
* Renders children only when the current viewport matches
|
|
9
|
+
* the given breakpoint using the mobile-first ("MtF") strategy.
|
|
10
|
+
*
|
|
11
|
+
* Internally it uses {@link useBreakpoint} with variant "MtF".
|
|
12
|
+
*/
|
|
7
13
|
export function For({ children, p }) {
|
|
8
14
|
const is = useBreakpoint(p, 'MtF');
|
|
9
15
|
if (is)
|
|
10
16
|
return _jsx(Fragment, { children: children });
|
|
11
17
|
return null;
|
|
12
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Renders children only when the current viewport matches
|
|
21
|
+
* the given breakpoint using the desktop-first ("DtF") strategy.
|
|
22
|
+
*
|
|
23
|
+
* Internally it uses {@link useBreakpoint} with variant "DtF".
|
|
24
|
+
*/
|
|
13
25
|
export function Before({ children, p }) {
|
|
14
26
|
const is = useBreakpoint(p, 'DtF');
|
|
15
27
|
if (is)
|
|
16
28
|
return _jsx(Fragment, { children: children });
|
|
17
29
|
return null;
|
|
18
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Renders children only when the current viewport is between
|
|
33
|
+
* two breakpoints (`min` and `max`).
|
|
34
|
+
*
|
|
35
|
+
* This component is an optimized alternative to combining `For`
|
|
36
|
+
* and `Before` when their ranges would overlap at the same pixel
|
|
37
|
+
* (e.g. `min-width: 300px` and `max-width: 300px` both including 300px).
|
|
38
|
+
*
|
|
39
|
+
* Under the hood it uses {@link useBreakpointBetween}, which shifts
|
|
40
|
+
* one of the boundaries by 1px depending on the preferred adaptive
|
|
41
|
+
* variant (see {@link PREFERRED_VARIANT}) to guarantee that a given
|
|
42
|
+
* pixel belongs to only one logical range.
|
|
43
|
+
*/
|
|
19
44
|
export function Between({ children, min, max }) {
|
|
20
45
|
const is = useBreakpointBetween(min, max);
|
|
21
46
|
if (is)
|
package/dist/default.config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TAdaptiveVariant } from "./interfaces/TAdaptiveVariant";
|
|
2
2
|
declare const PREFERRED_VARIANT: TAdaptiveVariant;
|
|
3
|
-
declare const HORIZONTAL_BREAKPOINTS: Record<string,
|
|
4
|
-
declare const VERTICAL_BREAKPOINTS: Record<string,
|
|
3
|
+
declare const HORIZONTAL_BREAKPOINTS: Record<string, number>;
|
|
4
|
+
declare const VERTICAL_BREAKPOINTS: Record<string, number>;
|
|
5
5
|
export { HORIZONTAL_BREAKPOINTS, VERTICAL_BREAKPOINTS, PREFERRED_VARIANT };
|
package/dist/default.config.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
// breakpointConfig.js
|
|
2
|
-
const PREFERRED_VARIANT = '
|
|
2
|
+
const PREFERRED_VARIANT = 'MtF'; // DESKTOP_TO_FIRST
|
|
3
3
|
const HORIZONTAL_BREAKPOINTS = {
|
|
4
|
-
xs:
|
|
5
|
-
sm:
|
|
6
|
-
md:
|
|
7
|
-
lg:
|
|
8
|
-
lt:
|
|
9
|
-
ltm:
|
|
10
|
-
ltl:
|
|
11
|
-
xl:
|
|
12
|
-
xxl:
|
|
13
|
-
qxl:
|
|
4
|
+
"xs": 320,
|
|
5
|
+
"sm": 576,
|
|
6
|
+
"md": 768,
|
|
7
|
+
"lg": 992,
|
|
8
|
+
"lt": 1024,
|
|
9
|
+
"ltm": 1200,
|
|
10
|
+
"ltl": 1440,
|
|
11
|
+
"xl": 1920,
|
|
12
|
+
"xxl": 2560,
|
|
13
|
+
"qxl": 384,
|
|
14
14
|
};
|
|
15
15
|
const VERTICAL_BREAKPOINTS = {
|
|
16
|
-
xs:
|
|
17
|
-
sm:
|
|
18
|
-
md:
|
|
19
|
-
lg:
|
|
20
|
-
xl:
|
|
21
|
-
xxl:
|
|
16
|
+
"xs": 600,
|
|
17
|
+
"sm": 800,
|
|
18
|
+
"md": 1000,
|
|
19
|
+
"lg": 1200,
|
|
20
|
+
"xl": 1600,
|
|
21
|
+
"xxl": 160,
|
|
22
22
|
};
|
|
23
23
|
export { HORIZONTAL_BREAKPOINTS, VERTICAL_BREAKPOINTS, PREFERRED_VARIANT };
|
|
@@ -1,4 +1,53 @@
|
|
|
1
1
|
import { TBreakpoint } from '../interfaces/TBreakpoint';
|
|
2
2
|
import { TAdaptiveVariant } from '../interfaces/TAdaptiveVariant';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Low-level hook that checks if the current viewport matches a horizontal breakpoint.
|
|
5
|
+
*
|
|
6
|
+
* It supports:
|
|
7
|
+
* - named breakpoints (e.g. "md", "lg"),
|
|
8
|
+
* - custom numeric pixel values (e.g. 768).
|
|
9
|
+
*
|
|
10
|
+
* The check is performed using `react-responsive` and the current adaptive variant:
|
|
11
|
+
* - for mobile-first (MtF) the hook uses `min-width`,
|
|
12
|
+
* - for desktop-first (DtF) the hook uses `max-width`.
|
|
13
|
+
*
|
|
14
|
+
* To avoid overlap between opposite variants (e.g. `min-width: 300px` and
|
|
15
|
+
* `max-width: 300px` both including 300px), the hook shifts the opposite
|
|
16
|
+
* boundary by 1px when the requested variant differs from `PREFERRED_VARIANT`.
|
|
17
|
+
*
|
|
18
|
+
* @param b Breakpoint name or explicit pixel value.
|
|
19
|
+
* @param variant Adaptive variant: "MtF" (mobile to first) or "DtF" (desktop to first).
|
|
20
|
+
* By default, uses {@link PREFERRED_VARIANT}.
|
|
21
|
+
* @returns `true` if the media query matches, otherwise `false` or `null`
|
|
22
|
+
* (depending on `react-responsive` behavior).
|
|
23
|
+
*/
|
|
24
|
+
export declare function useBreakpoint(b: TBreakpoint | number, variant?: TAdaptiveVariant): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Optimized hook for checking if the current viewport is between two breakpoints.
|
|
27
|
+
*
|
|
28
|
+
* This hook is designed as a safe alternative to using a combination of
|
|
29
|
+
* `For` (mobile-first) and `Before` (desktop-first) when their ranges would
|
|
30
|
+
* otherwise overlap.
|
|
31
|
+
*
|
|
32
|
+
* Example of the overlap problem:
|
|
33
|
+
* - `min-width: 300px` includes 300px,
|
|
34
|
+
* - `max-width: 300px` also includes 300px,
|
|
35
|
+
* so both conditions are `true` at exactly 300px.
|
|
36
|
+
*
|
|
37
|
+
* To prevent this, {@link useBreakpointBetween} automatically shifts the
|
|
38
|
+
* opposite boundary by 1px depending on the adaptive variant:
|
|
39
|
+
*
|
|
40
|
+
* - preferredVariant === "MtF":
|
|
41
|
+
* max = max - 1 (so the upper bound becomes exclusive by 1px),
|
|
42
|
+
* - preferredVariant === "DtF":
|
|
43
|
+
* min = min - 1 (so the lower bound becomes exclusive by 1px),
|
|
44
|
+
*
|
|
45
|
+
* ensuring that a particular pixel belongs to only one logical range.
|
|
46
|
+
*
|
|
47
|
+
* @param min Lower breakpoint (inclusive in the original definition).
|
|
48
|
+
* @param max Upper breakpoint (inclusive in the original definition).
|
|
49
|
+
* @param preferredVariant Adaptive variant used to resolve the 1px overlap.
|
|
50
|
+
* By default, uses {@link PREFERRED_VARIANT}.
|
|
51
|
+
* @returns `true` if the viewport width is within the adjusted [min, max] range.
|
|
52
|
+
*/
|
|
4
53
|
export declare function useBreakpointBetween(min: TBreakpoint | number, max: TBreakpoint | number, preferredVariant?: TAdaptiveVariant): boolean;
|
|
@@ -1,17 +1,64 @@
|
|
|
1
1
|
import { useMediaQuery } from 'react-responsive';
|
|
2
|
-
import { PREFERRED_VARIANT } from '../breakpoints.config';
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { PREFERRED_VARIANT, HORIZONTAL_BREAKPOINTS } from '../breakpoints.config';
|
|
3
|
+
/**
|
|
4
|
+
* Low-level hook that checks if the current viewport matches a horizontal breakpoint.
|
|
5
|
+
*
|
|
6
|
+
* It supports:
|
|
7
|
+
* - named breakpoints (e.g. "md", "lg"),
|
|
8
|
+
* - custom numeric pixel values (e.g. 768).
|
|
9
|
+
*
|
|
10
|
+
* The check is performed using `react-responsive` and the current adaptive variant:
|
|
11
|
+
* - for mobile-first (MtF) the hook uses `min-width`,
|
|
12
|
+
* - for desktop-first (DtF) the hook uses `max-width`.
|
|
13
|
+
*
|
|
14
|
+
* To avoid overlap between opposite variants (e.g. `min-width: 300px` and
|
|
15
|
+
* `max-width: 300px` both including 300px), the hook shifts the opposite
|
|
16
|
+
* boundary by 1px when the requested variant differs from `PREFERRED_VARIANT`.
|
|
17
|
+
*
|
|
18
|
+
* @param b Breakpoint name or explicit pixel value.
|
|
19
|
+
* @param variant Adaptive variant: "MtF" (mobile to first) or "DtF" (desktop to first).
|
|
20
|
+
* By default, uses {@link PREFERRED_VARIANT}.
|
|
21
|
+
* @returns `true` if the media query matches, otherwise `false` or `null`
|
|
22
|
+
* (depending on `react-responsive` behavior).
|
|
23
|
+
*/
|
|
5
24
|
export function useBreakpoint(b, variant = PREFERRED_VARIANT) {
|
|
6
|
-
let _bp = typeof b === 'number' ? b :
|
|
7
|
-
const v =
|
|
25
|
+
let _bp = typeof b === 'number' ? b : HORIZONTAL_BREAKPOINTS[b];
|
|
26
|
+
const v = variant === 'MtF' ? 'min' : 'max';
|
|
8
27
|
if (variant !== PREFERRED_VARIANT)
|
|
9
28
|
_bp = _bp - 1;
|
|
10
29
|
return useMediaQuery({ query: `(${v}-width: ${_bp}px)` });
|
|
11
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Optimized hook for checking if the current viewport is between two breakpoints.
|
|
33
|
+
*
|
|
34
|
+
* This hook is designed as a safe alternative to using a combination of
|
|
35
|
+
* `For` (mobile-first) and `Before` (desktop-first) when their ranges would
|
|
36
|
+
* otherwise overlap.
|
|
37
|
+
*
|
|
38
|
+
* Example of the overlap problem:
|
|
39
|
+
* - `min-width: 300px` includes 300px,
|
|
40
|
+
* - `max-width: 300px` also includes 300px,
|
|
41
|
+
* so both conditions are `true` at exactly 300px.
|
|
42
|
+
*
|
|
43
|
+
* To prevent this, {@link useBreakpointBetween} automatically shifts the
|
|
44
|
+
* opposite boundary by 1px depending on the adaptive variant:
|
|
45
|
+
*
|
|
46
|
+
* - preferredVariant === "MtF":
|
|
47
|
+
* max = max - 1 (so the upper bound becomes exclusive by 1px),
|
|
48
|
+
* - preferredVariant === "DtF":
|
|
49
|
+
* min = min - 1 (so the lower bound becomes exclusive by 1px),
|
|
50
|
+
*
|
|
51
|
+
* ensuring that a particular pixel belongs to only one logical range.
|
|
52
|
+
*
|
|
53
|
+
* @param min Lower breakpoint (inclusive in the original definition).
|
|
54
|
+
* @param max Upper breakpoint (inclusive in the original definition).
|
|
55
|
+
* @param preferredVariant Adaptive variant used to resolve the 1px overlap.
|
|
56
|
+
* By default, uses {@link PREFERRED_VARIANT}.
|
|
57
|
+
* @returns `true` if the viewport width is within the adjusted [min, max] range.
|
|
58
|
+
*/
|
|
12
59
|
export function useBreakpointBetween(min, max, preferredVariant = PREFERRED_VARIANT) {
|
|
13
|
-
let _min = typeof min === 'number' ? min :
|
|
14
|
-
let _max = typeof max === 'number' ? max :
|
|
60
|
+
let _min = typeof min === 'number' ? min : HORIZONTAL_BREAKPOINTS[min];
|
|
61
|
+
let _max = typeof max === 'number' ? max : HORIZONTAL_BREAKPOINTS[max];
|
|
15
62
|
switch (preferredVariant) {
|
|
16
63
|
case 'MtF':
|
|
17
64
|
_max = _max - 1;
|
|
@@ -1,30 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { render } from
|
|
3
|
-
import { useBreakpoint, useBreakpointBetween } from
|
|
4
|
-
|
|
5
|
-
jest.mock('react-responsive', () => ({
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import { useBreakpoint, useBreakpointBetween } from "./useBreakpoint";
|
|
4
|
+
jest.mock("react-responsive", () => ({
|
|
6
5
|
useMediaQuery: jest.fn(),
|
|
7
6
|
}));
|
|
8
|
-
jest.mock(
|
|
7
|
+
jest.mock("../breakpoints.config", () => ({
|
|
9
8
|
__esModule: true,
|
|
10
|
-
|
|
9
|
+
PREFERRED_VARIANT: "MtF",
|
|
11
10
|
}));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
getBreakpoint: jest.fn(),
|
|
15
|
-
}));
|
|
16
|
-
jest.mock('../breakpoints.config', () => ({
|
|
17
|
-
__esModule: true,
|
|
18
|
-
PREFERRED_VARIANT: 'MtF', // adjust to your real preferred variant if needed
|
|
19
|
-
}));
|
|
20
|
-
import { useMediaQuery } from 'react-responsive';
|
|
21
|
-
import useVariant from './useVariant';
|
|
22
|
-
import { getBreakpoint } from '../functions/getBreakpoint';
|
|
23
|
-
import { PREFERRED_VARIANT } from '../breakpoints.config';
|
|
11
|
+
import { useMediaQuery } from "react-responsive";
|
|
12
|
+
import { PREFERRED_VARIANT } from "../breakpoints.config";
|
|
24
13
|
const mockedUseMediaQuery = useMediaQuery;
|
|
25
|
-
const mockedUseVariant = useVariant;
|
|
26
|
-
const mockedGetBreakpoint = getBreakpoint;
|
|
27
|
-
// Small test components to use hooks inside React
|
|
28
14
|
function BreakpointTestComponent(props) {
|
|
29
15
|
const value = useBreakpoint(props.b, props.variant);
|
|
30
16
|
return _jsx("div", { "data-testid": "value", children: String(value) });
|
|
@@ -33,121 +19,56 @@ function BreakpointBetweenTestComponent(props) {
|
|
|
33
19
|
const value = useBreakpointBetween(props.min, props.max, props.preferredVariant);
|
|
34
20
|
return _jsx("div", { "data-testid": "value", children: String(value) });
|
|
35
21
|
}
|
|
36
|
-
describe(
|
|
22
|
+
describe("useBreakpoint", () => {
|
|
37
23
|
beforeEach(() => {
|
|
38
24
|
jest.clearAllMocks();
|
|
39
|
-
mockedUseVariant.mockReturnValue('min');
|
|
40
25
|
});
|
|
41
|
-
it(
|
|
26
|
+
it("uses min-width for numeric breakpoint when variant === PREFERRED_VARIANT", () => {
|
|
42
27
|
mockedUseMediaQuery.mockReturnValue(true);
|
|
43
28
|
const { getByTestId } = render(_jsx(BreakpointTestComponent, { b: 768, variant: PREFERRED_VARIANT }));
|
|
44
|
-
expect(mockedUseVariant).toHaveBeenCalledWith(PREFERRED_VARIANT);
|
|
45
29
|
expect(mockedUseMediaQuery).toHaveBeenCalledWith({
|
|
46
|
-
query:
|
|
30
|
+
query: "(min-width: 768px)",
|
|
47
31
|
});
|
|
48
|
-
expect(getByTestId(
|
|
32
|
+
expect(getByTestId("value").textContent).toBe("true");
|
|
49
33
|
});
|
|
50
|
-
it(
|
|
51
|
-
mockedGetBreakpoint.mockReturnValue('1024');
|
|
52
|
-
mockedUseMediaQuery.mockReturnValue(false);
|
|
53
|
-
const { getByTestId } = render(_jsx(BreakpointTestComponent, { b: 'lg', variant: PREFERRED_VARIANT }));
|
|
54
|
-
expect(mockedGetBreakpoint).toHaveBeenCalledWith('lg');
|
|
55
|
-
expect(mockedUseMediaQuery).toHaveBeenCalledWith({
|
|
56
|
-
query: '(min-width: 1024px)',
|
|
57
|
-
});
|
|
58
|
-
expect(getByTestId('value').textContent).toBe('false');
|
|
59
|
-
});
|
|
60
|
-
it('should decrease breakpoint by 1px when variant !== PREFERRED_VARIANT (numeric)', () => {
|
|
61
|
-
mockedUseVariant.mockReturnValue('max');
|
|
34
|
+
it("decreases breakpoint by 1px when variant !== PREFERRED_VARIANT (numeric)", () => {
|
|
62
35
|
mockedUseMediaQuery.mockReturnValue(true);
|
|
63
|
-
const { getByTestId } = render(_jsx(BreakpointTestComponent, { b: 500, variant:
|
|
64
|
-
expect(mockedUseVariant).toHaveBeenCalledWith('DtF');
|
|
65
|
-
expect(mockedUseMediaQuery).toHaveBeenCalledWith({
|
|
66
|
-
query: '(max-width: 499px)',
|
|
67
|
-
});
|
|
68
|
-
expect(getByTestId('value').textContent).toBe('true');
|
|
69
|
-
});
|
|
70
|
-
it('should also decrease named breakpoint by 1px when variant !== PREFERRED_VARIANT', () => {
|
|
71
|
-
mockedGetBreakpoint.mockReturnValue('600');
|
|
72
|
-
mockedUseVariant.mockReturnValue('max');
|
|
73
|
-
mockedUseMediaQuery.mockReturnValue(false);
|
|
74
|
-
const { getByTestId } = render(_jsx(BreakpointTestComponent, { b: 'md', variant: 'DtF' }));
|
|
75
|
-
expect(mockedGetBreakpoint).toHaveBeenCalledWith('md');
|
|
36
|
+
const { getByTestId } = render(_jsx(BreakpointTestComponent, { b: 500, variant: "DtF" }));
|
|
76
37
|
expect(mockedUseMediaQuery).toHaveBeenCalledWith({
|
|
77
|
-
query:
|
|
38
|
+
query: "(max-width: 499px)",
|
|
78
39
|
});
|
|
79
|
-
expect(getByTestId(
|
|
40
|
+
expect(getByTestId("value").textContent).toBe("true");
|
|
80
41
|
});
|
|
81
42
|
});
|
|
82
|
-
describe(
|
|
43
|
+
describe("useBreakpointBetween", () => {
|
|
83
44
|
beforeEach(() => {
|
|
84
45
|
jest.clearAllMocks();
|
|
85
46
|
});
|
|
86
|
-
it(
|
|
47
|
+
it("uses min/max as-is but decreases max by 1px when preferredVariant === PREFERRED_VARIANT (numeric)", () => {
|
|
87
48
|
mockedUseMediaQuery.mockReturnValue(true);
|
|
88
49
|
const { getByTestId } = render(_jsx(BreakpointBetweenTestComponent, { min: 320, max: 768, preferredVariant: PREFERRED_VARIANT }));
|
|
89
50
|
expect(mockedUseMediaQuery).toHaveBeenCalledWith({
|
|
90
51
|
minWidth: 320,
|
|
91
|
-
maxWidth: 767, // 768 - 1
|
|
52
|
+
maxWidth: 767, // 768 - 1
|
|
92
53
|
});
|
|
93
|
-
expect(getByTestId(
|
|
54
|
+
expect(getByTestId("value").textContent).toBe("true");
|
|
94
55
|
});
|
|
95
|
-
it('
|
|
96
|
-
mockedGetBreakpoint
|
|
97
|
-
.mockReturnValueOnce('320') // for min
|
|
98
|
-
.mockReturnValueOnce('768'); // for max
|
|
99
|
-
mockedUseMediaQuery.mockReturnValue(false);
|
|
100
|
-
const { getByTestId } = render(_jsx(BreakpointBetweenTestComponent, { min: 'sm', max: 'md', preferredVariant: PREFERRED_VARIANT }));
|
|
101
|
-
expect(mockedGetBreakpoint).toHaveBeenNthCalledWith(1, 'sm');
|
|
102
|
-
expect(mockedGetBreakpoint).toHaveBeenNthCalledWith(2, 'md');
|
|
103
|
-
expect(mockedUseMediaQuery).toHaveBeenCalledWith({
|
|
104
|
-
minWidth: 320,
|
|
105
|
-
maxWidth: 767, // 768 - 1 because PREFERRED_VARIANT === 'MtF'
|
|
106
|
-
});
|
|
107
|
-
expect(getByTestId('value').textContent).toBe('false');
|
|
108
|
-
});
|
|
109
|
-
it('for preferredVariant === "MtF" should decrease max by 1px', () => {
|
|
56
|
+
it('when preferredVariant === "MtF" it only decreases max by 1px', () => {
|
|
110
57
|
mockedUseMediaQuery.mockReturnValue(true);
|
|
111
|
-
const { getByTestId } = render(_jsx(BreakpointBetweenTestComponent, { min: 320, max: 768, preferredVariant:
|
|
58
|
+
const { getByTestId } = render(_jsx(BreakpointBetweenTestComponent, { min: 320, max: 768, preferredVariant: "MtF" }));
|
|
112
59
|
expect(mockedUseMediaQuery).toHaveBeenCalledWith({
|
|
113
60
|
minWidth: 320,
|
|
114
61
|
maxWidth: 767,
|
|
115
62
|
});
|
|
116
|
-
expect(getByTestId(
|
|
63
|
+
expect(getByTestId("value").textContent).toBe("true");
|
|
117
64
|
});
|
|
118
|
-
it('
|
|
65
|
+
it('when preferredVariant === "DtF" it only decreases min by 1px', () => {
|
|
119
66
|
mockedUseMediaQuery.mockReturnValue(false);
|
|
120
|
-
const { getByTestId } = render(_jsx(BreakpointBetweenTestComponent, { min: 320, max: 768, preferredVariant:
|
|
67
|
+
const { getByTestId } = render(_jsx(BreakpointBetweenTestComponent, { min: 320, max: 768, preferredVariant: "DtF" }));
|
|
121
68
|
expect(mockedUseMediaQuery).toHaveBeenCalledWith({
|
|
122
69
|
minWidth: 319,
|
|
123
70
|
maxWidth: 768,
|
|
124
71
|
});
|
|
125
|
-
expect(getByTestId(
|
|
126
|
-
});
|
|
127
|
-
it('MtF + named values: should decrease max after getBreakpoint', () => {
|
|
128
|
-
mockedGetBreakpoint
|
|
129
|
-
.mockReturnValueOnce('400') // min
|
|
130
|
-
.mockReturnValueOnce('900'); // max
|
|
131
|
-
mockedUseMediaQuery.mockReturnValue(true);
|
|
132
|
-
const { getByTestId } = render(_jsx(BreakpointBetweenTestComponent, { min: 'sm', max: 'xl', preferredVariant: 'MtF' }));
|
|
133
|
-
expect(mockedGetBreakpoint).toHaveBeenNthCalledWith(1, 'sm');
|
|
134
|
-
expect(mockedGetBreakpoint).toHaveBeenNthCalledWith(2, 'xl');
|
|
135
|
-
expect(mockedUseMediaQuery).toHaveBeenCalledWith({
|
|
136
|
-
minWidth: 400,
|
|
137
|
-
maxWidth: 899,
|
|
138
|
-
});
|
|
139
|
-
expect(getByTestId('value').textContent).toBe('true');
|
|
140
|
-
});
|
|
141
|
-
it('DtF + named values: should decrease min after getBreakpoint', () => {
|
|
142
|
-
mockedGetBreakpoint
|
|
143
|
-
.mockReturnValueOnce('400') // min
|
|
144
|
-
.mockReturnValueOnce('900'); // max
|
|
145
|
-
mockedUseMediaQuery.mockReturnValue(false);
|
|
146
|
-
const { getByTestId } = render(_jsx(BreakpointBetweenTestComponent, { min: 'sm', max: 'xl', preferredVariant: 'DtF' }));
|
|
147
|
-
expect(mockedUseMediaQuery).toHaveBeenCalledWith({
|
|
148
|
-
minWidth: 399,
|
|
149
|
-
maxWidth: 900,
|
|
150
|
-
});
|
|
151
|
-
expect(getByTestId('value').textContent).toBe('false');
|
|
72
|
+
expect(getByTestId("value").textContent).toBe("false");
|
|
152
73
|
});
|
|
153
74
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useMediaQuery } from 'react-responsive';
|
|
2
|
-
import
|
|
3
|
-
import { getVBreakpoint } from "../functions/getBreakpoint.js";
|
|
2
|
+
import { VERTICAL_BREAKPOINTS, PREFERRED_VARIANT } from "../breakpoints.config";
|
|
4
3
|
export function useVBreakpoint(b, variant = 'MtF') {
|
|
5
|
-
|
|
6
|
-
const v =
|
|
7
|
-
|
|
4
|
+
let _bp = typeof b === 'number' ? b : VERTICAL_BREAKPOINTS[b];
|
|
5
|
+
const v = variant === 'MtF' ? 'min' : 'max';
|
|
6
|
+
if (variant !== PREFERRED_VARIANT)
|
|
7
|
+
_bp = _bp - 1;
|
|
8
|
+
return useMediaQuery({ query: `(${v}-height: ${_bp}px)` });
|
|
8
9
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { TBreakpoint, TVerticalBreakpoint } from './interfaces/TBreakpoint';
|
|
|
2
2
|
import { TBreakpoints, TVerticalBreakpoints } from './interfaces/TBreakpoints';
|
|
3
3
|
import { useBreakpointBetween, useBreakpoint } from './hooks/useBreakpoint.js';
|
|
4
4
|
import { useVBreakpoint } from './hooks/useVBreakpoint.js';
|
|
5
|
-
import { getBreakpoint, getVBreakpoint } from './functions/getBreakpoint.js';
|
|
6
5
|
export type { TBreakpoints, TBreakpoint, TVerticalBreakpoint, TVerticalBreakpoints, };
|
|
7
|
-
export { useBreakpointBetween, useBreakpoint, useVBreakpoint,
|
|
6
|
+
export { useBreakpointBetween, useBreakpoint, useVBreakpoint, };
|
|
8
7
|
export * from './components/horizontal.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useBreakpointBetween, useBreakpoint } from './hooks/useBreakpoint.js';
|
|
2
2
|
import { useVBreakpoint } from './hooks/useVBreakpoint.js';
|
|
3
|
-
|
|
4
|
-
export { useBreakpointBetween, useBreakpoint, useVBreakpoint, getBreakpoint, getVBreakpoint, };
|
|
3
|
+
export { useBreakpointBetween, useBreakpoint, useVBreakpoint, };
|
|
5
4
|
export * from './components/horizontal.js';
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export type
|
|
1
|
+
import { HORIZONTAL_BREAKPOINTS, VERTICAL_BREAKPOINTS } from "../breakpoints.config";
|
|
2
|
+
export type TBreakpoint = keyof typeof HORIZONTAL_BREAKPOINTS;
|
|
3
|
+
export type TVerticalBreakpoint = keyof typeof VERTICAL_BREAKPOINTS;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import o from"fs";import n from"path";import{fileURLToPath as e}from"url";import{HORIZONTAL_BREAKPOINTS as r,VERTICAL_BREAKPOINTS as s,PREFERRED_VARIANT as i}from"../default.config.js";const l=e(import.meta.url),t=n.dirname(l),R=n.resolve(t,"../../../../breakpoints.config.js");(async()=>{let e=r,l=s,a=i;if(o.existsSync(R))try{console.log(`User config file found at: ${R}`);const o=await import(R);console.log(`Loaded user config: ${JSON.stringify(o,null,2)}`),o.HORIZONTAL_BREAKPOINTS?(e=o.HORIZONTAL_BREAKPOINTS,console.log("Using user provided horizontal breakpoints.")):console.log("Using default horizontal breakpoints."),o.VERTICAL_BREAKPOINTS?(l=o.VERTICAL_BREAKPOINTS,console.log("Using user provided vertical breakpoints.")):console.log("Using default vertical breakpoints."),o.PREFERRED_VARIANT?(a=o.PREFERRED_VARIANT,console.log("Using user provided preferred variant.")):console.log("Using default preferred variant.")}catch(o){console.error("Error loading user config:",o)}else console.log(`User config file not found at: ${R}. Using default breakpoints.`);const c=`\n
|
|
1
|
+
import o from"fs";import n from"path";import{fileURLToPath as e}from"url";import{HORIZONTAL_BREAKPOINTS as r,VERTICAL_BREAKPOINTS as s,PREFERRED_VARIANT as i}from"../default.config.js";const l=e(import.meta.url),t=n.dirname(l),R=n.resolve(t,"../../../../breakpoints.config.js");(async()=>{let e=r,l=s,a=i;if(o.existsSync(R))try{console.log(`User config file found at: ${R}`);const o=await import(R);console.log(`Loaded user config: ${JSON.stringify(o,null,2)}`),o.HORIZONTAL_BREAKPOINTS?(e=o.HORIZONTAL_BREAKPOINTS,console.log("Using user provided horizontal breakpoints.")):console.log("Using default horizontal breakpoints."),o.VERTICAL_BREAKPOINTS?(l=o.VERTICAL_BREAKPOINTS,console.log("Using user provided vertical breakpoints.")):console.log("Using default vertical breakpoints."),o.PREFERRED_VARIANT?(a=o.PREFERRED_VARIANT,console.log("Using user provided preferred variant.")):console.log("Using default preferred variant.")}catch(o){console.error("Error loading user config:",o)}else console.log(`User config file not found at: ${R}. Using default breakpoints.`);const c=`\n// breakpoints.config.mjs\nconst HORIZONTAL_BREAKPOINTS = ${JSON.stringify(e,null,2)};\n\nconst VERTICAL_BREAKPOINTS = ${JSON.stringify(l,null,2)};\n\nconst PREFERRED_VARIANT = ${JSON.stringify(a)};\n\nexport { HORIZONTAL_BREAKPOINTS, VERTICAL_BREAKPOINTS, PREFERRED_VARIANT };\n`;try{o.writeFileSync(n.resolve(t,"../breakpoints.config.js"),c),console.log("Config file has been generated successfully.")}catch(o){console.error("Error writing merged config file:",o)}})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import o from"fs";import e from"path";import{fileURLToPath as r}from"url";import{HORIZONTAL_BREAKPOINTS as s,VERTICAL_BREAKPOINTS as n}from"../breakpoints.config.js";const t=r(import.meta.url),i=e.dirname(t),m=(o,e)=>`$${e}-breakpoints: (\n${Object.entries(o).map((([o,e])=>` ${o}: ${e}`)).join(",\n")}\n);`,a=`\n${m(s,"horizontal")}\n${m(n,"vertical")}\n`;o.writeFileSync(e.resolve(i,"../scss/_custom-breakpoints.scss"),a),console.log("SCSS file with breakpoints maps has been generated successfully.");
|
|
1
|
+
import o from"fs";import e from"path";import{fileURLToPath as r}from"url";import{HORIZONTAL_BREAKPOINTS as s,VERTICAL_BREAKPOINTS as n}from"../breakpoints.config.js";const t=r(import.meta.url),i=e.dirname(t),m=(o,e)=>`$${e}-breakpoints: (\n${Object.entries(o).map((([o,e])=>` ${o}: ${e}px`)).join(",\n")}\n);`,a=`\n${m(s,"horizontal")}\n${m(n,"vertical")}\n`;o.writeFileSync(e.resolve(i,"../scss/_custom-breakpoints.scss"),a),console.log("SCSS file with breakpoints maps has been generated successfully.");
|
package/package.json
CHANGED
package/reinit.sh
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# Path to dist directory
|
|
4
4
|
DIST_DIR="./dist"
|
|
5
5
|
SCRIPT_DIR="$DIST_DIR/scripts"
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# Diagnostic information
|
|
8
8
|
echo "DIST_DIR: $DIST_DIR"
|
|
9
9
|
echo "SCRIPT_DIR: $SCRIPT_DIR"
|
|
10
10
|
|
|
11
|
-
#
|
|
11
|
+
# Check if dist and scripts directories exist
|
|
12
12
|
echo "Listing contents of current directory:"
|
|
13
13
|
ls -la
|
|
14
14
|
echo "Listing contents of DIST_DIR:"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
exit 1
|
|
20
20
|
fi
|
|
21
21
|
|
|
22
|
-
#
|
|
22
|
+
# Run createConfig.mjs from dist/scripts
|
|
23
23
|
echo "Running createConfig.mjs from package..."
|
|
24
24
|
node "$SCRIPT_DIR/createConfig.mjs"
|
|
25
25
|
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
exit 1
|
|
29
29
|
fi
|
|
30
30
|
|
|
31
|
-
#
|
|
31
|
+
# Run generateCustomBreakpointsSCSS.mjs from dist/scripts
|
|
32
32
|
echo "Running generateCustomBreakpointsSCSS.mjs from package..."
|
|
33
33
|
node "$SCRIPT_DIR/generateCustomBreakpointsSCSS.mjs"
|
|
34
34
|
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
exit 1
|
|
38
38
|
fi
|
|
39
39
|
|
|
40
|
-
#
|
|
40
|
+
# Run generateSCSS.mjs from dist/scripts
|
|
41
41
|
echo "Running generateSCSS.mjs from package..."
|
|
42
42
|
node "$SCRIPT_DIR/generateSCSS.mjs"
|
|
43
43
|
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
exit 1
|
|
47
47
|
fi
|
|
48
48
|
|
|
49
|
-
#
|
|
50
|
-
echo "Running generateTBreakpoint.mjs from package..."
|
|
51
|
-
node "$SCRIPT_DIR/generateTBreakpoint.mjs"
|
|
49
|
+
# Run generateTBreakpoint.mjs from dist/scripts
|
|
50
|
+
# echo "Running generateTBreakpoint.mjs from package..."
|
|
51
|
+
# node "$SCRIPT_DIR/generateTBreakpoint.mjs"
|
|
52
52
|
|
|
53
53
|
if [ $? -ne 0 ]; then
|
|
54
54
|
echo "Error occurred while running generateTBreakpoint.mjs"
|
package/dist/hooks/useVariant.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"fs";import r from"path";import{fileURLToPath as t}from"url";import{HORIZONTAL_BREAKPOINTS as o,VERTICAL_BREAKPOINTS as n}from"../breakpoints.config.js";const i=t(import.meta.url),p=r.dirname(i),s=(e,r)=>`export type ${r} =\n${Object.keys(e).map((e=>` | '${e}'`)).join("\n")}\n`,a=`\n${s(o,"TBreakpoint")}\n\n${s(n,"TVerticalBreakpoint")}\n`;e.writeFileSync(r.resolve(p,"../interfaces/TBreakpoint.d.ts"),a.trim()),console.log("TBreakpoint.ts file has been generated successfully.");
|