Hello, I followed the documentation for CSS & Styling in Astro to build this component:
---
import type { HTMLTag, Polymorphic } from "astro/types";
type SpaceString = `${number | string}${"px" | "em" | "rem" | "ch" | "vw" | "vh" | "vmin" | "vmax" | "%"}`;
type Props<Tag extends HTMLTag> = Polymorphic<{
as: Tag;
space?: SpaceString;
}>;
const { as: Tag = "div", space = "var(--s0)", class: className, ...props } = Astro.props;
---
<Tag
{...props}
class={`stack ${className ?? ""}`}
style={{
"--space": space,
}}
>
<slot />
</Tag>
<style>
.stack {
display: flex;
flex-direction: column;
justify-content: flex-start;
}
.stack > * {
margin-block: 0;
}
.stack > * + * {
margin-block-start: var(--space, 1.5rem);
}
</style>
Astro compiles it down to this:
.stack:where(.astro-2CSB2562) {
display: flex;
flex-direction: column;
justify-content: flex-start;
}
Which is great but it whenever I pass in space it doesn't do anything because the :where selector doesn't include:
.stack > * {
margin-block: 0;
}
.stack > * + * {
margin-block-start: var(--space, 1.5rem);
}
Is there a way to fix this?