react-responsive-tools 1.1.3 → 1.1.4
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 +153 -388
- package/package.json +1 -1
- /package/{reset-css.scss → reset.scss} +0 -0
package/README.MD
CHANGED
@@ -1,182 +1,137 @@
|
|
1
|
-
# react-
|
1
|
+
# react-responsive-tools
|
2
2
|
|
3
|
-
This project provides tools and configurations to simplify writing
|
3
|
+
This project provides tools and configurations to simplify writing responsive code for both vertical and horizontal layouts.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
The project includes the `scss` directory with the following files:
|
8
|
-
- `_data.scss`: Contains breakpoints.
|
9
|
-
- `_horizontal.scss` and `_vertical.scss`: Provide mixins for horizontal and vertical layouts, respectively.
|
10
|
-
- `_screen.scss`: An intermediate file for JS export.
|
11
|
-
- `_export.module.scss`: A file meant for explicit JS export.
|
12
|
-
|
13
|
-
The `hooks` directory includes:
|
14
|
-
- `useBreakpoint.ts`: Implements the `useBreakpoint` hook for identifying the current breakpoint.
|
15
|
-
- `useBreakpoints.ts`: Implements the `useBreakpoints` hook for retrieving the list of currently active breakpoints.
|
16
|
-
- `useVBreakpoint.ts`: Implements the `useVBreakpoint` hook for identifying the current vertical breakpoint.
|
17
|
-
- `useVBreakpoints.ts`: Implements the `useVBreakpoints` hook for retrieving the list of currently active vertical breakpoints.
|
18
|
-
|
19
|
-
The `components` directory includes:
|
20
|
-
- `ForMF.ts`: A utility component that takes breakpoint size and children as props. It uses the `useBreakpointMF` hook to determine if the display size matches the given breakpoint. If so, it renders the children; otherwise, it renders `null`.
|
21
|
-
- `ForDF.ts`: Similar to `ForMF`, but uses the `useBreakpointDF` hook.
|
22
|
-
|
23
|
-
## Breakpoints
|
24
|
-
|
25
|
-
We use a set of fixed variables for different screen sizes: `xs`, `sm`, `md`, `lg`, `xl`, `xxl`, and `xxxl`.
|
26
|
-
|
27
|
-
## Mixins Application
|
28
|
-
|
29
|
-
Mixins are bundled with the `include` decorator, providing descriptive statements for breakpoints based on them.
|
30
|
-
|
31
|
-
## Hooks
|
32
|
-
|
33
|
-
The project incorporates the following hooks based on `react-responsive` for use in React.js:# react-adaptable-scss: Adaptive SCSS Tools
|
34
|
-
|
35
|
-
This project provides tools and configurations to simplify writing adaptive code for both vertical and horizontal layouts.
|
36
|
-
|
37
|
-
## Project Structure
|
38
|
-
|
39
|
-
The project includes the `scss` directory with the following files:
|
40
|
-
- `_data.scss`: Contains breakpoints.
|
41
|
-
- `_horizontal.scss` and `_vertical.scss`: Provide mixins for horizontal and vertical layouts, respectively.
|
42
|
-
- `_screen.scss`: An intermediate file for JS export.
|
43
|
-
- `_export.module.scss`: A file meant for explicit JS export.
|
5
|
+
The package is based on the npm package [react-responsive](https://www.npmjs.com/package/react-responsive) for use in React.js. It assumes the use of scss for compilation.
|
44
6
|
|
45
|
-
|
46
|
-
- `useBreakpoint.ts`: Implements the `useBreakpoint` hook for identifying the current breakpoint.
|
47
|
-
- `useBreakpoints.ts`: Implements the `useBreakpoints` hook for retrieving the list of currently active breakpoints.
|
48
|
-
- `useVBreakpoint.ts`: Implements the `useVBreakpoint` hook for identifying the current vertical breakpoint.
|
49
|
-
- `useVBreakpoints.ts`: Implements the `useVBreakpoints` hook for retrieving the list of currently active vertical breakpoints.
|
7
|
+
In the future, the dependency on scss will be removed.
|
50
8
|
|
51
|
-
|
52
|
-
- `ForMF.ts`: A utility component that takes breakpoint size and children as props. It uses the `useBreakpointMF` hook to determine if the display size matches the given breakpoint. If so, it renders the children; otherwise, it renders `null`.
|
53
|
-
- `ForDF.ts`: Similar to `ForMF`, but uses the `useBreakpointDF` hook.
|
9
|
+
## Installation
|
54
10
|
|
55
|
-
|
11
|
+
To install the project, run the following command:
|
56
12
|
|
57
|
-
|
13
|
+
```sh
|
14
|
+
# Using Yarn
|
15
|
+
yarn add react-responsive-tools
|
58
16
|
|
59
|
-
|
60
|
-
|
61
|
-
```ecmascript 6
|
62
|
-
const horizontalBreakpoints = {
|
63
|
-
xs: '320px',
|
64
|
-
sm: '576px',
|
65
|
-
md: '768px',
|
66
|
-
lg: '992px',
|
67
|
-
lt: '1024px',
|
68
|
-
ltm: '1200px',
|
69
|
-
ltl: '1440px',
|
70
|
-
xl: '1920px',
|
71
|
-
xxl: '2560px',
|
72
|
-
qxl: '3840px',
|
73
|
-
};
|
17
|
+
# Using npm
|
18
|
+
npm install react-responsive-tools
|
74
19
|
```
|
75
20
|
|
76
|
-
|
21
|
+
To initialize the tools, you need to import the file from the library:
|
77
22
|
|
78
|
-
```
|
79
|
-
|
80
|
-
xs: '600px',
|
81
|
-
sm: '800px',
|
82
|
-
md: '1000px',
|
83
|
-
lg: '1200px',
|
84
|
-
xl: '1600px',
|
85
|
-
xxl: '1601px',
|
86
|
-
};
|
23
|
+
```scss
|
24
|
+
@import "react-responsive-tools/default"; // init breakpoints
|
87
25
|
```
|
88
26
|
|
89
|
-
|
27
|
+
This line imports the necessary CSS variables (breakpoints) required for the tools to work.
|
90
28
|
|
91
|
-
|
92
|
-
|
93
|
-
## Hooks
|
29
|
+
The package also includes a file to reset browser styles:
|
94
30
|
|
95
|
-
|
96
|
-
-
|
97
|
-
|
98
|
-
|
99
|
-
## Components
|
31
|
+
```scss
|
32
|
+
@import "react-responsive-tools/reset"; // reset browsers styles
|
33
|
+
```
|
100
34
|
|
101
|
-
|
35
|
+
### Default Horizontal and Vertical Breakpoints:
|
36
|
+
|
37
|
+
--vbp - vertical breakpoints
|
38
|
+
|
39
|
+
--bp - horizontal breakpoints
|
40
|
+
|
41
|
+
```scss
|
42
|
+
:root {
|
43
|
+
--bp-xs: 320px;
|
44
|
+
--bp-sm: 576px;
|
45
|
+
--bp-md: 768px;
|
46
|
+
--bp-lg: 992px;
|
47
|
+
--bp-lt: 1024px;
|
48
|
+
--bp-ltm: 1120px;
|
49
|
+
--bp-ltl: 1440px;
|
50
|
+
--bp-xl: 1920px;
|
51
|
+
--bp-xxl: 2560px;
|
52
|
+
--bp-qxl: 3840px;
|
53
|
+
|
54
|
+
--vbp-xs: 600px;
|
55
|
+
--vbp-sm: 800px;
|
56
|
+
--vbp-md: 1000px;
|
57
|
+
--vbp-lg: 1200px;
|
58
|
+
--vbp-xl: 1600px;
|
59
|
+
--vbp-xxl: 1920px;
|
60
|
+
}
|
61
|
+
```
|
102
62
|
|
103
|
-
|
63
|
+
Breakpoints override example:
|
104
64
|
|
105
|
-
|
106
|
-
-
|
107
|
-
- Configuring breakpoint names.
|
108
|
-
- Separate breakpoint configurations for vertical layout.
|
109
|
-
- Integration with the external library `react-responsive# react-adaptable-scss: Adaptive SCSS Tools
|
65
|
+
```scss
|
66
|
+
@import "react-responsive-tools/default"; // init breakpoints
|
110
67
|
|
111
|
-
|
68
|
+
:root {
|
69
|
+
//--bp-xxl: 2560px;
|
70
|
+
--bp-xxl: 2222px; // new point
|
71
|
+
}
|
72
|
+
```
|
112
73
|
|
113
|
-
##
|
74
|
+
## Using Mixins
|
114
75
|
|
115
|
-
|
116
|
-
- `_data.scss`: Contains breakpoints.
|
117
|
-
- `_horizontal.scss` and `_vertical.scss`: Provide mixins for horizontal and vertical layouts, respectively.
|
118
|
-
- `_screen.scss`: An intermediate file for JS export.
|
119
|
-
- `_export.module.scss`: A file meant for explicit JS export.
|
76
|
+
Mixins are packaged with an `include` decorator that provides descriptive instructions for breakpoints.
|
120
77
|
|
121
|
-
|
122
|
-
- `useBreakpoint.ts`: Implements the `useBreakpoint` hook for identifying the current breakpoint.
|
123
|
-
- `useBreakpoints.ts`: Implements the `useBreakpoints` hook for retrieving the list of currently active breakpoints.
|
124
|
-
- `useVBreakpoint.ts`: Implements the `useVBreakpoint` hook for identifying the current vertical breakpoint.
|
125
|
-
- `useVBreakpoints.ts`: Implements the `useVBreakpoints` hook for retrieving the list of currently active vertical breakpoints.
|
78
|
+
Example:
|
126
79
|
|
127
|
-
|
128
|
-
-
|
129
|
-
- `ForDF.ts`: Similar to `ForMF`, but uses the `useBreakpointDF` hook.
|
80
|
+
```scss
|
81
|
+
@import "react-responsive-tools";
|
130
82
|
|
131
|
-
|
83
|
+
div.supercool {
|
84
|
+
@include m-xs { // for mobile to first xs breakpoint
|
85
|
+
color: red;
|
86
|
+
font-size: 10px;
|
87
|
+
@include vm-sm {
|
88
|
+
font-size: 11px;
|
89
|
+
}
|
90
|
+
@include vm-md {
|
91
|
+
font-size: 14px;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
132
95
|
|
133
|
-
|
96
|
+
span.someclass {
|
97
|
+
@include d-xxl { // for desktop to first xxl breakpoint
|
98
|
+
color: white;
|
99
|
+
// vertical points in horizontal
|
100
|
+
@include vd-xs {
|
101
|
+
font-size: 10px;
|
102
|
+
}
|
103
|
+
@include vd-md {
|
104
|
+
font-size: 12px;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
134
108
|
|
135
|
-
|
109
|
+
aside.sidebar {
|
110
|
+
// custom breakpoint
|
111
|
+
@include mob-first(xs) {
|
112
|
+
...
|
113
|
+
}
|
114
|
+
// desktop to first
|
115
|
+
@include desk-first(md) {
|
116
|
+
...
|
117
|
+
}
|
136
118
|
|
137
|
-
|
138
|
-
|
139
|
-
xs: '320px',
|
140
|
-
sm: '576px',
|
141
|
-
md: '768px',
|
142
|
-
lg: '992px',
|
143
|
-
lt: '1024px',
|
144
|
-
ltm: '1200px',
|
145
|
-
ltl: '1440px',
|
146
|
-
xl: '1920px',
|
147
|
-
xxl: '2560px',
|
148
|
-
qxl: '3840px',
|
149
|
-
};
|
150
|
-
```
|
119
|
+
// vertical custom bp
|
120
|
+
@include v-desk-first(md) {
|
151
121
|
|
152
|
-
|
122
|
+
}
|
123
|
+
// mob first
|
124
|
+
@include v-mob-first(md) {
|
153
125
|
|
154
|
-
|
155
|
-
|
156
|
-
xs: '600px',
|
157
|
-
sm: '800px',
|
158
|
-
md: '1000px',
|
159
|
-
lg: '1200px',
|
160
|
-
xl: '1600px',
|
161
|
-
xxl: '1601px',
|
162
|
-
};
|
126
|
+
}
|
127
|
+
}
|
163
128
|
```
|
164
129
|
|
165
|
-
## Mixins Application
|
166
|
-
|
167
|
-
Mixins are bundled with the `include` decorator, providing descriptive statements for breakpoints based on them.
|
168
|
-
|
169
130
|
## Hooks
|
170
131
|
|
171
|
-
The project incorporates the following hooks based on `react-responsive` for use in React.js:
|
172
|
-
- `useBreakpoints`: Retrieve current screen breakpoints.
|
173
|
-
- `useBreakpoint`: Retrieve the current breakpoint.
|
174
|
-
- `useBreakpointMF`: Retrieve the current breakpoint for "MtF" variant.
|
175
|
-
- `useBreakpointDF`: Retrieve the current breakpoint for "MtF" variant.
|
176
|
-
|
177
132
|
### Hook Implementations
|
178
133
|
|
179
|
-
#### useBreakpoint
|
134
|
+
#### Hook `useBreakpoint`:
|
180
135
|
|
181
136
|
```typescript
|
182
137
|
import { useMediaQuery } from 'react-responsive';
|
@@ -186,83 +141,67 @@ import { TAdaptiveVariant } from '../../interfaces/TAdaptiveVariant';
|
|
186
141
|
import useVariant from '../useVariant';
|
187
142
|
|
188
143
|
export default function useBreakpoint(b: TBreakpoint, variant: TAdaptiveVariant = 'MtF') {
|
189
|
-
|
190
|
-
|
191
|
-
|
144
|
+
const p = breakpoints[b];
|
145
|
+
const v = useVariant(variant);
|
146
|
+
return useMediaQuery({ query: `(${v}-width: ${p}px)` });
|
192
147
|
}
|
193
148
|
|
194
149
|
export function useBreakpointMF(b: TBreakpoint) {
|
195
|
-
|
150
|
+
return useBreakpoint(b, 'MtF');
|
196
151
|
}
|
197
152
|
|
198
153
|
export function useBreakpointDF(b: TBreakpoint) {
|
199
|
-
|
154
|
+
return useBreakpoint(b, 'DtF');
|
200
155
|
}
|
201
156
|
```
|
202
157
|
|
203
|
-
### Usage Examples
|
158
|
+
### Usage Examples
|
204
159
|
|
205
|
-
#### useBreakpoint
|
160
|
+
#### Hook `useBreakpoint`:
|
206
161
|
|
207
162
|
```typescript
|
208
163
|
import useBreakpoint from './hooks/useBreakpoint';
|
209
164
|
|
210
165
|
const MyComponent = () => {
|
211
|
-
|
212
|
-
|
213
|
-
return (
|
214
|
-
<div>
|
215
|
-
{isMedium && <p>The current breakpoint is Medium (md)</p>}
|
216
|
-
</div>
|
217
|
-
);
|
218
|
-
};
|
219
|
-
```
|
220
|
-
|
221
|
-
#### useBreakpoints Hook:
|
222
|
-
|
223
|
-
```typescript
|
224
|
-
import { useBreakpoints } from './hooks/useBreakpoints';
|
225
|
-
|
226
|
-
const MyComponent = () => {
|
227
|
-
const breakpoints = useBreakpoints();
|
166
|
+
const isMedium = useBreakpoint('md');
|
228
167
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
168
|
+
return (
|
169
|
+
<div>
|
170
|
+
{isMedium && <p>Current breakpoint: Medium (md)</p>}
|
171
|
+
</div>
|
172
|
+
);
|
234
173
|
};
|
235
174
|
```
|
236
175
|
|
237
|
-
#### useBreakpointMF
|
176
|
+
#### Hook `useBreakpointMF`:
|
238
177
|
|
239
178
|
```typescript
|
240
179
|
import { useBreakpointMF } from './hooks/useBreakpoint';
|
241
180
|
|
242
181
|
const MyComponent = () => {
|
243
|
-
|
182
|
+
const isMedium = useBreakpointMF('md');
|
244
183
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
184
|
+
return (
|
185
|
+
<div>
|
186
|
+
{isMedium && <p>Current breakpoint: Medium (md) for Mobile First</p>}
|
187
|
+
</div>
|
188
|
+
);
|
250
189
|
};
|
251
190
|
```
|
252
191
|
|
253
|
-
#### useBreakpointDF
|
192
|
+
#### Hook `useBreakpointDF`:
|
254
193
|
|
255
194
|
```typescript
|
256
195
|
import { useBreakpointDF } from './hooks/useBreakpoint';
|
257
196
|
|
258
197
|
const MyComponent = () => {
|
259
|
-
|
198
|
+
const isLarge = useBreakpointDF('lg');
|
260
199
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
200
|
+
return (
|
201
|
+
<div>
|
202
|
+
{isLarge && <p>Current breakpoint: Large (lg) for Desktop First</p>}
|
203
|
+
</div>
|
204
|
+
);
|
266
205
|
};
|
267
206
|
```
|
268
207
|
|
@@ -270,232 +209,58 @@ const MyComponent = () => {
|
|
270
209
|
|
271
210
|
The project includes utility components to display content only at certain breakpoints.
|
272
211
|
|
273
|
-
### Usage Examples
|
212
|
+
### Usage Examples
|
274
213
|
|
275
|
-
#### ForMF
|
214
|
+
#### Component `ForMF`:
|
276
215
|
|
277
216
|
```typescript
|
278
217
|
import { ForMF } from './components/ForMF';
|
279
218
|
|
280
219
|
const MyComponent = () => (
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
);
|
285
|
-
```
|
286
|
-
# react-adaptable-scss: Adaptive SCSS Tools
|
287
|
-
|
288
|
-
This project provides tools and configurations to simplify writing adaptive code for both vertical and horizontal layouts.
|
289
|
-
|
290
|
-
## Project Structure
|
291
|
-
|
292
|
-
The project includes the `scss` directory with the following files:
|
293
|
-
- `_data.scss`: Contains breakpoints.
|
294
|
-
- `_horizontal.scss` and `_vertical.scss`: Provide mixins for horizontal and vertical layouts, respectively.
|
295
|
-
- `_screen.scss`: An intermediate file for JS export.
|
296
|
-
- `_export.module.scss`: A file meant for explicit JS export.
|
297
|
-
|
298
|
-
The `hooks` directory includes:
|
299
|
-
- `useBreakpoint.ts`: Implements the `useBreakpoint` hook for identifying the current breakpoint.
|
300
|
-
- `useBreakpoints.ts`: Implements the `useBreakpoints` hook for retrieving the list of currently active breakpoints.
|
301
|
-
- `useVBreakpoint.ts`: Implements the `useVBreakpoint` hook for identifying the current vertical breakpoint.
|
302
|
-
- `useVBreakpoints.ts`: Implements the `useVBreakpoints` hook for retrieving the list of currently active vertical breakpoints.
|
303
|
-
|
304
|
-
The `components` directory includes:
|
305
|
-
- `ForMF.ts`: A utility component that takes breakpoint size and children as props. It uses the `useBreakpointMF` hook to determine if the display size matches the given breakpoint. If so, it renders the children; otherwise, it renders `null`.
|
306
|
-
- `ForDF.ts`: Similar to `ForMF`, but uses the `useBreakpointDF` hook.
|
307
|
-
|
308
|
-
## Breakpoints
|
309
|
-
|
310
|
-
We use a set of fixed variables for different screen sizes.
|
311
|
-
|
312
|
-
### Horizontal Breakpoints (default):
|
313
|
-
|
314
|
-
```typescript
|
315
|
-
const horizontalBreakpoints = {
|
316
|
-
xs: '320px',
|
317
|
-
sm: '576px',
|
318
|
-
md: '768px',
|
319
|
-
lg: '992px',
|
320
|
-
lt: '1024px',
|
321
|
-
ltm: '1200px',
|
322
|
-
ltl: '1440px',
|
323
|
-
xl: '1920px',
|
324
|
-
xxl: '2560px',
|
325
|
-
qxl: '3840px',
|
326
|
-
};
|
327
|
-
```
|
328
|
-
|
329
|
-
### Vertical Breakpoints (default):
|
330
|
-
|
331
|
-
```typescript
|
332
|
-
const verticalBreakpoints = {
|
333
|
-
xs: '600px',
|
334
|
-
sm: '800px',
|
335
|
-
md: '1000px',
|
336
|
-
lg: '1200px',
|
337
|
-
xl: '1600px',
|
338
|
-
xxl: '1601px',
|
339
|
-
};
|
340
|
-
```
|
341
|
-
|
342
|
-
## Mixins Application
|
343
|
-
|
344
|
-
Mixins are bundled with the `include` decorator, providing descriptive statements for breakpoints based on them.
|
345
|
-
|
346
|
-
## Hooks
|
347
|
-
|
348
|
-
The project incorporates the following hooks based on `react-responsive` for use in React.js:
|
349
|
-
- `useBreakpoints`: Retrieve current screen breakpoints.
|
350
|
-
- `useBreakpoint`: Retrieve the current breakpoint.
|
351
|
-
- `useBreakpointMF`: Retrieve the current breakpoint for "Mobile to First" variant.
|
352
|
-
- `useBreakpointDF`: Retrieve the current breakpoint for "Desktop to First" variant.
|
353
|
-
|
354
|
-
### Hook Implementations
|
355
|
-
|
356
|
-
### Usage Examples:
|
357
|
-
|
358
|
-
#### useBreakpoint Hook with Predefined Breakpoints:
|
359
|
-
|
360
|
-
```typescript
|
361
|
-
import useBreakpoint from './hooks/useBreakpoint';
|
362
|
-
|
363
|
-
const MyComponent = () => {
|
364
|
-
const isMedium = useBreakpoint('md');
|
365
|
-
|
366
|
-
return (
|
367
|
-
<div>
|
368
|
-
{isMedium && <p>The current breakpoint is Medium (md)</p>}
|
369
|
-
</div>
|
370
|
-
);
|
371
|
-
};
|
372
|
-
```
|
373
|
-
|
374
|
-
#### useBreakpoint Hook with Custom Size:
|
375
|
-
|
376
|
-
```typescript
|
377
|
-
import useBreakpoint from './hooks/useBreakpoint';
|
378
|
-
|
379
|
-
const MyComponent = () => {
|
380
|
-
const isCustomSize = useBreakpoint(850);
|
381
|
-
|
382
|
-
return (
|
383
|
-
<div>
|
384
|
-
{isCustomSize && <p>The current breakpoint is Custom (850px)</p>}
|
385
|
-
</div>
|
386
|
-
);
|
387
|
-
};
|
388
|
-
```
|
389
|
-
|
390
|
-
#### useBreakpoints Hook:
|
391
|
-
|
392
|
-
```typescript
|
393
|
-
import { useBreakpoints } from './hooks/useBreakpoints';
|
394
|
-
|
395
|
-
const MyComponent = () => {
|
396
|
-
const breakpoints = useBreakpoints();
|
397
|
-
|
398
|
-
return (
|
399
|
-
<div>
|
400
|
-
{breakpoints.includes('lg') && <p>The Large (lg) breakpoint is active</p>}
|
401
|
-
</div>
|
402
|
-
);
|
403
|
-
};
|
404
|
-
```
|
405
|
-
|
406
|
-
#### useBreakpointMF Hook:
|
407
|
-
|
408
|
-
```typescript
|
409
|
-
import { useBreakpointMF } from './hooks/useBreakpoint';
|
410
|
-
|
411
|
-
const MyComponent = () => {
|
412
|
-
const isMedium = useBreakpointMF('md');
|
413
|
-
|
414
|
-
return (
|
415
|
-
<div>
|
416
|
-
{isMedium && <p>The current breakpoint is Medium (md) for Mobile First</p>}
|
417
|
-
</div>
|
418
|
-
);
|
419
|
-
};
|
420
|
-
```
|
421
|
-
|
422
|
-
#### useBreakpointDF Hook:
|
423
|
-
|
424
|
-
```typescript
|
425
|
-
import { useBreakpointDF } from './hooks/useBreakpoint';
|
426
|
-
|
427
|
-
const MyComponent = () => {
|
428
|
-
const isLarge = useBreakpointDF('lg');
|
429
|
-
|
430
|
-
return (
|
431
|
-
<div>
|
432
|
-
{isLarge && <p>The current breakpoint is Large (lg) for Desktop First</p>}
|
433
|
-
</div>
|
434
|
-
);
|
435
|
-
};
|
436
|
-
```
|
437
|
-
|
438
|
-
## Components
|
439
|
-
|
440
|
-
The project includes utility components to display content only at certain breakpoints.
|
441
|
-
|
442
|
-
### Usage Examples:
|
443
|
-
|
444
|
-
#### ForMF Component:
|
445
|
-
|
446
|
-
```typescript
|
447
|
-
import { ForMF } from './components/ForMF';
|
448
|
-
|
449
|
-
const MyComponent = () => (
|
450
|
-
<ForMF bp='md'>
|
451
|
-
<p>This content is only visible at the Medium (md) breakpoint</p>
|
452
|
-
</ForMF>
|
220
|
+
<ForMF bp='md'>
|
221
|
+
<p>This content is visible only at the Medium (md) breakpoint</p>
|
222
|
+
</ForMF>
|
453
223
|
);
|
454
224
|
|
455
225
|
const CustomSizeComponent = () => (
|
456
|
-
|
457
|
-
|
458
|
-
|
226
|
+
<ForMF bp={850}>
|
227
|
+
<p>This content is visible only at the Custom (850px) breakpoint</p>
|
228
|
+
</ForMF>
|
459
229
|
);
|
460
230
|
```
|
461
231
|
|
462
|
-
#### ForDF
|
232
|
+
#### Component `ForDF`:
|
463
233
|
|
464
234
|
```typescript
|
465
235
|
import { ForDF } from './components/ForDF';
|
466
236
|
|
467
237
|
const MyComponent = () => (
|
468
|
-
|
469
|
-
|
470
|
-
|
238
|
+
<ForDF bp='lg'>
|
239
|
+
<p>This content is visible only at the Large (lg) breakpoint</p>
|
240
|
+
</ForDF>
|
471
241
|
);
|
472
242
|
|
473
243
|
const CustomSizeComponent = () => (
|
474
|
-
|
475
|
-
|
476
|
-
|
244
|
+
<ForDF bp={1200}>
|
245
|
+
<p>This content is visible only at the Custom (1200px) breakpoint</p>
|
246
|
+
</ForDF>
|
477
247
|
);
|
478
248
|
```
|
479
249
|
|
480
|
-
##
|
250
|
+
## Project Structure
|
481
251
|
|
482
|
-
|
483
|
-
- Redefining SCSS variables.
|
484
|
-
- Configuring breakpoint names.
|
485
|
-
- Separate breakpoint configurations for vertical layout.
|
486
|
-
- Integration with the external library `react-responsive`.
|
487
|
-
- Addition of WebStorm live templates for quick layout designs.
|
488
|
-
#### ForDF Component:
|
252
|
+
The project includes the `scss` directory with the following files:
|
489
253
|
|
490
|
-
|
491
|
-
|
254
|
+
- `_data.scss`: Contains breakpoints.
|
255
|
+
- `_horizontal.scss` and `_vertical.scss`: Provide mixins for horizontal and vertical layouts, respectively.
|
256
|
+
- `_screen.scss`: Intermediate file for export to JS.
|
492
257
|
|
493
|
-
|
494
|
-
<ForDF bp='lg'>
|
495
|
-
<p>This content is only visible at the Large (lg) breakpoint</p>
|
496
|
-
</ForDF>
|
497
|
-
);
|
498
|
-
```
|
258
|
+
The `hooks` directory includes:
|
499
259
|
|
260
|
+
- `useBreakpoint.ts`: Implements the `useBreakpoint` hook to determine the current breakpoint.
|
261
|
+
- `useVBreakpoint.ts`: Implements the `useVBreakpoint` hook to determine the current vertical breakpoint.
|
500
262
|
|
263
|
+
The `components` directory includes:
|
501
264
|
|
265
|
+
- `ForMF.ts`: A utility component that takes a breakpoint size and children as props. It uses the `useBreakpointMF` hook to determine if the screen size matches the given breakpoint. If it does, it renders the children; otherwise, it renders `null`.
|
266
|
+
- `ForDF.ts`: Similar to `ForMF`, but uses the `useBreakpointDF` hook.
|
package/package.json
CHANGED
File without changes
|