Actions and forms
These are the buttons, links and fields a shopper uses to act and to answer. Use them for the cart, the checkout, filters and contact forms.
Button and ButtonGroup
Button is the thing a shopper clicks to do something: add to cart, check out, remove a line. ButtonGroup lays related buttons out together, or joins them into one segmented control.
<script setup lang="ts">
import { ref } from 'vue';
import { Button, ButtonGroup, TablerIcon } from '@eldrajs/ui';
const adding = ref(false);
const view = ref<'grid' | 'list'>('grid');
</script>
<template>
<Button variant="primary" :loading="adding" label="Adding to cart" @click="adding = !adding">
<template #leadingIcon><TablerIcon name="shopping-cart" /></template>
Add to cart
</Button>
<Button variant="outline">Save for later</Button>
<Button variant="ghost" icon-only label="Add Wool sweater to wishlist">
<template #leadingIcon><TablerIcon name="heart" /></template>
</Button>
<ButtonGroup attached aria-label="View">
<Button variant="outline" size="sm" :pressed="view === 'grid'" @click="view = 'grid'"
>Grid</Button
>
<Button variant="outline" size="sm" :pressed="view === 'list'" @click="view = 'list'"
>List</Button
>
</ButtonGroup>
</template>| Prop | Default | What it does |
|---|---|---|
variant | required | primary, secondary, outline, ghost, link or danger. |
size | md | sm, md or lg. |
type | button | The native type. Use submit for the button that sends a form. |
href | none | Renders a link that looks like a button. Use it only for navigation. |
loading | false | Shows a spinner and keeps the button's width. |
label | none | The name screen readers hear. Required with icon-only and while loading. |
attached (ButtonGroup) | false | Joins the buttons into one segmented control. |
TIP
An icon-only button needs a label that names the action and the product, like "Add Wool sweater to wishlist".
Link
Link takes a shopper to another page. Use it inline in a sentence, or on its own as a "Shop all" link.
<script setup lang="ts">
import { Link } from '@eldrajs/ui';
</script>
<template>
<p style="margin: 0">
Not sure about the fit? Read our <Link href="#size-guide">size guide</Link> first.
</p>
<Link href="#knitwear" variant="standalone" arrow>Shop all knitwear</Link>
<Link href="#returns" tone="muted">Returns</Link>
</template>| Prop | Default | What it does |
|---|---|---|
href | none | Where the link goes. Without it, plain text is shown. |
variant | inline | inline inside a sentence, standalone for a link on its own. |
arrow | false | Adds a trailing arrow to a standalone link. |
external | false | Opens in a new tab and says so to screen readers. |
tone | default | muted for footer and meta links. |
as | a | A router link component, such as NuxtLink. |
TIP
A Link goes somewhere. An action that only looks like text, such as "Clear all", is a Button with variant="link".
Input
Input is a single-line text field: an email, a name, a discount code or a search.
<script setup lang="ts">
import { ref } from 'vue';
import { Input, TablerIcon } from '@eldrajs/ui';
const email = ref('');
const search = ref('');
</script>
<template>
<div style="width: 100%; max-width: 16rem">
<Input
v-model="email"
type="email"
placeholder="you@example.is"
autocomplete="email"
aria-label="Email"
/>
</div>
<div style="width: 100%; max-width: 16rem">
<Input v-model="search" type="search" placeholder="Search sweaters" aria-label="Search">
<template #leadingIcon><TablerIcon name="search" /></template>
</Input>
</div>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | '' | The text in the field. |
type | text | text, email, tel, number, search, url or password. |
autocomplete | none | Lets the browser fill in personal data, such as email or postal-code. |
clearable | true for search | Shows a clear button while there is a value. |
mask | none | A format like ###-####. # is a digit, A a letter. |
size | md | sm, md or lg. |
TIP
A placeholder is an example, never the label. Put the field in a FieldWrapper to give it a visible label.
Textarea
Textarea is a multi-line text field, for a gift note or a message to the shop.
<script setup lang="ts">
import { ref } from 'vue';
import { Textarea } from '@eldrajs/ui';
const giftNote = ref('');
</script>
<template>
<div style="width: 100%; max-width: 22rem">
<Textarea
v-model="giftNote"
placeholder="Happy birthday, Anna!"
:max-length="150"
counter
aria-label="Gift note"
/>
</div>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | '' | The text in the field. |
max-length | none | The character limit the counter counts against. |
counter | false | Shows "12 / 150" under the field. |
hard-limit | false | Stops typing at the limit. |
min-height | 5rem | The starting height. Size it to the answer you expect. |
UnitInput and CurrencyInput
UnitInput is a number field that shows its unit, such as kilograms or percent. CurrencyInput is the same field for money.
<script setup lang="ts">
import { ref } from 'vue';
import { CurrencyInput, UnitInput } from '@eldrajs/ui';
const weight = ref<number | null>(0.45);
const giftCard = ref<number | null>(5000);
</script>
<template>
<UnitInput v-model="weight" unit="kilogram" locale="is-IS" label="Parcel weight" :step="0.05" />
<CurrencyInput
v-model="giftCard"
currency="ISK"
locale="is-IS"
label="Gift card amount"
:min="1000"
:step="500"
/>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | none | The value as a number, or null when empty. |
unit (UnitInput) | none | A unit name such as kilogram, centimeter or percent. |
currency (CurrencyInput) | USD | The currency code, such as ISK or EUR. |
locale | the app's locale | How the number is written, such as is-IS. |
min / max / step | 0 / none / 1 | The allowed range, and how far the arrow keys move. |
label | none | A label of its own. Leave it out inside a FieldWrapper. |
TIP
The value is the amount people read: 5000 is 5.000 kr. It is not in minor units like Price takes.
QuantityStepper
QuantityStepper sets how many of an item go in the cart, with minus and plus buttons.
<script setup lang="ts">
import { ref } from 'vue';
import { QuantityStepper } from '@eldrajs/ui';
const quantity = ref(1);
</script>
<template>
<QuantityStepper v-model="quantity" :max="5" item-name="Wool sweater" />
<QuantityStepper v-model="quantity" :max="5" size="sm" item-name="Wool sweater" />
<QuantityStepper :model-value="1" disabled item-name="Lopi mittens" />
</template>| Prop | Default | What it does |
|---|---|---|
v-model | min | The quantity. |
min | 1 | The lowest quantity. A cart line never goes to 0. |
max | 99 | The stock or the per-order limit. |
item-name | none | Names the product on the buttons, such as "Increase quantity, Wool sweater". |
error | none | A message under the stepper, such as "Only 5 left". |
size | md | md, or sm for cart lines. |
TIP
In a cart list, always set item-name. Otherwise every line has the same "Increase quantity" button.
Checkbox and CheckboxGroup
Checkbox is one yes-or-no choice, such as accepting the terms. CheckboxGroup asks one question with several answers, such as a material filter.
<script setup lang="ts">
import { ref } from 'vue';
import { Checkbox, CheckboxGroup } from '@eldrajs/ui';
const terms = ref(false);
const materials = ref<string[]>(['merino']);
const materialOptions = [
{ value: 'merino', label: 'Merino wool' },
{ value: 'lopi', label: 'Icelandic lopi' },
{ value: 'cotton', label: 'Organic cotton' },
];
</script>
<template>
<Checkbox v-model="terms" required-mark>I accept the terms of sale</Checkbox>
<CheckboxGroup v-model="materials" legend="Material" :options="materialOptions" />
</template>| Prop | Default | What it does |
|---|---|---|
v-model (Checkbox) | false | Checked or not. |
hint (Checkbox) | none | A second line under the label. |
error | none | A message under the box or the group. |
v-model (CheckboxGroup) | [] | The checked values, as an array. |
legend (CheckboxGroup) | required | The question the group answers. |
options (CheckboxGroup) | required | Each option's value and label. |
RadioGroup and Radio
RadioGroup asks a question with one answer, such as the delivery method. Use Radio alone when the options sit apart in your own layout.
<script setup lang="ts">
import { ref } from 'vue';
import { Radio, RadioGroup } from '@eldrajs/ui';
const shipping = ref('pickup');
const shippingOptions = [
{ value: 'pickup', label: 'Pick up in store', hint: 'Laugavegur 12, Reykjavík', meta: 'Free' },
{ value: 'dropp', label: 'Dropp locker', hint: '1–2 working days', meta: '790 kr.' },
{ value: 'home', label: 'Home delivery', hint: '2–3 working days', meta: '1.490 kr.' },
];
const wrap = ref<string | number>('none');
</script>
<template>
<div style="width: 100%; max-width: 24rem">
<RadioGroup v-model="shipping" legend="Delivery" layout="cards" :options="shippingOptions" />
</div>
<div role="radiogroup" aria-label="Gift wrapping">
<Radio v-model="wrap" name="wrap" value="none" label="No gift wrapping" />
<Radio
v-model="wrap"
name="wrap"
value="paper"
label="Gift wrapping"
hint="Recycled paper, 490 kr."
/>
</div>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | none | The chosen value. |
options (RadioGroup) | required | Each option's value, label, and optional hint and meta. |
legend (RadioGroup) | none | The question the group answers. |
layout (RadioGroup) | vertical | vertical, row, or cards for delivery and payment choices. |
error (RadioGroup) | none | A message under the options. |
value and name (Radio) | value required | This radio's own value, and the name it shares with its siblings. |
TIP
Keep a group to about six options. With more, use a Select.
Switch
Switch turns a setting on or off at once, such as an "In stock only" filter.
<script setup lang="ts">
import { ref } from 'vue';
import { Switch } from '@eldrajs/ui';
const inStockOnly = ref(true);
const giftReceipt = ref(false);
</script>
<template>
<Switch v-model="inStockOnly" size="sm">In stock only</Switch>
<Switch v-model="giftReceipt" description="Prices are left off the receipt.">Gift receipt</Switch>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | false | On or off. |
description | none | A second line under the label. |
size | md | md, or sm for filter bars. |
disabled | false | The switch cannot be changed. |
name | none | The field name when the switch is part of a posted form. |
TIP
A switch acts at once. For a choice that is only saved when a form is sent, use a Checkbox.
RangeSlider
RangeSlider picks a span of numbers with two handles, such as a price filter.
<script setup lang="ts">
import { ref } from 'vue';
import { RangeSlider } from '@eldrajs/ui';
const price = ref<[number, number]>([5000, 25000]);
const isk = new Intl.NumberFormat('is-IS', {
style: 'currency',
currency: 'ISK',
maximumFractionDigits: 0,
});
const formatIsk = (value: number) => isk.format(value);
</script>
<template>
<div style="width: 100%; max-width: 22rem">
<RangeSlider
v-model="price"
label="Price"
:min="0"
:max="40000"
:step="1000"
:format-value="formatIsk"
inputs
/>
</div>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | [min, max] | The chosen span, lowest first. |
min / max | 0 / 100 | The ends of the track. |
step | 1 | How far one move goes. For ISK prices, 100 or 1000 works well. |
label | none | The visible name, such as "Price". It also names both handles. |
format-value | the locale's number format | How numbers are written and read aloud, such as 5.000 kr. |
inputs | false | Adds typed "from" and "to" fields under the track. |
TIP
Run the filter on @change, not on every v-model update. change fires once, when the shopper lets go.
FieldWrapper
FieldWrapper gives a field its label, help text and error message. Put any input from this page inside it.
Enter a three-digit postcode, like 101.
<script setup lang="ts">
import { ref } from 'vue';
import { FieldWrapper, Input } from '@eldrajs/ui';
const email = ref('');
const postcode = ref('10');
</script>
<template>
<div style="width: 100%; max-width: 18rem">
<FieldWrapper label="Email" required help="We send the receipt here.">
<Input v-model="email" type="email" autocomplete="email" />
</FieldWrapper>
</div>
<div style="width: 100%; max-width: 18rem">
<FieldWrapper label="Postcode" required error="Enter a three-digit postcode, like 101.">
<Input v-model="postcode" inputmode="numeric" autocomplete="postal-code" />
</FieldWrapper>
</div>
</template>| Prop | Default | What it does |
|---|---|---|
label | none | The visible label, written as a noun ("Postcode"). |
required | false | Shows * and makes the field required. |
optional | false | Shows "(optional)". Use it on the few fields that are. |
help | none | A short instruction under the field. |
error | none | The error message. The field is marked invalid while it is set. |
group | false | Wraps a set of checkboxes or radios that answer one question. |
TIP
An error says how to fix the answer, such as "Enter a three-digit postcode, like 101". "Invalid input" helps no one.
FormLayout
FormLayout is the form itself: the fields in one or two columns, the buttons under them, and focus moved to the first error on submit.
<script setup lang="ts">
import { reactive, ref } from 'vue';
import { Button, FieldWrapper, FormLayout, Input, Textarea } from '@eldrajs/ui';
const contact = reactive({ name: '', email: '', message: '' });
const sending = ref(false);
const sent = ref('');
function onContactSubmit({ event }: { event: SubmitEvent }) {
event.preventDefault();
sent.value = 'Thanks, we will answer within one working day.';
}
</script>
<template>
<div style="width: 100%; max-width: 32rem">
<FormLayout
heading="Ask about this sweater"
:heading-level="3"
:submitting="sending"
:status-message="sent"
@submit="onContactSubmit"
>
<FieldWrapper label="Name" required
><Input v-model="contact.name" autocomplete="name"
/></FieldWrapper>
<FieldWrapper label="Email" required
><Input v-model="contact.email" type="email" autocomplete="email"
/></FieldWrapper>
<FieldWrapper label="Message" required>
<Textarea v-model="contact.message" placeholder="Does the large fit a 104 cm chest?" />
</FieldWrapper>
<template #actions>
<Button variant="primary" type="submit" label="Sending your question">Send question</Button>
</template>
</FormLayout>
</div>
</template>| Prop | Default | What it does |
|---|---|---|
layout | single | single, two for a two-column grid, or inline for one field and one button. |
heading | none | A visible title that names the form. |
aria-label | none | Names the form when it has no visible heading. |
submitting | false | Shows the submit button loading and disables the other actions. |
status-message | none | A sentence read aloud to screen readers, such as "Thanks, you're subscribed". |
TIP
@submit hands you { event, data } and leaves the native post alone. Call event.preventDefault() when you send the form with script.
SiteForm
SiteForm draws a form the merchant built in Studio, such as a contact or newsletter form, and sends the answers to Eldra. There is no live example here, because it needs the Eldra SDK and a real shop to read the form from.
<script setup lang="ts">
import { createEldraClient } from '@eldrajs/sdk';
import { SiteForm } from '@eldrajs/ui';
const eldra = createEldraClient({ orgId: useRuntimeConfig().public.eldraOrgId });
const { data: contact } = await useAsyncData('form:contact', () => eldra.forms.get('contact'));
</script>
<template>
<SiteForm :definition="contact" :client="eldra" locale="is-IS" heading="Contact us" />
</template>| Prop | Default | What it does |
|---|---|---|
client | required | The Eldra SDK client. It reads the form and sends the answers. |
locale | required | The shopper's language, such as is-IS. It picks the labels. |
definition | none | The form, read in your data loader so it is in the server-rendered page. |
form-key | none | The form's key. Use it instead of definition to read the form in the browser. |
layout | single | single, two or inline. |
submit-label | "Send" | The submit button's text. |
TIP
Pass definition rather than only form-key. Then the form is in the first HTML, and shoppers never see it load.