Skip to content

Commit 0c8b42a

Browse files
committed
fix(text): next.js fix dynamic creation for text component
1 parent 068f035 commit 0c8b42a

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

Diff for: src/components/Text.tsx

+40-37
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,45 @@ export type TextProps = React.HTMLAttributes<
1111

1212
export const Text = (props: TextProps) => {
1313
const { variant } = props;
14-
const variantMapping = {
15-
h1: {
16-
fontSize: "2em",
17-
fontWeight: 700
18-
},
19-
h2: {
20-
fontSize: "1.5em",
21-
fontWeight: 600
22-
},
23-
h3: {
24-
fontSize: "1.17em",
25-
fontWeight: 600
26-
},
27-
h4: {
28-
fontSize: "1em",
29-
fontWeight: 500
30-
},
31-
h5: {
32-
fontSize: "0.83em",
33-
fontWeight: 500
34-
},
35-
h6: {
36-
fontSize: "0.67em",
37-
fontWeight: 500
38-
},
39-
p: {
40-
fontSize: "1em",
41-
fontWeight: 400
42-
}
43-
};
44-
const TextElement = styled[variant ?? "p"]`
45-
font-family: "Poppins", sans-serif;
46-
font-weight: ${(props) => variantMapping[variant ?? "p"].fontWeight};
47-
font-size: ${(props) => variantMapping[variant ?? "p"].fontSize};
48-
color: ${(props) => props.theme.text};
49-
`;
5014
// @ts-ignore
51-
return <TextElement {...props} />;
15+
return <TextElement as={variant} {...props} />;
16+
};
17+
18+
19+
const variantMapping = {
20+
h1: {
21+
fontSize: "2em",
22+
fontWeight: 700
23+
},
24+
h2: {
25+
fontSize: "1.5em",
26+
fontWeight: 600
27+
},
28+
h3: {
29+
fontSize: "1.17em",
30+
fontWeight: 600
31+
},
32+
h4: {
33+
fontSize: "1em",
34+
fontWeight: 500
35+
},
36+
h5: {
37+
fontSize: "0.83em",
38+
fontWeight: 500
39+
},
40+
h6: {
41+
fontSize: "0.67em",
42+
fontWeight: 500
43+
},
44+
p: {
45+
fontSize: "1em",
46+
fontWeight: 400
47+
}
5248
};
49+
50+
const TextElement = styled.p<TextProps>`
51+
font-family: "Poppins", sans-serif;
52+
font-weight: ${(props) => variantMapping[props.variant ?? "p"].fontWeight};
53+
font-size: ${(props) => variantMapping[props.variant ?? "p"].fontSize};
54+
color: ${(props) => props.theme.text};
55+
`;

0 commit comments

Comments
 (0)