Skip to content

Commit 7d39847

Browse files
committed
Add GithubLink component
Refactor styles and components
1 parent 7b2bd96 commit 7d39847

File tree

11 files changed

+132
-11
lines changed

11 files changed

+132
-11
lines changed

package-lock.json

Lines changed: 42 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"lint-staged": "^13.2.3",
5151
"prettier": "^3.0.0",
5252
"react-scripts": "^5.0.1",
53+
"sass": "^1.64.2",
5354
"stylelint": "^15.10.2",
5455
"stylelint-config-prettier": "^9.0.5",
5556
"stylelint-config-recommended": "^13.0.0",

src/app.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.sierpinski-triangle {
2+
position: relative;
3+
width: 100%;
4+
height: 100%;
5+
}

src/app.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import type { FunctionComponent } from "react";
2-
import "./app.css";
3-
import { SierpinskiTriangle } from "./sierpinskiTriangle";
2+
import "./app.scss";
3+
import { GithubLink } from "./components/githubLink";
4+
import { SierpinskiTriangle } from "./components/sierpinskiTriangle";
45

56
export const App: FunctionComponent<Record<string, never>> = () => {
6-
return <SierpinskiTriangle className="canvas" />;
7+
return (
8+
<div className="sierpinski-triangle">
9+
<SierpinskiTriangle />
10+
<GithubLink />
11+
</div>
12+
);
713
};

src/components/github-mark.svg

Lines changed: 1 addition & 0 deletions
Loading

src/components/githubLink.scss

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.github-link {
2+
position: absolute;
3+
top: 0;
4+
right: 0;
5+
width: 100px;
6+
height: 100px;
7+
8+
&--triangle {
9+
position: absolute;
10+
top: 0;
11+
right: 0;
12+
border-top: 100px solid black;
13+
border-left: 100px solid transparent;
14+
}
15+
16+
&--icon-container {
17+
position: absolute;
18+
top: 5px;
19+
right: 5px;
20+
width: 50px;
21+
height: 50px;
22+
overflow: hidden;
23+
box-sizing: border-box;
24+
}
25+
26+
&--icon {
27+
width: 100%;
28+
height: 100%;
29+
transform: rotate(45deg);
30+
transition: transform 0.2s ease-in-out;
31+
color: white;
32+
33+
&:hover {
34+
transform: rotate(405deg);
35+
}
36+
}
37+
}

src/components/githubLink.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { FunctionComponent } from "react";
2+
import { ReactComponent as GithubMark } from "./github-mark.svg";
3+
import "./githubLink.scss";
4+
5+
export const GithubLink: FunctionComponent<Record<string, never>> = () => {
6+
return (
7+
<>
8+
<div className="github-link--triangle"></div>
9+
<a
10+
href="https://github.com/Constantiner/sierpinski-triangle-react"
11+
target="_blank"
12+
rel="noopener noreferrer"
13+
className="github-link"
14+
>
15+
<div className="github-link--icon-container">
16+
<GithubMark className="github-link--icon" />
17+
</div>
18+
</a>
19+
</>
20+
);
21+
};
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
.canvas {
1+
.sierpinski-triangle-canvas {
22
width: 100%;
33
height: 100%;
44
background-color: white;
55
position: absolute;
66
top: 0;
77
left: 0;
8-
z-index: 1;
98
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useCallback, useEffect, useRef, type CanvasHTMLAttributes, type FunctionComponent } from "react";
2-
import { useAnimation } from "./hooks/useAnimation";
3-
import { useCanvas } from "./hooks/useCanvas";
4-
import { drawTriangle, type Coordinates, type FillStyle, type TriangleCoordinates } from "./util/canvasUtil";
2+
import { useAnimation } from "../hooks/useAnimation";
3+
import { useCanvas } from "../hooks/useCanvas";
4+
import { drawTriangle, type Coordinates, type FillStyle, type TriangleCoordinates } from "../util/canvasUtil";
5+
import "./sierpinskiTriangle.scss";
56

67
/**
78
* Recursively draws Sierpiński triangles within a bounding triangle.
@@ -143,5 +144,5 @@ export const SierpinskiTriangle: FunctionComponent<CanvasHTMLAttributes<HTMLCanv
143144
}, [contextReference, height, startAnimation, width]);
144145

145146
// Return the canvas element.
146-
return <canvas ref={canvasReference} {...properties} />;
147+
return <canvas className="sierpinski-triangle-canvas" ref={canvasReference} {...properties} />;
147148
};

src/index.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
:root,
2+
html,
3+
body,
4+
#root {
5+
width: 100%;
6+
max-width: 100%;
7+
height: 100%;
8+
max-height: 100%;
9+
}
10+
111
body {
212
margin: 0;
313
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans",

0 commit comments

Comments
 (0)