Book a callGitHub224

Order summary

3 items
  • Speckled green stoneware cup Speckled stoneware cupMoss glaze · $28.00 each $56.00
    2
  • Cream metal gooseneck desk lamp Gooseneck desk lampCream metal · $96.00 each $96.00
    1
Promo code
AUTUMN15 · 15% off
Subtotal
$152.00
Discount, 15%
−$22.80
Shipping
Free
Sales tax, 8.25%
$10.66
Total
$139.86USD

Charged to the card ending 2861. Free returns within 30 days.

Live preview: try it.

Source
<!-- Icons: Lucide (lucide.dev), ISC licence -->
<style>
.odl-order-summary { box-sizing: border-box; inline-size: 100%; max-inline-size: 28rem; margin-inline: auto; container-type: inline-size; text-wrap: pretty; }
.odl-order-summary *, .odl-order-summary *::before { box-sizing: border-box; }
.odl-order-summary svg { flex: none; stroke-width: var(--ds-icon-stroke-md); }
.odl-order-summary .odl-card { --odl-thumb: calc(var(--ds-size-control-lg) * 1.5); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--ds-space-stack-lg); padding: var(--ds-space-inset-xl); background: var(--ds-color-surface-raised); color: var(--ds-color-text-primary);
  border: var(--ds-border-width-default) solid var(--ds-color-border-subtle); border-radius: var(--ds-radius-container); box-shadow: var(--ds-elevation-raised); font: var(--ds-text-body-md); }
.odl-order-summary .odl-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--ds-space-inline-md); }
.odl-order-summary h3 { margin: 0; font: var(--ds-text-title-md); }
.odl-order-summary .odl-head span { color: var(--ds-color-text-secondary); font: var(--ds-text-body-sm); font-variant-numeric: tabular-nums; }
.odl-order-summary ul { margin: 0; padding: 0; list-style: none; display: grid; }
.odl-order-summary .odl-item { display: grid; grid-template-columns: var(--odl-thumb) minmax(0, 1fr) auto; column-gap: var(--ds-space-inline-md); row-gap: var(--ds-space-stack-sm);
  padding-block: var(--ds-space-stack-md); }
.odl-order-summary .odl-item:not([hidden]) + .odl-item { border-block-start: var(--ds-border-width-default) solid var(--ds-color-border-subtle); }
.odl-order-summary .odl-item:first-child, .odl-order-summary .odl-item[hidden] + .odl-item { padding-block-start: 0; }
.odl-order-summary .odl-item:last-child { padding-block-end: 0; }
.odl-order-summary .odl-thumb { grid-row: span 2; inline-size: var(--odl-thumb); block-size: var(--odl-thumb); border-radius: var(--ds-radius-nested); overflow: hidden;
  background: var(--ds-color-surface-sunken); border: var(--ds-border-width-default) solid var(--ds-color-border-subtle); }
.odl-order-summary .odl-thumb img { display: block; inline-size: 100%; block-size: 100%; object-fit: cover; }
.odl-order-summary .odl-name { display: grid; align-content: start; gap: var(--ds-space-stack-xs); min-inline-size: 0; }
.odl-order-summary .odl-name b { font: var(--ds-text-label-lg); font-weight: var(--ds-font-weight-heading); }
.odl-order-summary .odl-name small { color: var(--ds-color-text-secondary); font: var(--ds-text-body-sm); font-variant-numeric: tabular-nums; }
.odl-order-summary .odl-line { font-variant-numeric: tabular-nums; text-align: end; font-weight: var(--ds-font-weight-label); }
.odl-order-summary .odl-step { grid-column: 2 / -1; justify-self: start; align-self: end; display: inline-flex; align-items: center; border: var(--ds-border-width-default) solid var(--ds-color-border-default);
  border-radius: var(--ds-radius-control); background: var(--ds-color-surface-raised); }
.odl-order-summary .odl-step button { display: grid; place-items: center; min-inline-size: var(--ds-size-target-min); min-block-size: var(--ds-size-target-min); padding: 0;
  border: 0; border-radius: var(--ds-radius-control); background: transparent; color: var(--ds-color-text-primary); cursor: pointer;
  transition: background-color var(--ds-motion-duration-short) var(--ds-motion-easing-standard); }
