responsive-scale-mixins 1.0.0 → 1.1.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.
- package/README.md +341 -157
- package/package.json +2 -2
- package/scss/_mixins.scss +21 -13
package/README.md
CHANGED
|
@@ -2,148 +2,313 @@
|
|
|
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
|
+
[](https://badge.fury.io/js/responsive-scale-mixins)
|
|
6
|
+
[](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
|
-
|
|
44
|
+
// app/globals.css or app/styles/globals.scss
|
|
45
|
+
@import "~responsive-scale-mixins";
|
|
9
46
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
@include responsive-scale(
|
|
13
|
-
@include responsive-scale(
|
|
47
|
+
:root {
|
|
48
|
+
// Define CSS variables globally (required)
|
|
49
|
+
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
50
|
+
// Or use defaults: @include responsive-scale-variables();
|
|
14
51
|
}
|
|
52
|
+
|
|
53
|
+
// Import in app/layout.tsx: import './globals.css'
|
|
15
54
|
```
|
|
16
55
|
|
|
17
|
-
|
|
56
|
+
#### Next.js (Pages Router)
|
|
57
|
+
|
|
58
|
+
```scss
|
|
59
|
+
// styles/globals.scss
|
|
60
|
+
@import "~responsive-scale-mixins";
|
|
61
|
+
|
|
62
|
+
:root {
|
|
63
|
+
// Define CSS variables globally (required)
|
|
64
|
+
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
65
|
+
// Or use defaults: @include responsive-scale-variables();
|
|
66
|
+
}
|
|
18
67
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
- [Advanced Usage](#advanced-usage)
|
|
22
|
-
- [Property Examples](#property-examples)
|
|
23
|
-
- [Percentage Properties](#percentage-properties)
|
|
24
|
-
- [Tips & Best Practices](#tips--best-practices)
|
|
68
|
+
// Import in pages/_app.js: import '../styles/globals.scss'
|
|
69
|
+
```
|
|
25
70
|
|
|
26
|
-
|
|
71
|
+
**Next.js Setup:**
|
|
27
72
|
|
|
28
|
-
|
|
73
|
+
- **App Router**: Put `:root` in `app/globals.css` (imported in `layout.tsx`)
|
|
74
|
+
- **Pages Router**: Put `:root` in `styles/globals.scss` (imported in `pages/_app.js`)
|
|
75
|
+
- The `:root` selector defines global CSS custom properties accessible everywhere
|
|
29
76
|
|
|
30
|
-
|
|
77
|
+
#### Create React App
|
|
31
78
|
|
|
32
79
|
```scss
|
|
33
|
-
|
|
80
|
+
// src/index.scss or src/styles/main.scss
|
|
81
|
+
@import "~responsive-scale-mixins";
|
|
82
|
+
|
|
83
|
+
:root {
|
|
84
|
+
// Define CSS variables globally (required)
|
|
85
|
+
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
86
|
+
// Or use defaults: @include responsive-scale-variables();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Import in src/index.js: import './index.scss'
|
|
34
90
|
```
|
|
35
91
|
|
|
36
|
-
|
|
92
|
+
**Create React App Setup:**
|
|
93
|
+
|
|
94
|
+
- Put `:root` in your main SCSS file (e.g., `src/index.scss`)
|
|
95
|
+
- Import the SCSS file in `src/index.js`
|
|
96
|
+
- The `:root` selector makes CSS variables available app-wide
|
|
97
|
+
|
|
98
|
+
#### Vue.js
|
|
99
|
+
|
|
100
|
+
```scss
|
|
101
|
+
// src/assets/styles/main.scss
|
|
102
|
+
@import "~responsive-scale-mixins";
|
|
37
103
|
|
|
38
|
-
|
|
104
|
+
:root {
|
|
105
|
+
// Define CSS variables globally (required)
|
|
106
|
+
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
107
|
+
// Or use defaults: @include responsive-scale-variables();
|
|
108
|
+
}
|
|
39
109
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
- `--computed-mobile-scale-factor-px` (Mobile: 390px)
|
|
110
|
+
// Import in src/main.js: import './assets/styles/main.scss'
|
|
111
|
+
```
|
|
43
112
|
|
|
44
|
-
|
|
113
|
+
**Vue.js Setup:**
|
|
45
114
|
|
|
46
|
-
|
|
115
|
+
- Put `:root` in your global SCSS file
|
|
116
|
+
- Import in `src/main.js` or use in a global style resource
|
|
117
|
+
- The `:root` selector defines app-wide CSS variables
|
|
47
118
|
|
|
48
|
-
|
|
119
|
+
#### Angular
|
|
49
120
|
|
|
50
121
|
```scss
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
122
|
+
// src/styles.scss (global styles)
|
|
123
|
+
@import "~responsive-scale-mixins";
|
|
124
|
+
|
|
125
|
+
:root {
|
|
126
|
+
// Define CSS variables globally (required)
|
|
127
|
+
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
128
|
+
// Or use defaults: @include responsive-scale-variables();
|
|
55
129
|
}
|
|
130
|
+
|
|
131
|
+
// This file is automatically included by Angular CLI
|
|
56
132
|
```
|
|
57
133
|
|
|
58
|
-
**
|
|
134
|
+
**Angular Setup:**
|
|
59
135
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
136
|
+
- Put `:root` in `src/styles.scss` (automatically included by Angular CLI)
|
|
137
|
+
- No manual import needed - Angular handles it
|
|
138
|
+
- The `:root` selector defines global CSS variables
|
|
139
|
+
|
|
140
|
+
#### Vite + Vue/React
|
|
64
141
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
142
|
+
```scss
|
|
143
|
+
// src/styles/main.scss
|
|
144
|
+
@import "responsive-scale-mixins";
|
|
145
|
+
|
|
146
|
+
:root {
|
|
147
|
+
// Customize for your design system (optional)
|
|
148
|
+
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
149
|
+
// Or use defaults: @include responsive-scale-variables();
|
|
69
150
|
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### Gatsby
|
|
70
154
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
155
|
+
```scss
|
|
156
|
+
// src/styles/global.scss
|
|
157
|
+
@import "~responsive-scale-mixins";
|
|
158
|
+
|
|
159
|
+
:root {
|
|
160
|
+
// Customize for your design system (optional)
|
|
161
|
+
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
162
|
+
// Or use defaults: @include responsive-scale-variables();
|
|
75
163
|
}
|
|
76
164
|
```
|
|
77
165
|
|
|
78
|
-
|
|
166
|
+
#### Nuxt.js
|
|
79
167
|
|
|
80
|
-
|
|
168
|
+
```scss
|
|
169
|
+
// assets/styles/main.scss
|
|
170
|
+
@import "~responsive-scale-mixins";
|
|
171
|
+
|
|
172
|
+
:root {
|
|
173
|
+
// Customize for your design system (optional)
|
|
174
|
+
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
175
|
+
// Or use defaults: @include responsive-scale-variables();
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### SvelteKit
|
|
81
180
|
|
|
82
181
|
```scss
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
182
|
+
// src/app.scss
|
|
183
|
+
@import "responsive-scale-mixins";
|
|
184
|
+
|
|
185
|
+
:root {
|
|
186
|
+
// Customize for your design system (optional)
|
|
187
|
+
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
188
|
+
// Or use defaults: @include responsive-scale-variables();
|
|
87
189
|
}
|
|
88
190
|
```
|
|
89
191
|
|
|
90
|
-
|
|
192
|
+
#### Astro
|
|
91
193
|
|
|
92
|
-
```
|
|
93
|
-
.
|
|
94
|
-
|
|
95
|
-
|
|
194
|
+
```scss
|
|
195
|
+
// src/styles/global.scss
|
|
196
|
+
@import "responsive-scale-mixins";
|
|
197
|
+
|
|
198
|
+
:root {
|
|
199
|
+
// Customize for your design system (optional)
|
|
200
|
+
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
201
|
+
// Or use defaults: @include responsive-scale-variables();
|
|
96
202
|
}
|
|
203
|
+
```
|
|
97
204
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
205
|
+
#### CSS Modules
|
|
206
|
+
|
|
207
|
+
```scss
|
|
208
|
+
// styles.module.scss
|
|
209
|
+
@import "~responsive-scale-mixins";
|
|
210
|
+
|
|
211
|
+
// Variables must be in global scope
|
|
212
|
+
// In your main CSS file:
|
|
213
|
+
:root {
|
|
214
|
+
--computed-scale-factor-px: calc(100vw / 1920);
|
|
215
|
+
--computed-scale-factor-rem: calc(100vw / 1920 / 16);
|
|
216
|
+
--computed-tablet-scale-factor-px: calc(100vw / 768);
|
|
217
|
+
--computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
|
|
218
|
+
--computed-mobile-scale-factor-px: calc(100vw / 390);
|
|
219
|
+
--computed-mobile-scale-factor-rem: calc(100vw / 390 / 16);
|
|
220
|
+
--tablet-proportion-scale-factor: calc((100vw - 390px) / (1920px - 390px));
|
|
109
221
|
}
|
|
110
222
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
height: calc(var(--computed-mobile-scale-factor-px) * 40);
|
|
115
|
-
}
|
|
223
|
+
// Then in your module
|
|
224
|
+
.myClass {
|
|
225
|
+
@include responsive-scale(font-size, 24, 16);
|
|
116
226
|
}
|
|
117
227
|
```
|
|
118
228
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
### REM Units
|
|
229
|
+
#### Tailwind CSS Integration
|
|
122
230
|
|
|
123
231
|
```scss
|
|
124
|
-
.
|
|
125
|
-
|
|
232
|
+
// styles/main.scss
|
|
233
|
+
@import "~responsive-scale-mixins";
|
|
234
|
+
|
|
235
|
+
:root {
|
|
236
|
+
@include responsive-scale-variables();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Use alongside Tailwind
|
|
240
|
+
.custom-element {
|
|
241
|
+
@include responsive-scale(padding, 20 40, 10 20);
|
|
242
|
+
@apply bg-blue-500 text-white; // Tailwind classes still work
|
|
126
243
|
}
|
|
127
244
|
```
|
|
128
245
|
|
|
129
|
-
|
|
246
|
+
#### Styled Components
|
|
130
247
|
|
|
131
248
|
```scss
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
249
|
+
// If using styled-components with SCSS preprocessing
|
|
250
|
+
import styled from 'styled-components';
|
|
251
|
+
import './styles/responsive-mixins.scss'; // Import in your main file
|
|
252
|
+
|
|
253
|
+
const StyledComponent = styled.div`
|
|
254
|
+
${props => props.theme.responsiveScale('font-size', 24, 16)}
|
|
255
|
+
`;
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Basic Usage
|
|
259
|
+
|
|
260
|
+
```scss
|
|
261
|
+
// In your main SCSS file
|
|
262
|
+
@import "~responsive-scale-mixins";
|
|
263
|
+
|
|
264
|
+
// Include variables in your root element (required)
|
|
265
|
+
:root {
|
|
266
|
+
@include responsive-scale-variables();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Use the mixin anywhere
|
|
270
|
+
.my-element {
|
|
271
|
+
@include responsive-scale(font-size, 24, 16);
|
|
272
|
+
@include responsive-scale(padding, 20 40, 10 20);
|
|
135
273
|
}
|
|
136
274
|
```
|
|
137
275
|
|
|
138
|
-
##
|
|
276
|
+
## 📖 API Reference
|
|
277
|
+
|
|
278
|
+
### `responsive-scale-variables($desktop-width, $tablet-width, $mobile-width)`
|
|
279
|
+
|
|
280
|
+
Defines the CSS custom properties for scaling calculations.
|
|
281
|
+
|
|
282
|
+
**Parameters:**
|
|
283
|
+
|
|
284
|
+
- `$desktop-width`: Design width for desktop (default: 1920px)
|
|
285
|
+
- `$tablet-width`: Design width for tablet (default: 768px)
|
|
286
|
+
- `$mobile-width`: Design width for mobile (default: 390px)
|
|
287
|
+
|
|
288
|
+
### `responsive-scale($property, $desktop-value, $mobile-value, $unit, $is-percentage, $desktop-relative, $mobile-relative, $important)`
|
|
289
|
+
|
|
290
|
+
The main responsive scaling mixin.
|
|
291
|
+
|
|
292
|
+
**Parameters:**
|
|
293
|
+
|
|
294
|
+
- `$property`: CSS property name (e.g., `font-size`, `padding`)
|
|
295
|
+
- `$desktop-value`: Value for desktop screens
|
|
296
|
+
- `$mobile-value`: Value for mobile screens
|
|
297
|
+
- `$unit`: Unit for scaling (`px` or `rem`, default: `px`)
|
|
298
|
+
- `$is-percentage`: Whether the value is a percentage (default: `false`)
|
|
299
|
+
- `$desktop-relative`: Base value for percentage calculations on desktop
|
|
300
|
+
- `$mobile-relative`: Base value for percentage calculations on mobile
|
|
301
|
+
- `$important`: String to append (e.g., `" !important"` for override, default: `null`)
|
|
302
|
+
|
|
303
|
+
## 🎯 Examples
|
|
139
304
|
|
|
140
305
|
### Typography
|
|
141
306
|
|
|
142
307
|
```scss
|
|
143
|
-
.
|
|
144
|
-
@include responsive-scale(font-size,
|
|
145
|
-
@include responsive-scale(line-height, 1.
|
|
146
|
-
@include responsive-scale(letter-spacing, -
|
|
308
|
+
.hero-title {
|
|
309
|
+
@include responsive-scale(font-size, 48, 32);
|
|
310
|
+
@include responsive-scale(line-height, 1.2, 1.3);
|
|
311
|
+
@include responsive-scale(letter-spacing, -1, -0.5);
|
|
147
312
|
}
|
|
148
313
|
```
|
|
149
314
|
|
|
@@ -151,8 +316,8 @@ When desktop and mobile need different values:
|
|
|
151
316
|
|
|
152
317
|
```scss
|
|
153
318
|
.card {
|
|
154
|
-
@include responsive-scale(padding,
|
|
155
|
-
@include responsive-scale(margin,
|
|
319
|
+
@include responsive-scale(padding, 32 48, 16 24);
|
|
320
|
+
@include responsive-scale(margin-bottom, 24, 16);
|
|
156
321
|
}
|
|
157
322
|
```
|
|
158
323
|
|
|
@@ -161,116 +326,135 @@ When desktop and mobile need different values:
|
|
|
161
326
|
```scss
|
|
162
327
|
.button {
|
|
163
328
|
@include responsive-scale(width, 200, 150);
|
|
164
|
-
@include responsive-scale(height,
|
|
329
|
+
@include responsive-scale(height, 56, 44);
|
|
165
330
|
@include responsive-scale(border-radius, 8, 6);
|
|
166
331
|
}
|
|
167
332
|
```
|
|
168
333
|
|
|
169
|
-
###
|
|
334
|
+
### Percentage-based Properties
|
|
170
335
|
|
|
171
336
|
```scss
|
|
172
|
-
.
|
|
173
|
-
|
|
174
|
-
@include responsive-scale(
|
|
337
|
+
.text {
|
|
338
|
+
// Letter-spacing as 1% of font-size
|
|
339
|
+
@include responsive-scale(letter-spacing, 1, 1, px, true, 48, 32);
|
|
175
340
|
}
|
|
176
341
|
```
|
|
177
342
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
For properties that are percentages of other values:
|
|
343
|
+
### Override Specificity
|
|
181
344
|
|
|
182
345
|
```scss
|
|
183
|
-
.
|
|
346
|
+
.override-bootstrap {
|
|
184
347
|
@include responsive-scale(
|
|
185
|
-
|
|
186
|
-
-1.5,
|
|
187
|
-
// Desktop percentage
|
|
188
|
-
-1.5,
|
|
189
|
-
// Mobile percentage
|
|
190
|
-
px,
|
|
191
|
-
true,
|
|
192
|
-
// Is percentage-based
|
|
348
|
+
font-size,
|
|
193
349
|
24,
|
|
194
|
-
|
|
195
|
-
|
|
350
|
+
16,
|
|
351
|
+
px,
|
|
352
|
+
false,
|
|
353
|
+
null,
|
|
354
|
+
null,
|
|
355
|
+
" !important"
|
|
356
|
+
);
|
|
357
|
+
@include responsive-scale(
|
|
358
|
+
padding,
|
|
359
|
+
16 32,
|
|
360
|
+
8 16,
|
|
361
|
+
px,
|
|
362
|
+
false,
|
|
363
|
+
null,
|
|
364
|
+
null,
|
|
365
|
+
" !important"
|
|
196
366
|
);
|
|
197
367
|
}
|
|
198
368
|
```
|
|
199
369
|
|
|
200
|
-
|
|
370
|
+
## 🔧 Configuration
|
|
201
371
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
372
|
+
### Custom Design Widths
|
|
373
|
+
|
|
374
|
+
Easily customize the design widths to match your project's breakpoints:
|
|
206
375
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
(
|
|
212
|
-
var(--computed-tablet-scale-factor-px) *
|
|
213
|
-
(16 + var(--tablet-proportion-scale-factor) * (24 - 16))
|
|
214
|
-
)
|
|
215
|
-
);
|
|
216
|
-
}
|
|
376
|
+
```scss
|
|
377
|
+
:root {
|
|
378
|
+
// Custom design widths (desktop, tablet, mobile)
|
|
379
|
+
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
217
380
|
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
**Default values:**
|
|
384
|
+
|
|
385
|
+
- Desktop: 1920px
|
|
386
|
+
- Tablet: 768px
|
|
387
|
+
- Mobile: 390px
|
|
218
388
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
389
|
+
### REM Units
|
|
390
|
+
|
|
391
|
+
```scss
|
|
392
|
+
.element {
|
|
393
|
+
@include responsive-scale(font-size, 3, 2, rem); // 3rem / 2rem
|
|
225
394
|
}
|
|
226
395
|
```
|
|
227
396
|
|
|
228
|
-
|
|
397
|
+
### Manual CSS Variables (Alternative)
|
|
398
|
+
|
|
399
|
+
If you prefer manual control, you can set the CSS variables directly:
|
|
229
400
|
|
|
230
|
-
|
|
401
|
+
```scss
|
|
402
|
+
:root {
|
|
403
|
+
--computed-scale-factor-px: calc(100vw / 1440); // Your desktop width
|
|
404
|
+
--computed-scale-factor-rem: calc(100vw / 1440 / 16);
|
|
405
|
+
--computed-tablet-scale-factor-px: calc(100vw / 768); // Your tablet width
|
|
406
|
+
--computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
|
|
407
|
+
--computed-mobile-scale-factor-px: calc(100vw / 375); // Your mobile width
|
|
408
|
+
--computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
|
|
409
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
410
|
+
}
|
|
411
|
+
```
|
|
231
412
|
|
|
232
|
-
|
|
233
|
-
- Test on multiple screen sizes
|
|
234
|
-
- Use the same base values from your Figma design
|
|
235
|
-
- Combine with your existing CSS variables
|
|
413
|
+
## 📱 Breakpoints
|
|
236
414
|
|
|
237
|
-
|
|
415
|
+
- **Desktop**: ≥992px (scales from desktop design width)
|
|
416
|
+
- **Tablet**: 768px - 991px (interpolated values)
|
|
417
|
+
- **Mobile**: ≤767px (scales from mobile design width)
|
|
238
418
|
|
|
239
|
-
|
|
240
|
-
- Don't use negative values for dimensions
|
|
241
|
-
- Don't forget to import the mixins
|
|
419
|
+
## 🛠 Development
|
|
242
420
|
|
|
243
|
-
###
|
|
421
|
+
### Building
|
|
244
422
|
|
|
423
|
+
```bash
|
|
424
|
+
npm install
|
|
425
|
+
# No build step required - pure SCSS
|
|
245
426
|
```
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
427
|
+
|
|
428
|
+
### Testing
|
|
429
|
+
|
|
430
|
+
```bash
|
|
431
|
+
npm test
|
|
249
432
|
```
|
|
250
433
|
|
|
251
|
-
|
|
434
|
+
## 🤝 Contributing
|
|
252
435
|
|
|
253
|
-
|
|
436
|
+
1. Fork the repository
|
|
437
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
438
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
439
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
440
|
+
5. Open a Pull Request
|
|
254
441
|
|
|
255
|
-
|
|
256
|
-
--scale-factor: calc(100vw / 1920); // Change desktop width
|
|
257
|
-
--mobile-scale-factor: calc(100vw / 375); // Change mobile width
|
|
258
|
-
```
|
|
442
|
+
## 📄 License
|
|
259
443
|
|
|
260
|
-
|
|
444
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
261
445
|
|
|
262
|
-
|
|
263
|
-
@import "../styles/mixins";
|
|
446
|
+
## 🙏 Acknowledgments
|
|
264
447
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
@include responsive-scale(border-radius, 8, 6);
|
|
269
|
-
@include responsive-scale(height, 50, 44);
|
|
448
|
+
- Inspired by Figma's responsive design principles
|
|
449
|
+
- Built for modern web development workflows
|
|
450
|
+
- Compatible with CSS Modules, Styled Components, and traditional CSS
|
|
270
451
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
452
|
+
## 📞 Support
|
|
453
|
+
|
|
454
|
+
- 📧 Email: saheedodulaja@gmail.com
|
|
455
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/Sidodus/responsive-scale-mixins/issues)
|
|
456
|
+
- 📖 Docs: [Full Documentation](https://github.com/Sidodus/responsive-scale-mixins#readme)
|
|
457
|
+
|
|
458
|
+
---
|
|
275
459
|
|
|
276
|
-
|
|
460
|
+
**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.
|
|
3
|
+
"version": "1.1.1",
|
|
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
|
-
// // Here
|
|
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 "
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
162
|
+
$scaled-value: scaled-value($mobile-value, $mobile-scale-factor, $unit);
|
|
163
|
+
#{$property}: #{$scaled-value}#{$important};
|
|
156
164
|
}
|
|
157
165
|
}
|
|
158
166
|
}
|