[ @sdxc/u/layout ]
hstack
A horizontal flex stack.
import { hstack } from "@sdxc/u/layout";Quick reference
Every documented call, beside the CSS it emits.
| Call | CSS |
|---|---|
u.hstack({ gap: 4, align: "center", justify: "between" }) | css({ display: "flex", flexDirection: "row", gap: "calc(var(--ui-spacing, 0.25rem) * 4)", alignItems: "center", justifyContent: "space-between" }) |
Examples
Basic example
Use hstack() to lay children out in a row, with the gap option setting the space between them:
01
02
03
<div mix={[hstack({ gap: 4 }), ...]}>
<div mix={[...]}>01</div>
<div mix={[...]}>02</div>
<div mix={[...]}>03</div>
</div>Aligning items
Use the align option to place items on the vertical axis, like align: "center":
01
02
03
<div mix={[hstack({ gap: 4, align: "center" }), ...]}>
<div mix={[bs(12), ...]}>01</div>
<div mix={[bs(24), ...]}>02</div>
<div mix={[bs(16), ...]}>03</div>
</div>Justifying items
Use the justify option to distribute items along the row, like justify: "between" for a toolbar:
Inbox
<div mix={[hstack({ align: "center", justify: "between" }), ...]}>
<span mix={[weight("semibold")]}>Inbox</span>
<div mix={[hstack({ gap: 2 })]}>
<button type="button" mix={[...]}>
Archive
</button>
<button type="button" mix={[...]}>
Reply
</button>
</div>
</div>Applying on a state
Wrap the call in a state utility to scope it to one selector.
u.hover(u.hstack({ gap: 4, align: "center", justify: "between" }))Responsive design
Wrap the call in a container query to scope it to one width.
u.at("md", u.hstack({ gap: 4, align: "center", justify: "between" }))Customizing your theme
Customizing spacing
Every numeric step multiplies --ui-spacing, so redefining it rescales every spacing and sizing utility at once:
:root {
--ui-spacing: 0.25rem;
}Every call that names the step now reads the new value:
p(4)Signature
u.hstack(options?: StackOptions)