.odl-order-summary .odl-step button:hover:not(:disabled) { background: var(--ds-color-bg-neutral-subtle); }
.odl-order-summary .odl-step button:disabled { color: var(--ds-color-text-disabled); cursor: not-allowed; }
.odl-order-summary .odl-step svg { inline-size: var(--ds-size-icon-sm); block-size: var(--ds-size-icon-sm); }
.odl-order-summary .odl-step output { min-inline-size: 3ch; text-align: center; font: var(--ds-text-label-lg); font-variant-numeric: tabular-nums; }
.odl-order-summary .odl-promo { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--ds-space-stack-sm); padding-block-start: var(--ds-space-stack-lg); border-block-start: var(--ds-border-width-default) solid var(--ds-color-border-subtle); }
.odl-order-summary .odl-lab { color: var(--ds-color-text-secondary); font: var(--ds-text-label-md); }
.odl-order-summary .odl-field { display: flex; gap: var(--ds-space-inline-sm); }
.odl-order-summary input { flex: 1; inline-size: 0; min-inline-size: 0; min-block-size: max(var(--ds-size-control-md), var(--ds-size-target-min)); padding: 0 var(--ds-space-inset-sm);
  border: var(--ds-border-width-default) solid var(--ds-color-border-input); border-radius: var(--ds-radius-control); background: var(--ds-color-bg-field); color: var(--ds-color-text-primary);
  font: var(--ds-text-body-md); text-transform: uppercase; }
.odl-order-summary input::placeholder { color: var(--ds-color-text-tertiary); text-transform: none; }
.odl-order-summary input[aria-invalid="true"] { border-color: var(--ds-color-border-danger); }
.odl-order-summary .odl-apply { min-block-size: max(var(--ds-size-control-md), var(--ds-size-target-min)); padding: 0 var(--ds-space-inset-md); border: var(--ds-border-width-default) solid var(--ds-color-border-default);
  border-radius: var(--ds-radius-control); background: var(--ds-color-surface-raised); color: var(--ds-color-text-primary); font: var(--ds-text-label-lg); cursor: pointer;
  transition: background-color var(--ds-motion-duration-short) var(--ds-motion-easing-standard); }
.odl-order-summary .odl-apply:hover { background: var(--ds-color-bg-neutral-subtle); }
.odl-order-summary .odl-msg { margin: 0; color: var(--ds-color-text-danger); font: var(--ds-text-body-sm); }
.odl-order-summary .odl-msg:empty { display: none; }
.odl-order-summary .odl-chip { justify-self: start; display: inline-flex; align-items: center; gap: var(--ds-space-inline-sm); padding-inline-start: var(--ds-space-inset-sm);
  border-radius: var(--ds-radius-full); background: var(--ds-color-bg-neutral-subtle); color: var(--ds-color-text-primary); font: var(--ds-text-label-md); }
.odl-order-summary .odl-chip[hidden] { display: none; }
.odl-order-summary .odl-chip code { font: var(--ds-text-code-sm); font-weight: var(--ds-font-weight-label); }
.odl-order-summary .odl-chip svg { inline-size: var(--ds-size-icon-sm); block-size: var(--ds-size-icon-sm); color: var(--ds-color-icon-subtle); }
.odl-order-summary .odl-chip button { display: grid; place-items: center; min-inline-size: var(--ds-size-target-min); min-block-size: var(--ds-size-target-min); padding: 0;
  border: 0; border-radius: var(--ds-radius-full); background: transparent; color: inherit; cursor: pointer; }
.odl-order-summary .odl-chip button:hover svg { color: var(--ds-color-text-primary); }
.odl-order-summary dl { margin: 0; display: grid; gap: var(--ds-space-stack-sm); padding-block-start: var(--ds-space-stack-lg); border-block-start: var(--ds-border-width-default) solid var(--ds-color-border-subtle);
  font-variant-numeric: tabular-nums; }
