Skip to content

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.

vue
<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>
PropDefaultWhat it does
variantrequiredprimary, secondary, outline, ghost, link or danger.
sizemdsm, md or lg.
typebuttonThe native type. Use submit for the button that sends a form.
hrefnoneRenders a link that looks like a button. Use it only for navigation.
loadingfalseShows a spinner and keeps the button's width.
labelnoneThe name screen readers hear. Required with icon-only and while loading.
attached (ButtonGroup)falseJoins 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 takes a shopper to another page. Use it inline in a sentence, or on its own as a "Shop all" link.

Not sure about the fit? Read our size guide first.

Shop all knitwearReturns
vue
<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>
PropDefaultWhat it does
hrefnoneWhere the link goes. Without it, plain text is shown.
variantinlineinline inside a sentence, standalone for a link on its own.
arrowfalseAdds a trailing arrow to a standalone link.
externalfalseOpens in a new tab and says so to screen readers.
tonedefaultmuted for footer and meta links.
asaA 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.

vue
<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>
PropDefaultWhat it does
v-model''The text in the field.
typetexttext, email, tel, number, search, url or password.
autocompletenoneLets the browser fill in personal data, such as email or postal-code.
clearabletrue for searchShows a clear button while there is a value.
masknoneA format like ###-####. # is a digit, A a letter.
sizemdsm, 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.

0 / 150

vue
<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>
PropDefaultWhat it does
v-model''The text in the field.
max-lengthnoneThe character limit the counter counts against.
counterfalseShows "12 / 150" under the field.
hard-limitfalseStops typing at the limit.
min-height5remThe 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.

vue
<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>
PropDefaultWhat it does
v-modelnoneThe value as a number, or null when empty.
unit (UnitInput)noneA unit name such as kilogram, centimeter or percent.
currency (CurrencyInput)USDThe currency code, such as ISK or EUR.
localethe app's localeHow the number is written, such as is-IS.
min / max / step0 / none / 1The allowed range, and how far the arrow keys move.
labelnoneA 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.

vue
<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>
PropDefaultWhat it does
v-modelminThe quantity.
min1The lowest quantity. A cart line never goes to 0.
max99The stock or the per-order limit.
item-namenoneNames the product on the buttons, such as "Increase quantity, Wool sweater".
errornoneA message under the stepper, such as "Only 5 left".
sizemdmd, 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.

Material
vue
<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>
PropDefaultWhat it does
v-model (Checkbox)falseChecked or not.
hint (Checkbox)noneA second line under the label.
errornoneA message under the box or the group.
v-model (CheckboxGroup)[]The checked values, as an array.
legend (CheckboxGroup)requiredThe question the group answers.
options (CheckboxGroup)requiredEach 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.

Delivery
vue
<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>
PropDefaultWhat it does
v-modelnoneThe chosen value.
options (RadioGroup)requiredEach option's value, label, and optional hint and meta.
legend (RadioGroup)noneThe question the group answers.
layout (RadioGroup)verticalvertical, row, or cards for delivery and payment choices.
error (RadioGroup)noneA message under the options.
value and name (Radio)value requiredThis 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.

vue
<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>
PropDefaultWhat it does
v-modelfalseOn or off.
descriptionnoneA second line under the label.
sizemdmd, or sm for filter bars.
disabledfalseThe switch cannot be changed.
namenoneThe 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.

Price
vue
<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>
PropDefaultWhat it does
v-model[min, max]The chosen span, lowest first.
min / max0 / 100The ends of the track.
step1How far one move goes. For ISK prices, 100 or 1000 works well.
labelnoneThe visible name, such as "Price". It also names both handles.
format-valuethe locale's number formatHow numbers are written and read aloud, such as 5.000 kr.
inputsfalseAdds 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.

We send the receipt here.

Enter a three-digit postcode, like 101.

vue
<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>
PropDefaultWhat it does
labelnoneThe visible label, written as a noun ("Postcode").
requiredfalseShows * and makes the field required.
optionalfalseShows "(optional)". Use it on the few fields that are.
helpnoneA short instruction under the field.
errornoneThe error message. The field is marked invalid while it is set.
groupfalseWraps 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.

Ask about this sweater

vue
<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>
PropDefaultWhat it does
layoutsinglesingle, two for a two-column grid, or inline for one field and one button.
headingnoneA visible title that names the form.
aria-labelnoneNames the form when it has no visible heading.
submittingfalseShows the submit button loading and disables the other actions.
status-messagenoneA 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.

vue
<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>
PropDefaultWhat it does
clientrequiredThe Eldra SDK client. It reads the form and sends the answers.
localerequiredThe shopper's language, such as is-IS. It picks the labels.
definitionnoneThe form, read in your data loader so it is in the server-rendered page.
form-keynoneThe form's key. Use it instead of definition to read the form in the browser.
layoutsinglesingle, 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.

Eldra