Skip to content

Commit 878fb6e

Browse files
committed
refactor: use mixin based typography
1 parent 9af8f07 commit 878fb6e

File tree

3 files changed

+151
-67
lines changed

3 files changed

+151
-67
lines changed
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
@import "@react-ck/theme";
2+
@import "variables";
3+
4+
@mixin text-variant($key, $map) {
5+
$props: map-get-strict($map, $key);
6+
$defaultProps: map-get-strict($props, default);
7+
$hoverProps: map-get-strict($props, hover);
8+
9+
@each $propName, $propValue in $defaultProps {
10+
@include define-css-var(text, $propName, $propValue);
11+
}
12+
13+
&:hover {
14+
@each $propName, $propValue in $hoverProps {
15+
@include define-css-var(text, $propName, $propValue);
16+
}
17+
}
18+
}
19+
20+
@mixin text-variation($key) {
21+
@include text-variant($key, $text-variations);
22+
}
23+
24+
@mixin text-type($key) {
25+
@include text-variant($key, $text-types);
26+
}
227

3-
// TODO: move to typography
428
@mixin font-base {
5-
font-family: get-css-var(font, family);
6-
font-size: get-css-var(font, base-size);
29+
@include text-type(p);
30+
@include define-css-var(text, color, get-color(neutral-900));
31+
@include define-css-var(text, text-decoration, none);
32+
33+
font-family: get-css-var(text, font-family);
34+
font-size: get-css-var(text, font-size);
35+
font-weight: get-css-var(text, font-weight);
36+
line-height: get-css-var(text, line-height);
37+
text-decoration: get-css-var(text, text-decoration);
38+
color: get-css-var(text, color);
739
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
@import "@react-ck/theme";
2+
@import "@react-ck/scss-utils";
3+
4+
$text-types: (
5+
p: (
6+
default: (
7+
font-family: get-css-var(font, family),
8+
font-size: get-css-var(font, base-size),
9+
line-height: 24px,
10+
font-weight: 500,
11+
color: get-color(neutral-900),
12+
),
13+
hover: (),
14+
),
15+
huge: (
16+
default: (
17+
font-size: 60px,
18+
font-weight: 700,
19+
line-height: 60px,
20+
),
21+
hover: (),
22+
),
23+
soft: (
24+
default: (
25+
color: #718096,
26+
),
27+
hover: (),
28+
),
29+
h1: (
30+
default: (
31+
font-size: 29px,
32+
font-weight: 500,
33+
line-height: 36px,
34+
),
35+
hover: (),
36+
),
37+
h2: (
38+
default: (
39+
font-size: 24px,
40+
font-weight: 500,
41+
line-height: 36px,
42+
color: #1a202c,
43+
),
44+
hover: (),
45+
),
46+
h3: (
47+
default: (
48+
font-size: 20px,
49+
font-weight: 500,
50+
line-height: 24px,
51+
),
52+
hover: (),
53+
),
54+
h4: (
55+
default: (),
56+
hover: (),
57+
),
58+
h5: (
59+
default: (),
60+
hover: (),
61+
),
62+
h6: (
63+
default: (),
64+
hover: (),
65+
),
66+
);
67+
68+
$text-variations: (
69+
small: (
70+
default: (
71+
font-size: 14px,
72+
font-weight: 400,
73+
line-height: 21px,
74+
),
75+
hover: (),
76+
),
77+
bold: (
78+
default: (
79+
font-weight: 700,
80+
),
81+
hover: (),
82+
),
83+
link: (
84+
default: (
85+
color: #0052cc,
86+
),
87+
hover: (
88+
color: #003e99,
89+
),
90+
),
91+
link_hidden: (
92+
default: (
93+
text-decoration: none,
94+
),
95+
hover: (
96+
color: #003e99,
97+
text-decoration: underline,
98+
),
99+
),
100+
inverted: (
101+
default: (
102+
color: get-color(neutral-0),
103+
),
104+
hover: (),
105+
),
106+
);
Lines changed: 10 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
@import "@react-ck/theme";
22
@import "@react-ck/scss-utils";
3+
@import "mixins";
4+
@import "variables";
35

46
.root {
5-
@include define-css-var(text, font-size, 16px);
6-
@include define-css-var(text, line-height, 24px);
7-
@include define-css-var(text, font-weight, 500);
7+
@include font-base;
88
@include define-css-var(text, margin-top, 0);
99
@include define-css-var(text, margin-bottom, 0);
10-
@include define-css-var(text, color, get-color(neutral-900));
1110

12-
color: get-css-var(text, color);
13-
font-family: sans-serif;
14-
font-size: get-css-var(text, font-size);
15-
font-weight: get-css-var(text, font-weight);
1611
margin-top: get-css-var(text, margin-top);
1712
margin-bottom: get-css-var(text, margin-bottom);
18-
line-height: get-css-var(text, line-height);
1913

2014
&:not(:only-child).margin {
2115
&:not(.p, a) {
@@ -40,64 +34,16 @@
4034
display: block;
4135
}
4236

43-
.h1 {
44-
@include define-css-var(text, font-size, 29px);
45-
@include define-css-var(text, font-weight, 500);
46-
@include define-css-var(text, line-height, 36px);
47-
}
48-
49-
.h2 {
50-
@include define-css-var(text, font-size, 24px);
51-
@include define-css-var(text, font-weight, 500);
52-
@include define-css-var(text, line-height, 36px);
53-
@include define-css-var(text, color, #1a202c);
54-
}
55-
56-
.h3 {
57-
@include define-css-var(text, font-size, 20px);
58-
@include define-css-var(text, font-weight, 500);
59-
@include define-css-var(text, line-height, 24px);
60-
}
61-
62-
.huge {
63-
@include define-css-var(text, font-size, 60px);
64-
@include define-css-var(text, line-height, 60px);
65-
@include define-css-var(text, font-weight, 700);
66-
}
67-
68-
.soft {
69-
@include define-css-var(text, color, #718096);
70-
}
71-
72-
// Variations
73-
74-
.small {
75-
@include define-css-var(text, font-size, 14px);
76-
@include define-css-var(text, font-weight, 400);
77-
@include define-css-var(text, line-height, 21px);
78-
}
79-
80-
.bold {
81-
@include define-css-var(text, font-weight, 700);
82-
}
83-
84-
.link {
85-
@include define-css-var(text, color, #0052cc);
86-
87-
&:hover {
88-
@include define-css-var(text, color, #003e99);
37+
@each $type in map-keys($text-types) {
38+
.#{$type} {
39+
@include text-type($type);
8940
}
9041
}
9142

92-
.link_hidden {
93-
text-decoration: none;
43+
// Variations
9444

95-
&:hover {
96-
@include define-css-var(text, color, #003e99);
97-
text-decoration: underline;
45+
@each $variation in map-keys($text-variations) {
46+
.#{$variation} {
47+
@include text-variation($variation);
9848
}
9949
}
100-
101-
.inverted {
102-
@include define-css-var(text, color, get-color(neutral-0));
103-
}

0 commit comments

Comments
 (0)