.odl-order-summary dl div { display: flex; justify-content: space-between; gap: var(--ds-space-inline-md); }
.odl-order-summary dt { color: var(--ds-color-text-secondary); }
.odl-order-summary dd { margin: 0; text-align: end; }
.odl-order-summary .odl-off dd { color: var(--ds-color-text-success); }
.odl-order-summary .odl-off[hidden] { display: none; }
.odl-order-summary .odl-total { align-items: baseline; margin-block-start: var(--ds-space-stack-xs); padding-block-start: var(--ds-space-stack-md); border-block-start: var(--ds-border-width-default) solid var(--ds-color-border-subtle); }
.odl-order-summary .odl-total dt { color: var(--ds-color-text-primary); font: var(--ds-text-label-lg); font-weight: var(--ds-font-weight-heading); }
.odl-order-summary .odl-total dd { font: var(--ds-text-numeric-md); font-weight: var(--ds-font-weight-heading); }
.odl-order-summary .odl-total dd small { margin-inline-start: var(--ds-space-inline-xs); color: var(--ds-color-text-tertiary); font: var(--ds-text-label-md); }
.odl-order-summary .odl-pay { display: inline-flex; align-items: center; justify-content: center; gap: var(--ds-space-inline-sm); inline-size: 100%;
  min-block-size: max(var(--ds-size-control-lg), var(--ds-size-target-min)); padding: 0 var(--ds-space-inset-md); border: 0; border-radius: var(--ds-radius-control);
  background: var(--ds-color-bg-action-primary); color: var(--ds-color-text-on-action); font: var(--ds-text-label-lg); font-weight: var(--ds-font-weight-heading); font-variant-numeric: tabular-nums; cursor: pointer;
  transition: background-color var(--ds-motion-duration-short) var(--ds-motion-easing-standard); }
