Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Card component #11

Merged
merged 2 commits into from
Jun 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/components/Card.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
const { colour, title, description } = Astro.props;
---

<style define:vars={{ colour }}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually really interesting, I didn't consider how and if astro could handle passing code level variables to the style.

Copy link
Contributor Author

@xxArchitect xxArchitect Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking how to set this up with as little hustle as possible and found this to be the fastest way to do so. Here is the link to Astro docs if you are interested.

* {
font-family: Helvetica, sans-serif;
}

div {
background-color: var(--colour);
border-radius: 0.3em;
width: 30em;
height: 15em;
}

h1, p, button {
position: relative;
Copy link
Member

@MathyouMB MathyouMB Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using position relative and super positioning everything using top, left, and right units I'd recommend using margin and padding. You'll save a lot of lines by having a padding of 1 rem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point! I will update it to use margins/padding instead of positioning.

}

h1 {
left: 1em;
top: 1em;
left: 1em;
font-weight: 300;
}

p {
top: 2em;
left: 2.2em;
}

button {
bottom: -5.5rem;
left: 2.5em;
width: 5.5em;
height: 2.5em;
font-size: medium;
border-radius: 5em;
border: 0em solid black;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why you use em instead of rem for most of the units?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure... I can fix it to have to rem instead of em.

background-color: black;
color: white;
font-weight: 200;
}
</style>

<div>
<h1>{title}</h1>
<p>{description}</p>
<button>Read</button>
</div>