Promo code field collapsed — Storefront block

Pro

storefront-promo-code-field-collapsed · for cart, checkout pages

Promo code field collapsed

A quiet "Promo code" link that opens the field: the default, so the cart does not tempt a visitor to go hunting for coupons

Documentation

Installation

One command copies the block into your project with the shadcn CLI (the registry is set once: Installation).

pnpm dlx shadcn-vue@latest add @trame/storefront-promo-code-field-collapsed

Usage

Its demo data, shortened (Using blocks).

<script setup lang="ts">
import StorefrontPromoCodeFieldCollapsed from '@/components/trame/blocks/storefront/storefront-promo-code-field-collapsed.vue'

const props = {
label: "Promo code",
action: "cart.promo",
rules: "One code per order; cannot be combined with items already on sale."
}
</script>

<template>
<StorefrontPromoCodeFieldCollapsed v-bind="props" />
</template>

Props

Each prop says who changes it: Words, Picture, Action, Design, Data.* required.

PropTypeDescription
label*stringWordswhat the field is called ("Promo code")
action*stringActionthe page action that checks a code (posted by the form, field "code"); only real codes validate
resultResultDatathe answer of the promo tool after a try, absent before any try
removeActionstringActionthe page action that removes the applied code (posted by the form)
rulesstringWordsthe merchant’s rule sentence ("One code per order, cannot be combined with the sale")
optionsOptionsthe block’s settings: layout choices and secondary words, read by every variant
Result result · 3 props
PropTypeDescription
status*'applied' | 'refused'the result’s status: applied, refused
code*stringthe code the buyer typed, kept in the field when refused, shown as a chip when applied
messagestringthe server’s words: what the code gives, or why it was refused
Options options · 3 props
PropTypeDescription
placeholderstringWordsan example of the format, never a real code
submitLabelstringWordswhat the button does ("Apply")
mood'inverse' | 'brand' | 'warm' | 'tint' | stringa band of the page that redefines the theme surfaces inside it
What it asks your app for

The block never knows your app: it asks it, through one context provided once, where its links lead, what its actions do, how a price reads and which words to say (The host context).

MemberWhat it is for
hrefthe address an action leads to, or null to hide what leads there
actruns a change (subscribe, add to cart, save) and answers { ok } or { ok: false, error }
canwhether the page has this action
cartCountthe cart badge’s number
cartDrawerwhether your app has a cart drawer
cartOpenwhether the cart drawer is open
labelyour word for an interface key, or undefined to keep the block’s own

The words it says itself, in English and French; label(key) replaces any of them:

KeyEnglishFrench
newsletter.alreadyYou are already subscribed.Vous êtes déjà inscrit.
newsletter.doneDone: you are subscribed.C’est noté : vous êtes inscrit.
newsletter.invalidCheck the email address.Vérifiez l’adresse e-mail.
newsletter.tooManyToo many attempts, try again in a moment.Trop de tentatives, réessayez dans un moment.

Features

  • Every word in the server HTML
  • Same markup in Vue and React
  • Theme tokens only: every theme, light and dark
  • Shows what you give it, invents nothing
  • No motion; still under reduced motion
  • Real buttons and links, a visible focus
  • Asks your app through actions: action, removeAction

A storefront section, for cart, checkout pages; it uses @lucide/vue, @vueuse/core, class-variance-authority, clsx, reka-ui, tailwind-merge.

Built with

The components this block is made of; each one installs on its own too.

More storefront blocks

  • Product trust facts list: icon lines under the buy button, one fact per line: the usual place for delivery, returns and guarantee.
  • Product trust facts tiles: a 2 by 2 grid of small cards with a big figure and a caption: when the facts are numbers worth reading at a glance.
  • Product upgrade comparison: the product they have beside the one a step up, the differences in bold, keep or trade up: a considered upgrade.
  • Products by date headed: products grouped under small headings by date (this week, last week): new arrivals told as they came; the merchant’s own products and figures only.
  • Promo split: the offer’s picture beside its words, its code and its end: a full offer told calmly; the merchant’s own only.
  • Protection choice rows: three choices in radio rows, each saying what it adds, with the total: a protection or a service offered with a product.
  • Quick estimate estimator: a quick estimate from the merchant’s own grid: a few choices, one large figure, the rule it uses written beside it.
  • Quick order table: a trade buyer who knows what they want: every reference in a table, a quantity per line, the total running.

All 409 storefront blocks