.odl-order-summary .odl-pay:hover { background: var(--ds-color-bg-action-primary-hover); }
.odl-order-summary .odl-pay:active { background: var(--ds-color-bg-action-primary-pressed); }
.odl-order-summary .odl-pay svg { inline-size: var(--ds-size-icon-sm); block-size: var(--ds-size-icon-sm); }
.odl-order-summary .odl-fine { margin: calc(-1 * var(--ds-space-stack-sm)) 0 0; color: var(--ds-color-text-secondary); font: var(--ds-text-body-sm); text-align: center; text-wrap: balance; }
.odl-order-summary button:focus-visible, .odl-order-summary input:focus-visible { outline: var(--ds-focus-ring-width) solid var(--ds-color-border-focus); outline-offset: var(--ds-focus-ring-offset); }
/* Phone: less outer padding and a slightly smaller photo; the photo stays, the stepper sits under the name. */
@container (max-width: 26rem) {
  .odl-order-summary .odl-card { --odl-thumb: calc(var(--ds-size-control-lg) * 1.25); padding: var(--ds-space-inset-lg); }
}
/* Smallest phones: the price moves under the name so nothing is squeezed. */
@container (max-width: 21rem) {
  .odl-order-summary .odl-card { --odl-thumb: var(--ds-size-control-lg); }
  .odl-order-summary .odl-item { grid-template-columns: var(--odl-thumb) minmax(0, 1fr); }
  .odl-order-summary .odl-thumb { grid-row: span 3; }
  .odl-order-summary .odl-line { grid-column: 2; text-align: start; }
  .odl-order-summary .odl-step { grid-column: 2; }
}
@media (prefers-reduced-motion: reduce) { .odl-order-summary, .odl-order-summary *, .odl-order-summary *::before { transition: none !important; animation: none !important; } }
.odl-order-summary [data-od-template][hidden] { display: none; }
</style>
<section class="odl-order-summary" aria-label="Order summary">
  <div class="odl-card">
    <div class="odl-head"><h3 data-od-slot="title">Order summary</h3><span class="odl-count">3 items</span><data data-od-slot="currency" hidden>USD</data></div>
    <ul data-od-list="items">
      <li class="odl-item" data-od-item data-od-template hidden>
        <span class="odl-thumb"><img data-od-media="photo" data-od-optional alt="" width="72" height="72" loading="lazy" decoding="async" src="https://images.unsplash.com/photo-1782351076283-73aa35f76058?w=144&h=144&fit=crop&auto=format&q=70"></span>
        <span class="odl-name"><b data-od-slot="name"></b><small data-od-slot="variant" data-od-optional></small></span>
        <span class="odl-line"></span>
        <div class="odl-step" role="group" data-od-label="name">
          <button type="button" data-d="-1" aria-label="One fewer"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/></svg></button>
          <output aria-live="polite" data-od-slot="quantity">1</output>
          <button type="button" data-d="1" aria-label="One more"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="M12 5v14"/></svg></button>
        </div>
        <data data-od-slot="price" hidden></data><data data-od-slot="unit" data-od-optional hidden></data><data data-od-slot="units" data-od-optional hidden></data>
      </li>
      <li class="odl-item" data-od-item data-price="28" data-unit="cup" data-units="cups">
        <span class="odl-thumb"><img src="https://images.unsplash.com/photo-1782351076283-73aa35f76058?w=144&h=144&fit=crop&auto=format&q=70" alt="Speckled green stoneware cup" width="72" height="72" loading="lazy" decoding="async"></span>
        <span class="odl-name"><b>Speckled stoneware cup</b><small>Moss glaze · $28.00 each</small></span>
        <span class="odl-line">$56.00</span>
        <div class="odl-step" role="group" aria-label="Stoneware cup quantity">
          <button type="button" data-d="-1" aria-label="One cup fewer"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/></svg></button>
          <output aria-live="polite">2</output>
          <button type="button" data-d="1" aria-label="One cup more"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="M12 5v14"/></svg></button>
        </div>
      </li>
      <li class="odl-item" data-od-item data-price="96" data-unit="lamp" data-units="lamps">
        <span class="odl-thumb"><img src="https://images.unsplash.com/photo-1570974802254-4b0ad1a755f5?w=144&h=144&fit=crop&crop=focalpoint&fp-x=0.5&fp-y=0.55&fp-z=1&auto=format&q=70" alt="Cream metal gooseneck desk lamp" width="72" height="72" loading="lazy" decoding="async"></span>
        <span class="odl-name"><b>Gooseneck desk lamp</b><small>Cream metal · $96.00 each</small></span>
        <span class="odl-line">$96.00</span>
        <div class="odl-step" role="group" aria-label="Desk lamp quantity">
          <button type="button" data-d="-1" aria-label="One lamp fewer"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/></svg></button>
          <output aria-live="polite">1</output>
          <button type="button" data-d="1" aria-label="One lamp more"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="M12 5v14"/></svg></button>
        </div>
      </li>
    </ul>
    <div class="odl-promo">
      <span class="odl-lab">Promo code</span>
      <div class="odl-field">
        <input type="text" aria-label="Promo code" autocomplete="off" spellcheck="false" placeholder="Enter a code">
        <button type="button" class="odl-apply">Apply</button>
      </div>
      <p class="odl-msg" role="alert"></p>
      <span class="odl-chip" data-od-optional><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z"/><circle cx="7.5" cy="7.5" r=".5" fill="currentColor"/></svg>
        <span><code data-od-slot="promo_code">AUTUMN15</code> · <bdi data-od-slot="promo_label">15% off</bdi><data data-od-slot="promo_rate" hidden>0.15</data></span>
        <button type="button" class="odl-remove" aria-label="Remove code AUTUMN15"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button></span>
    </div>
    <dl data-od-list="totals">
      <div data-od-item data-od-template hidden><dt data-od-slot="label"></dt><dd data-od-slot="value"></dd></div>
      <div data-od-item><dt>Subtotal</dt><dd class="odl-sub">$152.00</dd></div>
      <div data-od-item class="odl-off"><dt>Discount, 15%</dt><dd class="odl-disc">−$22.80</dd></div>
      <div data-od-item><dt>Shipping</dt><dd>Free</dd></div>
      <div data-od-item><dt>Sales tax, 8.25%</dt><dd class="odl-tax">$10.66</dd></div>
      <div data-od-item class="odl-total"><dt>Total</dt><dd><span class="odl-sum">$139.86</span><small>USD</small></dd></div>
    </dl>
    <button type="button" class="odl-pay" data-od-action="pay" data-od-effect="change"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg><span data-od-slot="label">Pay</span> <span class="odl-paysum">$139.86</span></button>
    <p class="odl-fine" data-od-slot="fine" data-od-optional>Charged to the card ending 2861. Free returns within 30 days.</p>
  </div>
