Add Qty
Add Qty component
Install
npx ui8kit add add-qtyPulls in: button, compose, group, kit-box, kit-button, lucide-icon, number-field, utils
Preview
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 add-qty<!-- 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 quantity field named after the dish (minus and plus buttons with their own names) beside an add button.
Static markup.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type AddQtyProps = {
name: string;
dish: string;
labels: { qtyOf: string; decreaseOf: string; increaseOf: string; add: string };
value?: string;
};
</script>
<script lang="ts">
import Button from "../compose/Button.svelte";
import Group from "../compose/Group.svelte";
import LucideIcon from "../icons/LucideIcon.svelte";
import NumberField from "../components/number-field.svelte";
import { tpl } from "../utils";
let { name, dish, labels, value = "1" }: AddQtyProps = $props();
</script>
<Group gap="2" align="center" justify="between" class="flex-wrap" data-slot="add-qty">
<NumberField
value={value}
name={name}
min="0"
label={tpl(labels.qtyOf, dish)}
decrease={tpl(labels.decreaseOf, dish)}
increase={tpl(labels.increaseOf, dish)}
/>
<Button variant="default" size="default" type="button">
<LucideIcon name="plus" size={16} />
{labels.add}
</Button>
</Group>
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 add-qty// 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 quantity field named after the dish (minus and plus buttons with their own names) beside an add button.
* Static markup.
*/
import { type ReactNode } from "react";
import { Button, Group } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { NumberField } from "../components/number-field";
import { tpl } from "../utils";
export type AddQtyProps = {
name: string;
dish: string;
labels: { qtyOf: string; decreaseOf: string; increaseOf: string; add: string };
value?: string;
};
export function AddQty({ name, dish, labels, value = "1" }: AddQtyProps) {
return (
<Group gap="2" align="center" justify="between" className="flex-wrap" data-slot="add-qty">
<NumberField
value={value}
name={name}
min="0"
label={tpl(labels.qtyOf, dish)}
decrease={tpl(labels.decreaseOf, dish)}
increase={tpl(labels.increaseOf, dish)}
/>
<Button variant="default" size="default" type="button">
<LucideIcon name="plus" size={16} />
{labels.add}
</Button>
</Group>
);
}
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 add-qty<!-- 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 quantity field named after the dish (minus and plus buttons with their own names) beside an add button.
Static markup.
-->
<script lang="ts">
export type AddQtyProps = {
name: string;
dish: string;
labels: { qtyOf: string; decreaseOf: string; increaseOf: string; add: string };
value?: string;
};
</script>
<script setup lang="ts">
import Button from "../compose/Button.vue";
import Group from "../compose/Group.vue";
import LucideIcon from "../icons/LucideIcon.vue";
import NumberField from "../components/number-field.vue";
import { tpl } from "../utils";
const { name, dish, labels, value = "1" } = defineProps<AddQtyProps>();
</script>
<template>
<Group gap="2" align="center" justify="between" class="flex-wrap" data-slot="add-qty">
<NumberField
:value="value"
:name="name"
min="0"
:label="tpl(labels.qtyOf, dish)"
:decrease="tpl(labels.decreaseOf, dish)"
:increase="tpl(labels.increaseOf, dish)"
/>
<Button variant="default" size="default" type="button">
<LucideIcon name="plus" :size="16" />
{{ labels.add }}
</Button>
</Group>
</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 add-qty// 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 quantity field named after the dish (minus and plus buttons with their own names) beside an add button.
* Static markup.
*/
import { type JSX } from "solid-js";
import { Button, Group } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { NumberField } from "../components/number-field";
import { tpl } from "../utils";
export type AddQtyProps = {
name: string;
dish: string;
labels: { qtyOf: string; decreaseOf: string; increaseOf: string; add: string };
value?: string;
};
export function AddQty({ name, dish, labels, value = "1" }: AddQtyProps) {
return (
<Group gap="2" align="center" justify="between" class="flex-wrap" data-slot="add-qty">
<NumberField
value={value}
name={name}
min="0"
label={tpl(labels.qtyOf, dish)}
decrease={tpl(labels.decreaseOf, dish)}
increase={tpl(labels.increaseOf, dish)}
/>
<Button variant="default" size="default" type="button">
<LucideIcon name="plus" size={16} />
{labels.add}
</Button>
</Group>
);
}
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 add-qty// 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/add-qty.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/icons"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// AddQtyProps are the props of AddQty; the values are the JSON shapes of the TypeScript props.
type AddQtyProps struct {
Name any `json:"name"`
Dish any `json:"dish"`
Labels any `json:"labels"`
Value any `json:"value"`
}
// A quantity field named after the dish (minus and plus buttons with their own names) beside an add button. Static markup.
templ AddQty(p AddQtyProps) {
{{ vName := p.Name }}
{{ vDish := p.Dish }}
{{ vLabels := p.Labels }}
{{ vValue := uiutils.Def(p.Value, "1") }}
@compose.Group(compose.GroupProps{Gap: "2", Align: "center", Justify: "between", BoxProps: box.BoxProps{Class: "flex-wrap", Attrs: uiutils.Attrs("data-slot", "add-qty")}}) {
@NumberField(NumberFieldProps{Value: vValue, Name: vName, Min: "0", Label: uiutils.Tpl(uiutils.Get(vLabels, "qtyOf"), vDish), Decrease: uiutils.Tpl(uiutils.Get(vLabels, "decreaseOf"), vDish), Increase: uiutils.Tpl(uiutils.Get(vLabels, "increaseOf"), vDish)})
@compose.Button(compose.ButtonProps{Variant: "default", Size: "default", ButtonProps: button.ButtonProps{Type: "button"}}) {
@icons.LucideIcon(icons.LucideIconProps{Name: "plus", Size: 16})
{ uiutils.Text(uiutils.Get(vLabels, "add")) }
}
}
}
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 add-qty{#- 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/add-qty.json
A quantity field named after the dish (minus and plus buttons with their own names) beside an add button. Static markup.
Props (p): name, dish, labels, value. -#}
{%- set v_name = (p.name ?? null) -%}
{%- set v_dish = (p.dish ?? null) -%}
{%- set v_labels = (p.labels ?? null) -%}
{%- set v_value = (p.value ?? '1') -%}
{%- set c_2 -%}
{{ include('blocks/number-field.html.twig', {'p': {'value': v_value, 'name': v_name, 'min': '0', 'label': og_tpl(og_get(v_labels, ['qtyOf']), [v_dish]), 'decrease': og_tpl(og_get(v_labels, ['decreaseOf']), [v_dish]), 'increase': og_tpl(og_get(v_labels, ['increaseOf']), [v_dish])}}, with_context = false) }}
{%- set c_1 -%}
{{ include('icons/LucideIcon.html.twig', {'name': 'plus', 'size': 16}, with_context = false) }}
{{ og_text(og_get(v_labels, ['add'])) }}
{%- endset -%}
{{ include('compose/Button.html.twig', {'variant': 'default', 'size': 'default', 'type': 'button', 'children': c_1}, with_context = false) }}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '2', 'align': 'center', 'justify': 'between', 'class': 'flex-wrap', 'attrs': og_attrs(['data-slot', 'add-qty']), 'children': c_2}, 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 add-qty{* 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/add-qty.json
A quantity field named after the dish (minus and plus buttons with their own names) beside an add button. Static markup.
Props (p): name, dish, labels, value. *}
{var $v_name = ($p['name'] ?? null)}
{var $v_dish = ($p['dish'] ?? null)}
{var $v_labels = ($p['labels'] ?? null)}
{var $v_value = ($p['value'] ?? '1')}
{capture $c_2}
{=og_include('blocks/number-field.latte', ['p' => ['value' => $v_value, 'name' => $v_name, 'min' => '0', 'label' => og_tpl(og_get($v_labels, ['qtyOf']), [$v_dish]), 'decrease' => og_tpl(og_get($v_labels, ['decreaseOf']), [$v_dish]), 'increase' => og_tpl(og_get($v_labels, ['increaseOf']), [$v_dish])]])|noescape}
{capture $c_1}
{=og_include('icons/LucideIcon.latte', ['name' => 'plus', 'size' => 16])|noescape}
{=og_text(og_get($v_labels, ['add']))}
{/capture}
{=og_include('compose/Button.latte', ['variant' => 'default', 'size' => 'default', 'type' => 'button', 'children' => (string) $c_1])|noescape}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '2', 'align' => 'center', 'justify' => 'between', 'class' => 'flex-wrap', 'attrs' => og_attrs(['data-slot', 'add-qty']), 'children' => (string) $c_2])|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 add-qty{#- 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/add-qty.json
A quantity field named after the dish (minus and plus buttons with their own names) beside an add button. Static markup.
Props (p): name, dish, labels, value. -#}
{%- set v_name = og_def(p['name'], none) -%}
{%- set v_dish = og_def(p['dish'], none) -%}
{%- set v_labels = og_def(p['labels'], none) -%}
{%- set v_value = og_def(p['value'], '1') -%}
{%- set c_2 -%}
{{ og_include('blocks/number-field.html.j2', {'p': {'value': v_value, 'name': v_name, 'min': '0', 'label': og_tpl(og_get(v_labels, ['qtyOf']), [v_dish]), 'decrease': og_tpl(og_get(v_labels, ['decreaseOf']), [v_dish]), 'increase': og_tpl(og_get(v_labels, ['increaseOf']), [v_dish])}}) }}
{%- set c_1 -%}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'plus', 'Size': 16}}) }}
{{ og_text(og_get(v_labels, ['add'])) }}
{%- endset -%}
{{ og_include('compose/button.html.j2', {'p': {'Variant': 'default', 'Size': 'default', 'Type': 'button'}, 'children': c_1}) }}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '2', 'Align': 'center', 'Justify': 'between', 'Class': 'flex-wrap', 'Attrs': og_attrs(['data-slot', 'add-qty'])}, 'children': c_2}) }}
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 quantity field named after the dish (minus and plus buttons with their own names) beside an add button. Static markup.
| Prop | Type | Default | Description |
|---|---|---|---|
| name (required) | string | - | name of the quantity field |
| dish (required) | string | - | the dish name, put into the labels |
| labels (required) | { qtyOf: string; decreaseOf: string; increaseOf: string; add: string } | - | |
| value | string | "1" |