Overlays and feedback
These components open on top of the page or tell the shopper what just happened. Use them for dialogs, side panels, menus, hints and messages.
Dialog
A modal window for a short question or a small form that needs the shopper's answer before they go on.
<script setup lang="ts">
import { ref } from 'vue';
import { Button, Dialog } from '@eldrajs/ui';
const dialogOpen = ref(false);
const confirmOpen = ref(false);
</script>
<template>
<Button variant="outline" @click="dialogOpen = true">Save to wishlist</Button>
<Dialog
v-model="dialogOpen"
title="Saved to your wishlist"
description="You can find it any time under Account, Wishlist."
>
<template #footer>
<Button variant="primary" @click="dialogOpen = false">Got it</Button>
</template>
</Dialog>
<Button variant="danger" @click="confirmOpen = true">Empty cart</Button>
<Dialog
v-model="confirmOpen"
size="sm"
title="Empty your cart?"
description="This removes all 3 items. You cannot undo it."
:dismissable="false"
>
<template #footer>
<Button variant="ghost" @click="confirmOpen = false">Keep items</Button>
<Button variant="danger" @click="confirmOpen = false">Empty cart</Button>
</template>
</Dialog>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | false | Opens and closes the dialog. |
title | none | The heading. It also names the dialog for screen readers. |
description | none | A line of text under the title. Leave it out when the body is a form. |
size | "md" | "sm" for a short message, "md" for most dialogs. |
dismissable | true | Whether a click on the backdrop closes it. Esc and the close button always do. |
Put the body in the default slot and the buttons in the footer slot.
TIP
Set :dismissable="false" on a destructive confirm or a half-filled form. A stray click outside should not count as an answer.
Drawer
A panel that slides in from the side of the screen, for the cart, filters or the mobile menu.
<script setup lang="ts">
import { ref } from 'vue';
import { Button, Drawer } from '@eldrajs/ui';
const cartOpen = ref(false);
const menuOpen = ref(false);
</script>
<template>
<Button variant="primary" @click="cartOpen = true">Open cart</Button>
<Drawer v-model="cartOpen" title="Your cart" :count="3">
<p>Wool sweater · Oatmeal · M</p>
<p>Wool beanie · Moss</p>
<p>Wool socks · Fjord blue · 2 pairs</p>
<template #footer>
<Button variant="primary" block @click="cartOpen = false">Go to checkout · 32.970 kr.</Button>
</template>
</Drawer>
<Button variant="outline" @click="menuOpen = true">Open menu</Button>
<Drawer v-model="menuOpen" side="left" aria-label="Menu">
<nav>
<p><a href="#drawer">Women</a></p>
<p><a href="#drawer">Men</a></p>
<p><a href="#drawer">Knitwear</a></p>
</nav>
</Drawer>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | false | Opens and closes the drawer. |
side | "right" | "left" for the mobile menu, "right" for everything else. |
title | none | The visible heading, such as "Your cart". |
aria-label | none | A name for screen readers when there is no visible title. |
count | none | A number after the title: "Your cart (3)". |
mobile-sheet | false | On phones, open as a sheet from the bottom instead of full screen. |
TIP
Give every drawer a title or an aria-label. Without one, screen reader users do not know what opened.
Popover
A small panel that opens under a button, for a short menu or a quick filter.
<script setup lang="ts">
import { h } from 'vue';
import { Button, Popover, TablerIcon } from '@eldrajs/ui';
const ShareIcon = () => h(TablerIcon, { name: 'share' });
</script>
<template>
<Popover aria-label="Share this product">
<template #trigger="{ attrs }">
<Button variant="outline" :icon-left="ShareIcon" v-bind="attrs">Share</Button>
</template>
<template #default="{ close }">
<div style="display: flex; flex-direction: column; padding: 0.5rem; gap: 0.25rem;">
<a href="#popover" @click="close()">Copy link</a>
<a href="#popover" @click="close()">Send by email</a>
</div>
</template>
</Popover>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | false | Opens and closes the panel. Optional: the popover manages itself when unbound. |
placement | "auto" | Where the panel opens: "auto" (below, flips above), "above", or a corner like "bottom-end". |
aria-label | none | A name for the panel when it has no visible heading. |
match-width | none | true keeps the panel at least as wide as the button. |
close-on-outside-click | true | Close when the shopper clicks elsewhere. |
The button goes in the trigger slot. The panel content goes in the default slot, which also gives you a close function.
TIP
Spread the trigger slot's attrs onto your button with v-bind="attrs". That wires up the click, the keyboard and the screen reader state.
Tooltip
A small label that shows when the shopper hovers over or focuses a button. Use it to name an icon-only button.
<script setup lang="ts">
import { h } from 'vue';
import { Button, TablerIcon, Tooltip } from '@eldrajs/ui';
const HeartIcon = () => h(TablerIcon, { name: 'heart' });
const ShareIcon = () => h(TablerIcon, { name: 'share' });
</script>
<template>
<Tooltip text="Add to wishlist">
<Button variant="ghost" icon-only :icon="HeartIcon" label="Add wool sweater to wishlist" />
</Tooltip>
<Tooltip text="Opens a share menu" role="description" placement="bottom">
<Button variant="outline" :icon-left="ShareIcon">Share</Button>
</Tooltip>
</template>| Prop | Default | What it does |
|---|---|---|
text | required | The label, a few words. |
placement | "top" | "top" or "bottom" of the button. |
align | "center" | "start" or "end" for a button near the edge of the screen. |
role | "label" | "label" names an icon-only button. "description" adds a hint to a button that already has text. |
TIP
Never put a price, an error or a link in a tooltip. Touch screens cannot hover, so many shoppers never see it.
Toast and Toaster
A toast is a short message that pops up in a corner, such as "Added to cart". Put one Toaster in your app and raise toasts from anywhere with useToast().
<script setup lang="ts">
import { Button, Toaster, useToast } from '@eldrajs/ui';
const toast = useToast();
function addToCart() {
toast.show({
title: 'Added to cart',
text: 'Wool sweater · Oatmeal · M',
action: { label: 'View cart (3)', href: '#toast-and-toaster' },
});
}
function lowStock() {
toast.show({ variant: 'warning', title: 'Only 2 left in stock' });
}
</script>
<template>
<Button variant="primary" @click="addToCart">Add to cart</Button>
<Button variant="outline" @click="lowStock">Show stock warning</Button>
<Toaster />
</template>You can also draw a single Toast yourself, for example in a layout preview:
Added to cart
Wool sweater · Oatmeal · M
Couldn't update your cart
<script setup lang="ts">
import { Toast } from '@eldrajs/ui';
</script>
<template>
<Toast title="Added to cart" text="Wool sweater · Oatmeal · M" :closable="false" />
<Toast variant="danger" title="Couldn't update your cart" :closable="false" />
</template>toast.show() option | Default | What it does |
|---|---|---|
title | required | The message. |
variant | "success" | "success", "info", "warning" or "danger". Sets the icon, colour and timing. |
text | none | One supporting line under the title. |
action | none | One link ({ label, href }) or button ({ label, onActivate }). |
duration | per variant | Milliseconds before it closes. 0 keeps it open. A danger toast always stays. |
Toaster prop | Default | What it does |
|---|---|---|
position | "bottom-right" | The corner the stack sits in, such as "top-center". |
newest-on-top | false | Show the newest toast first. |
max-visible | all | Show at most this many toasts at once. |
TIP
Mount Toaster once, near the root of your app. Two toasters would show every toast twice.
Notice
A message that sits in the page, such as a delivery note or an order confirmation. Unlike a toast, it stays.
Free delivery
Thank you for your order
<script setup lang="ts">
import { Notice } from '@eldrajs/ui';
</script>
<template>
<Notice
title="Free delivery"
text="Orders over 15.000 kr. ship free within Iceland."
:announce="false"
/>
<Notice
tone="success"
title="Thank you for your order"
text="We have sent a receipt to your email."
:announce="false"
/>
<Notice tone="warning" text="Only 2 left in stock in size M." :announce="false" />
</template>| Prop | Default | What it does |
|---|---|---|
tone | "info" | "info", "success", "warning" or "danger". Sets the colour and icon. |
title | none | An optional heading line. |
text | none | The message. Use the default slot instead for links or several paragraphs. |
heading-level | none | Makes the title a real heading, such as 2 for a confirmation page. |
announce | true | Reads the notice aloud when it appears. Set false for a notice that is there from page load. |
Buttons or links for the notice go in the actions slot.
TIP
Keep the icon on success, warning and danger notices. Colour alone is not enough for shoppers who cannot see it.
Lightbox
A full-screen photo viewer for product images, with arrows, thumbnails and zoom.
<script setup lang="ts">
import { ref } from 'vue';
import { Lightbox } from '@eldrajs/ui';
const photos = [
{
src: '/images/sweater-oatmeal.jpg',
alt: 'Wool sweater in oatmeal, front',
caption: 'Oatmeal',
width: 1200,
height: 1500,
},
{
src: '/images/sweater-blue.jpg',
alt: 'Wool sweater in fjord blue, front',
caption: 'Fjord blue',
width: 1200,
height: 1500,
},
{
src: '/images/sweater-moss.jpg',
alt: 'Wool sweater in moss green, front',
caption: 'Moss',
width: 1200,
height: 1500,
},
];
const lightboxOpen = ref(false);
const lightboxIndex = ref(0);
function openPhoto(i: number) {
lightboxIndex.value = i;
lightboxOpen.value = true;
}
</script>
<template>
<button
v-for="(photo, i) in photos"
:key="photo.src"
type="button"
style="padding: 0; border: 0; background: none; cursor: zoom-in;"
@click="openPhoto(i)"
>
<img
:src="photo.src"
:alt="photo.alt"
width="96"
height="120"
style="display: block; border-radius: 0.25rem;"
/>
</button>
<Lightbox
v-model="lightboxOpen"
v-model:index="lightboxIndex"
:images="photos"
aria-label="Wool sweater, images"
thumbnails
zoom
/>
</template>| Prop | Default | What it does |
|---|---|---|
images | required | The photos, each with src, alt, width, height and an optional caption. |
aria-label | required | A name for the viewer, such as "Wool sweater, images". |
v-model | false | Opens and closes the viewer. |
v-model:index | 0 | Which photo shows. Set it to the photo the shopper clicked. |
thumbnails | false | Shows a strip of small pictures to jump between. |
zoom | false | Lets the shopper click to see the photo at full size. |
TIP
Give each image its real width and height in pixels. The viewer uses them to keep each photo's shape.
Layout helpers
Four small building blocks for page layout and accessibility.
Container and Section
Section is one band of the page with a background and vertical spacing. Container keeps the content inside at a readable width.
Every sweater is knitted in Iceland from local wool.
Get 10% off your first order.
<script setup lang="ts">
import { Container, Section } from '@eldrajs/ui';
</script>
<template>
<Section background="surface" spacing="sm" aria-label="Our wool">
<Container width="narrow">
<p>Every sweater is knitted in Iceland from local wool.</p>
</Container>
</Section>
<Section background="primary" spacing="sm" aria-label="Newsletter">
<Container width="narrow">
<p>Get 10% off your first order.</p>
</Container>
</Section>
</template>| Prop | Default | What it does |
|---|---|---|
Section background | "none" | "none", "surface", "surface-strong", "primary" or "accent". |
Section spacing | "md" | Space above and below: "none", "sm", "md" or "lg". |
Section labelled-by / aria-label | none | Names the section for screen readers. Use labelled-by with the id of its visible heading. |
Container width | "content" | "narrow" for text, "content" for most blocks, "wide" for product grids, "full" for edge-to-edge images. |
TIP
Never put a Section inside another Section. Nest Containers instead.
VisuallyHidden
Text that screen readers read but the page does not show. Use it for skip links and for extra context next to an icon.
<script setup lang="ts">
import { VisuallyHidden } from '@eldrajs/ui';
</script>
<template>
<VisuallyHidden as="a" href="#layout-helpers" focusable>Skip to content</VisuallyHidden>
<span>3.490 kr. <VisuallyHidden>, was 4.990 kr.</VisuallyHidden></span>
</template>Press Tab in the example above to see the skip link appear.
| Prop | Default | What it does |
|---|---|---|
as | "span" | The element to render, such as "a" for a skip link. |
focusable | false | Shows the content while it has focus. Use it for skip links. |
EditorPlaceholder
A dashed box that shows in the page editor where a block has no content yet. Render it only while editing, so shoppers never see it.
Add products
Pick a collection or up to 12 products to show in this grid.
Add a heading
<script setup lang="ts">
import { EditorPlaceholder } from '@eldrajs/ui';
</script>
<template>
<EditorPlaceholder
label="Add products"
help="Pick a collection or up to 12 products to show in this grid."
/>
<EditorPlaceholder label="Add a heading" inline />
</template>| Prop | Default | What it does |
|---|---|---|
label | required | The action, such as "Add products". |
help | none | One line of guidance under the label. |
inline | false | Smaller padding, for an empty heading or text field. |
icon | none | An icon component shown above the label. |