Skip to content

Commit 41f849a

Browse files
authored
Merge pull request #50 from tklepzig/introduce-scaling
Introduce scaling
2 parents 16e45b1 + 254e3c2 commit 41f849a

8 files changed

Lines changed: 98 additions & 42 deletions

File tree

.changeset/rude-ligers-matter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ada-ui": major
3+
---
4+
5+
Renamed font-size tokens from `--scale` to `--text`.

.changeset/slow-comics-dress.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"ada-ui": minor
3+
---
4+
5+
Added possibility to define a scaling factor by setting the CSS class `scaled`
6+
and the CSS custom property `--scale` to a number. This allows to easily scale
7+
down or up any part of the UI.
8+
9+
```css
10+
11+
```

index.html

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<a href="#padding" class="command shade1">Padding</a>
3535
<a href="#spacing" class="command shade1">Spacing</a>
3636
<a href="#colors" class="command shade1">Colors</a>
37+
<a href="#scaling" class="command shade2">Scaling</a>
3738
<a href="#page-layout" class="command shade1">Page Layout</a>
3839
<a
3940
href="#command"
@@ -68,37 +69,37 @@
6869
<header><h2 id="typography">Typography</h2></header>
6970
<article class="typography">
7071
<p>
71-
<code style="font-size: var(--scale-3xl)">--scale-3xl</code>
72+
<code style="font-size: var(--text-3xl)">--text-3xl</code>
7273
<span>1.8rem</span>
7374
<span>Headline 1, Text in Compound Commands</span>
7475
</p>
7576
<p>
76-
<code style="font-size: var(--scale-2xl)">--scale-2xl</code>
77+
<code style="font-size: var(--text-2xl)">--text-2xl</code>
7778
<span>1.6rem</span>
7879
<span>Headline 2</span>
7980
</p>
8081
<p>
81-
<code style="font-size: var(--scale-xl)">--scale-xl</code>
82+
<code style="font-size: var(--text-xl)">--text-xl</code>
8283
<span>1.4rem</span>
8384
<span>Headline 3</span>
8485
</p>
8586
<p>
86-
<code style="font-size: var(--scale-lg)">--scale-lg</code>
87+
<code style="font-size: var(--text-lg)">--text-lg</code>
8788
<span>1.2rem</span>
8889
<span>Headline 4</span>
8990
</p>
9091
<p>
91-
<code style="font-size: var(--scale-base)">--scale-base</code>
92+
<code style="font-size: var(--text-base)">--text-base</code>
9293
<span>1rem</span>
9394
<span>Normal Text, Command Label</span>
9495
</p>
9596
<p>
96-
<code style="font-size: var(--scale-sm)">--scale-sm</code>
97+
<code style="font-size: var(--text-sm)">--text-sm</code>
9798
<span>0.85rem</span>
9899
<span>Small Text, Panel Footer</span>
99100
</p>
100101
<p>
101-
<code style="font-size: var(--scale-xs)">--scale-xs</code>
102+
<code style="font-size: var(--text-xs)">--text-xs</code>
102103
<span>0.75rem</span>
103104
<span>Tile Footer</span>
104105
</p>
@@ -122,7 +123,7 @@
122123
<div class="padding-box lg shade2"></div>
123124
<p>&rarr; Paddings are responsive (in rem).</p>
124125
<p>
125-
Usage: paddings, anything which should grow/shrink with the
126+
Usage: paddings, anything which should grow/shrink with the root
126127
font-size
127128
</p>
128129
</article>
@@ -219,6 +220,24 @@ <h3>Usage</h3>
219220
</article>
220221
<footer></footer>
221222
</div>
223+
<div class="panel">
224+
<header><h2 id="scaling">Scaling</h2></header>
225+
<article style="display: grid; gap: var(--spacing)">
226+
<p>
227+
By adding the class <code>scaled</code> and setting the CSS custom
228+
property <code>--scaled</code> to a number like <code>1.5</code>,
229+
every responsive token (sizes, paddings, font-size) is scaled in
230+
this scope. See the scaled tile as an example:
231+
</p>
232+
<div class="tile scaled shade2" style="--scale: 1.5">
233+
<header></header>
234+
<article>Scaled Tile (factor 1.5)</article>
235+
<footer></footer>
236+
</div>
237+
</article>
238+
<footer></footer>
239+
</div>
240+
222241
<div class="panel">
223242
<header><h2 id="page-layout">Page Layout</h2></header>
224243
<article>

