Usage Calculator
A slider for how much is used and the price it gives. The estimate follows the slider; the page keeps the value.
Install
npx ui8kit add usage-calculatorPulls in: button, compose, group, kit-box, kit-button, kit-input, kit-text, range, section-frame, stack, text, utils
Preview
Estimate your bill
Move the slider to the number of requests you expect each month.
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-cdnnpx ui8kit add usage-calculator<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
A price that follows a slider: the chosen amount of use, the price per unit and the estimate. The page keeps
the amount and updates it on the `usage` event. Axes: layout (card, plain), ends (show: the smallest and the
largest amount under the slider, hide), tone.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
import type { UsageSlider, UsagePrice } from "./usage-calculator.types";
export type UsageCalculatorProps = {
id: string;
title: string;
text: string;
usage: number;
slider: UsageSlider;
price: UsagePrice;
cta: string;
href?: string;
layout?: "card" | "plain";
ends?: "show" | "hide";
tone?: "default" | "muted";
landmarkLabel?: string;
onusage?: (value: string) => void;
};
</script>
<script lang="ts">
import Button from "../compose/Button.svelte";
import Group from "../compose/Group.svelte";
import Range from "../compose/Range.svelte";
import Stack from "../compose/Stack.svelte";
import Text from "../compose/Text.svelte";
import SectionFrame from "../components/section-frame.svelte";
import { cn, fmtMoney, tpl, urlOf } from "../utils";
let {
id,
title,
text,
usage,
slider,
price,
cta,
href,
layout = "card",
ends = "show",
tone = "default",
landmarkLabel,
onusage,
}: UsageCalculatorProps = $props();
</script>
<SectionFrame id={id} title={title} lead={text} tone={tone} align="center" landmarkLabel={landmarkLabel}>
<Stack
gap="4"
align="stretch"
class={cn(
"mx-auto w-full max-w-xl",
(((layout as string) === "card") ? "rounded bg-card p-6 inset-ring inset-ring-border" : "")
)}
data-slot="usage"
>
<Group justify="between" align="baseline">
<Text size="xl" weight="bold">
{tpl(slider.unit, usage)}
</Text>
<Text size="sm" class="text-muted-foreground">
{slider.label}
</Text>
</Group>
<Range
min={slider.min}
max={slider.max}
value={usage}
aria-label={slider.label}
data-slot="slider"
oninput={(event: Event & { currentTarget: HTMLInputElement }) => onusage?.(event.currentTarget.value)}
/>
{#if ((ends as string) === "show")}
<Group justify="between" data-slot="ends">
<Text size="xs" class="text-muted-foreground">
{tpl(slider.unit, slider.min)}
</Text>
<Text size="xs" class="text-muted-foreground">
{tpl(slider.unit, slider.max)}
</Text>
</Group>
{/if}
<Group justify="between" align="center" class="flex-wrap">
<Stack gap="0">
<Text size="xs" class="text-muted-foreground">
{price.label}
</Text>
<Text size="4xl" weight="bold" data-slot="estimate">
{fmtMoney((usage * price.rate), price.currency)}
</Text>
</Stack>
<Button variant="default" size="default" href={urlOf(href)}>
{cta}
</Button>
</Group>
</Stack>
</SectionFrame>
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
export type UsageSlider = {
min: number;
max: number;
/** accessible name of the slider */
label: string;
/** template of an amount, e.g. `{0} credits` */
unit: string;
};
export type UsagePrice = {
/** price of one unit in minor units (cents) */
rate: number;
currency: string;
/** name of the estimate */
label: string;
};
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-cdnnpx ui8kit add usage-calculator// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* A price that follows a slider: the chosen amount of use, the price per unit and the estimate. The page keeps
* the amount and updates it on the `usage` event. Axes: layout (card, plain), ends (show: the smallest and the
* largest amount under the slider, hide), tone.
*/
import { type ChangeEvent, type ReactNode } from "react";
import { Button, Group, Range, Stack, Text } from "../compose";
import { SectionFrame } from "../components/section-frame";
import { cn, fmtMoney, tpl, urlOf } from "../utils";
import type { UsageSlider, UsagePrice } from "./usage-calculator.types";
export type UsageCalculatorProps = {
id: string;
title: string;
text: string;
usage: number;
slider: UsageSlider;
price: UsagePrice;
cta: string;
href?: string;
layout?: "card" | "plain";
ends?: "show" | "hide";
tone?: "default" | "muted";
landmarkLabel?: string;
onUsage?: (value: string) => void;
};
export function UsageCalculator({
id,
title,
text,
usage,
slider,
price,
cta,
href,
layout = "card",
ends = "show",
tone = "default",
landmarkLabel,
onUsage,
}: UsageCalculatorProps) {
return (
<SectionFrame id={id} title={title} lead={text} tone={tone} align="center" landmarkLabel={landmarkLabel}>
<Stack
gap="4"
align="stretch"
className={cn(
"mx-auto w-full max-w-xl",
(((layout as string) === "card") ? "rounded bg-card p-6 inset-ring inset-ring-border" : "")
)}
data-slot="usage"
>
<Group justify="between" align="baseline">
<Text size="xl" weight="bold">
{tpl(slider.unit, usage)}
</Text>
<Text size="sm" className="text-muted-foreground">
{slider.label}
</Text>
</Group>
<Range
min={slider.min}
max={slider.max}
value={usage}
aria-label={slider.label}
data-slot="slider"
onChange={(event: ChangeEvent<HTMLInputElement>) => onUsage?.(event.currentTarget.value)}
/>
{((ends as string) === "show") ? (
<Group justify="between" data-slot="ends">
<Text size="xs" className="text-muted-foreground">
{tpl(slider.unit, slider.min)}
</Text>
<Text size="xs" className="text-muted-foreground">
{tpl(slider.unit, slider.max)}
</Text>
</Group>
) : null}
<Group justify="between" align="center" className="flex-wrap">
<Stack gap="0">
<Text size="xs" className="text-muted-foreground">
{price.label}
</Text>
<Text size="4xl" weight="bold" data-slot="estimate">
{fmtMoney((usage * price.rate), price.currency)}
</Text>
</Stack>
<Button variant="default" size="default" href={urlOf(href)}>
{cta}
</Button>
</Group>
</Stack>
</SectionFrame>
);
}
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
export type UsageSlider = {
min: number;
max: number;
/** accessible name of the slider */
label: string;
/** template of an amount, e.g. `{0} credits` */
unit: string;
};
export type UsagePrice = {
/** price of one unit in minor units (cents) */
rate: number;
currency: string;
/** name of the estimate */
label: string;
};
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-cdnnpx ui8kit add usage-calculator// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
export type UsageSlider = {
min: number;
max: number;
/** accessible name of the slider */
label: string;
/** template of an amount, e.g. `{0} credits` */
unit: string;
};
export type UsagePrice = {
/** price of one unit in minor units (cents) */
rate: number;
currency: string;
/** name of the estimate */
label: string;
};
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
A price that follows a slider: the chosen amount of use, the price per unit and the estimate. The page keeps
the amount and updates it on the `usage` event. Axes: layout (card, plain), ends (show: the smallest and the
largest amount under the slider, hide), tone.
-->
<script lang="ts">
import type { UsageSlider, UsagePrice } from "./usage-calculator.types";
export type UsageCalculatorProps = {
id: string;
title: string;
text: string;
usage: number;
slider: UsageSlider;
price: UsagePrice;
cta: string;
href?: string;
layout?: "card" | "plain";
ends?: "show" | "hide";
tone?: "default" | "muted";
landmarkLabel?: string;
};
</script>
<script setup lang="ts">
import Button from "../compose/Button.vue";
import Group from "../compose/Group.vue";
import Range from "../compose/Range.vue";
import Stack from "../compose/Stack.vue";
import Text from "../compose/Text.vue";
import SectionFrame from "../components/section-frame.vue";
import { cn, fmtMoney, tpl, urlOf } from "../utils";
const {
id,
title,
text,
usage,
slider,
price,
cta,
href,
layout = "card",
ends = "show",
tone = "default",
landmarkLabel,
} = defineProps<UsageCalculatorProps>();
const emit = defineEmits<{ usage: [value: string] }>();
</script>
<template>
<SectionFrame :id="id" :title="title" :lead="text" :tone="tone" align="center" :landmarkLabel="landmarkLabel">
<Stack
gap="4"
align="stretch"
:class="cn(
'mx-auto w-full max-w-xl',
(((layout as string) === 'card') ? 'rounded bg-card p-6 inset-ring inset-ring-border' : '')
)"
data-slot="usage"
>
<Group justify="between" align="baseline">
<Text size="xl" weight="bold">
{{ tpl(slider.unit, usage) }}
</Text>
<Text size="sm" class="text-muted-foreground">
{{ slider.label }}
</Text>
</Group>
<Range
:min="slider.min"
:max="slider.max"
:value="usage"
:aria-label="slider.label"
data-slot="slider"
@input="(event: Event & { currentTarget: HTMLInputElement }) => emit('usage', event.currentTarget.value)"
/>
<Group v-if="((ends as string) === 'show')" justify="between" data-slot="ends">
<Text size="xs" class="text-muted-foreground">
{{ tpl(slider.unit, slider.min) }}
</Text>
<Text size="xs" class="text-muted-foreground">
{{ tpl(slider.unit, slider.max) }}
</Text>
</Group>
<Group justify="between" align="center" class="flex-wrap">
<Stack gap="0">
<Text size="xs" class="text-muted-foreground">
{{ price.label }}
</Text>
<Text size="4xl" weight="bold" data-slot="estimate">
{{ fmtMoney((usage * price.rate), price.currency) }}
</Text>
</Stack>
<Button variant="default" size="default" :href="urlOf(href)">
{{ cta }}
</Button>
</Group>
</Stack>
</SectionFrame>
</template>
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-cdnnpx ui8kit add usage-calculator// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* A price that follows a slider: the chosen amount of use, the price per unit and the estimate. The page keeps
* the amount and updates it on the `usage` event. Axes: layout (card, plain), ends (show: the smallest and the
* largest amount under the slider, hide), tone.
*/
import { type JSX } from "solid-js";
import { Button, Group, Range, Stack, Text } from "../compose";
import { SectionFrame } from "../components/section-frame";
import { cn, fmtMoney, tpl, urlOf } from "../utils";
import type { UsageSlider, UsagePrice } from "./usage-calculator.types";
export type UsageCalculatorProps = {
id: string;
title: string;
text: string;
usage: number;
slider: UsageSlider;
price: UsagePrice;
cta: string;
href?: string;
layout?: "card" | "plain";
ends?: "show" | "hide";
tone?: "default" | "muted";
landmarkLabel?: string;
onUsage?: (value: string) => void;
};
export function UsageCalculator({
id,
title,
text,
usage,
slider,
price,
cta,
href,
layout = "card",
ends = "show",
tone = "default",
landmarkLabel,
onUsage,
}: UsageCalculatorProps) {
return (
<SectionFrame id={id} title={title} lead={text} tone={tone} align="center" landmarkLabel={landmarkLabel}>
<Stack
gap="4"
align="stretch"
class={cn(
"mx-auto w-full max-w-xl",
(((layout as string) === "card") ? "rounded bg-card p-6 inset-ring inset-ring-border" : "")
)}
data-slot="usage"
>
<Group justify="between" align="baseline">
<Text size="xl" weight="bold">
{tpl(slider.unit, usage)}
</Text>
<Text size="sm" class="text-muted-foreground">
{slider.label}
</Text>
</Group>
<Range
min={slider.min}
max={slider.max}
value={usage}
aria-label={slider.label}
data-slot="slider"
onInput={(event: InputEvent & { currentTarget: HTMLInputElement }) => onUsage?.(event.currentTarget.value)}
/>
{((ends as string) === "show") ? (
<Group justify="between" data-slot="ends">
<Text size="xs" class="text-muted-foreground">
{tpl(slider.unit, slider.min)}
</Text>
<Text size="xs" class="text-muted-foreground">
{tpl(slider.unit, slider.max)}
</Text>
</Group>
) : null}
<Group justify="between" align="center" class="flex-wrap">
<Stack gap="0">
<Text size="xs" class="text-muted-foreground">
{price.label}
</Text>
<Text size="4xl" weight="bold" data-slot="estimate">
{fmtMoney((usage * price.rate), price.currency)}
</Text>
</Stack>
<Button variant="default" size="default" href={urlOf(href)}>
{cta}
</Button>
</Group>
</Stack>
</SectionFrame>
);
}
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
export type UsageSlider = {
min: number;
max: number;
/** accessible name of the slider */
label: string;
/** template of an amount, e.g. `{0} credits` */
unit: string;
};
export type UsagePrice = {
/** price of one unit in minor units (cents) */
rate: number;
currency: string;
/** name of the estimate */
label: string;
};
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-cdnnpx ui8kit add usage-calculator// 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/usage-calculator.json
package blocks
import (
"github.com/ui8kit/codegen/generated/templ/ui/box"
"github.com/ui8kit/codegen/generated/templ/ui/button"
"github.com/ui8kit/codegen/generated/templ/compose"
"github.com/ui8kit/codegen/generated/templ/ui/input"
"github.com/ui8kit/codegen/generated/templ/ui/text"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// UsageCalculatorProps are the props of UsageCalculator; the values are the JSON shapes of the TypeScript props.
type UsageCalculatorProps struct {
Id any `json:"id"`
Title any `json:"title"`
Text any `json:"text"`
Usage any `json:"usage"`
Slider any `json:"slider"`
Price any `json:"price"`
Cta any `json:"cta"`
Href any `json:"href"`
Layout any `json:"layout"`
Ends any `json:"ends"`
Tone any `json:"tone"`
LandmarkLabel any `json:"landmarkLabel"`
}
// A price that follows a slider: the chosen amount of use, the price per unit and the estimate. The page keeps the amount and updates it on the `usage` event. Axes: layout (card, plain), ends (show: the smallest and the largest amount under the slider, hide), tone.
templ UsageCalculator(p UsageCalculatorProps) {
{{ vId := p.Id }}
{{ vTitle := p.Title }}
{{ vText := p.Text }}
{{ vUsage := p.Usage }}
{{ vSlider := p.Slider }}
{{ vPrice := p.Price }}
{{ vCta := p.Cta }}
{{ vHref := p.Href }}
{{ vLayout := uiutils.Def(p.Layout, "card") }}
{{ vEnds := uiutils.Def(p.Ends, "show") }}
{{ vTone := uiutils.Def(p.Tone, "default") }}
{{ vLandmarkLabel := p.LandmarkLabel }}
@SectionFrame(SectionFrameProps{Id: vId, Title: vTitle, Lead: vText, Tone: vTone, Align: "center", LandmarkLabel: vLandmarkLabel}) {
@compose.Stack(compose.StackProps{Gap: "4", Align: "stretch", BoxProps: box.BoxProps{Class: uiutils.S(uiutils.Cnv("mx-auto w-full max-w-xl", uiutils.Cond(uiutils.T(uiutils.Eq(vLayout, "card")), "rounded bg-card p-6 inset-ring inset-ring-border", ""))), Attrs: uiutils.Attrs("data-slot", "usage")}}) {
@compose.Group(compose.GroupProps{Justify: "between", Align: "baseline", BoxProps: box.BoxProps{}}) {
@compose.Text(compose.TextProps{Size: "xl", Weight: "bold", TextProps: text.TextProps{}}) {
{ uiutils.Text(uiutils.Tpl(uiutils.Get(vSlider, "unit"), vUsage)) }
}
@compose.Text(compose.TextProps{Size: "sm", TextProps: text.TextProps{Class: "text-muted-foreground"}}) {
{ uiutils.Text(uiutils.Get(vSlider, "label")) }
}
}
@compose.Range(compose.RangeProps{InputProps: input.InputProps{Min: uiutils.S(uiutils.Get(vSlider, "min")), Max: uiutils.S(uiutils.Get(vSlider, "max")), Value: uiutils.SP(vUsage), Attrs: uiutils.Attrs("aria-label", uiutils.Get(vSlider, "label"), "data-slot", "slider")}})
if uiutils.Eq(vEnds, "show") {
@compose.Group(compose.GroupProps{Justify: "between", BoxProps: box.BoxProps{Attrs: uiutils.Attrs("data-slot", "ends")}}) {
@compose.Text(compose.TextProps{Size: "xs", TextProps: text.TextProps{Class: "text-muted-foreground"}}) {
{ uiutils.Text(uiutils.Tpl(uiutils.Get(vSlider, "unit"), uiutils.Get(vSlider, "min"))) }
}
@compose.Text(compose.TextProps{Size: "xs", TextProps: text.TextProps{Class: "text-muted-foreground"}}) {
{ uiutils.Text(uiutils.Tpl(uiutils.Get(vSlider, "unit"), uiutils.Get(vSlider, "max"))) }
}
}
}
@compose.Group(compose.GroupProps{Justify: "between", Align: "center", BoxProps: box.BoxProps{Class: "flex-wrap"}}) {
@compose.Stack(compose.StackProps{Gap: "0", BoxProps: box.BoxProps{}}) {
@compose.Text(compose.TextProps{Size: "xs", TextProps: text.TextProps{Class: "text-muted-foreground"}}) {
{ uiutils.Text(uiutils.Get(vPrice, "label")) }
}
@compose.Text(compose.TextProps{Size: "4xl", Weight: "bold", TextProps: text.TextProps{Attrs: uiutils.Attrs("data-slot", "estimate")}}) {
{ uiutils.Text(uiutils.Money(uiutils.Mul(vUsage, uiutils.Get(vPrice, "rate")), uiutils.Get(vPrice, "currency"))) }
}
}
@compose.Button(compose.ButtonProps{Variant: "default", Size: "default", ButtonProps: button.ButtonProps{Href: uiutils.URL(vHref, false)}}) {
{ uiutils.Text(vCta) }
}
}
}
}
}
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-cdnnpx ui8kit add usage-calculator{#- 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/usage-calculator.json
A price that follows a slider: the chosen amount of use, the price per unit and the estimate. The page keeps the amount and updates it on the `usage` event. Axes: layout (card, plain), ends (show: the smallest and the largest amount under the slider, hide), tone.
Props (p): id, title, text, usage, slider, price, cta, href, layout, ends, tone, landmarkLabel. -#}
{%- set v_id = (p.id ?? null) -%}
{%- set v_title = (p.title ?? null) -%}
{%- set v_text = (p.text ?? null) -%}
{%- set v_usage = (p.usage ?? null) -%}
{%- set v_slider = (p.slider ?? null) -%}
{%- set v_price = (p.price ?? null) -%}
{%- set v_cta = (p.cta ?? null) -%}
{%- set v_href = (p.href ?? null) -%}
{%- set v_layout = (p.layout ?? 'card') -%}
{%- set v_ends = (p.ends ?? 'show') -%}
{%- set v_tone = (p.tone ?? 'default') -%}
{%- set v_landmarkLabel = (p.landmarkLabel ?? null) -%}
{%- set c_13 -%}
{%- set c_12 -%}
{%- set c_3 -%}
{%- set c_1 -%}
{{ og_text(og_tpl(og_get(v_slider, ['unit']), [v_usage])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'xl', 'weight': 'bold', 'children': c_1}, with_context = false) }}
{%- set c_2 -%}
{{ og_text(og_get(v_slider, ['label'])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'sm', 'class': 'text-muted-foreground', 'children': c_2}, with_context = false) }}
{%- endset -%}
{{ include('compose/Group.html.twig', {'justify': 'between', 'align': 'baseline', 'children': c_3}, with_context = false) }}
{{ include('compose/Range.html.twig', {'min': og_i(og_get(v_slider, ['min'])), 'max': og_i(og_get(v_slider, ['max'])), 'value': og_s(v_usage), 'attrs': og_attrs(['aria-label', og_get(v_slider, ['label']), 'data-slot', 'slider'])}, with_context = false) }}
{%- if og_t(og_eq(v_ends, 'show')) %}
{%- set c_6 -%}
{%- set c_4 -%}
{{ og_text(og_tpl(og_get(v_slider, ['unit']), [og_get(v_slider, ['min'])])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'xs', 'class': 'text-muted-foreground', 'children': c_4}, with_context = false) }}
{%- set c_5 -%}
{{ og_text(og_tpl(og_get(v_slider, ['unit']), [og_get(v_slider, ['max'])])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'xs', 'class': 'text-muted-foreground', 'children': c_5}, with_context = false) }}
{%- endset -%}
{{ include('compose/Group.html.twig', {'justify': 'between', 'attrs': og_attrs(['data-slot', 'ends']), 'children': c_6}, with_context = false) }}
{%- endif %}
{%- set c_11 -%}
{%- set c_9 -%}
{%- set c_7 -%}
{{ og_text(og_get(v_price, ['label'])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'xs', 'class': 'text-muted-foreground', 'children': c_7}, with_context = false) }}
{%- set c_8 -%}
{{ og_text(og_money(og_mul(v_usage, og_get(v_price, ['rate'])), og_get(v_price, ['currency']))) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': '4xl', 'weight': 'bold', 'attrs': og_attrs(['data-slot', 'estimate']), 'children': c_8}, with_context = false) }}
{%- endset -%}
{{ include('compose/Stack.html.twig', {'gap': '0', 'children': c_9}, with_context = false) }}
{%- set c_10 -%}
{{ og_text(v_cta) }}
{%- endset -%}
{{ include('compose/Button.html.twig', {'variant': 'default', 'size': 'default', 'href': og_url(og_s(v_href)), 'children': c_10}, with_context = false) }}
{%- endset -%}
{{ include('compose/Group.html.twig', {'justify': 'between', 'align': 'center', 'class': 'flex-wrap', 'children': c_11}, with_context = false) }}
{%- endset -%}
{{ include('compose/Stack.html.twig', {'gap': '4', 'align': 'stretch', 'class': og_s(og_cnv(['mx-auto w-full max-w-xl', (og_t(og_eq(v_layout, 'card')) ? 'rounded bg-card p-6 inset-ring inset-ring-border' : '')])), 'attrs': og_attrs(['data-slot', 'usage']), 'children': c_12}, with_context = false) }}
{%- endset -%}
{{ include('blocks/section-frame.html.twig', {'p': {'id': v_id, 'title': v_title, 'lead': v_text, 'tone': v_tone, 'align': 'center', 'landmarkLabel': v_landmarkLabel}, 'children': og_markup(c_13)}, with_context = false) }}
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-cdnnpx ui8kit add usage-calculator{* 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/usage-calculator.json
A price that follows a slider: the chosen amount of use, the price per unit and the estimate. The page keeps the amount and updates it on the `usage` event. Axes: layout (card, plain), ends (show: the smallest and the largest amount under the slider, hide), tone.
Props (p): id, title, text, usage, slider, price, cta, href, layout, ends, tone, landmarkLabel. *}
{var $v_id = ($p['id'] ?? null)}
{var $v_title = ($p['title'] ?? null)}
{var $v_text = ($p['text'] ?? null)}
{var $v_usage = ($p['usage'] ?? null)}
{var $v_slider = ($p['slider'] ?? null)}
{var $v_price = ($p['price'] ?? null)}
{var $v_cta = ($p['cta'] ?? null)}
{var $v_href = ($p['href'] ?? null)}
{var $v_layout = ($p['layout'] ?? 'card')}
{var $v_ends = ($p['ends'] ?? 'show')}
{var $v_tone = ($p['tone'] ?? 'default')}
{var $v_landmarkLabel = ($p['landmarkLabel'] ?? null)}
{capture $c_13}
{capture $c_12}
{capture $c_3}
{capture $c_1}
{=og_text(og_tpl(og_get($v_slider, ['unit']), [$v_usage]))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'xl', 'weight' => 'bold', 'children' => (string) $c_1])|noescape}
{capture $c_2}
{=og_text(og_get($v_slider, ['label']))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'sm', 'class' => 'text-muted-foreground', 'children' => (string) $c_2])|noescape}
{/capture}
{=og_include('compose/Group.latte', ['justify' => 'between', 'align' => 'baseline', 'children' => (string) $c_3])|noescape}
{=og_include('compose/Range.latte', ['min' => og_i(og_get($v_slider, ['min'])), 'max' => og_i(og_get($v_slider, ['max'])), 'value' => og_s($v_usage), 'attrs' => og_attrs(['aria-label', og_get($v_slider, ['label']), 'data-slot', 'slider'])])|noescape}
{if og_t(og_eq($v_ends, 'show'))}
{capture $c_6}
{capture $c_4}
{=og_text(og_tpl(og_get($v_slider, ['unit']), [og_get($v_slider, ['min'])]))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'xs', 'class' => 'text-muted-foreground', 'children' => (string) $c_4])|noescape}
{capture $c_5}
{=og_text(og_tpl(og_get($v_slider, ['unit']), [og_get($v_slider, ['max'])]))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'xs', 'class' => 'text-muted-foreground', 'children' => (string) $c_5])|noescape}
{/capture}
{=og_include('compose/Group.latte', ['justify' => 'between', 'attrs' => og_attrs(['data-slot', 'ends']), 'children' => (string) $c_6])|noescape}
{/if}
{capture $c_11}
{capture $c_9}
{capture $c_7}
{=og_text(og_get($v_price, ['label']))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'xs', 'class' => 'text-muted-foreground', 'children' => (string) $c_7])|noescape}
{capture $c_8}
{=og_text(og_money(og_mul($v_usage, og_get($v_price, ['rate'])), og_get($v_price, ['currency'])))}
{/capture}
{=og_include('compose/Text.latte', ['size' => '4xl', 'weight' => 'bold', 'attrs' => og_attrs(['data-slot', 'estimate']), 'children' => (string) $c_8])|noescape}
{/capture}
{=og_include('compose/Stack.latte', ['gap' => '0', 'children' => (string) $c_9])|noescape}
{capture $c_10}
{=og_text($v_cta)}
{/capture}
{=og_include('compose/Button.latte', ['variant' => 'default', 'size' => 'default', 'href' => og_url(og_s($v_href)), 'children' => (string) $c_10])|noescape}
{/capture}
{=og_include('compose/Group.latte', ['justify' => 'between', 'align' => 'center', 'class' => 'flex-wrap', 'children' => (string) $c_11])|noescape}
{/capture}
{=og_include('compose/Stack.latte', ['gap' => '4', 'align' => 'stretch', 'class' => og_s(og_cnv(['mx-auto w-full max-w-xl', (og_t(og_eq($v_layout, 'card')) ? 'rounded bg-card p-6 inset-ring inset-ring-border' : '')])), 'attrs' => og_attrs(['data-slot', 'usage']), 'children' => (string) $c_12])|noescape}
{/capture}
{=og_include('blocks/section-frame.latte', ['p' => ['id' => $v_id, 'title' => $v_title, 'lead' => $v_text, 'tone' => $v_tone, 'align' => 'center', 'landmarkLabel' => $v_landmarkLabel], 'children' => og_markup($c_13)])|noescape}
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-cdnnpx ui8kit add usage-calculator{#- 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/usage-calculator.json
A price that follows a slider: the chosen amount of use, the price per unit and the estimate. The page keeps the amount and updates it on the `usage` event. Axes: layout (card, plain), ends (show: the smallest and the largest amount under the slider, hide), tone.
Props (p): id, title, text, usage, slider, price, cta, href, layout, ends, tone, landmarkLabel. -#}
{%- set v_id = og_def(p['id'], none) -%}
{%- set v_title = og_def(p['title'], none) -%}
{%- set v_text = og_def(p['text'], none) -%}
{%- set v_usage = og_def(p['usage'], none) -%}
{%- set v_slider = og_def(p['slider'], none) -%}
{%- set v_price = og_def(p['price'], none) -%}
{%- set v_cta = og_def(p['cta'], none) -%}
{%- set v_href = og_def(p['href'], none) -%}
{%- set v_layout = og_def(p['layout'], 'card') -%}
{%- set v_ends = og_def(p['ends'], 'show') -%}
{%- set v_tone = og_def(p['tone'], 'default') -%}
{%- set v_landmarkLabel = og_def(p['landmarkLabel'], none) -%}
{%- set c_13 -%}
{%- set c_12 -%}
{%- set c_3 -%}
{%- set c_1 -%}
{{ og_text(og_tpl(og_get(v_slider, ['unit']), [v_usage])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'xl', 'Weight': 'bold'}, 'children': c_1}) }}
{%- set c_2 -%}
{{ og_text(og_get(v_slider, ['label'])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'sm', 'Class': 'text-muted-foreground'}, 'children': c_2}) }}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Justify': 'between', 'Align': 'baseline'}, 'children': c_3}) }}
{{ og_include('compose/range.html.j2', {'p': {'Min': og_i(og_get(v_slider, ['min'])), 'Max': og_i(og_get(v_slider, ['max'])), 'Value': og_s(v_usage), 'Attrs': og_attrs(['aria-label', og_get(v_slider, ['label']), 'data-slot', 'slider'])}}) }}
{%- if og_t(og_eq(v_ends, 'show')) %}
{%- set c_6 -%}
{%- set c_4 -%}
{{ og_text(og_tpl(og_get(v_slider, ['unit']), [og_get(v_slider, ['min'])])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'xs', 'Class': 'text-muted-foreground'}, 'children': c_4}) }}
{%- set c_5 -%}
{{ og_text(og_tpl(og_get(v_slider, ['unit']), [og_get(v_slider, ['max'])])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'xs', 'Class': 'text-muted-foreground'}, 'children': c_5}) }}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Justify': 'between', 'Attrs': og_attrs(['data-slot', 'ends'])}, 'children': c_6}) }}
{%- endif %}
{%- set c_11 -%}
{%- set c_9 -%}
{%- set c_7 -%}
{{ og_text(og_get(v_price, ['label'])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'xs', 'Class': 'text-muted-foreground'}, 'children': c_7}) }}
{%- set c_8 -%}
{{ og_text(og_money(og_mul(v_usage, og_get(v_price, ['rate'])), og_get(v_price, ['currency']))) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': '4xl', 'Weight': 'bold', 'Attrs': og_attrs(['data-slot', 'estimate'])}, 'children': c_8}) }}
{%- endset -%}
{{ og_include('compose/stack.html.j2', {'p': {'Gap': '0'}, 'children': c_9}) }}
{%- set c_10 -%}
{{ og_text(v_cta) }}
{%- endset -%}
{{ og_include('compose/button.html.j2', {'p': {'Variant': 'default', 'Size': 'default', 'Href': og_url(og_s(v_href))}, 'children': c_10}) }}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Justify': 'between', 'Align': 'center', 'Class': 'flex-wrap'}, 'children': c_11}) }}
{%- endset -%}
{{ og_include('compose/stack.html.j2', {'p': {'Gap': '4', 'Align': 'stretch', 'Class': og_s(og_cnv(['mx-auto w-full max-w-xl', ('rounded bg-card p-6 inset-ring inset-ring-border' if og_t(og_eq(v_layout, 'card')) else '')])), 'Attrs': og_attrs(['data-slot', 'usage'])}, 'children': c_12}) }}
{%- endset -%}
{{ og_include('blocks/section-frame.html.j2', {'p': {'id': v_id, 'title': v_title, 'lead': v_text, 'tone': v_tone, 'align': 'center', 'landmarkLabel': v_landmarkLabel}, 'children': og_markup(c_13)}) }}
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.
A price that follows a slider: the chosen amount of use, the price per unit and the estimate. The page keeps the amount and updates it on the `usage` event. Axes: layout (card, plain), ends (show: the smallest and the largest amount under the slider, hide), tone.
| Prop | Type | Default | Description |
|---|---|---|---|
| id (required) | string | - | |
| title (required) | string | - | |
| text (required) | string | - | |
| usage (required) | number | - | the chosen amount |
| slider (required) | UsageSlider | - | the range of the slider and its labels |
| price (required) | UsagePrice | - | how the estimate is computed and named |
| cta (required) | string | - | |
| href | string | - | |
| layout | "card" | "plain" | "card" | |
| ends | "show" | "hide" | "show" | |
| tone | "default" | "muted" | "default" | |
| landmarkLabel | string | - | accessible name of the landmark of this component when the page shows it more than once (a variant); replaces the heading name of the root landmark, follows the name of a nested one |