Skip to content
ui8kit

component / components

Product Price

Product Price component

Install

npx ui8kit add product-price

Pulls in: badge, compose, group, inline, kit-box, kit-text, text, utils

Preview

$89

New

Code

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdn
npx ui8kit add product-price
components/product-price.svelte
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
  The price line of a product page: the price (integer minor units in the currency), the old price (compare_at)
  struck through when higher, and the badge.
-->
<script lang="ts" module>
  import type { Snippet } from "svelte";

  export type ProductPriceProps = {
    price: number;
    compareAt?: number;
    currency: string;
    badge?: string;
    was: string;
  };
</script>

<script lang="ts">
  import Badge from "../compose/Badge.svelte";
  import Group from "../compose/Group.svelte";
  import Inline from "../compose/Inline.svelte";
  import Text from "../compose/Text.svelte";
  import { fmtMoney } from "../utils";

  let { price, compareAt, currency, badge = "", was }: ProductPriceProps = $props();
</script>

<Group gap="4" align="center" class="flex-wrap" data-slot="product-price">
  <Text size="4xl" weight="bold">
    {fmtMoney(price, currency)}
  </Text>
  {#if (compareAt && (compareAt > price))}
    <Text tag="del" size="lg" class="relative text-muted-foreground" data-slot="compare-at">
      <Inline class="sr-only">
        {was}
      </Inline>
      {fmtMoney(compareAt, currency)}
    </Text>
  {/if}
  {#if badge}
    <Badge variant="default" size="default">
      {badge}
    </Badge>
  {/if}
</Group>

Svelte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdn
npx ui8kit add product-price
components/product-price.tsx
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
 * The price line of a product page: the price (integer minor units in the currency), the old price (compare_at)
 * struck through when higher, and the badge.
 */
import { type ReactNode } from "react";
import { Badge, Group, Inline, Text } from "../compose";
import { fmtMoney } from "../utils";

export type ProductPriceProps = {
  price: number;
  compareAt?: number;
  currency: string;
  badge?: string;
  was: string;
};

export function ProductPrice({ price, compareAt, currency, badge = "", was }: ProductPriceProps) {
  return (
    <Group gap="4" align="center" className="flex-wrap" data-slot="product-price">
      <Text size="4xl" weight="bold">
        {fmtMoney(price, currency)}
      </Text>
      {(compareAt && (compareAt > price)) ? (
        <Text tag="del" size="lg" className="relative text-muted-foreground" data-slot="compare-at">
          <Inline className="sr-only">
            {was}
          </Inline>
          {fmtMoney(compareAt, currency)}
        </Text>
      ) : null}
      {badge ? (
        <Badge variant="default" size="default">
          {badge}
        </Badge>
      ) : null}
    </Group>
  );
}

React registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdn
npx ui8kit add product-price
components/product-price.vue
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
  The price line of a product page: the price (integer minor units in the currency), the old price (compare_at)
  struck through when higher, and the badge.
-->
<script lang="ts">
export type ProductPriceProps = {
  price: number;
  compareAt?: number;
  currency: string;
  badge?: string;
  was: string;
};
</script>

<script setup lang="ts">
import Badge from "../compose/Badge.vue";
import Group from "../compose/Group.vue";
import Inline from "../compose/Inline.vue";
import Text from "../compose/Text.vue";
import { fmtMoney } from "../utils";

const { price, compareAt, currency, badge = "", was } = defineProps<ProductPriceProps>();
</script>

<template>
  <Group gap="4" align="center" class="flex-wrap" data-slot="product-price">
    <Text size="4xl" weight="bold">
      {{ fmtMoney(price, currency) }}
    </Text>
    <Text
      v-if="(compareAt && (compareAt > price))"
      tag="del"
      size="lg"
      class="relative text-muted-foreground"
      data-slot="compare-at"
    >
      <Inline class="sr-only">
        {{ was }}
      </Inline>
      {{ fmtMoney(compareAt, currency) }}
    </Text>
    <Badge v-if="badge" variant="default" size="default">
      {{ badge }}
    </Badge>
  </Group>
</template>

Vue registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdn
npx ui8kit add product-price
components/product-price.tsx
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
 * The price line of a product page: the price (integer minor units in the currency), the old price (compare_at)
 * struck through when higher, and the badge.
 */
import { type JSX } from "solid-js";
import { Badge, Group, Inline, Text } from "../compose";
import { fmtMoney } from "../utils";

export type ProductPriceProps = {
  price: number;
  compareAt?: number;
  currency: string;
  badge?: string;
  was: string;
};

export function ProductPrice({ price, compareAt, currency, badge = "", was }: ProductPriceProps) {
  return (
    <Group gap="4" align="center" class="flex-wrap" data-slot="product-price">
      <Text size="4xl" weight="bold">
        {fmtMoney(price, currency)}
      </Text>
      {(compareAt && (compareAt > price)) ? (
        <Text tag="del" size="lg" class="relative text-muted-foreground" data-slot="compare-at">
          <Inline class="sr-only">
            {was}
          </Inline>
          {fmtMoney(compareAt, currency)}
        </Text>
      ) : null}
      {badge ? (
        <Badge variant="default" size="default">
          {badge}
        </Badge>
      ) : null}
    </Group>
  );
}

Solid registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdn
npx ui8kit add product-price
blocks/product-price.templ
// Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Source: packages/compose-gen/specs/organisms/product-price.json

package blocks

import (
	"github.com/ui8kit/codegen/generated/templ/ui/box"
	"github.com/ui8kit/codegen/generated/templ/compose"
	"github.com/ui8kit/codegen/generated/templ/ui/text"
	uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)

// ProductPriceProps are the props of ProductPrice; the values are the JSON shapes of the TypeScript props.
type ProductPriceProps struct {
	Price any `json:"price"`
	CompareAt any `json:"compareAt"`
	Currency any `json:"currency"`
	Badge any `json:"badge"`
	Was any `json:"was"`
}

// The price line of a product page: the price (integer minor units in the currency), the old price (compare_at) struck through when higher, and the badge.
templ ProductPrice(p ProductPriceProps) {
	{{ vPrice := p.Price }}
	{{ vCompareAt := p.CompareAt }}
	{{ vCurrency := p.Currency }}
	{{ vBadge := uiutils.Def(p.Badge, "") }}
	{{ vWas := p.Was }}
	@compose.Group(compose.GroupProps{Gap: "4", Align: "center", BoxProps: box.BoxProps{Class: "flex-wrap", Attrs: uiutils.Attrs("data-slot", "product-price")}}) {
		@compose.Text(compose.TextProps{Size: "4xl", Weight: "bold", TextProps: text.TextProps{}}) {
			{ uiutils.Text(uiutils.Money(vPrice, vCurrency)) }
		}
		if uiutils.T(uiutils.And(vCompareAt, uiutils.Gt(vCompareAt, vPrice))) {
			@compose.Text(compose.TextProps{Size: "lg", TextProps: text.TextProps{Tag: "del", Class: "relative text-muted-foreground", Attrs: uiutils.Attrs("data-slot", "compare-at")}}) {
				@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "sr-only"}}) {
					{ uiutils.Text(vWas) }
				}
				{ uiutils.Text(uiutils.Money(vCompareAt, vCurrency)) }
			}
		}
		if uiutils.T(vBadge) {
			@compose.Badge(compose.BadgeProps{Variant: "default", Size: "default", TextProps: text.TextProps{}}) {
				{ uiutils.Text(vBadge) }
			}
		}
	}
}

