Skip to content

Commit 460222d

Browse files
committed
fix: text black border plus animate line
1 parent 3c8cd48 commit 460222d

1 file changed

Lines changed: 47 additions & 9 deletions

File tree

src/components/Introduction.js

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useContext, useState, useEffect } from "react";
1+
import { useContext, useState, useEffect, useRef, useLayoutEffect } from "react";
22
import { ThemeContext } from "../utils/themes/ThemeContext";
33
import { Box, Typography } from "@mui/material";
44
import styled from 'styled-components';
@@ -18,23 +18,36 @@ const sentences = [
1818
"?"
1919
];
2020

21-
const BlinkingTriangle = styled.div`
22-
width: 0;
23-
height: 0;
24-
border-left: 15px solid transparent;
25-
border-right: 15px solid transparent;
26-
border-bottom: 25px solid ${props => props.color};
21+
const TriangleWrapper = styled.div`
2722
animation: blink 1s infinite;
23+
transform: translateZ(0);
24+
2825
@keyframes blink {
2926
0% { opacity: 1; }
3027
50% { opacity: 0; }
3128
100% { opacity: 1; }
3229
}
3330
`;
3431

32+
const Triangle = styled.div`
33+
width: 0;
34+
height: 0;
35+
border-left: 15px solid transparent;
36+
border-right: 15px solid transparent;
37+
border-bottom: 25px solid ${props => props.color};
38+
`;
39+
3540
const Introduction = () => {
3641
const {theme} = useContext(ThemeContext);
3742
const [currentSentence, setCurrentSentence] = useState(0);
43+
const textRef = useRef(null);
44+
const [lineWidth, setLineWidth] = useState(0);
45+
46+
useLayoutEffect(() => {
47+
if (textRef.current) {
48+
setLineWidth(textRef.current.offsetWidth);
49+
}
50+
}, [currentSentence]);
3851

3952
useEffect(() => {
4053
console.log("Length of sentences: ", sentences.length);
@@ -46,8 +59,33 @@ const Introduction = () => {
4659

4760
return (
4861
<Box id="home" sx={{display: "flex", flexDirection: "column", justifyContent: "center", alignItems: "center", backgroundColor: theme.BackgroundColor, paddingTop: "120px", minHeight: "calc(100vh - 120px)"}}>
49-
<Typography sx={{fontSize: 40, color: theme.BoldTextColor, textDecoration: 'underline', textUnderlineOffset: '10px', marginBottom: "10px", fontWeight: "bold", fontFamily: "'Magda Clean Mono', monospace"}}>{sentences[currentSentence]}</Typography>
50-
<BlinkingTriangle color={theme.MainColor} />
62+
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
63+
<Typography
64+
ref={textRef}
65+
sx={{
66+
fontSize: 40,
67+
color: theme.BoldTextColor,
68+
fontWeight: "bold",
69+
fontFamily: "'Magda Clean Mono', monospace",
70+
display: "inline-block"
71+
}}
72+
>
73+
{sentences[currentSentence]}
74+
</Typography>
75+
76+
<Box
77+
sx={{
78+
height: "2px",
79+
backgroundColor: theme.BoldTextColor,
80+
width: lineWidth,
81+
transition: "width 0.5s ease-in-out",
82+
marginBottom: "10px",
83+
}}
84+
/>
85+
</Box>
86+
<TriangleWrapper>
87+
<Triangle color={theme.MainColor} />
88+
</TriangleWrapper>
5189
</Box>
5290
);
5391
};

0 commit comments

Comments
 (0)