Skip to content

Commit 9bc99e8

Browse files
committed
chore: refactor Text component
1 parent 189cc82 commit 9bc99e8

File tree

4 files changed

+51
-44
lines changed

4 files changed

+51
-44
lines changed

lib/components/Text/Text.scss

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1+
// TODO: Refactor this file to use css variables
12
$color-map: (
2-
"general": #333333,
3-
"primary": #999999,
4-
"success": #4bb4b3,
5-
"warning": #ffad3a,
6-
"error": #ec3f3f,
7-
"white": #ffffff,
8-
"black": #000000,
9-
"less-prominent": #999999,
10-
"red": #ff444f,
11-
"blue": #377cfc,
12-
"green": #17eabd,
13-
"orange": #ff9c13,
14-
"system-dark-2-general-text": #c2c2c2,
3+
"prominent": var(--du-text-prominent),
4+
"less-prominent": var(--du-text-less-prominent, #999999),
5+
"general": var(--du-text-general, #333333),
6+
"primary": var(--du-text-primary, #999999),
7+
"success": var(--du-text-profit-success, #4bb4b3),
8+
"warning": var(--du-text-warning, #ffad3a),
9+
"error": var(--du-text-loss-danger, #ec3f3f),
10+
"red": var(--du-text-red, #ff444f),
11+
"blue": var(--du-text-info-blue, #377cfc),
12+
"green": var(--du-text-green, #17eabd),
1513
);
1614

1715
$desktop-font-size-map: (
@@ -116,18 +114,6 @@ $line-height-map: (
116114
"7xl": 36px,
117115
);
118116

119-
$font-weight-map: (
120-
light: 300,
121-
normal: 400,
122-
bold: 700,
123-
);
124-
125-
$font-align-map: (
126-
left: left,
127-
center: center,
128-
right: right,
129-
);
130-
131117
$font-style-map: (
132118
italic: italic,
133119
normal: normal,
@@ -142,16 +128,14 @@ $font-style-map: (
142128

143129
@each $size, $values in $desktop-font-size-map {
144130
&__size--#{$size} {
145-
@include desktop {
146-
font-size: map-get($values, size);
147-
line-height: map-get($values, line_height);
148-
}
131+
font-size: map-get($values, size);
132+
line-height: map-get($values, line_height);
149133
}
150134
}
151135

152136
@each $size, $values in $mobile-font-size-map {
153137
&__size--#{$size} {
154-
@include mobile-up {
138+
@include tablet-down {
155139
font-size: map-get($values, size);
156140
line-height: map-get($values, line_height);
157141
}
@@ -164,13 +148,13 @@ $font-style-map: (
164148
}
165149
}
166150

167-
@each $weight, $value in $font-weight-map {
151+
@each $weight, $value in $font-weights {
168152
&__weight--#{$weight} {
169153
font-weight: $value;
170154
}
171155
}
172156

173-
@each $align, $value in $font-align-map {
157+
@each $align, $value in $font-align {
174158
&__align--#{$align} {
175159
text-align: $value;
176160
}

lib/components/Text/index.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import React, { CSSProperties, ElementType, ReactNode } from "react";
22
import clsx from "clsx";
3-
43
import "./Text.scss";
54

5+
type TextColors =
6+
| "prominent"
7+
| "less-prominent"
8+
| "general"
9+
| "primary"
10+
| "success"
11+
| "warning"
12+
| "error"
13+
| "red"
14+
| "blue"
15+
| "green";
16+
617
type TGenericSizes =
718
| "2xl"
819
| "2xs"
@@ -21,18 +32,11 @@ export interface TextProps {
2132
align?: CSSProperties["textAlign"];
2233
as?: ElementType;
2334
children: ReactNode;
24-
color?:
25-
| CSSProperties["color"]
26-
| "error"
27-
| "general"
28-
| "less-prominent"
29-
| "primary"
30-
| "success"
31-
| "warning";
35+
color?: TextColors;
3236
fontStyle?: CSSProperties["fontStyle"];
3337
lineHeight?: TGenericSizes;
3438
size?: Exclude<TGenericSizes, "3xs" | "6xl" | "7xl">;
35-
weight?: CSSProperties["fontWeight"];
39+
weight?: Exclude<CSSProperties["fontWeight"], "bolder" | "lighter">;
3640
className?: string;
3741
}
3842

lib/styles/abstracts/_typography.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ $font-sizes: (
1414
"3xs": 6px,
1515
);
1616

17+
$font-align: (
18+
"left": left,
19+
"center": center,
20+
"right": right,
21+
);
22+
1723
$font-weights: (
1824
"bold": 700,
1925
"semibold": 500,

src/stories/Text.stories.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,23 @@ const meta = {
2626
// More on argTypes: https://storybook.js.org/docs/api/argtypes
2727
argTypes: {
2828
color: {
29-
control: { type: "text" },
29+
options: [
30+
"prominent",
31+
"less-prominent",
32+
"general",
33+
"primary",
34+
"success",
35+
"warning",
36+
"error",
37+
"red",
38+
"blue",
39+
"green",
40+
],
41+
control: { type: "select" },
3042
},
3143
weight: {
32-
control: { type: "text" },
44+
options: ["normal", "bold", "semi-bold", "light"],
45+
control: { type: "select" },
3346
},
3447
as: {
3548
control: { type: "text" },

0 commit comments

Comments
 (0)