react-responsive-tools 1.0.2 → 1.1.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 CHANGED
@@ -496,3 +496,6 @@ const MyComponent = () => (
496
496
  </ForDF>
497
497
  );
498
498
  ```
499
+
500
+
501
+
package/package.json CHANGED
@@ -1,24 +1,23 @@
1
1
  {
2
2
  "name": "react-responsive-tools",
3
- "version": "1.0.2",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "scripts": {
9
9
  "dev": "webpack --mode development --watch",
10
- "build": "npm run generate-breakpoints && tsc && webpack --mode production",
11
10
  "tsc": "tsc",
12
11
  "test": "jest",
13
12
  "lint": "eslint \"{**/*,*}.{js,ts,jsx,tsx}\"",
14
13
  "lint-fix": "eslint \"{**/*,*}.{js,ts,jsx,tsx}\" --fix",
15
- "generate-breakpoints": "node loadBreakpoints.js",
16
- "postinstall": "npm run generate-breakpoints"
14
+
15
+ "build": "tsc && webpack --mode production"
16
+
17
17
  },
18
18
  "files": [
19
19
  "src",
20
20
  "*.ts",
21
- "loadBreakpoints.js",
22
21
  "*.scss",
23
22
  "index.js",
24
23
  "index.d.ts"
@@ -32,7 +31,6 @@
32
31
  "author": "westprophet",
33
32
  "license": "ISC",
34
33
  "dependencies": {
35
- "classnames": "^2.5.1",
36
34
  "react-responsive": "^10.0.0"
37
35
  },
38
36
  "devDependencies": {
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import { TBreakpoint } from '../interfaces/TBreakpoint';
6
- import { useBreakpointDF, useBreakpointMF } from '../hooks/horizontal/useBreakpoint';
6
+ import { useBreakpointDF, useBreakpointMF } from '../hooks/useBreakpoint';
7
7
 
8
8
  interface Props {
9
9
  children: any;
@@ -0,0 +1 @@
1
+ @import "scss/breakpoints";
@@ -0,0 +1,16 @@
1
+ import {TBreakpoint, TVerticalBreakpoint} from "../interfaces/TBreakpoint";
2
+
3
+ export function getCSSVariable(variableName: string) {
4
+ const root = document.documentElement;
5
+ const variableValue = getComputedStyle(root).getPropertyValue(variableName);
6
+ return variableValue.trim();
7
+ }
8
+
9
+
10
+ export function getCSSBreakpoint(bp: TBreakpoint) {
11
+ return getCSSVariable(`--bp-${bp}`)
12
+ }
13
+
14
+ export function getCSSVBreakpoint(bp: TVerticalBreakpoint) {
15
+ return getCSSVariable(`--vbp-${bp}`)
16
+ }
@@ -7,7 +7,7 @@
7
7
  useMediaQuery: jest.fn(),
8
8
  }));
9
9
 
10
- jest.mock('../useVariant', () => jest.fn(() => 'min'));
10
+ jest.mock('./useVariant', () => jest.fn(() => 'min'));
11
11
 
12
12
  describe('useBreakpoint', () => {
13
13
  it('should return true for the media query that matches the breakpoint', () => {
@@ -1,14 +1,15 @@
1
1
  import { useMediaQuery } from 'react-responsive';
2
2
 
3
3
  import breakpoints from '../../scss/_horizontal.export.scss';
4
- import { TBreakpoint } from '../../interfaces/TBreakpoint';
5
- import { TAdaptiveVariant } from '../../interfaces/TAdaptiveVariant';
6
- import useVariant from '../useVariant';
4
+ import { TBreakpoint } from '../interfaces/TBreakpoint';
5
+ import { TAdaptiveVariant } from '../interfaces/TAdaptiveVariant';
6
+ import useVariant from './useVariant';
7
+ import {getCSSBreakpoint} from "./getCSSVariable";
7
8
 
8
9
  export default function useBreakpoint(b: TBreakpoint | number, variant: TAdaptiveVariant = 'MtF') {
9
- const p = typeof b === 'number' ? b : breakpoints[b];
10
+ const _bp = typeof b === 'number' ? b + 'px' : getCSSBreakpoint(b);
10
11
  const v = useVariant(variant);
11
- return useMediaQuery({ query: `(${v}-width: ${p}px)` });
12
+ return useMediaQuery({ query: `(${v}-width: ${_bp})` });
12
13
  }
13
14
 
14
15
  export function useBreakpointMF(b: TBreakpoint | number) {
@@ -1,14 +1,14 @@
1
1
  import { useMediaQuery } from 'react-responsive';
2
2
 
3
- import breakpoints from '../../scss/_vertical.export.scss';
4
- import { TVerticalBreakpoint } from '../../interfaces/TBreakpoint';
5
- import { TAdaptiveVariant } from '../../interfaces/TAdaptiveVariant';
6
- import useVariant from '../useVariant';
3
+ import { TVerticalBreakpoint } from '../interfaces/TBreakpoint';
4
+ import { TAdaptiveVariant } from '../interfaces/TAdaptiveVariant';
5
+ import useVariant from './useVariant';
6
+ import {getCSSBreakpoint, getCSSVBreakpoint} from "./getCSSVariable";
7
7
 
8
8
  export default function useVBreakpoint(b: TVerticalBreakpoint | number, variant: TAdaptiveVariant = 'MtF') {
9
- const p = typeof b === 'number' ? b : breakpoints[b];
9
+ const _bp = typeof b === 'number' ? b + 'px' : getCSSVBreakpoint(b);
10
10
  const v = useVariant(variant);
11
- return useMediaQuery({ query: `(${v}-height: ${p}px)` });
11
+ return useMediaQuery({ query: `(${v}-height: ${_bp})` });
12
12
  }
13
13
 
14
14
  export function useVBreakpointMF(b: TVerticalBreakpoint | number) {
package/src/index.scss CHANGED
@@ -1,4 +1,2 @@
1
- @import "scss/data";
2
1
  @import "scss/vertical";
3
2
  @import "scss/horizontal";
4
-
package/src/index.ts CHANGED
@@ -3,11 +3,8 @@ import { TBreakpoint, TVerticalBreakpoint } from './interfaces/TBreakpoint';
3
3
 
4
4
  export * from 'react-responsive';
5
5
 
6
- export * from './hooks/horizontal/useBreakpoints';
7
- export * from './hooks/horizontal/useBreakpoint';
8
-
9
- export * from './hooks/vertical/useVBreakpoint';
10
- export * from './hooks/vertical/useVBreakpoints';
6
+ export * from './hooks/useBreakpoint';
7
+ export * from './hooks/useVBreakpoint';
11
8
 
12
9
  export type {
13
10
  TBreakpoints,
@@ -0,0 +1,19 @@
1
+ :root {
2
+ --bp-xs: 320px;
3
+ --bp-sm: 576px;
4
+ --bp-md: 768px;
5
+ --bp-lg: 992px;
6
+ --bp-lt: 1024px;
7
+ --bp-ltm: 1120px;
8
+ --bp-ltl: 1440px;
9
+ --bp-xl: 1920px;
10
+ --bp-xxl: 2560px;
11
+ --bp-qxl: 3840px;
12
+
13
+ --vbp-xs: 600px;
14
+ --vbp-sm: 800px;
15
+ --vbp-md: 1000px;
16
+ --vbp-lg: 1200px;
17
+ --vbp-xl: 1600px;
18
+ --vbp-xxl: 1920px;
19
+ }
@@ -1,118 +1,116 @@
1
1
 
2
- @mixin mobile-first($breakpoint){
3
- $breakpoint-value: map-get($horizontal-breakpoints, $breakpoint);
4
- @media (min-width: #{$breakpoint-value}px) {
2
+ @mixin mob-first($breakpoint){
3
+ @media (min-width: var(--bp-#{$breakpoint})) {
5
4
  @content;
6
5
  }
7
6
  }
8
7
 
9
- @mixin desktop-first($breakpoint){
10
- $breakpoint-value: map-get($horizontal-breakpoints, $breakpoint);
11
- @media (max-width: #{$breakpoint-value}px) {
8
+ @mixin desk-first($breakpoint){
9
+ @media (max-width: var(--bp-#{$breakpoint})) {
12
10
  @content;
13
11
  }
14
12
  }
15
13
 
16
14
 
17
15
  @mixin m-xs(){
18
- @include mobile-first(xs){
16
+ @include mob-first(xs){
19
17
  @content;
20
18
  }
21
19
  }
22
20
  @mixin m-sm(){
23
- @include mobile-first(sm){
21
+ @include mob-first(sm){
24
22
  @content;
25
23
  }
26
24
  }
27
25
  @mixin m-md(){
28
- @include mobile-first(md){
26
+ @include mob-first(md){
29
27
  @content;
30
28
  }
31
29
  }
32
30
  @mixin m-lg(){
33
- @include mobile-first(lg){
31
+ @include mob-first(lg){
34
32
  @content;
35
33
  }
36
34
  }
37
35
  @mixin m-lt(){
38
- @include mobile-first(lt){
36
+ @include mob-first(lt){
39
37
  @content;
40
38
  }
41
39
  }
42
40
  @mixin m-ltm(){
43
- @include mobile-first(ltm){
41
+ @include mob-first(ltm){
44
42
  @content;
45
43
  }
46
44
  }
47
45
  @mixin m-ltl(){
48
- @include mobile-first(ltl){
46
+ @include mob-first(ltl){
49
47
  @content;
50
48
  }
51
49
  }
52
50
  @mixin m-xl(){
53
- @include mobile-first(xl){
51
+ @include mob-first(xl){
54
52
  @content;
55
53
  }
56
54
  }
57
55
  @mixin m-xxl(){
58
- @include mobile-first(xxl){
56
+ @include mob-first(xxl){
59
57
  @content;
60
58
  }
61
59
  }
62
60
  @mixin m-qxl(){
63
- @include mobile-first(qxl){
61
+ @include mob-first(qxl){
64
62
  @content;
65
63
  }
66
64
  }
67
65
 
68
66
 
69
67
  @mixin d-xs(){
70
- @include desktop-first(xs){
68
+ @include desk-first(xs){
71
69
  @content;
72
70
  }
73
71
  }
74
72
  @mixin d-sm(){
75
- @include desktop-first(sm){
73
+ @include desk-first(sm){
76
74
  @content;
77
75
  }
78
76
  }
79
77
  @mixin d-md(){
80
- @include desktop-first(md){
78
+ @include desk-first(md){
81
79
  @content;
82
80
  }
83
81
  }
84
82
  @mixin d-lg(){
85
- @include desktop-first(lg){
83
+ @include desk-first(lg){
86
84
  @content;
87
85
  }
88
86
  }
89
87
  @mixin d-lt(){
90
- @include desktop-first(lt){
88
+ @include desk-first(lt){
91
89
  @content;
92
90
  }
93
91
  }
94
92
  @mixin d-ltm(){
95
- @include desktop-first(ltm){
93
+ @include desk-first(ltm){
96
94
  @content;
97
95
  }
98
96
  }
99
97
  @mixin d-ltl(){
100
- @include desktop-first(ltl){
98
+ @include desk-first(ltl){
101
99
  @content;
102
100
  }
103
101
  }
104
102
  @mixin d-xl(){
105
- @include desktop-first(xl){
103
+ @include desk-first(xl){
106
104
  @content;
107
105
  }
108
106
  }
109
107
  @mixin d-xxl(){
110
- @include desktop-first(xxl){
108
+ @include desk-first(xxl){
111
109
  @content;
112
110
  }
113
111
  }
114
112
  @mixin d-qxl(){
115
- @include desktop-first(qxl){
113
+ @include desk-first(qxl){
116
114
  @content;
117
115
  }
118
116
  }
@@ -1,76 +1,73 @@
1
-
2
- @mixin v-mobile-first($breakpoint){
3
- $breakpoint-value: map-get($vertical-breakpoints, $breakpoint);
4
- @media (min-height: #{$breakpoint-value}px) {
1
+ @mixin v-mob-first($breakpoint){
2
+ @media (min-height: var(--bp-#{$breakpoint})) {
5
3
  @content;
6
4
  }
7
5
  }
8
6
 
9
- @mixin v-desktop-first($breakpoint){
10
- $breakpoint-value: map-get($vertical-breakpoints, $breakpoint);
11
- @media (max-height: #{$breakpoint-value}px) {
7
+ @mixin v-desk-first($breakpoint){
8
+ @media (max-height: var(--bp-#{$breakpoint})) {
12
9
  @content;
13
10
  }
14
11
  }
15
12
 
16
13
  @mixin vm-xs(){
17
- @include v-mobile-first(xs){
14
+ @include v-mob-first(xs){
18
15
  @content;
19
16
  }
20
17
  }
21
18
  @mixin vm-sm(){
22
- @include v-mobile-first(sm){
19
+ @include v-mob-first(sm){
23
20
  @content;
24
21
  }
25
22
  }
26
23
  @mixin vm-md(){
27
- @include v-mobile-first(md){
24
+ @include v-mob-first(md){
28
25
  @content;
29
26
  }
30
27
  }
31
28
  @mixin vm-lg(){
32
- @include v-mobile-first(lg){
29
+ @include v-mob-first(lg){
33
30
  @content;
34
31
  }
35
32
  }
36
33
  @mixin vm-xl(){
37
- @include v-mobile-first(xl){
34
+ @include v-mob-first(xl){
38
35
  @content;
39
36
  }
40
37
  }
41
38
  @mixin vm-xxl(){
42
- @include v-mobile-first(xxl){
39
+ @include v-mob-first(xxl){
43
40
  @content;
44
41
  }
45
42
  }
46
43
 
47
44
  @mixin vd-xs(){
48
- @include v-desktop-first(xs){
45
+ @include v-desk-first(xs){
49
46
  @content;
50
47
  }
51
48
  }
52
49
  @mixin vd-sm(){
53
- @include v-desktop-first(sm){
50
+ @include v-desk-first(sm){
54
51
  @content;
55
52
  }
56
53
  }
57
54
  @mixin vd-md(){
58
- @include v-desktop-first(md){
55
+ @include v-desk-first(md){
59
56
  @content;
60
57
  }
61
58
  }
62
59
  @mixin vd-lg(){
63
- @include v-desktop-first(lg){
60
+ @include v-desk-first(lg){
64
61
  @content;
65
62
  }
66
63
  }
67
64
  @mixin vd-xl(){
68
- @include v-desktop-first(xl){
65
+ @include v-desk-first(xl){
69
66
  @content;
70
67
  }
71
68
  }
72
69
  @mixin vd-xxl(){
73
- @include v-desktop-first(xxl){
70
+ @include v-desk-first(xxl){
74
71
  @content;
75
72
  }
76
73
  }
@@ -1,4 +1,4 @@
1
- @import "data";
1
+ @import "breakpoints";
2
2
  @import "vertical";
3
3
  @import "horizontal";
4
4
 
@@ -1,44 +0,0 @@
1
- // loadBreakpoints.js
2
- import {
3
- HORIZONTAL_BREAKPOINTS as defaultHorizontalBreakpoints,
4
- VERTICAL_BREAKPOINTS as defaultVerticalBreakpoint
5
- } from './src/breakpoints.configs';
6
-
7
- import fs from 'fs';
8
- import path from 'path';
9
-
10
- // Путь к пользовательскому конфигурационному файлу
11
- const userConfigPath = path.resolve(__dirname, './breakpoints.config.js');
12
-
13
- // Функция объединения значений по умолчанию с пользовательскими значениями
14
- const mergeConfigs = (defaultConfig, userConfig) => ({
15
- ...defaultConfig,
16
- ...userConfig,
17
- });
18
-
19
- let horizontalBreakpoints = defaultHorizontalBreakpoints;
20
- let verticalBreakpoints = defaultVerticalBreakpoint;
21
-
22
- // Проверяем, существует ли пользовательский конфигурационный файл
23
- if (fs.existsSync(userConfigPath)) {
24
- const userConfig = require(userConfigPath);
25
- horizontalBreakpoints = mergeConfigs(defaultHorizontalBreakpoints, userConfig.HORIZONTAL_BREAKPOINTS || {});
26
- verticalBreakpoints = mergeConfigs(defaultVerticalBreakpoints, userConfig.VERTICAL_BREAKPOINTS || {});
27
- }
28
-
29
- const generateSCSSContent = (breakpoints, name) => {
30
- return `$${name}-breakpoints: (\n${Object.entries(breakpoints)
31
- .map(([key, value]) => ` ${key}: ${value}`)
32
- .join(',\n')}\n);`;
33
- };
34
-
35
- const scssContent = `
36
- // Этот файл генерируется автоматически. Не редактируйте его напрямую.
37
- ${generateSCSSContent(horizontalBreakpoints, 'horizontal')}
38
- ${generateSCSSContent(verticalBreakpoints, 'vertical')}
39
- `;
40
-
41
- fs.writeFileSync(
42
- path.resolve(__dirname, './scss/_custom-breakpoints.scss'),
43
- scssContent
44
- );
@@ -1,25 +0,0 @@
1
- // breakpointConfig.js
2
-
3
- const HORIZONTAL_BREAKPOINTS = {
4
- xs: '320px',
5
- sm: '576px',
6
- md: '768px',
7
- lg: '992px',
8
- lt: '1024px',
9
- ltm: '1200px',
10
- ltl: '1440px',
11
- xl: '1920px',
12
- xxl: '2560px',
13
- qxl: '3840px',
14
- };
15
-
16
- const VERTICAL_BREAKPOINTS = {
17
- xs: '600px',
18
- sm: '800px',
19
- md: '1000px',
20
- lg: '1200px',
21
- xl: '1600px',
22
- xxl: '1601px',
23
- };
24
-
25
- export { HORIZONTAL_BREAKPOINTS, VERTICAL_BREAKPOINTS };
@@ -1,30 +0,0 @@
1
- import { useMediaQuery } from 'react-responsive';
2
-
3
- import breakpoints from '../../scss/_horizontal.export.scss';
4
- import { TBreakpoints } from '../../interfaces/TBreakpoints';
5
- import { TAdaptiveVariant } from '../../interfaces/TAdaptiveVariant';
6
- import useVariant from '../useVariant';
7
-
8
- export default function useBreakpoints(variant: TAdaptiveVariant = 'MtF'): TBreakpoints<boolean> {
9
- const v = useVariant(variant);
10
- return {
11
- xs: useMediaQuery({ query: `(${v}-width: ${breakpoints.xs}px)` }),
12
- sm: useMediaQuery({ query: `(${v}-width: ${breakpoints.sm}px)` }),
13
- md: useMediaQuery({ query: `(${v}-width: ${breakpoints.md}px)` }),
14
- lg: useMediaQuery({ query: `(${v}-width: ${breakpoints.lg}px)` }),
15
- lt: useMediaQuery({ query: `(${v}-width: ${breakpoints.lt})px` }),
16
- ltm: useMediaQuery({ query: `(${v}-width: ${breakpoints.ltm})px` }),
17
- ltl: useMediaQuery({ query: `(${v}-width: ${breakpoints.ltl})px` }),
18
- xl: useMediaQuery({ query: `(${v}-width: ${breakpoints.xl})px` }),
19
- xxl: useMediaQuery({ query: `(${v}-width: ${breakpoints.xxl})px` }),
20
- qxl: useMediaQuery({ query: `(${v}-width: ${breakpoints.qxl})px` }),
21
- };
22
- }
23
-
24
- export function useBreakpointsMF(): TBreakpoints<boolean> {
25
- return useBreakpoints('MtF');
26
- }
27
-
28
- export function useBreakpointsDF(): TBreakpoints<boolean> {
29
- return useBreakpoints('DtF');
30
- }
@@ -1,26 +0,0 @@
1
- import { useMediaQuery } from 'react-responsive';
2
-
3
- import breakpoints from '../../scss/_vertical.export.scss';
4
- import { TVerticalBreakpoints } from '../../interfaces/TBreakpoints';
5
- import { TAdaptiveVariant } from '../../interfaces/TAdaptiveVariant';
6
- import useVariant from '../useVariant';
7
-
8
- export default function useVBreakpoints(variant: TAdaptiveVariant = 'MtF'): TVerticalBreakpoints<boolean> {
9
- const v = useVariant(variant);
10
- return {
11
- xs: useMediaQuery({ query: `(${v}-height: ${breakpoints.xs}px)` }),
12
- sm: useMediaQuery({ query: `(${v}-height: ${breakpoints.sm}px)` }),
13
- md: useMediaQuery({ query: `(${v}-height: ${breakpoints.md}px)` }),
14
- lg: useMediaQuery({ query: `(${v}-height: ${breakpoints.lg}px)` }),
15
- xl: useMediaQuery({ query: `(${v}-height: ${breakpoints.xl})px` }),
16
- xxl: useMediaQuery({ query: `(${v}-height: ${breakpoints.xxl})px` }),
17
- };
18
- }
19
-
20
- export function useVBreakpointsMF(): TVerticalBreakpoints<boolean> {
21
- return useVBreakpoints('MtF');
22
- }
23
-
24
- export function useVBreakpointsDF(): TVerticalBreakpoints<boolean> {
25
- return useVBreakpoints('DtF');
26
- }
@@ -1,24 +0,0 @@
1
- // _data.scss
2
- @import './custom-breakpoints';
3
-
4
- :export {
5
- // Экспорт горизонтальных брейкпоинтов
6
- xs: map-get($horizontal-breakpoints, xs);
7
- sm: map-get($horizontal-breakpoints, sm);
8
- md: map-get($horizontal-breakpoints, md);
9
- lg: map-get($horizontal-breakpoints, lg);
10
- lt: map-get($horizontal-breakpoints, lt);
11
- ltm: map-get($horizontal-breakpoints, ltm);
12
- ltl: map-get($horizontal-breakpoints, ltl);
13
- xl: map-get($horizontal-breakpoints, xl);
14
- xxl: map-get($horizontal-breakpoints, xxl);
15
- qxl: map-get($horizontal-breakpoints, qxl);
16
-
17
- // Экспорт вертикальных брейкпоинтов
18
- vxs: map-get($vertical-breakpoints, xs);
19
- vsm: map-get($vertical-breakpoints, sm);
20
- vmd: map-get($vertical-breakpoints, md);
21
- vlg: map-get($vertical-breakpoints, lg);
22
- vxl: map-get($vertical-breakpoints, xl);
23
- vxxl: map-get($vertical-breakpoints, xxl);
24
- }
@@ -1,14 +0,0 @@
1
- @import "data";
2
-
3
- :export{
4
- xs:map-get($horizontal-breakpoints,xs);
5
- sm:map-get($horizontal-breakpoints,sm);
6
- md:map-get($horizontal-breakpoints,md);
7
- lg:map-get($horizontal-breakpoints,lg);
8
- lt:map-get($horizontal-breakpoints,lt);
9
- ltm:map-get($horizontal-breakpoints,ltm);
10
- ltl:map-get($horizontal-breakpoints,ltl);
11
- xl:map-get($horizontal-breakpoints,xl);
12
- xxl:map-get($horizontal-breakpoints,xxl);
13
- qxl:map-get($horizontal-breakpoints,qxl);
14
- }
@@ -1,10 +0,0 @@
1
- @import "data";
2
-
3
- :export{
4
- xs: map-get($vertical-breakpoints, xs);
5
- sm: map-get($vertical-breakpoints, sm);
6
- md: map-get($vertical-breakpoints, md);
7
- lg: map-get($vertical-breakpoints, lg);
8
- xl: map-get($vertical-breakpoints, xl);
9
- xxl: map-get($vertical-breakpoints, xxl);
10
- }