scss/_command.scss

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
border-color: transparent;
1010
border-width: var(--border-width);
1111
padding: var(--padding-xs) var(--padding-sm);
12-
min-height: 3rem;
13-
min-width: 3rem;
12+
min-height: var(--command-min-size);
13+
min-width: var(--command-min-size);
1414
border-radius: var(--border-radius);
1515
overflow: hidden;
1616
outline: none;
1717
color: var(--color100);
1818
font-family: inherit;
19-
font-size: var(--scale-base);
19+
font-size: var(--text-base);
2020
cursor: pointer;
2121
user-select: none;
2222
vertical-align: middle;
@@ -82,8 +82,8 @@
8282
> .spacer {
8383
background-color: var(--color800);
8484
box-shadow: var(--box-shadow);
85-
min-width: 1rem;
86-
min-height: 1rem;
85+
min-width: var(--compound-spacer-min-size);
86+
min-height: var(--compound-spacer-min-size);
8787

8888
&.outline {
8989
background-color: transparent;
@@ -92,8 +92,8 @@
9292
}
9393

9494
> .text {
95-
font-size: var(--scale-3xl);
96-
line-height: var(--scale-3xl);
95+
font-size: var(--text-3xl);
96+
line-height: var(--text-3xl);
9797
align-self: center;
9898
padding: var(--padding-xs);
9999
}

scss/_global.scss

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1+
@function scalable($value) {
2+
@return calc(#{$value} * var(--scale, 1));
3+
}
4+
15
:root {
26
--font-family: "Open Sans", sans-serif;
37
--font-size: 16px;
4-
--scale-xs: 0.75rem;
5-
--scale-sm: 0.85rem;
6-
--scale-base: 1rem;
7-
--scale-lg: 1.2rem;
8-
--scale-xl: 1.4rem;
9-
--scale-2xl: 1.6rem;
10-
--scale-3xl: 1.8rem;
11-
--box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.4);
12-
--padding-xs: 0.15rem;
13-
--padding-sm: 0.4rem;
14-
--padding: 0.75rem;
15-
--padding-lg: 1rem;
8+
169
--spacing-xs: 2px;
1710
--spacing-sm: 6px;
1811
--spacing: 10px;
1912
--spacing-lg: 14px;
13+
2014
--border-width-sm: 1px;
2115
--border-width: 2px;
22-
--border-radius: 0.3rem;
16+
17+
--box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.4);
18+
19+
@extend .scaled;
2320

2421
@media screen and (min-width: 640px) {
2522
--font-size: 14px;
@@ -30,6 +27,29 @@
3027
}
3128
}
3229

30+
.scaled {
31+
--text-xs: #{scalable(0.75rem)};
32+
--text-sm: #{scalable(0.85rem)};
33+
--text-base: #{scalable(1rem)};
34+
--text-lg: #{scalable(1.2rem)};
35+
--text-xl: #{scalable(1.4rem)};
36+
--text-2xl: #{scalable(1.6rem)};
37+
--text-3xl: #{scalable(1.8rem)};
38+
39+
--padding-xs: #{scalable(0.15rem)};
40+
--padding-sm: #{scalable(0.4rem)};
41+
--padding: #{scalable(0.75rem)};
42+
--padding-lg: #{scalable(1rem)};
43+
44+
--border-radius: #{scalable(0.3rem)};
45+
46+
--command-min-size: #{scalable(3rem)};
47+
--compound-spacer-min-size: #{scalable(1rem)};
48+
49+
--corner-size: #{scalable(1rem)};
50+
--corner-small-size: #{scalable(0.75rem)};
51+
}
52+
3353
%scrollbar {
3454
&::-webkit-scrollbar {
3555
width: var(--spacing-sm);
@@ -53,7 +73,7 @@ html {
5373
}
5474

5575
body {
56-
font-size: 1rem;
76+
font-size: var(--text-base);
5777
padding: var(--padding);
5878
background: var(--bg-body);
5979
color: var(--fg-body);

scss/_input.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
background-color: transparent;
99
transition: border-color 0.15s ease-in-out;
1010
padding: var(--padding);
11-
font-size: var(--scale-base);
11+
font-size: var(--text-base);
1212

1313
&:focus {
1414
border: var(--border-width) solid var(--color500);

scss/_panel.scss

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
border-style: solid;
44
border-color: var(--color700);
55
position: absolute;
6-
height: 1rem;
7-
width: 1rem;
6+
height: var(--corner-size);
7+
width: var(--corner-size);
88
z-index: 2;
99

1010
--thickness: var(--border-width);
1111

1212
.tile > & {
13-
height: 0.75rem;
14-
width: 0.75rem;
13+
height: var(--corner-small-size);
14+
width: var(--corner-small-size);
1515
border-color: var(--color600);
1616

1717
--thickness: var(--border-width-sm);
@@ -29,7 +29,7 @@
2929
> header {
3030
position: relative;
3131
@extend %header;
32-
font-size: var(--scale-2xl);
32+
font-size: var(--text-2xl);
3333

3434
padding: var(--padding-sm) var(--padding);
3535

@@ -57,14 +57,15 @@
5757
z-index: 1;
5858
padding: var(--padding);
5959
overflow: auto;
60+
font-size: var(--text-base);
6061

6162
@extend %scrollbar;
6263
}
6364
> footer {
6465
position: relative;
6566

6667
padding: var(--padding-sm) var(--padding);
67-
font-size: var(--scale-sm);
68+
font-size: var(--text-sm);
6869
text-align: right;
6970

7071
&:empty {
@@ -94,10 +95,10 @@
9495
background: oklch(var(--800) / 0.75);
9596

9697
> header {
97-
font-size: var(--scale-lg);
98+
font-size: var(--text-lg);
9899
}
99100

100101
> footer {
101-
font-size: var(--scale-xs);
102+
font-size: var(--text-xs);
102103
}
103104
}

scss/_typography.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ h4,
99
}
1010

1111
h1 {
12-
font-size: var(--scale-3xl);
12+
font-size: var(--text-3xl);
1313
}
1414

1515
h2 {
16-
font-size: var(--scale-2xl);
16+
font-size: var(--text-2xl);
1717
}
1818

1919
h3 {
20-
font-size: var(--scale-xl);
20+
font-size: var(--text-xl);
2121
}
2222

2323
h4 {
24-
font-size: var(--scale-lg);
24+
font-size: var(--text-lg);
2525
}

0 commit comments

Comments
 (0)