responsive-scale-mixins 1.0.0 → 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.
Files changed (3) hide show
  1. package/README.md +682 -150
  2. package/package.json +2 -2
  3. package/scss/_mixins.scss +21 -13
package/README.md CHANGED
@@ -2,148 +2,355 @@
2
2
 
3
3
  A powerful SCSS mixin system for creating perfectly responsive designs that maintain Figma proportions across all screen sizes.
4
4
 
5
+ [![npm version](https://badge.fury.io/js/responsive-scale-mixins.svg)](https://badge.fury.io/js/responsive-scale-mixins)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## ✨ Features
9
+
10
+ - **Figma Proportions**: Maintains exact proportions from your Figma designs
11
+ - **Automatic Scaling**: No manual breakpoint calculations needed
12
+ - **Tablet Interpolation**: Smart interpolation between mobile and desktop values
13
+ - **CSS Custom Properties**: Uses modern CSS variables for optimal performance
14
+ - **Framework Agnostic**: Works with any CSS framework or vanilla CSS
15
+ - **TypeScript Ready**: Compatible with CSS Modules and CSS-in-JS solutions
16
+
5
17
  ## 🚀 Quick Start
6
18
 
19
+ ### Installation
20
+
21
+ #### npm
22
+
23
+ ```bash
24
+ npm install responsive-scale-mixins
25
+ ```
26
+
27
+ #### Yarn
28
+
29
+ ```bash
30
+ yarn add responsive-scale-mixins
31
+ ```
32
+
33
+ #### pnpm
34
+
35
+ ```bash
36
+ pnpm add responsive-scale-mixins
37
+ ```
38
+
39
+ ### Framework-Specific Setup
40
+
41
+ #### Next.js (App Router)
42
+
7
43
  ```scss
8
- @import "./src/styles/mixins";
44
+ // app/globals.css or app/styles/globals.scss
45
+ @import "~responsive-scale-mixins";
46
+
47
+ :root {
48
+ // Replace 1440 with your design width or leave default (desktop)
49
+ // Replace 768 with your design width or leave default (tablet)
50
+ // Replace 375 with your design width or leave default (mobile)
51
+ // Define CSS variables globally (required)
52
+ @include responsive-scale-variables(1440px, 768px, 375px);
53
+ // Or use defaults: @include responsive-scale-variables();
54
+ }
9
55
 
10
- // Basic usage
11
- .my-element {
12
- @include responsive-scale(font-size, 24, 16);
13
- @include responsive-scale(padding, 20 40, 10 20);
56
+ // Import in app/layout.tsx: import './globals.css'
57
+ ```
58
+
59
+ #### Next.js (Pages Router)
60
+
61
+ ```scss
62
+ // styles/globals.scss
63
+ @import "~responsive-scale-mixins";
64
+
65
+ :root {
66
+ // Define CSS variables globally (required)
67
+
68
+ // Replace 1440 with your design width or leave default (desktop)
69
+ // Replace 768 with your design width or leave default (tablet)
70
+ // Replace 375 with your design width or leave default (mobile)
71
+ @include responsive-scale-variables(1440px, 768px, 375px);
72
+ // Or use defaults: @include responsive-scale-variables();
14
73
  }
74
+
75
+ // Import in pages/_app.js: import '../styles/globals.scss'
15
76
  ```
16
77
 
17
- ## 📋 Table of Contents
78
+ **Next.js Setup:**
18
79
 
19
- - [Setup](#setup)
20
- - [Basic Usage](#basic-usage)
21
- - [Advanced Usage](#advanced-usage)
22
- - [Property Examples](#property-examples)
23
- - [Percentage Properties](#percentage-properties)
24
- - [Tips & Best Practices](#tips--best-practices)
80
+ - **App Router**: Put `:root` in `app/globals.css` (imported in `layout.tsx`)
81
+ - **Pages Router**: Put `:root` in `styles/globals.scss` (imported in `pages/_app.js`)
82
+ - The `:root` selector defines global CSS custom properties accessible everywhere
25
83
 
26
- ## 🔧 Setup
84
+ #### Create React App
27
85
 
28
- ### 1. Import the Mixins
86
+ ```scss
87
+ // src/index.scss or src/styles/main.scss
88
+ @import "~responsive-scale-mixins";
89
+
90
+ :root {
91
+ // Define CSS variables globally (required)
92
+
93
+ // Replace 1440 with your design width or leave default (desktop)
94
+ // Replace 768 with your design width or leave default (tablet)
95
+ // Replace 375 with your design width or leave default (mobile)
96
+ @include responsive-scale-variables(1440px, 768px, 375px);
97
+ // Or use defaults: @include responsive-scale-variables();
98
+ }
99
+
100
+ // Import in src/index.js: import './index.scss'
101
+ ```
102
+
103
+ **Create React App Setup:**
29
104
 
30
- Add this to your SCSS file:
105
+ - Put `:root` in your main SCSS file (e.g., `src/index.scss`)
106
+ - Import the SCSS file in `src/index.js`
107
+ - The `:root` selector makes CSS variables available app-wide
108
+
109
+ #### Vue.js
31
110
 
32
111
  ```scss
33
- @import "../styles/mixins"; // Adjust path as needed
112
+ // src/assets/styles/main.scss
113
+ @import "~responsive-scale-mixins";
114
+
115
+ :root {
116
+ // Define CSS variables globally (required)
117
+
118
+ // Replace 1440 with your design width or leave default (desktop)
119
+ // Replace 768 with your design width or leave default (tablet)
120
+ // Replace 375 with your design width or leave default (mobile)
121
+ @include responsive-scale-variables(1440px, 768px, 375px);
122
+ // Or use defaults: @include responsive-scale-variables();
123
+ }
124
+
125
+ // Import in src/main.js: import './assets/styles/main.scss'
34
126
  ```
35
127
 
36
- ### 2. CSS Variables (Already configured in `global.scss`)
128
+ **Vue.js Setup:**
129
+
130
+ - Put `:root` in your global SCSS file
131
+ - Import in `src/main.js` or use in a global style resource
132
+ - The `:root` selector defines app-wide CSS variables
37
133
 
38
- The mixin uses these responsive scale factors:
134
+ #### Angular
39
135
 
40
- - `--computed-scale-factor-px` (Desktop: 1913px)
41
- - `--computed-tablet-scale-factor-px` (Tablet: 768px)
42
- - `--computed-mobile-scale-factor-px` (Mobile: 390px)
136
+ ```scss
137
+ // src/styles.scss (global styles)
138
+ @import "~responsive-scale-mixins";
139
+
140
+ :root {
141
+ // Define CSS variables globally (required)
43
142
 
44
- ## 🎯 Basic Usage
143
+ // Replace 1440 with your design width or leave default (desktop)
144
+ // Replace 768 with your design width or leave default (tablet)
145
+ // Replace 375 with your design width or leave default (mobile)
146
+ @include responsive-scale-variables(1440px, 768px, 375px);
147
+ // Or use defaults: @include responsive-scale-variables();
148
+ }
45
149
 
46
- ### Same Value for All Screens
150
+ // This file is automatically included by Angular CLI
151
+ ```
47
152
 
48
- When you want the same value across desktop, tablet, and mobile:
153
+ **Angular Setup:**
154
+
155
+ - Put `:root` in `src/styles.scss` (automatically included by Angular CLI)
156
+ - No manual import needed - Angular handles it
157
+ - The `:root` selector defines global CSS variables
158
+
159
+ #### Vite + Vue/React
49
160
 
50
161
  ```scss
51
- // Single parameter - same value for all breakpoints
52
- .element {
53
- @include responsive-scale(border-radius, 10);
54
- @include responsive-scale(font-weight, 500);
162
+ // src/styles/main.scss
163
+ @import "responsive-scale-mixins";
164
+
165
+ :root {
166
+ // Customize for your design system (optional)
167
+
168
+ // Replace 1440 with your design width or leave default (desktop)
169
+ // Replace 768 with your design width or leave default (tablet)
170
+ // Replace 375 with your design width or leave default (mobile)
171
+ @include responsive-scale-variables(1440px, 768px, 375px);
172
+ // Or use defaults: @include responsive-scale-variables();
55
173
  }
56
174
  ```
57
175
 
58
- **Output:**
176
+ #### Gatsby
59
177
 
60
- ```css
61
- .element {
62
- border-radius: calc(var(--computed-scale-factor-px) * 10);
178
+ ```scss
179
+ // src/styles/global.scss
180
+ @import "~responsive-scale-mixins";
181
+
182
+ :root {
183
+ // Customize for your design system (optional)
184
+
185
+ // Replace 1440 with your design width or leave default (desktop)
186
+ // Replace 768 with your design width or leave default (tablet)
187
+ // Replace 375 with your design width or leave default (mobile)
188
+ @include responsive-scale-variables(1440px, 768px, 375px);
189
+ // Or use defaults: @include responsive-scale-variables();
63
190
  }
191
+ ```
192
+
193
+ #### Nuxt.js
194
+
195
+ ```scss
196
+ // assets/styles/main.scss
197
+ @import "~responsive-scale-mixins";
64
198
 
65
- @media (min-width: 768px) and (max-width: 991px) {
66
- .element {
67
- border-radius: calc(var(--computed-tablet-scale-factor-px) * 10);
68
- }
199
+ :root {
200
+ // Customize for your design system (optional)
201
+
202
+ // Replace 1440 with your design width or leave default (desktop)
203
+ // Replace 768 with your design width or leave default (tablet)
204
+ // Replace 375 with your design width or leave default (mobile)
205
+ @include responsive-scale-variables(1440px, 768px, 375px);
206
+ // Or use defaults: @include responsive-scale-variables();
69
207
  }
208
+ ```
209
+
210
+ #### SvelteKit
70
211
 
71
- @media (max-width: 767px) {
72
- .element {
73
- border-radius: calc(var(--computed-mobile-scale-factor-px) * 10);
74
- }
212
+ ```scss
213
+ // src/app.scss
214
+ @import "responsive-scale-mixins";
215
+
216
+ :root {
217
+ // Customize for your design system (optional)
218
+
219
+ // Replace 1440 with your design width or leave default (desktop)
220
+ // Replace 768 with your design width or leave default (tablet)
221
+ // Replace 375 with your design width or leave default (mobile)
222
+ @include responsive-scale-variables(1440px, 768px, 375px);
223
+ // Or use defaults: @include responsive-scale-variables();
75
224
  }
76
225
  ```
77
226
 
78
- ### Different Values for Desktop & Mobile
227
+ #### Astro
228
+
229
+ ```scss
230
+ // src/styles/global.scss
231
+ @import "responsive-scale-mixins";
232
+
233
+ :root {
234
+ // Customize for your design system (optional)
79
235
 
80
- When desktop and mobile need different values:
236
+ // Replace 1440 with your design width or leave default (desktop)
237
+ // Replace 768 with your design width or leave default (tablet)
238
+ // Replace 375 with your design width or leave default (mobile)
239
+ @include responsive-scale-variables(1440px, 768px, 375px);
240
+ // Or use defaults: @include responsive-scale-variables();
241
+ }
242
+ ```
243
+
244
+ #### CSS Modules
81
245
 
82
246
  ```scss
83
- // Two parameters - desktop and mobile values
84
- .element {
247
+ // styles.module.scss
248
+ @import "~responsive-scale-mixins";
249
+
250
+ // Variables must be in global scope
251
+ // In your main CSS file:
252
+ :root {
253
+ // Replace 1440 with your design width or leave default (desktop)
254
+ // Replace 768 with your design width or leave default (tablet)
255
+ // Replace 375 with your design width or leave default (mobile)
256
+ --computed-scale-factor-px: calc(100vw / 1920);
257
+ --computed-scale-factor-rem: calc(100vw / 1920 / 16);
258
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
259
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
260
+ --computed-mobile-scale-factor-px: calc(100vw / 390);
261
+ --computed-mobile-scale-factor-rem: calc(100vw / 390 / 16);
262
+ --tablet-proportion-scale-factor: calc((100vw - 390px) / (1920px - 390px));
263
+ }
264
+
265
+ // Then in your module
266
+ .myClass {
85
267
  @include responsive-scale(font-size, 24, 16);
86
- @include responsive-scale(height, 60, 40);
87
268
  }
88
269
  ```
89
270
 
90
- **Output:**
271
+ #### Tailwind CSS Integration
91
272
 
92
- ```css
93
- .element {
94
- font-size: calc(var(--computed-scale-factor-px) * 24);
95
- height: calc(var(--computed-scale-factor-px) * 60);
96
- }
273
+ ```scss
274
+ // styles/main.scss
275
+ @import "~responsive-scale-mixins";
97
276
 
98
- @media (min-width: 768px) and (max-width: 991px) {
99
- .element {
100
- font-size: calc(
101
- var(--computed-tablet-scale-factor-px) *
102
- (16 + var(--tablet-proportion-scale-factor) * (24 - 16))
103
- );
104
- height: calc(
105
- var(--computed-tablet-scale-factor-px) *
106
- (40 + var(--tablet-proportion-scale-factor) * (60 - 40))
107
- );
108
- }
277
+ :root {
278
+ @include responsive-scale-variables();
109
279
  }
110
280
 
111
- @media (max-width: 767px) {
112
- .element {
113
- font-size: calc(var(--computed-mobile-scale-factor-px) * 16);
114
- height: calc(var(--computed-mobile-scale-factor-px) * 40);
115
- }
281
+ // Use alongside Tailwind
282
+ .custom-element {
283
+ @include responsive-scale(padding, 20 40, 10 20);
284
+ @apply bg-blue-500 text-white; // Tailwind classes still work
116
285
  }
117
286
  ```
118
287
 
119
- ## Advanced Usage
120
-
121
- ### REM Units
288
+ #### Styled Components
122
289
 
123
290
  ```scss
124
- .element {
125
- @include responsive-scale(font-size, 2, 1.5, rem);
126
- }
291
+ // If using styled-components with SCSS preprocessing
292
+ import styled from 'styled-components';
293
+ import './styles/responsive-mixins.scss'; // Import in your main file
294
+
295
+ const StyledComponent = styled.div`
296
+ ${props => props.theme.responsiveScale('font-size', 24, 16)}
297
+ `;
127
298
  ```
128
299
 
129
- ### Multi-Value Properties
300
+ ### Basic Usage
130
301
 
131
302
  ```scss
132
- .element {
133
- @include responsive-scale(padding, 20 40 20 40, 10 20 10 20);
134
- @include responsive-scale(margin, 0 10, 0 5);
303
+ // In your main SCSS file
304
+ @import "~responsive-scale-mixins";
305
+
306
+ // Include variables in your root element (required)
307
+ :root {
308
+ @include responsive-scale-variables();
309
+ }
310
+
311
+ // Use the mixin anywhere
312
+ .my-element {
313
+ @include responsive-scale(font-size, 24, 16);
314
+ @include responsive-scale(padding, 20 40, 10 20);
135
315
  }
136
316
  ```
137
317
 
138
- ## 📏 Property Examples
318
+ ## 📖 API Reference
319
+
320
+ ### `responsive-scale-variables($desktop-width, $tablet-width, $mobile-width)`
321
+
322
+ Defines the CSS custom properties for scaling calculations.
323
+
324
+ **Parameters:**
325
+
326
+ - `$desktop-width`: Design width for desktop (default: 1920px)
327
+ - `$tablet-width`: Design width for tablet (default: 768px)
328
+ - `$mobile-width`: Design width for mobile (default: 390px)
329
+
330
+ ### `responsive-scale($property, $desktop-value, $mobile-value, $unit, $is-percentage, $desktop-relative, $mobile-relative, $important)`
331
+
332
+ The main responsive scaling mixin.
333
+
334
+ **Parameters:**
335
+
336
+ - `$property`: CSS property name (e.g., `font-size`, `padding`)
337
+ - `$desktop-value`: Value for desktop screens
338
+ - `$mobile-value`: Value for mobile screens
339
+ - `$unit`: Unit for scaling (`px` or `rem`, default: `px`)
340
+ - `$is-percentage`: Whether the value is a percentage (default: `false`)
341
+ - `$desktop-relative`: Base value for percentage calculations on desktop
342
+ - `$mobile-relative`: Base value for percentage calculations on mobile
343
+ - `$important`: String to append (e.g., `" !important"` for override, default: `null`)
344
+
345
+ ## 🎯 Examples
139
346
 
140
347
  ### Typography
141
348
 
142
349
  ```scss
143
- .text {
144
- @include responsive-scale(font-size, 24, 16);
145
- @include responsive-scale(line-height, 1.5, 1.4);
146
- @include responsive-scale(letter-spacing, -0.5, -0.3);
350
+ .hero-title {
351
+ @include responsive-scale(font-size, 48, 32);
352
+ @include responsive-scale(line-height, 1.2, 1.3);
353
+ @include responsive-scale(letter-spacing, -1, -0.5);
147
354
  }
148
355
  ```
149
356
 
@@ -151,8 +358,8 @@ When desktop and mobile need different values:
151
358
 
152
359
  ```scss
153
360
  .card {
154
- @include responsive-scale(padding, 20 30, 15 20);
155
- @include responsive-scale(margin, 0 0 20 0, 0 0 15 0);
361
+ @include responsive-scale(padding, 32 48, 16 24);
362
+ @include responsive-scale(margin-bottom, 24, 16);
156
363
  }
157
364
  ```
158
365
 
@@ -161,116 +368,441 @@ When desktop and mobile need different values:
161
368
  ```scss
162
369
  .button {
163
370
  @include responsive-scale(width, 200, 150);
164
- @include responsive-scale(height, 50, 40);
371
+ @include responsive-scale(height, 56, 44);
165
372
  @include responsive-scale(border-radius, 8, 6);
166
373
  }
167
374
  ```
168
375
 
169
- ### Borders & Shadows
376
+ ### Percentage-based Properties
170
377
 
171
378
  ```scss
172
- .box {
173
- @include responsive-scale(border-width, 2, 1);
174
- @include responsive-scale(border-radius, 10, 8);
379
+ .text {
380
+ // Letter-spacing as 1% of font-size
381
+ @include responsive-scale(letter-spacing, 1, 1, px, true, 48, 32);
175
382
  }
176
383
  ```
177
384
 
178
- ## 📊 Percentage Properties
179
-
180
- For properties that are percentages of other values:
385
+ ### Override Specificity
181
386
 
182
387
  ```scss
183
- .element {
388
+ .override-bootstrap {
184
389
  @include responsive-scale(
185
- letter-spacing,
186
- -1.5,
187
- // Desktop percentage
188
- -1.5,
189
- // Mobile percentage
190
- px,
191
- true,
192
- // Is percentage-based
390
+ font-size,
193
391
  24,
194
- // Desktop base value (font-size)
195
- 16 // Mobile base value (font-size)
392
+ 16,
393
+ px,
394
+ false,
395
+ null,
396
+ null,
397
+ " !important"
398
+ );
399
+ @include responsive-scale(
400
+ padding,
401
+ 16 32,
402
+ 8 16,
403
+ px,
404
+ false,
405
+ null,
406
+ null,
407
+ " !important"
196
408
  );
197
409
  }
198
410
  ```
199
411
 
200
- **Output:**
412
+ ## 🔧 Configuration
413
+
414
+ ### Custom Design Widths
415
+
416
+ Easily customize the design widths to match your project's breakpoints:
201
417
 
202
- ```css
418
+ ```scss
419
+ :root {
420
+ // Replace 1440 with your design width or leave default (desktop)
421
+ // Replace 768 with your design width or leave default (tablet)
422
+ // Replace 375 with your design width or leave default (mobile)
423
+
424
+ // Custom design widths (desktop, tablet, mobile)
425
+ @include responsive-scale-variables(1440px, 768px, 375px);
426
+ // Or use defaults: @include responsive-scale-variables();
427
+ }
428
+ ```
429
+
430
+ **Default values:**
431
+
432
+ - Desktop: 1920px
433
+ - Tablet: 768px
434
+ - Mobile: 390px
435
+
436
+ ### REM Units
437
+
438
+ ```scss
203
439
  .element {
204
- letter-spacing: calc(-1.5 / 100 * (var(--computed-scale-factor-px) * 24));
440
+ @include responsive-scale(font-size, 3, 2, rem); // 3rem / 2rem
205
441
  }
442
+ ```
443
+
444
+ ### Manual CSS Variables (Alternative)
445
+
446
+ If you prefer manual control, you can set the CSS variables directly:
447
+
448
+ ```scss
449
+ :root {
450
+ // Replace 1440 with your design width or leave default (desktop)
451
+ // Replace 768 with your design width or leave default (tablet)
452
+ // Replace 375 with your design width or leave default (mobile)
453
+ --computed-scale-factor-px: calc(100vw / 1440); // Your desktop width
454
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
455
+ --computed-tablet-scale-factor-px: calc(100vw / 768); // Your tablet width
456
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
457
+ --computed-mobile-scale-factor-px: calc(100vw / 375); // Your mobile width
458
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
459
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
460
+ }
461
+ ```
206
462
 
207
- @media (min-width: 768px) and (max-width: 991px) {
208
- .element {
209
- letter-spacing: calc(
210
- -1.5 / 100 *
211
- (
212
- var(--computed-tablet-scale-factor-px) *
213
- (16 + var(--tablet-proportion-scale-factor) * (24 - 16))
214
- )
215
- );
216
- }
463
+ ## 🔧 Troubleshooting
464
+
465
+ If the `@include responsive-scale-variables()` mixin doesn't work in your setup (e.g., due to SCSS compilation issues), use the manual CSS variables approach. Below are manual setups for each framework:
466
+
467
+ ### Why the Manual Approach Works
468
+
469
+ The `@include responsive-scale-variables()` mixin may fail in certain SCSS compilation environments (like some Next.js setups) because the imported mixins aren't processed correctly. The manual CSS variables approach bypasses this by directly defining the required `--computed-scale-factor-*` variables in `:root`.
470
+
471
+ ### Next.js (App Router) - Manual Setup
472
+
473
+ ```scss
474
+ // app/globals.css or app/styles/globals.scss
475
+ :root {
476
+ // Replace 1440 with your design width or leave default (desktop)
477
+ // Replace 768 with your design width or leave default (tablet)
478
+ // Replace 375 with your design width or leave default (mobile)
479
+ --computed-scale-factor-px: calc(100vw / 1440); // Your design desktop width
480
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
481
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
482
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
483
+ --computed-mobile-scale-factor-px: calc(100vw / 375);
484
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
485
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
217
486
  }
218
487
 
219
- @media (max-width: 767px) {
220
- .element {
221
- letter-spacing: calc(
222
- -1.5 / 100 * (var(--computed-mobile-scale-factor-px) * 16)
223
- );
224
- }
488
+ // In component files
489
+ @import "responsive-scale-mixins";
490
+ .my-element {
491
+ @include responsive-scale(font-size, 24, 16);
225
492
  }
226
493
  ```
227
494
 
228
- ## 💡 Tips & Best Practices
495
+ ### Next.js (Pages Router) - Manual Setup
229
496
 
230
- ### ✅ Do's
497
+ ```scss
498
+ // styles/globals.scss
499
+ :root {
500
+ // Replace 1440 with your design width or leave default (desktop)
501
+ // Replace 768 with your design width or leave default (tablet)
502
+ // Replace 375 with your design width or leave default (mobile)
503
+ --computed-scale-factor-px: calc(100vw / 1440);
504
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
505
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
506
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
507
+ --computed-mobile-scale-factor-px: calc(100vw / 375);
508
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
509
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
510
+ }
231
511
 
232
- - Use consistent units (px for most cases, rem for typography)
233
- - Test on multiple screen sizes
234
- - Use the same base values from your Figma design
235
- - Combine with your existing CSS variables
512
+ // In component files
513
+ @import "responsive-scale-mixins";
514
+ ```
236
515
 
237
- ### Don'ts
516
+ ### Create React App - Manual Setup
238
517
 
239
- - Don't mix units in the same property
240
- - Don't use negative values for dimensions
241
- - Don't forget to import the mixins
518
+ ```scss
519
+ // src/index.scss
520
+ :root {
521
+ // Replace 1440 with your design width or leave default (desktop)
522
+ // Replace 768 with your design width or leave default (tablet)
523
+ // Replace 375 with your design width or leave default (mobile)
524
+ --computed-scale-factor-px: calc(100vw / 1440);
525
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
526
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
527
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
528
+ --computed-mobile-scale-factor-px: calc(100vw / 375);
529
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
530
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
531
+ }
242
532
 
243
- ### 🎨 Visual Guide
533
+ // In component files
534
+ @import "responsive-scale-mixins";
535
+ ```
536
+
537
+ ### Vue.js - Manual Setup
538
+
539
+ ```scss
540
+ // src/assets/styles/main.scss
541
+ :root {
542
+ // Replace 1440 with your design width or leave default (desktop)
543
+ // Replace 768 with your design width or leave default (tablet)
544
+ // Replace 375 with your design width or leave default (mobile)
545
+ --computed-scale-factor-px: calc(100vw / 1440);
546
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
547
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
548
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
549
+ --computed-mobile-scale-factor-px: calc(100vw / 375);
550
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
551
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
552
+ }
244
553
 
554
+ // In component styles
555
+ @import "responsive-scale-mixins";
245
556
  ```
246
- Desktop (≥992px) → Uses desktop scale factor
247
- Tablet (768-991px) Auto-interpolated values
248
- Mobile (≤767px) → Uses mobile scale factor
557
+
558
+ ### Angular - Manual Setup
559
+
560
+ ```scss
561
+ // src/styles.scss
562
+ :root {
563
+ // Replace 1440 with your design width or leave default (desktop)
564
+ // Replace 768 with your design width or leave default (tablet)
565
+ // Replace 375 with your design width or leave default (mobile)
566
+ --computed-scale-factor-px: calc(100vw / 1440);
567
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
568
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
569
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
570
+ --computed-mobile-scale-factor-px: calc(100vw / 375);
571
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
572
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
573
+ }
574
+
575
+ // In component styles
576
+ @import "responsive-scale-mixins";
249
577
  ```
250
578
 
251
- ### 🔧 Customization
579
+ ### Vite + Vue/React - Manual Setup
252
580
 
253
- Adjust scale factors in `global.scss`:
581
+ ```scss
582
+ // src/styles/main.scss
583
+ :root {
584
+ // Replace 1440 with your design width or leave default (desktop)
585
+ // Replace 768 with your design width or leave default (tablet)
586
+ // Replace 375 with your design width or leave default (mobile)
587
+ --computed-scale-factor-px: calc(100vw / 1440);
588
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
589
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
590
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
591
+ --computed-mobile-scale-factor-px: calc(100vw / 375);
592
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
593
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
594
+ }
595
+
596
+ // In components
597
+ @import "responsive-scale-mixins";
598
+ ```
599
+
600
+ ### Gatsby - Manual Setup
254
601
 
255
602
  ```scss
256
- --scale-factor: calc(100vw / 1920); // Change desktop width
257
- --mobile-scale-factor: calc(100vw / 375); // Change mobile width
603
+ // src/styles/global.scss
604
+ :root {
605
+ // Replace 1440 with your design width or leave default (desktop)
606
+ // Replace 768 with your design width or leave default (tablet)
607
+ // Replace 375 with your design width or leave default (mobile)
608
+ --computed-scale-factor-px: calc(100vw / 1440);
609
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
610
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
611
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
612
+ --computed-mobile-scale-factor-px: calc(100vw / 375);
613
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
614
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
615
+ }
616
+
617
+ // In components
618
+ @import "responsive-scale-mixins";
258
619
  ```
259
620
 
260
- ## 📚 Complete Example
621
+ ### Nuxt.js - Manual Setup
261
622
 
262
623
  ```scss
263
- @import "../styles/mixins";
624
+ // assets/styles/main.scss
625
+ :root {
626
+ // Replace 1440 with your design width or leave default (desktop)
627
+ // Replace 768 with your design width or leave default (tablet)
628
+ // Replace 375 with your design width or leave default (mobile)
629
+ --computed-scale-factor-px: calc(100vw / 1440);
630
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
631
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
632
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
633
+ --computed-mobile-scale-factor-px: calc(100vw / 375);
634
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
635
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
636
+ }
264
637
 
265
- .hero-button {
266
- @include responsive-scale(font-size, 20, 16);
267
- @include responsive-scale(padding, 15 30, 12 24);
268
- @include responsive-scale(border-radius, 8, 6);
269
- @include responsive-scale(height, 50, 44);
638
+ // In components
639
+ @import "responsive-scale-mixins";
640
+ ```
641
+
642
+ ### SvelteKit - Manual Setup
643
+
644
+ ```scss
645
+ // src/app.scss
646
+ :root {
647
+ // Replace 1440 with your design width or leave default (desktop)
648
+ // Replace 768 with your design width or leave default (tablet)
649
+ // Replace 375 with your design width or leave default (mobile)
650
+ --computed-scale-factor-px: calc(100vw / 1440);
651
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
652
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
653
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
654
+ --computed-mobile-scale-factor-px: calc(100vw / 375);
655
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
656
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
657
+ }
658
+
659
+ // In components
660
+ @import "responsive-scale-mixins";
661
+ ```
662
+
663
+ ### Astro - Manual Setup
664
+
665
+ ```scss
666
+ // src/styles/global.scss
667
+ :root {
668
+ // Replace 1440 with your design width or leave default (desktop)
669
+ // Replace 768 with your design width or leave default (tablet)
670
+ // Replace 375 with your design width or leave default (mobile)
671
+ --computed-scale-factor-px: calc(100vw / 1440);
672
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
673
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
674
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
675
+ --computed-mobile-scale-factor-px: calc(100vw / 375);
676
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
677
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
678
+ }
679
+
680
+ // In components
681
+ @import "responsive-scale-mixins";
682
+ ```
683
+
684
+ ### CSS Modules - Manual Setup
685
+
686
+ ```scss
687
+ // In your global CSS file (e.g., globals.scss)
688
+ :root {
689
+ // Replace 1440 with your design width or leave default (desktop)
690
+ // Replace 768 with your design width or leave default (tablet)
691
+ // Replace 375 with your design width or leave default (mobile)
692
+ --computed-scale-factor-px: calc(100vw / 1920);
693
+ --computed-scale-factor-rem: calc(100vw / 1920 / 16);
694
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
695
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
696
+ --computed-mobile-scale-factor-px: calc(100vw / 390);
697
+ --computed-mobile-scale-factor-rem: calc(100vw / 390 / 16);
698
+ --tablet-proportion-scale-factor: calc((100vw - 390px) / (1920px - 390px));
699
+ }
700
+
701
+ // In your module files
702
+ @import "responsive-scale-mixins";
703
+ .myClass {
704
+ @include responsive-scale(font-size, 24, 16);
705
+ }
706
+ ```
707
+
708
+ ### Tailwind CSS - Manual Setup
709
+
710
+ ```scss
711
+ // styles/main.scss
712
+ :root {
713
+ // Replace 1440 with your design width or leave default (desktop)
714
+ // Replace 768 with your design width or leave default (tablet)
715
+ // Replace 375 with your design width or leave default (mobile)
716
+ --computed-scale-factor-px: calc(100vw / 1440);
717
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
718
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
719
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
720
+ --computed-mobile-scale-factor-px: calc(100vw / 375);
721
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
722
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
723
+ }
724
+
725
+ // In components
726
+ @import "responsive-scale-mixins";
727
+ .custom-element {
728
+ @include responsive-scale(padding, 20 40, 10 20);
729
+ @apply bg-blue-500 text-white;
730
+ }
731
+ ```
732
+
733
+ ### Styled Components - Manual Setup
270
734
 
271
- // Percentage-based
272
- @include responsive-scale(letter-spacing, -1, -1, px, true, 20, 16);
735
+ ```scss
736
+ // In your global styles
737
+ :root {
738
+ // Replace 1440 with your design width or leave default (desktop)
739
+ // Replace 768 with your design width or leave default (tablet)
740
+ // Replace 375 with your design width or leave default (mobile)
741
+ --computed-scale-factor-px: calc(100vw / 1440);
742
+ --computed-scale-factor-rem: calc(100vw / 1440 / 16);
743
+ --computed-tablet-scale-factor-px: calc(100vw / 768);
744
+ --computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
745
+ --computed-mobile-scale-factor-px: calc(100vw / 375);
746
+ --computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
747
+ --tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
273
748
  }
749
+
750
+ // In styled components with SCSS preprocessing
751
+ import styled from 'styled-components';
752
+ import './styles/responsive-mixins.scss';
753
+
754
+ const StyledComponent = styled.div`
755
+ ${props => props.theme.responsiveScale('font-size', 24, 16)}
756
+ `;
757
+ ```
758
+
759
+ **Note:** Replace `1440`, `768`, `375` with your actual design widths. The manual approach ensures compatibility across all build tools and frameworks.
760
+
761
+ ## 📱 Breakpoints
762
+
763
+ - **Desktop**: ≥992px (scales from desktop design width)
764
+ - **Tablet**: 768px - 991px (interpolated values)
765
+ - **Mobile**: ≤767px (scales from mobile design width)
766
+
767
+ ## 🛠 Development
768
+
769
+ ### Building
770
+
771
+ ```bash
772
+ npm install
773
+ # No build step required - pure SCSS
774
+ ```
775
+
776
+ ### Testing
777
+
778
+ ```bash
779
+ npm test
274
780
  ```
275
781
 
276
- This creates a perfectly responsive button that scales beautifully across all devices! 🎉
782
+ ## 🤝 Contributing
783
+
784
+ 1. Fork the repository
785
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
786
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
787
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
788
+ 5. Open a Pull Request
789
+
790
+ ## 📄 License
791
+
792
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
793
+
794
+ ## 🙏 Acknowledgments
795
+
796
+ - Inspired by Figma's responsive design principles
797
+ - Built for modern web development workflows
798
+ - Compatible with CSS Modules, Styled Components, and traditional CSS
799
+
800
+ ## 📞 Support
801
+
802
+ - 📧 Email: saheedodulaja@gmail.com
803
+ - 🐛 Issues: [GitHub Issues](https://github.com/Sidodus/responsive-scale-mixins/issues)
804
+ - 📖 Docs: [Full Documentation](https://github.com/Sidodus/responsive-scale-mixins#readme)
805
+
806
+ ---
807
+
808
+ **Made with ❤️ by [Saheed Odulaja](https://github.com/Sidodus)**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "responsive-scale-mixins",
3
- "version": "1.0.0",
3
+ "version": "1.1.2",
4
4
  "description": "Powerful SCSS mixins for responsive design with Figma proportions. Automatically scales typography, spacing, and dimensions across desktop, tablet, and mobile breakpoints.",
5
5
  "main": "index.scss",
6
6
  "style": "index.scss",
@@ -38,7 +38,7 @@
38
38
  "license": "MIT",
39
39
  "repository": {
40
40
  "type": "git",
41
- "url": "https://github.com/Sidodus/responsive-scale-mixins.git"
41
+ "url": "git+https://github.com/Sidodus/responsive-scale-mixins.git"
42
42
  },
43
43
  "bugs": {
44
44
  "url": "https://github.com/Sidodus/responsive-scale-mixins.git/issues"
package/scss/_mixins.scss CHANGED
@@ -1,12 +1,12 @@
1
1
  /* // ✅ Figma Proportions: Maintains the same proportions as the Figma design.
2
2
 
3
- // // Heres a SCSS mixin that dynamically calculates font-size, line-height, padding, margins, and other scalable properties across desktop, tablet, and mobile screens.
3
+ // // Here's a SCSS mixin that dynamically calculates font-size, line-height, padding, margins, and other scalable properties across desktop, tablet, and mobile screens.
4
4
  // ✅ Consistent Scaling: No need to manually adjust for medium screens.
5
5
  // ✅ Reusable: Works for font-size, line-height, margins, paddings, etc.
6
6
  // ✅ Automatic Scaling: Dynamically scales values based on the screen size.
7
7
 
8
8
  // 📌 How to Use It
9
- // Import the mixins in your SCSS file: @import "../styles/mixins";
9
+ // Import the mixins in your SCSS file: @import "~responsive-scale-mixins/scss/mixins";
10
10
  // .title {
11
11
  // @include responsive-scale(font-size, 40, 24);
12
12
  // @include responsive-scale(padding, 20 73, 8 16); // Multi-value
@@ -16,10 +16,11 @@
16
16
  // @include responsive-scale(letter-spacing, -1.5, -1.5, px, true, 40, 24);
17
17
  // }
18
18
 
19
- // Parameters: property, desktop-value, mobile-value, unit (default px), is-percentage (default false), desktop-relative, mobile-relative
19
+ // Parameters: property, desktop-value, mobile-value, unit (default px), is-percentage (default false), desktop-relative, mobile-relative, important (default null)
20
20
  // Pass values as numbers (e.g., 20 for 20px, 20 73 for 20px 73px).
21
21
  // Tablet values are automatically interpolated using the tablet-proportion-scale-factor.
22
22
  // For percentage-based values, provide the percentage for desktop and mobile, and the base values (e.g., font-size for letter-spacing).
23
+ // Pass " !important" as the important parameter to append !important to the generated CSS rules.
23
24
  // Media queries: Desktop (default), Tablet (768-991px), Mobile (≤767px). */
24
25
 
25
26
  @function scaled-value($val, $scale-var, $unit: px) {
@@ -33,7 +34,8 @@
33
34
  $unit: px,
34
35
  $is-percentage: false,
35
36
  $desktop-relative: null,
36
- $mobile-relative: null
37
+ $mobile-relative: null,
38
+ $important: null
37
39
  ) {
38
40
  $scale-factor: if(
39
41
  $unit == px,
@@ -44,9 +46,10 @@
44
46
  // If it's a percentage-based value (like letter-spacing), scale it based on the relative property
45
47
  @if $is-percentage == true {
46
48
  @if $desktop-relative != null {
47
- #{$property}: calc(
49
+ $calc-value: calc(
48
50
  #{$desktop-value} / 100 * (var(#{$scale-factor}) * #{$desktop-relative})
49
51
  );
52
+ #{$property}: #{$calc-value}#{$important};
50
53
  }
51
54
 
52
55
  @media screen and (min-width: 768px) and (max-width: 991px) {
@@ -56,7 +59,7 @@
56
59
  unquote("--computed-tablet-scale-factor-rem")
57
60
  );
58
61
  @if $desktop-relative != null and $mobile-relative != null {
59
- #{$property}: calc(
62
+ $calc-value: calc(
60
63
  #{$mobile-value} /
61
64
  100 *
62
65
  (
@@ -68,6 +71,7 @@
68
71
  )
69
72
  )
70
73
  );
74
+ #{$property}: #{$calc-value}#{$important};
71
75
  }
72
76
  }
73
77
 
@@ -78,11 +82,12 @@
78
82
  unquote("--computed-mobile-scale-factor-rem")
79
83
  );
80
84
  @if $mobile-relative != null {
81
- #{$property}: calc(
85
+ $calc-value: calc(
82
86
  #{$mobile-value} /
83
87
  100 *
84
88
  (var(#{$mobile-scale-factor}) * #{$mobile-relative})
85
89
  );
90
+ #{$property}: #{$calc-value}#{$important};
86
91
  }
87
92
  }
88
93
  } @else {
@@ -95,9 +100,10 @@
95
100
  scaled-value($val, $scale-factor, $unit)
96
101
  );
97
102
  }
98
- #{$property}: $desktop-scaled;
103
+ #{$property}: #{$desktop-scaled}#{$important};
99
104
  } @else {
100
- #{$property}: scaled-value($desktop-value, $scale-factor, $unit);
105
+ $scaled-value: scaled-value($desktop-value, $scale-factor, $unit);
106
+ #{$property}: #{$scaled-value}#{$important};
101
107
  }
102
108
 
103
109
  @media screen and (min-width: 768px) and (max-width: 991px) {
@@ -123,9 +129,9 @@
123
129
  )
124
130
  );
125
131
  }
126
- #{$property}: $tablet-scaled;
132
+ #{$property}: #{$tablet-scaled}#{$important};
127
133
  } @else {
128
- #{$property}: calc(
134
+ $calc-value: calc(
129
135
  var(#{$tablet-scale-factor}) *
130
136
  (
131
137
  #{$mobile-value} +
@@ -133,6 +139,7 @@
133
139
  (#{$desktop-value} - #{$mobile-value})
134
140
  )
135
141
  );
142
+ #{$property}: #{$calc-value}#{$important};
136
143
  }
137
144
  }
138
145
 
@@ -150,9 +157,10 @@
150
157
  scaled-value($val, $mobile-scale-factor, $unit)
151
158
  );
152
159
  }
153
- #{$property}: $mobile-scaled;
160
+ #{$property}: #{$mobile-scaled}#{$important};
154
161
  } @else {
155
- #{$property}: scaled-value($mobile-value, $mobile-scale-factor, $unit);
162
+ $scaled-value: scaled-value($mobile-value, $mobile-scale-factor, $unit);
163
+ #{$property}: #{$scaled-value}#{$important};
156
164
  }
157
165
  }
158
166
  }