</section>
<script>
document.querySelectorAll(".odl-order-summary").forEach((root) => {
  if (root.dataset.odlReady) return; // wire once, even if the file is pasted twice
  root.dataset.odlReady = "1";
  // Prices, units and the promo come from marked parts, so a rendered answer works like the sample.
  const slot = (el, n) => ((el.querySelector(`[data-od-slot="${n}"]`) || {}).textContent || "").trim(), num = (t) => parseFloat(String(t).replace(/[^\d.-]/g, ""));
  const cur = slot(root, "currency") || "USD", lang = (root.closest("[lang]") || {}).lang || "en-US";
  const money = (n) => { try { return new Intl.NumberFormat(lang, { style: "currency", currency: cur }).format(n); } catch (e) { return `${cur} ${n.toFixed(2)}`; } };
  const $ = (s) => root.querySelector(s), put = (s, t) => { const el = $(s); if (el) el.textContent = t; };
  const CODE = slot(root, "promo_code"), RATE = num(slot(root, "promo_rate")) || 0, TAX = 0.0825, sample = !!$(".odl-sub");
  const items = [...root.querySelectorAll(".odl-item:not([data-od-template])")];
  items.forEach((item) => {
    if (item.dataset.price) return; // the sample's rows carry their price already
    item.dataset.price = String(num(slot(item, "price")) || 0);
    item.dataset.unit = slot(item, "unit") || "item"; item.dataset.units = slot(item, "units") || item.dataset.unit + "s";
    const out = item.querySelector("output"); if (!(Number(out.textContent) >= 1)) out.textContent = "1";
    const v = item.querySelector('[data-od-slot="variant"]'); if (v) v.textContent = `${v.textContent} · ${money(Number(item.dataset.price))} each`;
    const name = slot(item, "name"), group = item.querySelector(".odl-step");
    group.setAttribute("aria-label", `${name} quantity`);
    group.querySelector('[data-d="-1"]').setAttribute("aria-label", `One ${item.dataset.unit} fewer, ${name}`);
    group.querySelector('[data-d="1"]').setAttribute("aria-label", `One ${item.dataset.unit} more, ${name}`);
  });
  if (!sample) { const rows = root.querySelectorAll("dl > div:not([data-od-template])"), last = rows[rows.length - 1]; if (last) { last.classList.add("odl-total"); put(".odl-paysum", slot(last, "value")); } }
  const input = $("input"), msg = $(".odl-msg"), chip = $(".odl-chip");
  const remove = $(".odl-remove"); if (remove && CODE) remove.setAttribute("aria-label", `Remove code ${CODE}`);
  let applied = !!chip && !!CODE;
  const update = () => {
    let sub = 0, count = 0;
    items.forEach((item) => {
      const q = Number(item.querySelector("output").textContent), line = q * Number(item.dataset.price);
      sub += line; count += q;
      item.querySelector(".odl-line").textContent = money(line);
      item.querySelector('[data-d="-1"]').disabled = q <= 1;
      item.querySelector('[data-d="1"]').disabled = q >= 20;
    });
    const disc = applied ? Math.round(sub * RATE * 100) / 100 : 0;
    const tax = Math.round((sub - disc) * TAX * 100) / 100, total = sub - disc + tax;
    put(".odl-count", `${count} ${count === 1 ? "item" : "items"}`);
    if (chip) chip.hidden = !applied;
    if (!sample) return; // a rendered answer's totals are the app's own
    $(".odl-sub").textContent = money(sub);
    $(".odl-disc").textContent = "−" + money(disc);
    $(".odl-off").hidden = !applied;
    $(".odl-tax").textContent = money(tax);
    $(".odl-sum").textContent = money(total);
    $(".odl-paysum").textContent = money(total);
  };
  root.querySelectorAll(".odl-step button").forEach((b) => b.addEventListener("click", () => {
    const out = b.parentElement.querySelector("output");
    out.textContent = Math.min(20, Math.max(1, Number(out.textContent) + Number(b.dataset.d)));
    update();
  }));
  if (remove) remove.addEventListener("click", () => { applied = false; update(); input.focus(); });
  const apply = () => {
    const code = input.value.trim().toUpperCase();
    if (!code) return;
    const ok = !!CODE && code === CODE.toUpperCase() && !!chip;
    msg.textContent = ok ? "" : `${code} isn't a valid code. Check it and try again.`;
    input.setAttribute("aria-invalid", String(!ok));
    if (ok) { applied = true; input.value = ""; update(); }
  };
  $(".odl-apply").addEventListener("click", apply);
  input.addEventListener("keydown", (e) => { if (e.key === "Enter") apply(); });
  update();
});
</script>

More like this

ConsumerFriendly · Travel

Stay card

A holiday rental or hotel listing.

B2BFriendly · SaaS

Plan picker

Three plans as cards you select.

Your kit

Nothing here yet. Add parts with Add to kit, and a look if you want the whole system.

    Parts
    0
    Files to fetch
    0 KB
    Licence
    MIT
    Total
    Free, now and later

    How do you want it?

    Your prompt

    No sign-up. Nothing leaves your browser until you paste it.

    Free