Skip to content

Commit 175e930

Browse files
committed
Create heading component
1 parent 78a9c46 commit 175e930

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

src/components/ui/heading.astro

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
type Props = {
3+
content: string | { heading: string; subheading: string };
4+
};
5+
6+
let heading;
7+
let subheading;
8+
9+
if (typeof Astro.props.content === "string") {
10+
heading = Astro.props.content;
11+
}
12+
13+
if (typeof Astro.props.content === "object" && Astro.props.content !== null) {
14+
heading = Astro.props.content.heading;
15+
subheading = Astro.props.content.subheading;
16+
}
17+
---
18+
19+
<h1 class:list={{ "no-subheading": typeof subheading !== "string" }}>
20+
{heading}
21+
</h1>
22+
{typeof subheading === "string" && <p>{subheading}</p>}
23+
24+
<style lang="scss">
25+
p {
26+
margin-bottom: v-size(8, "em");
27+
}
28+
.no-subheading {
29+
margin-bottom: v-size(5, "em");
30+
}
31+
</style>

src/pages/projects.astro

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
import ItemCard from "@components/projects/item-card.astro";
3+
import Heading from "@components/ui/heading.astro";
34
import Layout from "@layout/layout.astro";
45
56
import eslintConfigMcecodeGif from "@assets/eslint-config-mcecode.gif";
@@ -10,7 +11,7 @@ import pdfMadeEasyGif from "@assets/pdf-made-easy.gif";
1011
---
1112

1213
<Layout title="Projects">
13-
<h1>Projects</h1>
14+
<Heading content="Projects" />
1415
<ul>
1516
<ItemCard
1617
title="PDF Made Easy"
@@ -59,9 +60,3 @@ import pdfMadeEasyGif from "@assets/pdf-made-easy.gif";
5960
/>
6061
</ul>
6162
</Layout>
62-
63-
<style lang="scss">
64-
h1 {
65-
margin-bottom: v-size(5, "em");
66-
}
67-
</style>

0 commit comments

Comments
 (0)