Hvor er vi?
Astro-components
├── src/
└── components/
└── Header.astro
└── CardSection.astro
└── Card.astro
└── Button.astro
└── Footer.astro
Astro-components
<!-- Card.astro -->
<li>
<h3>Animation</h3>
<p>
Learn the latest animation techniques to create stunning motion
design and captivate your audience.
</p>
<a href="/animation" class="btn" data-variant="ghost">Get started</a>
</li>
Astro-components
---
import Card from "../components/Card.astro";
---
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
Props
---
const { title, description } = Astro.props;
---
<article>
<h2>{title}</h2>
<p>{description}</p>
</article>
Saml props op
---
import Card from "../components/Card.astro";
---
<Card title="Jeg er en overskrift"
description="Jeg er en beskrivelse"
/>
Send props til Card-component
Props
---
import Card from "../components/Card.astro";
---
<Card title="Jeg er en overskrift"
description="Jeg er en beskrivelse"
/>
<Card title="Jeg er anderledes"
description="Også mig..."
/>
Scoped styles
---
const { title, description } = Astro.props;
---
<article>
<h2>{title}</h2>
<p>{description}</p>
</article>
<style>
h2 {
color: red;
}
</style>
---
const { variant } = Astro.props;
---
<button class={variant}>
<slot />
</button>
<style>
.secondary {
background: red;
}
</style>
dynamisk
<button>
<slot />
</button>
<Button variant="secondary">Knap</Button>
<button>
<slot />
</button>
Knap
<Button variant="secondary">Knap</Button>
<button>
<slot />
</button>
Knap
øvelse
Sæt dig sammen med sidemakkeren og kig på min løsning (se mere på Fronter).
Giver min tilgang mening?
øvelse
Opret en gratis konto på Netlify.app og læg dit site live
Layouts & Conditionals
speciel mappe
<nav>
<a href="/">Home</a> <!-- index.astro -->
<a href="/search">Search</a> <!-- search.astro -->
</nav>
Genbrugelige sideskabeloner
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Search</title>
</head>
<body>
<h1>Search</h1>
</body>
</html>
point of interest
---
import MainLayout from '../layouts/MainLayout.astro';
---
<MainLayout title="Search">
<h1>Search</h1>
</MainLayout>
point of interest
skabelon med prop
Genbrugelige sideskabeloner
---
const { title } = Astro.props;
---
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
</head>
<body>
<slot />
</body>
</html>
prop
---
import MainLayout from '../layouts/MainLayout.astro';
---
<MainLayout title="Search">
<h1>Search</h1>
</MainLayout>
Genbrugelige sideskabeloner
---
const { title } = Astro.props;
---
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
</head>
<body>
<slot />
</body>
</html>
---
import MainLayout from '../layouts/MainLayout.astro';
---
<MainLayout title="Search">
<h1>Search</h1>
</MainLayout>
sideindhold her
Genbrugelige sideskabeloner
We conventionally use the term “layout” for Astro components that provide common UI elements shared across pages such as headers, navigation bars, and footers.
Genbrugelige sideskabeloner
---
const { title } = Astro.props;
---
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
</head>
<body>
<Header />
<Sidebar />
<main>
<slot />
</main>
<Footer />
</body>
</html>
Vis eller skjul indhold baseret på bestemte betingelser
<article>
<h2>...</h2>
<p class="badge">New</p>
<img />
</article>
<article>
<h2>...</h2>
<img />
</article>
Astro can conditionally display HTML
<p class="badge">New</p>
---
const visible = true;
---
<article>
<h2>...</h2>
<img />
</article>
{
}
&&
visible
<p class="badge">New</p>
---
const visible = true;
---
<article>
<h2>...</h2>
<img />
</article>
<p class="badge">New</p>
{
}
&&
visible
---
const visible = true;
---
<article>
<h2>...</h2>
<img />
</article>
<p class="badge">New</p>
{
}
&&
visible
hvis visible er sand
---
const visible = true;
---
<article>
<h2>...</h2>
<img />
</article>
vis HTML
<p class="badge">New</p>
{
}
&&
visible
---
const { newBadge } = Astro.props;
---
<article>
<h2>...</h2>
{newBadge && <p class="badge">New</p>}
<img />
</article>
<CategoryCard
newBadge={true}
...
/>
---
const { newBadge } = Astro.props;
---
<article>
<h2>...</h2>
{newBadge && <p class="badge">New</p>}
<img />
</article>
<CategoryCard
newBadge={true}
...
/>
<CategoryCard
...
/>
---
const { title } = Astro.props;
---
<article>
{title && <h2>{title}</h2>}
<img />
</article>
<Card
title="Card Heading"
description="Lorem..."
/>
<Card
description="Lorem..."
/>
Dynamiske klasser
<Component
isActive={true}
...
/>
---
const { isActive } = Astro.props;
---
<div class={isActive && "active"}>
...
</div>
hvis isActive er sand -> "active"
active
Dynamiske klasser
Developer Tools
---
const { isActive } = Astro.props;
---
<div class={isActive && "active"}>
...
</div>
active
Dynamiske klasser
Developer Tools
---
const { isActive } = Astro.props;
---
<div class={isActive && "active"}>
...
</div>
active
Dynamiske klasser
Kom i gang
Den færdige løsning
Tekniske krav
Mandag
I morgen
Projektarbejde
Én af jer opretter et projekt, og de andre kloner og kører npm install
GitHub-organization?