react-responsive-tools 1.1.4 → 2.0.1

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.
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync } = require('child_process');
4
+ const path = require('path');
5
+
6
+ // Полный путь к вашему скрипту
7
+ const scriptPath = path.resolve(__dirname, '../reinit.sh');
8
+
9
+ const command = process.argv[2];
10
+
11
+ if (command === 'run' && process.argv[3] === 'reinit') {
12
+ try {
13
+ execSync(`sh ${scriptPath}`, { stdio: 'inherit' });
14
+ } catch (error) {
15
+ console.error('Error executing the reinit.sh script:', error);
16
+ process.exit(1);
17
+ }
18
+ } else {
19
+ console.log('Usage: react-responsive-tools run reinit');
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-responsive-tools",
3
- "version": "1.1.4",
3
+ "version": "2.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -11,9 +11,8 @@
11
11
  "test": "jest",
12
12
  "lint": "eslint \"{**/*,*}.{js,ts,jsx,tsx}\"",
13
13
  "lint-fix": "eslint \"{**/*,*}.{js,ts,jsx,tsx}\" --fix",
14
-
15
- "build": "tsc && webpack --mode production"
16
-
14
+ "build": "tsc && webpack --mode production",
15
+ "postinstall": "echo 'To recreate all files, run: react-responsive-tools run reinit'"
17
16
  },
18
17
  "files": [
19
18
  "src",
@@ -30,7 +29,7 @@
30
29
  ],
31
30
  "author": "westprophet",
32
31
  "license": "ISC",
33
- "dependencies": {
32
+ "peerDependencies": {
34
33
  "react-responsive": "^10.0.0"
35
34
  },
36
35
  "devDependencies": {
@@ -69,5 +68,8 @@
69
68
  "typescript": "^5.5.4",
70
69
  "webpack": "^5.94.0",
71
70
  "webpack-cli": "^5.1.4"
71
+ },
72
+ "bin": {
73
+ "react-responsive-tools": "./bin/react-responsive-tools.js"
72
74
  }
73
75
  }
@@ -0,0 +1,4 @@
1
+ declare module 'breakpoints.config' {
2
+ export const HORIZONTAL_BREAKPOINTS: { [key: string]: string };
3
+ export const VERTICAL_BREAKPOINTS: { [key: string]: string };
4
+ }
@@ -0,0 +1,25 @@
1
+
2
+ // breakpoints.config.js
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 };
@@ -13,14 +13,14 @@ interface ForComponentProps extends Props {
13
13
  p: TBreakpoint | number;
14
14
  }
15
15
 