templ registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdn
npx ui8kit add product-price
blocks/product-price.html.twig
{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/organisms/product-price.json
    The price line of a product page: the price (integer minor units in the currency), the old price (compare_at) struck through when higher, and the badge.
    Props (p): price, compareAt, currency, badge, was. -#}
{%- set v_price = (p.price ?? null) -%}
{%- set v_compareAt = (p.compareAt ?? null) -%}
{%- set v_currency = (p.currency ?? null) -%}
{%- set v_badge = (p.badge ?? '') -%}
{%- set v_was = (p.was ?? null) -%}
{%- set c_5 -%}
  {%- set c_1 -%}
    {{ og_text(og_money(v_price, v_currency)) }}
  {%- endset -%}
  {{ include('compose/Text.html.twig', {'size': '4xl', 'weight': 'bold', 'children': c_1}, with_context = false) }}
  {%- if og_t(og_and([v_compareAt, og_gt(v_compareAt, v_price)])) %}
    {%- set c_3 -%}
      {%- set c_2 -%}
        {{ og_text(v_was) }}
      {%- endset -%}
      {{ include('compose/Inline.html.twig', {'class': 'sr-only', 'children': c_2}, with_context = false) }}
      {{ og_text(og_money(v_compareAt, v_currency)) }}
    {%- endset -%}
    {{ include('compose/Text.html.twig', {'tag': 'del', 'size': 'lg', 'class': 'relative text-muted-foreground', 'attrs': og_attrs(['data-slot', 'compare-at']), 'children': c_3}, with_context = false) }}
  {%- endif %}
  {%- if og_t(v_badge) %}
    {%- set c_4 -%}
      {{ og_text(v_badge) }}
    {%- endset -%}
    {{ include('compose/Badge.html.twig', {'variant': 'default', 'size': 'default', 'children': c_4}, with_context = false) }}
  {%- endif %}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '4', 'align': 'center', 'class': 'flex-wrap', 'attrs': og_attrs(['data-slot', 'product-price']), 'children': c_5}, with_context = false) }}

