responsive-scale-mixins 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Saheed Odulaja
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,276 @@
1
+ # 🎨 Responsive Scale Mixins
2
+
3
+ A powerful SCSS mixin system for creating perfectly responsive designs that maintain Figma proportions across all screen sizes.
4
+
5
+ ## 🚀 Quick Start
6
+
7
+ ```scss
8
+ @import "./src/styles/mixins";
9
+
10
+ // Basic usage
11
+ .my-element {
12
+ @include responsive-scale(font-size, 24, 16);
13
+ @include responsive-scale(padding, 20 40, 10 20);
14
+ }
15
+ ```
16
+
17
+ ## 📋 Table of Contents
18
+
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)
25
+
26
+ ## 🔧 Setup
27
+
28
+ ### 1. Import the Mixins
29
+
30
+ Add this to your SCSS file:
31
+
32
+ ```scss
33
+ @import "../styles/mixins"; // Adjust path as needed
34
+ ```
35
+
36
+ ### 2. CSS Variables (Already configured in `global.scss`)
37
+
38
+ The mixin uses these responsive scale factors:
39
+
40
+ - `--computed-scale-factor-px` (Desktop: 1913px)
41
+ - `--computed-tablet-scale-factor-px` (Tablet: 768px)
42
+ - `--computed-mobile-scale-factor-px` (Mobile: 390px)
43
+
44
+ ## 🎯 Basic Usage
45
+
46
+ ### Same Value for All Screens
47
+
48
+ When you want the same value across desktop, tablet, and mobile:
49
+
50
+ ```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);
55
+ }
56
+ ```
57
+
58
+ **Output:**
59
+
60
+ ```css
61
+ .element {
62
+ border-radius: calc(var(--computed-scale-factor-px) * 10);
63
+ }
64
+
65
+ @media (min-width: 768px) and (max-width: 991px) {
66
+ .element {
67
+ border-radius: calc(var(--computed-tablet-scale-factor-px) * 10);
68
+ }
69
+ }
70
+
71
+ @media (max-width: 767px) {
72
+ .element {
73
+ border-radius: calc(var(--computed-mobile-scale-factor-px) * 10);
74
+ }
75
+ }
76
+ ```
77
+
78
+ ### Different Values for Desktop & Mobile
79
+
80
+ When desktop and mobile need different values:
81
+
82
+ ```scss
83
+ // Two parameters - desktop and mobile values
84
+ .element {
85
+ @include responsive-scale(font-size, 24, 16);
86
+ @include responsive-scale(height, 60, 40);
87
+ }
88
+ ```
89
+
90
+ **Output:**
91
+
92
+ ```css
93
+ .element {
94
+ font-size: calc(var(--computed-scale-factor-px) * 24);
95
+ height: calc(var(--computed-scale-factor-px) * 60);
96
+ }
97
+
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
+ }
109
+ }
110
+
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
+ }
116
+ }
117
+ ```
118
+
119
+ ## ⚡ Advanced Usage
120
+
121
+ ### REM Units
122
+
123
+ ```scss
124
+ .element {
125
+ @include responsive-scale(font-size, 2, 1.5, rem);
126
+ }
127
+ ```
128
+
129
+ ### Multi-Value Properties
130
+
131
+ ```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);
135
+ }
136
+ ```
137
+
138
+ ## 📏 Property Examples
139
+
140
+ ### Typography
141
+
142
+ ```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);
147
+ }
148
+ ```
149
+
150
+ ### Spacing
151
+
152
+ ```scss
153
+ .card {
154
+ @include responsive-scale(padding, 20 30, 15 20);
155
+ @include responsive-scale(margin, 0 0 20 0, 0 0 15 0);
156
+ }
157
+ ```
158
+
159
+ ### Dimensions
160
+
161
+ ```scss
162
+ .button {
163
+ @include responsive-scale(width, 200, 150);
164
+ @include responsive-scale(height, 50, 40);
165
+ @include responsive-scale(border-radius, 8, 6);
166
+ }
167
+ ```
168
+
169
+ ### Borders & Shadows
170
+
171
+ ```scss
172
+ .box {
173
+ @include responsive-scale(border-width, 2, 1);
174
+ @include responsive-scale(border-radius, 10, 8);
175
+ }
176
+ ```
177
+
178
+ ## 📊 Percentage Properties
179
+
180
+ For properties that are percentages of other values:
181
+
182
+ ```scss
183
+ .element {
184
+ @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
193
+ 24,
194
+ // Desktop base value (font-size)
195
+ 16 // Mobile base value (font-size)
196
+ );
197
+ }
198
+ ```
199
+
200
+ **Output:**
201
+
202
+ ```css
203
+ .element {
204
+ letter-spacing: calc(-1.5 / 100 * (var(--computed-scale-factor-px) * 24));
205
+ }
206
+
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
+ }
217
+ }
218
+
219
+ @media (max-width: 767px) {
220
+ .element {
221
+ letter-spacing: calc(
222
+ -1.5 / 100 * (var(--computed-mobile-scale-factor-px) * 16)
223
+ );
224
+ }
225
+ }
226
+ ```
227
+
228
+ ## 💡 Tips & Best Practices
229
+
230
+ ### ✅ Do's
231
+
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
236
+
237
+ ### ❌ Don'ts
238
+
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
242
+
243
+ ### 🎨 Visual Guide
244
+
245
+ ```
246
+ Desktop (≥992px) → Uses desktop scale factor
247
+ Tablet (768-991px) → Auto-interpolated values
248
+ Mobile (≤767px) → Uses mobile scale factor
249
+ ```
250
+
251
+ ### 🔧 Customization
252
+
253
+ Adjust scale factors in `global.scss`:
254
+
255
+ ```scss
256
+ --scale-factor: calc(100vw / 1920); // Change desktop width
257
+ --mobile-scale-factor: calc(100vw / 375); // Change mobile width
258
+ ```
259
+
260
+ ## 📚 Complete Example
261
+
262
+ ```scss
263
+ @import "../styles/mixins";
264
+
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);
270
+
271
+ // Percentage-based
272
+ @include responsive-scale(letter-spacing, -1, -1, px, true, 20, 16);
273
+ }
274
+ ```
275
+
276
+ This creates a perfectly responsive button that scales beautifully across all devices! 🎉
package/index.scss ADDED
@@ -0,0 +1,8 @@
1
+ // Responsive Scale Mixins
2
+ // A powerful SCSS mixin system for creating perfectly responsive designs
3
+
4
+ // Import the variables mixin (must be included in your root element)
5
+ @import "scss/variables";
6
+
7
+ // Import the responsive scale mixin
8
+ @import "scss/mixins";
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "responsive-scale-mixins",
3
+ "version": "1.0.0",
4
+ "description": "Powerful SCSS mixins for responsive design with Figma proportions. Automatically scales typography, spacing, and dimensions across desktop, tablet, and mobile breakpoints.",
5
+ "main": "index.scss",
6
+ "style": "index.scss",
7
+ "scripts": {
8
+ "test": "echo \"No tests specified\" && exit 0"
9
+ },
10
+ "keywords": [
11
+ "scss",
12
+ "sass",
13
+ "responsive",
14
+ "mixins",
15
+ "figma",
16
+ "typography",
17
+ "spacing",
18
+ "dimensions",
19
+ "breakpoints",
20
+ "css",
21
+ "frontend",
22
+ "design-system",
23
+ "react",
24
+ "vue",
25
+ "angular",
26
+ "nextjs",
27
+ "nuxt",
28
+ "svelte",
29
+ "astro",
30
+ "tailwind",
31
+ "bootstrap",
32
+ "mobile-first",
33
+ "responsive-design",
34
+ "css-variables",
35
+ "custom-properties"
36
+ ],
37
+ "author": "Saheed Odulaja",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/Sidodus/responsive-scale-mixins.git"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/Sidodus/responsive-scale-mixins.git/issues"
45
+ },
46
+ "homepage": "https://github.com/Sidodus/responsive-scale-mixins.git#readme",
47
+ "files": [
48
+ "index.scss",
49
+ "scss/"
50
+ ],
51
+ "engines": {
52
+ "node": ">=12.0.0"
53
+ }
54
+ }
@@ -0,0 +1,159 @@
1
+ /* // ✅ Figma Proportions: Maintains the same proportions as the Figma design.
2
+
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
+ // ✅ Consistent Scaling: No need to manually adjust for medium screens.
5
+ // ✅ Reusable: Works for font-size, line-height, margins, paddings, etc.
6
+ // ✅ Automatic Scaling: Dynamically scales values based on the screen size.
7
+
8
+ // 📌 How to Use It
9
+ // Import the mixins in your SCSS file: @import "../styles/mixins";
10
+ // .title {
11
+ // @include responsive-scale(font-size, 40, 24);
12
+ // @include responsive-scale(padding, 20 73, 8 16); // Multi-value
13
+ // @include responsive-scale(line-height, 65, 40);
14
+
15
+ // // Letter-spacing is -1.5% of font-size
16
+ // @include responsive-scale(letter-spacing, -1.5, -1.5, px, true, 40, 24);
17
+ // }
18
+
19
+ // Parameters: property, desktop-value, mobile-value, unit (default px), is-percentage (default false), desktop-relative, mobile-relative
20
+ // Pass values as numbers (e.g., 20 for 20px, 20 73 for 20px 73px).
21
+ // Tablet values are automatically interpolated using the tablet-proportion-scale-factor.
22
+ // For percentage-based values, provide the percentage for desktop and mobile, and the base values (e.g., font-size for letter-spacing).
23
+ // Media queries: Desktop (default), Tablet (768-991px), Mobile (≤767px). */
24
+
25
+ @function scaled-value($val, $scale-var, $unit: px) {
26
+ @return calc(var(#{$scale-var}) * #{$val});
27
+ }
28
+
29
+ @mixin responsive-scale(
30
+ $property,
31
+ $desktop-value,
32
+ $mobile-value,
33
+ $unit: px,
34
+ $is-percentage: false,
35
+ $desktop-relative: null,
36
+ $mobile-relative: null
37
+ ) {
38
+ $scale-factor: if(
39
+ $unit == px,
40
+ unquote("--computed-scale-factor-px"),
41
+ unquote("--computed-scale-factor-rem")
42
+ );
43
+
44
+ // If it's a percentage-based value (like letter-spacing), scale it based on the relative property
45
+ @if $is-percentage == true {
46
+ @if $desktop-relative != null {
47
+ #{$property}: calc(
48
+ #{$desktop-value} / 100 * (var(#{$scale-factor}) * #{$desktop-relative})
49
+ );
50
+ }
51
+
52
+ @media screen and (min-width: 768px) and (max-width: 991px) {
53
+ $tablet-scale-factor: if(
54
+ $unit == px,
55
+ unquote("--computed-tablet-scale-factor-px"),
56
+ unquote("--computed-tablet-scale-factor-rem")
57
+ );
58
+ @if $desktop-relative != null and $mobile-relative != null {
59
+ #{$property}: calc(
60
+ #{$mobile-value} /
61
+ 100 *
62
+ (
63
+ var(#{$tablet-scale-factor}) *
64
+ (
65
+ #{$mobile-relative} +
66
+ var(--tablet-proportion-scale-factor) *
67
+ (#{$desktop-relative} - #{$mobile-relative})
68
+ )
69
+ )
70
+ );
71
+ }
72
+ }
73
+
74
+ @media screen and (max-width: 767px) {
75
+ $mobile-scale-factor: if(
76
+ $unit == px,
77
+ unquote("--computed-mobile-scale-factor-px"),
78
+ unquote("--computed-mobile-scale-factor-rem")
79
+ );
80
+ @if $mobile-relative != null {
81
+ #{$property}: calc(
82
+ #{$mobile-value} /
83
+ 100 *
84
+ (var(#{$mobile-scale-factor}) * #{$mobile-relative})
85
+ );
86
+ }
87
+ }
88
+ } @else {
89
+ // Regular absolute scaling
90
+ @if type-of($desktop-value) == list {
91
+ $desktop-scaled: ();
92
+ @each $val in $desktop-value {
93
+ $desktop-scaled: append(
94
+ $desktop-scaled,
95
+ scaled-value($val, $scale-factor, $unit)
96
+ );
97
+ }
98
+ #{$property}: $desktop-scaled;
99
+ } @else {
100
+ #{$property}: scaled-value($desktop-value, $scale-factor, $unit);
101
+ }
102
+
103
+ @media screen and (min-width: 768px) and (max-width: 991px) {
104
+ $tablet-scale-factor: if(
105
+ $unit == px,
106
+ unquote("--computed-tablet-scale-factor-px"),
107
+ unquote("--computed-tablet-scale-factor-rem")
108
+ );
109
+ @if type-of($desktop-value) == list {
110
+ $tablet-scaled: ();
111
+ @for $i from 1 through length($desktop-value) {
112
+ $d-val: nth($desktop-value, $i);
113
+ $m-val: nth($mobile-value, $i);
114
+ $tablet-scaled: append(
115
+ $tablet-scaled,
116
+ calc(
117
+ var(#{$tablet-scale-factor}) *
118
+ (
119
+ #{$m-val} +
120
+ var(--tablet-proportion-scale-factor) *
121
+ (#{$d-val} - #{$m-val})
122
+ )
123
+ )
124
+ );
125
+ }
126
+ #{$property}: $tablet-scaled;
127
+ } @else {
128
+ #{$property}: calc(
129
+ var(#{$tablet-scale-factor}) *
130
+ (
131
+ #{$mobile-value} +
132
+ var(--tablet-proportion-scale-factor) *
133
+ (#{$desktop-value} - #{$mobile-value})
134
+ )
135
+ );
136
+ }
137
+ }
138
+
139
+ @media screen and (max-width: 767px) {
140
+ $mobile-scale-factor: if(
141
+ $unit == px,
142
+ unquote("--computed-mobile-scale-factor-px"),
143
+ unquote("--computed-mobile-scale-factor-rem")
144
+ );
145
+ @if type-of($mobile-value) == list {
146
+ $mobile-scaled: ();
147
+ @each $val in $mobile-value {
148
+ $mobile-scaled: append(
149
+ $mobile-scaled,
150
+ scaled-value($val, $mobile-scale-factor, $unit)
151
+ );
152
+ }
153
+ #{$property}: $mobile-scaled;
154
+ } @else {
155
+ #{$property}: scaled-value($mobile-value, $mobile-scale-factor, $unit);
156
+ }
157
+ }
158
+ }
159
+ }
@@ -0,0 +1,27 @@
1
+ /* Responsive Scale Variables Mixin
2
+ * Include this mixin in your root element to define the scaling factors.
3
+ * Adjust the design widths to match your design system breakpoints.
4
+ */
5
+
6
+ @mixin responsive-scale-variables(
7
+ $desktop-width: 1920px,
8
+ $tablet-width: 768px,
9
+ $mobile-width: 390px
10
+ ) {
11
+ // Desktop scale factor
12
+ --computed-scale-factor-px: calc(100vw / #{$desktop-width});
13
+ --computed-scale-factor-rem: calc(100vw / #{$desktop-width} / 16);
14
+
15
+ // Tablet scale factor
16
+ --computed-tablet-scale-factor-px: calc(100vw / #{$tablet-width});
17
+ --computed-tablet-scale-factor-rem: calc(100vw / #{$tablet-width} / 16);
18
+
19
+ // Mobile scale factor
20
+ --computed-mobile-scale-factor-px: calc(100vw / #{$mobile-width});
21
+ --computed-mobile-scale-factor-rem: calc(100vw / #{$mobile-width} / 16);
22
+
23
+ // Tablet proportion scale factor for interpolation between mobile and desktop values
24
+ --tablet-proportion-scale-factor: calc(
25
+ (100vw - #{$mobile-width}) / (#{$desktop-width} - #{$mobile-width})
26
+ );
27
+ }