16
- export function ForMF({children, p}: ForComponentProps) {
16
+ export function For({children, p}: ForComponentProps) {
17
17
  const is = useBreakpointMF(p);
18
18
  if (is) return children;
19
19
  return null;
20
20
  }
21
21
 
22
22
 
23
- export function ForDF({children ,p}: ForComponentProps) {
23
+ export function Before({children ,p}: ForComponentProps) {
24
24
  const is = useBreakpointDF(p);
25
25
  if (is) return children;
26
26
  return null;
@@ -0,0 +1,25 @@
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 };
@@ -0,0 +1,11 @@
1
+ // @ts-ignore
2
+ import { HORIZONTAL_BREAKPOINTS, VERTICAL_BREAKPOINTS } from '../breakpoints.config';
3
+ import { TBreakpoint, TVerticalBreakpoint } from '../interfaces/TBreakpoint';
4
+
5
+ export default function getBreakpoint(b: TBreakpoint): string {
6
+ return HORIZONTAL_BREAKPOINTS[b];
7
+ }
8
+
9
+ export function getVBreakpoint(b: TVerticalBreakpoint): string {
10
+ return VERTICAL_BREAKPOINTS[b];
11
+ }
@@ -1,13 +1,12 @@
1
1
  import { useMediaQuery } from 'react-responsive';
2
2
 
3
- import breakpoints from '../../scss/_horizontal.export.scss';
4
3
  import { TBreakpoint } from '../interfaces/TBreakpoint';
5
4
  import { TAdaptiveVariant } from '../interfaces/TAdaptiveVariant';
6
5
  import useVariant from './useVariant';
7
- import {getCSSBreakpoint} from "./getCSSVariable";
6
+ import getBreakpoint from "../functions/getBreakpoint";
8
7
 
9
8
  export default function useBreakpoint(b: TBreakpoint | number, variant: TAdaptiveVariant = 'MtF') {
10
- const _bp = typeof b === 'number' ? b + 'px' : getCSSBreakpoint(b);
9
+ const _bp = typeof b === 'number' ? b + 'px' : getBreakpoint(b);
11
10
  const v = useVariant(variant);
12
11
  return useMediaQuery({ query: `(${v}-width: ${_bp})` });
13
12
  }
@@ -3,10 +3,10 @@ import { useMediaQuery } from 'react-responsive';
3
3
  import { TVerticalBreakpoint } from '../interfaces/TBreakpoint';
4
4
  import { TAdaptiveVariant } from '../interfaces/TAdaptiveVariant';
5
5
  import useVariant from './useVariant';
6
- import {getCSSBreakpoint, getCSSVBreakpoint} from "./getCSSVariable";
6
+ import getBreakpoint, {getVBreakpoint} from "../functions/getBreakpoint";
7
7
 
8
8
  export default function useVBreakpoint(b: TVerticalBreakpoint | number, variant: TAdaptiveVariant = 'MtF') {
9
- const _bp = typeof b === 'number' ? b + 'px' : getCSSVBreakpoint(b);
9
+ const _bp = typeof b === 'number' ? b + 'px' : getVBreakpoint(b);
10
10
  const v = useVariant(variant);
11
11
  return useMediaQuery({ query: `(${v}-height: ${_bp})` });
12
12
  }
package/src/index.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import { TBreakpoints, TVerticalBreakpoints } from './interfaces/TBreakpoints';
2
2
  import { TBreakpoint, TVerticalBreakpoint } from './interfaces/TBreakpoint';
3
3
 
4
- export * from 'react-responsive';
5
-
6
4
  export * from './hooks/useBreakpoint';
7
5
  export * from './hooks/useVBreakpoint';
8
6
 
@@ -17,5 +17,4 @@ export type TVerticalBreakpoint =
17
17
  | 'md'
18
18
  | 'lg'
19
19
  | 'xl'
20
- | 'xxl'
21
-
20
+ | 'xxl'
@@ -0,0 +1,49 @@
1
+ // mergeBreakpointConfigs.js
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import { HORIZONTAL_BREAKPOINTS as defaultHorizontalBreakpoints, VERTICAL_BREAKPOINTS as defaultVerticalBreakpoints } from '../default.config.js';
6
+
7
+ // Определение __filename и __dirname
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ // Путь к пользовательскому конфигурационному файлу
12
+ const userConfigPath = path.resolve(__dirname, '../breakpoints.config.js');
13
+
14
+ // Функция объединения значений по умолчанию с пользовательскими значениями
15
+ const mergeConfigs = (defaultConfig, userConfig) => ({
16
+ ...defaultConfig,
17
+ ...userConfig,
18
+ });
19
+
20
+ const mergeBreakpointConfigs = async () => {
21
+ let horizontalBreakpoints = defaultHorizontalBreakpoints;
22
+ let verticalBreakpoints = defaultVerticalBreakpoints;
23
+
24
+ // Проверяем, существует ли пользовательский конфигурационный файл
25
+ if (fs.existsSync(userConfigPath)) {
26
+ const userConfig = await import(userConfigPath);
27
+ horizontalBreakpoints = mergeConfigs(defaultHorizontalBreakpoints, userConfig.HORIZONTAL_BREAKPOINTS || {});
28
+ verticalBreakpoints = mergeConfigs(defaultVerticalBreakpoints, userConfig.VERTICAL_BREAKPOINTS || {});
29
+ }
30
+
31
+ const mergedConfigContent = `
32
+ // breakpoints.config.js
33
+ const HORIZONTAL_BREAKPOINTS = ${JSON.stringify(horizontalBreakpoints, null, 2)};
34
+
35
+ const VERTICAL_BREAKPOINTS = ${JSON.stringify(verticalBreakpoints, null, 2)};
36
+
37
+ export { HORIZONTAL_BREAKPOINTS, VERTICAL_BREAKPOINTS };
38
+ `;
39
+
40
+ // Создаем новый файл с именем breakpoints.config.js
41
+ fs.writeFileSync(
42
+ path.resolve(__dirname, '../breakpoints.config.js'),
43
+ mergedConfigContent
44
+ );
45
+
46
+ console.log('Config file have been generated successfully.');
47
+ };
48
+
49
+ mergeBreakpointConfigs();
@@ -0,0 +1,30 @@
1
+ // generateSCSSMaps.js
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url'; // Импортируем необходимую функцию из 'url'
5
+ import { HORIZONTAL_BREAKPOINTS, VERTICAL_BREAKPOINTS } from '../breakpoints.config.js';
6
+
7
+ // Определение __filename и __dirname
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ // Функция генерации SCSS map
12
+ const generateSCSSMap = (breakpoints, name) => {
13
+ return `$${name}-breakpoints: (\n${Object.entries(breakpoints)
14
+ .map(([key, value]) => ` ${key}: ${value}`)
15
+ .join(',\n')}\n);`;
16
+ };
17
+
18
+ // Создаем содержимое SCSS файла
19
+ const scssContent = `
20
+ ${generateSCSSMap(HORIZONTAL_BREAKPOINTS, 'horizontal')}
21
+ ${generateSCSSMap(VERTICAL_BREAKPOINTS, 'vertical')}
22
+ `;
23
+
24
+ // Записываем содержимое в файл _custom-breakpoints.scss
25
+ fs.writeFileSync(
26
+ path.resolve(__dirname, '../scss/_custom-breakpoints.scss'),
27
+ scssContent
28
+ );
29
+
30
+ console.log('SCSS file with breakpoints maps has been generated successfully.');
@@ -0,0 +1,51 @@
1
+ // generateSCSS.js
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import { HORIZONTAL_BREAKPOINTS, VERTICAL_BREAKPOINTS } from '../breakpoints.config.js';
6
+
7
+ // Определение __filename и __dirname
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ // Функция генерации SCSS содержимого для горизонтальных брейкпоинтов
12
+ const generateHorizontalSCSS = (breakpoints) => {
13
+ const beforeMixins = Object.keys(breakpoints).map(bp => `@mixin for-${bp}(){\n @include mob-first(${bp}){\n @content;\n }\n}`).join('\n');
14
+ const afterMixins = Object.keys(breakpoints).map(bp => `@mixin before-${bp}(){\n @include desk-first(${bp}){\n @content;\n }\n}`).join('\n');
15
+ return `
16
+ @import "horizontal";
17
+
18
+ ${beforeMixins}
19
+
20
+ ${afterMixins}
21
+ `;
22
+ };
23
+
24
+ // Функция генерации SCSS содержимого для вертикальных брейкпоинтов
25
+ const generateVerticalSCSS = (breakpoints) => {
26
+ const beforeMixins = Object.keys(breakpoints).map(bp => `@mixin v-for-${bp}(){\n @include v-mob-first(${bp}){\n @content;\n }\n}`).join('\n');
27
+ const afterMixins = Object.keys(breakpoints).map(bp => `@mixin v-before-${bp}(){\n @include v-desk-first(${bp}){\n @content;\n }\n}`).join('\n');
28
+ return `
29
+ @import "vertical";
30
+
31
+ ${beforeMixins}
32
+
33
+ ${afterMixins}
34
+ `;
35
+ };
36
+
37
+ // Создаем файлы SCSS с миксинами
38
+ const horizontalSCSSContent = generateHorizontalSCSS(HORIZONTAL_BREAKPOINTS);
39
+ const verticalSCSSContent = generateVerticalSCSS(VERTICAL_BREAKPOINTS);
40
+
41
+ fs.writeFileSync(
42
+ path.resolve(__dirname, '../scss/_horizontal-breakpoints.scss'),
43
+ horizontalSCSSContent
44
+ );
45
+
46
+ fs.writeFileSync(
47
+ path.resolve(__dirname, '../scss/_vertical-breakpoints.scss'),
48
+ verticalSCSSContent
49
+ );
50
+
51
+ console.log('SCSS files have been generated successfully.');
@@ -0,0 +1,30 @@
1
+ // generateTBreakpoint.js
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import { HORIZONTAL_BREAKPOINTS, VERTICAL_BREAKPOINTS } from '../breakpoints.config.js';
6
+
7
+ // Определение __filename и __dirname
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ // Функция для генерации type alias на основе брейкпоинтов
12
+ const generateTypeAlias = (breakpoints, typeName) => {
13
+ const types = Object.keys(breakpoints).map(bp => ` | '${bp}'`).join('\n');
14
+ return `export type ${typeName} =\n${types}\n`;
15
+ };
16
+
17
+ // Генерируем содержимое файла TBreakpoint.ts
18
+ const content = `
19
+ ${generateTypeAlias(HORIZONTAL_BREAKPOINTS, 'TBreakpoint')}
20
+
21
+ ${generateTypeAlias(VERTICAL_BREAKPOINTS, 'TVerticalBreakpoint')}
22
+ `;
23
+
24
+ // Создаем файл TBreakpoint.ts и записываем туда содержимое
25
+ fs.writeFileSync(
26
+ path.resolve(__dirname, '../interfaces/TBreakpoint.ts'),
27
+ content.trim()
28
+ );
29
+
30
+ console.log('TBreakpoint.ts file has been generated successfully.');
@@ -0,0 +1,21 @@
1
+
2
+ $horizontal-breakpoints: (
3
+ xs: 320px,
4
+ sm: 576px,
5
+ md: 768px,
6
+ lg: 992px,
7
+ lt: 1024px,
8
+ ltm: 1200px,
9
+ ltl: 1440px,
10
+ xl: 1920px,
11
+ xxl: 2560px,
12
+ qxl: 3840px
13
+ );
14
+ $vertical-breakpoints: (
15
+ xs: 600px,
16
+ sm: 800px,
17
+ md: 1000px,
18
+ lg: 1200px,
19
+ xl: 1600px,
20
+ xxl: 1601px
21
+ );
@@ -0,0 +1,104 @@
1
+
2
+ @import "horizontal";
3
+
4
+ @mixin for-xs(){
5
+ @include mob-first(xs){
6
+ @content;
7
+ }
8
+ }
9
+ @mixin for-sm(){
10
+ @include mob-first(sm){
11
+ @content;
12
+ }
13
+ }
14
+ @mixin for-md(){
15
+ @include mob-first(md){
16
+ @content;
17
+ }
18
+ }
19
+ @mixin for-lg(){
20
+ @include mob-first(lg){
21
+ @content;
22
+ }
23
+ }
24
+ @mixin for-lt(){
25
+ @include mob-first(lt){
26
+ @content;
27
+ }
28
+ }
29
+ @mixin for-ltm(){
30
+ @include mob-first(ltm){
31
+ @content;
32
+ }
33
+ }
34
+ @mixin for-ltl(){
35
+ @include mob-first(ltl){
36
+ @content;
37
+ }
38
+ }
39
+ @mixin for-xl(){
40
+ @include mob-first(xl){
41
+ @content;
42
+ }
43
+ }
44
+ @mixin for-xxl(){
45
+ @include mob-first(xxl){
46
+ @content;
47
+ }
48
+ }
49
+ @mixin for-qxl(){
50
+ @include mob-first(qxl){
51
+ @content;
52
+ }
53
+ }
54
+
55
+ @mixin before-xs(){
56
+ @include desk-first(xs){
57
+ @content;
58
+ }
59
+ }
60
+ @mixin before-sm(){
61
+ @include desk-first(sm){
62
+ @content;
63
+ }
64
+ }
65
+ @mixin before-md(){
66
+ @include desk-first(md){
67
+ @content;
68
+ }
69
+ }
70
+ @mixin before-lg(){
71
+ @include desk-first(lg){
72
+ @content;
73
+ }
74
+ }
75
+ @mixin before-lt(){
76
+ @include desk-first(lt){
77
+ @content;
78
+ }
79
+ }
80
+ @mixin before-ltm(){
81
+ @include desk-first(ltm){
82
+ @content;
83
+ }
84
+ }
85
+ @mixin before-ltl(){
86
+ @include desk-first(ltl){
87
+ @content;
88
+ }
89
+ }
90
+ @mixin before-xl(){
91
+ @include desk-first(xl){
92
+ @content;
93
+ }
94
+ }
95
+ @mixin before-xxl(){
96
+ @include desk-first(xxl){
97
+ @content;
98
+ }
99
+ }
100
+ @mixin before-qxl(){
101
+ @include desk-first(qxl){
102
+ @content;
103
+ }
104
+ }
@@ -1,116 +1,15 @@
1
+ @import "_custom-breakpoints";
1
2
 
2
3
  @mixin mob-first($breakpoint){
3
- @media (min-width: var(--bp-#{$breakpoint})) {
4
+ @media (min-width: map-get($horizontal-breakpoints, $breakpoint)) {
4
5
  @content;
5
6
  }
6
7
  }
7
8
 
8
9
  @mixin desk-first($breakpoint){
9
- @media (max-width: var(--bp-#{$breakpoint})) {
10
+ @media (max-width: map-get($horizontal-breakpoints, $breakpoint)) {
10
11
  @content;
11
12
  }
12
13
  }
13
14
 
14
15
 
15
- @mixin m-xs(){
16
- @include mob-first(xs){
17
- @content;
18
- }
19
- }
20
- @mixin m-sm(){
21
- @include mob-first(sm){
22
- @content;
23
- }
24
- }
25
- @mixin m-md(){
26
- @include mob-first(md){
27
- @content;
28
- }
29
- }
30
- @mixin m-lg(){
31
- @include mob-first(lg){
32
- @content;
33
- }
34
- }
35
- @mixin m-lt(){
36
- @include mob-first(lt){
37
- @content;
38
- }
39
- }
40
- @mixin m-ltm(){
41
- @include mob-first(ltm){
42
- @content;
43
- }
44
- }
45
- @mixin m-ltl(){
46
- @include mob-first(ltl){
47
- @content;
48
- }
49
- }
50
- @mixin m-xl(){
51
- @include mob-first(xl){
52
- @content;
53
- }
54
- }
55
- @mixin m-xxl(){
56
- @include mob-first(xxl){
57
- @content;
58
- }
59
- }
60
- @mixin m-qxl(){
61
- @include mob-first(qxl){
62
- @content;
63
- }
64
- }
65
-
66
-
67
- @mixin d-xs(){
68
- @include desk-first(xs){
69
- @content;
70
- }
71
- }
72
- @mixin d-sm(){
73
- @include desk-first(sm){
74
- @content;
75
- }
76
- }
77
- @mixin d-md(){
78
- @include desk-first(md){
79
- @content;
80
- }
81
- }
82
- @mixin d-lg(){
83
- @include desk-first(lg){
84
- @content;
85
- }
86
- }
87
- @mixin d-lt(){
88
- @include desk-first(lt){
89
- @content;
90
- }
91
- }
92
- @mixin d-ltm(){
93
- @include desk-first(ltm){
94
- @content;
95
- }
96
- }
97
- @mixin d-ltl(){
98
- @include desk-first(ltl){
99
- @content;
100
- }
101
- }
102
- @mixin d-xl(){
103
- @include desk-first(xl){
104
- @content;
105
- }
106
- }
107
- @mixin d-xxl(){
108
- @include desk-first(xxl){
109
- @content;
110
- }
111
- }
112
- @mixin d-qxl(){
113
- @include desk-first(qxl){
114
- @content;
115
- }
116
- }
@@ -0,0 +1,64 @@
1
+
2
+ @import "vertical";
3
+
4
+ @mixin v-for-xs(){
5
+ @include v-mob-first(xs){
6
+ @content;
7
+ }
8
+ }
9
+ @mixin v-for-sm(){
10
+ @include v-mob-first(sm){
11
+ @content;
12
+ }
13
+ }
14
+ @mixin v-for-md(){
15
+ @include v-mob-first(md){
16
+ @content;
17
+ }
18
+ }
19
+ @mixin v-for-lg(){
20
+ @include v-mob-first(lg){
21
+ @content;
22
+ }
23
+ }
24
+ @mixin v-for-xl(){
25
+ @include v-mob-first(xl){
26
+ @content;
27
+ }
28
+ }
29
+ @mixin v-for-xxl(){
30
+ @include v-mob-first(xxl){
31
+ @content;
32
+ }
33
+ }
34
+
35
+ @mixin v-before-xs(){
36
+ @include v-desk-first(xs){
37
+ @content;
38
+ }
39
+ }
40
+ @mixin v-before-sm(){
41
+ @include v-desk-first(sm){
42
+ @content;
43
+ }
44
+ }
45
+ @mixin v-before-md(){
46
+ @include v-desk-first(md){
47
+ @content;
48
+ }
49
+ }
50
+ @mixin v-before-lg(){
51
+ @include v-desk-first(lg){
52
+ @content;
53
+ }
54
+ }
55
+ @mixin v-before-xl(){
56
+ @include v-desk-first(xl){
57
+ @content;
58
+ }
59
+ }
60
+ @mixin v-before-xxl(){
61
+ @include v-desk-first(xxl){
62
+ @content;
63
+ }
64
+ }