Twig registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdn
npx ui8kit add product-price
blocks/product-price.latte
{* Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/organisms/product-price.json
    The price line of a product page: the price (integer minor units in the currency), the old price (compare_at) struck through when higher, and the badge.
    Props (p): price, compareAt, currency, badge, was. *}
{var $v_price = ($p['price'] ?? null)}
{var $v_compareAt = ($p['compareAt'] ?? null)}
{var $v_currency = ($p['currency'] ?? null)}
{var $v_badge = ($p['badge'] ?? '')}
{var $v_was = ($p['was'] ?? null)}
{capture $c_5}
  {capture $c_1}
    {=og_text(og_money($v_price, $v_currency))}
  {/capture}
  {=og_include('compose/Text.latte', ['size' => '4xl', 'weight' => 'bold', 'children' => (string) $c_1])|noescape}
  {if og_t(og_and([$v_compareAt, og_gt($v_compareAt, $v_price)]))}
    {capture $c_3}
      {capture $c_2}
        {=og_text($v_was)}
      {/capture}
      {=og_include('compose/Inline.latte', ['class' => 'sr-only', 'children' => (string) $c_2])|noescape}
      {=og_text(og_money($v_compareAt, $v_currency))}
    {/capture}
    {=og_include('compose/Text.latte', ['tag' => 'del', 'size' => 'lg', 'class' => 'relative text-muted-foreground', 'attrs' => og_attrs(['data-slot', 'compare-at']), 'children' => (string) $c_3])|noescape}
  {/if}
  {if og_t($v_badge)}
    {capture $c_4}
      {=og_text($v_badge)}
    {/capture}
    {=og_include('compose/Badge.latte', ['variant' => 'default', 'size' => 'default', 'children' => (string) $c_4])|noescape}
  {/if}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '4', 'align' => 'center', 'class' => 'flex-wrap', 'attrs' => og_attrs(['data-slot', 'product-price']), 'children' => (string) $c_5])|noescape}

Latte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdn
npx ui8kit add product-price
blocks/product-price.html.j2
{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/organisms/product-price.json
    The price line of a product page: the price (integer minor units in the currency), the old price (compare_at) struck through when higher, and the badge.
    Props (p): price, compareAt, currency, badge, was. -#}
{%- set v_price = og_def(p['price'], none) -%}
{%- set v_compareAt = og_def(p['compareAt'], none) -%}
{%- set v_currency = og_def(p['currency'], none) -%}
{%- set v_badge = og_def(p['badge'], '') -%}
{%- set v_was = og_def(p['was'], none) -%}
{%- set c_5 -%}
  {%- set c_1 -%}
    {{ og_text(og_money(v_price, v_currency)) }}
  {%- endset -%}
  {{ og_include('compose/text.html.j2', {'p': {'Size': '4xl', 'Weight': 'bold'}, 'children': c_1}) }}
  {%- if og_t(og_and([v_compareAt, og_gt(v_compareAt, v_price)])) %}
    {%- set c_3 -%}
      {%- set c_2 -%}
        {{ og_text(v_was) }}
      {%- endset -%}
      {{ og_include('compose/inline.html.j2', {'p': {'Class': 'sr-only'}, 'children': c_2}) }}
      {{ og_text(og_money(v_compareAt, v_currency)) }}
    {%- endset -%}
    {{ og_include('compose/text.html.j2', {'p': {'Tag': 'del', 'Size': 'lg', 'Class': 'relative text-muted-foreground', 'Attrs': og_attrs(['data-slot', 'compare-at'])}, 'children': c_3}) }}
  {%- endif %}
  {%- if og_t(v_badge) %}
    {%- set c_4 -%}
      {{ og_text(v_badge) }}
    {%- endset -%}
    {{ og_include('compose/badge.html.j2', {'p': {'Variant': 'default', 'Size': 'default'}, 'children': c_4}) }}
  {%- endif %}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '4', 'Align': 'center', 'Class': 'flex-wrap', 'Attrs': og_attrs(['data-slot', 'product-price'])}, 'children': c_5}) }}

Jinja2 registry item (JSON)

Props

Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.

The price line of a product page: the price (integer minor units in the currency), the old price (compare_at) struck through when higher, and the badge.

Props of ProductPrice
PropTypeDefault Description
price (required)number-integer minor units
compareAt number-the old price, same currency; shown only when higher than the price
currency (required)string-
badge string""the label of the badge; empty: none
was (required)string-the screen reader word before the old price

Used in