Skip to content
ui8kit

component / components

Number Field

Number Field component

Install

npx ui8kit add number-field

Pulls in: box, button, compose, input, kit-box, kit-button, kit-input, lucide-icon, 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-cdn
npx ui8kit add number-field
components/number-field.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. -->
<!--
  A narrow number field between a minus and a plus ghost icon button, drawn as one control (4px inside its
  ring). Static markup: the buttons carry no logic; the page wires them.
-->
<script lang="ts" module>
  import type { Snippet } from "svelte";

  export type NumberFieldProps = {
    value?: string;
    name?: string;
    min?: string;
    label: string;
    decrease: string;
    increase: string;
  };
</script>

<script lang="ts">
  import Box from "../compose/Box.svelte";
  import Button from "../compose/Button.svelte";
  import Input from "../compose/Input.svelte";
  import LucideIcon from "../icons/LucideIcon.svelte";

  let { value = "", name = "", min = "", label, decrease, increase }: NumberFieldProps = $props();
</script>

<Box
  class="inline-flex h-10 items-center gap-1 rounded bg-background p-1 inset-ring inset-ring-input"
  data-slot="number-field"
>
  <Button variant="ghost" size="sm" layout="icon" type="button" aria-label={decrease}>
    <LucideIcon name="minus" size={16} />
  </Button>
  <Input
    type="number"
    name={name}
    value={value}
    min={min}
    aria-label={label}
    size="sm"
    class="number-bare w-8 bg-transparent px-0 text-center inset-ring-0"
  />
  <Button variant="ghost" size="sm" layout="icon" type="button" aria-label={increase}>
    <LucideIcon name="plus" size={16} />
  </Button>
</Box>

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 number-field
components/number-field.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.
/**
 * A narrow number field between a minus and a plus ghost icon button, drawn as one control (4px inside its
 * ring). Static markup: the buttons carry no logic; the page wires them.
 */
import { type ReactNode } from "react";
import { Box, Button, Input } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";

export type NumberFieldProps = {
  value?: string;
  name?: string;
  min?: string;
  label: string;
  decrease: string;
  increase: string;
};

export function NumberField({
  value = "",
  name = "",
  min = "",
  label,
  decrease,
  increase,
}: NumberFieldProps) {
  return (
    <Box
      className={"inline-flex h-10 items-center gap-1 rounded bg-background p-1 inset-ring inset-ring-input"}
      data-slot="number-field"
    >
      <Button variant="ghost" size="sm" layout="icon" type="button" aria-label={decrease}>
        <LucideIcon name="minus" size={16} />
      </Button>
      <Input
        type="number"
        name={name}
        value={value}
        min={min}
        aria-label={label}
        size="sm"
        className="number-bare w-8 bg-transparent px-0 text-center inset-ring-0"
      />
      <Button variant="ghost" size="sm" layout="icon" type="button" aria-label={increase}>
        <LucideIcon name="plus" size={16} />
      </Button>
    </Box>
  );
}

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 number-field
components/number-field.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. -->
<!--
  A narrow number field between a minus and a plus ghost icon button, drawn as one control (4px inside its
  ring). Static markup: the buttons carry no logic; the page wires them.
-->
<script lang="ts">
export type NumberFieldProps = {
  value?: string;
  name?: string;
  min?: string;
  label: string;
  decrease: string;
  increase: string;
};
</script>

<script setup lang="ts">
import Box from "../compose/Box.vue";
import Button from "../compose/Button.vue";
import Input from "../compose/Input.vue";
import LucideIcon from "../icons/LucideIcon.vue";

const { value = "", name = "", min = "", label, decrease, increase } = defineProps<NumberFieldProps>();
</script>

<template>
  <Box
    class="inline-flex h-10 items-center gap-1 rounded bg-background p-1 inset-ring inset-ring-input"
    data-slot="number-field"
  >
    <Button variant="ghost" size="sm" layout="icon" type="button" :aria-label="decrease">
      <LucideIcon name="minus" :size="16" />
    </Button>
    <Input
      type="number"
      :name="name"
      :value="value"
      :min="min"
      :aria-label="label"
      size="sm"
      class="number-bare w-8 bg-transparent px-0 text-center inset-ring-0"
    />
    <Button variant="ghost" size="sm" layout="icon" type="button" :aria-label="increase">
      <LucideIcon name="plus" :size="16" />
    </Button>
  </Box>
</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 number-field
components/number-field.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.
/**
 * A narrow number field between a minus and a plus ghost icon button, drawn as one control (4px inside its
 * ring). Static markup: the buttons carry no logic; the page wires them.
 */
import { type JSX } from "solid-js";
import { Box, Button, Input } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";

export type NumberFieldProps = {
  value?: string;
  name?: string;
  min?: string;
  label: string;
  decrease: string;
  increase: string;
};

export function NumberField({
  value = "",
  name = "",
  min = "",
  label,
  decrease,
  increase,
}: NumberFieldProps) {
  return (
    <Box
      class="inline-flex h-10 items-center gap-1 rounded bg-background p-1 inset-ring inset-ring-input"
      data-slot="number-field"
    >
      <Button variant="ghost" size="sm" layout="icon" type="button" aria-label={decrease}>
        <LucideIcon name="minus" size={16} />
      </Button>
      <Input
        type="number"
        name={name}
        value={value}
        min={min}
        aria-label={label}
        size="sm"
        class="number-bare w-8 bg-transparent px-0 text-center inset-ring-0"
      />
      <Button variant="ghost" size="sm" layout="icon" type="button" aria-label={increase}>
        <LucideIcon name="plus" size={16} />
      </Button>
    </Box>
  );
}

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 number-field
blocks/number-field.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/number-field.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"
	"github.com/ui8kit/codegen/generated/templ/ui/input"
	uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)

// NumberFieldProps are the props of NumberField; the values are the JSON shapes of the TypeScript props.
type NumberFieldProps struct {
	Value any `json:"value"`
	Name any `json:"name"`
	Min any `json:"min"`
	Label any `json:"label"`
	Decrease any `json:"decrease"`
	Increase any `json:"increase"`
}

// A narrow number field between a minus and a plus ghost icon button, drawn as one control (4px inside its ring). Static markup: the buttons carry no logic; the page wires them.
templ NumberField(p NumberFieldProps) {
	{{ vValue := uiutils.Def(p.Value, "") }}
	{{ vName := uiutils.Def(p.Name, "") }}
	{{ vMin := uiutils.Def(p.Min, "") }}
	{{ vLabel := p.Label }}
	{{ vDecrease := p.Decrease }}
	{{ vIncrease := p.Increase }}
	@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: "inline-flex h-10 items-center gap-1 rounded bg-background p-1 inset-ring inset-ring-input", Attrs: uiutils.Attrs("data-slot", "number-field")}}) {
		@compose.Button(compose.ButtonProps{Variant: "ghost", Size: "sm", Layout: "icon", ButtonProps: button.ButtonProps{Type: "button", AriaLabel: uiutils.S(vDecrease)}}) {
			@icons.LucideIcon(icons.LucideIconProps{Name: "minus", Size: 16})
		}
		@compose.Input(compose.InputProps{Size: "sm", InputProps: input.InputProps{Type: "number", Name: uiutils.S(vName), Value: uiutils.SP(vValue), Min: uiutils.S(vMin), Class: "number-bare w-8 bg-transparent px-0 text-center inset-ring-0", Attrs: uiutils.Attrs("aria-label", vLabel)}})
		@compose.Button(compose.ButtonProps{Variant: "ghost", Size: "sm", Layout: "icon", ButtonProps: button.ButtonProps{Type: "button", AriaLabel: uiutils.S(vIncrease)}}) {
			@icons.LucideIcon(icons.LucideIconProps{Name: "plus", Size: 16})
		}
	}
}

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 number-field
blocks/number-field.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/number-field.json
    A narrow number field between a minus and a plus ghost icon button, drawn as one control (4px inside its ring). Static markup: the buttons carry no logic; the page wires them.
    Props (p): value, name, min, label, decrease, increase. -#}
{%- set v_value = (p.value ?? '') -%}
{%- set v_name = (p.name ?? '') -%}
{%- set v_min = (p.min ?? '') -%}
{%- set v_label = (p.label ?? null) -%}
{%- set v_decrease = (p.decrease ?? null) -%}
{%- set v_increase = (p.increase ?? null) -%}
{%- set c_3 -%}
  {%- set c_1 -%}
    {{ include('icons/LucideIcon.html.twig', {'name': 'minus', 'size': 16}, with_context = false) }}
  {%- endset -%}
  {{ include('compose/Button.html.twig', {'variant': 'ghost', 'size': 'sm', 'layout': 'icon', 'type': 'button', 'ariaLabel': og_s(v_decrease), 'children': c_1}, with_context = false) }}
  {{ include('compose/Input.html.twig', {'type': 'number', 'name': og_s(v_name), 'value': og_s(v_value), 'min': og_s(v_min), 'size': 'sm', 'class': 'number-bare w-8 bg-transparent px-0 text-center inset-ring-0', 'attrs': og_attrs(['aria-label', v_label])}, with_context = false) }}
  {%- set c_2 -%}
    {{ include('icons/LucideIcon.html.twig', {'name': 'plus', 'size': 16}, with_context = false) }}
  {%- endset -%}
  {{ include('compose/Button.html.twig', {'variant': 'ghost', 'size': 'sm', 'layout': 'icon', 'type': 'button', 'ariaLabel': og_s(v_increase), 'children': c_2}, with_context = false) }}
{%- endset -%}
{{ include('compose/Box.html.twig', {'class': 'inline-flex h-10 items-center gap-1 rounded bg-background p-1 inset-ring inset-ring-input', 'attrs': og_attrs(['data-slot', 'number-field']), 'children': c_3}, 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 number-field
blocks/number-field.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/number-field.json
    A narrow number field between a minus and a plus ghost icon button, drawn as one control (4px inside its ring). Static markup: the buttons carry no logic; the page wires them.
    Props (p): value, name, min, label, decrease, increase. *}
{var $v_value = ($p['value'] ?? '')}
{var $v_name = ($p['name'] ?? '')}
{var $v_min = ($p['min'] ?? '')}
{var $v_label = ($p['label'] ?? null)}
{var $v_decrease = ($p['decrease'] ?? null)}
{var $v_increase = ($p['increase'] ?? null)}
{capture $c_3}
  {capture $c_1}
    {=og_include('icons/LucideIcon.latte', ['name' => 'minus', 'size' => 16])|noescape}
  {/capture}
  {=og_include('compose/Button.latte', ['variant' => 'ghost', 'size' => 'sm', 'layout' => 'icon', 'type' => 'button', 'ariaLabel' => og_s($v_decrease), 'children' => (string) $c_1])|noescape}
  {=og_include('compose/Input.latte', ['type' => 'number', 'name' => og_s($v_name), 'value' => og_s($v_value), 'min' => og_s($v_min), 'size' => 'sm', 'class' => 'number-bare w-8 bg-transparent px-0 text-center inset-ring-0', 'attrs' => og_attrs(['aria-label', $v_label])])|noescape}
  {capture $c_2}
    {=og_include('icons/LucideIcon.latte', ['name' => 'plus', 'size' => 16])|noescape}
  {/capture}
  {=og_include('compose/Button.latte', ['variant' => 'ghost', 'size' => 'sm', 'layout' => 'icon', 'type' => 'button', 'ariaLabel' => og_s($v_increase), 'children' => (string) $c_2])|noescape}
{/capture}
{=og_include('compose/Box.latte', ['class' => 'inline-flex h-10 items-center gap-1 rounded bg-background p-1 inset-ring inset-ring-input', 'attrs' => og_attrs(['data-slot', 'number-field']), 'children' => (string) $c_3])|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 number-field
blocks/number-field.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/number-field.json
    A narrow number field between a minus and a plus ghost icon button, drawn as one control (4px inside its ring). Static markup: the buttons carry no logic; the page wires them.
    Props (p): value, name, min, label, decrease, increase. -#}
{%- set v_value = og_def(p['value'], '') -%}
{%- set v_name = og_def(p['name'], '') -%}
{%- set v_min = og_def(p['min'], '') -%}
{%- set v_label = og_def(p['label'], none) -%}
{%- set v_decrease = og_def(p['decrease'], none) -%}
{%- set v_increase = og_def(p['increase'], none) -%}
{%- set c_3 -%}
  {%- set c_1 -%}
    {{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'minus', 'Size': 16}}) }}
  {%- endset -%}
  {{ og_include('compose/button.html.j2', {'p': {'Variant': 'ghost', 'Size': 'sm', 'Layout': 'icon', 'Type': 'button', 'AriaLabel': og_s(v_decrease)}, 'children': c_1}) }}
  {{ og_include('compose/input.html.j2', {'p': {'Type': 'number', 'Name': og_s(v_name), 'Value': og_s(v_value), 'Min': og_s(v_min), 'Size': 'sm', 'Class': 'number-bare w-8 bg-transparent px-0 text-center inset-ring-0', 'Attrs': og_attrs(['aria-label', v_label])}}) }}
  {%- set c_2 -%}
    {{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'plus', 'Size': 16}}) }}
  {%- endset -%}
  {{ og_include('compose/button.html.j2', {'p': {'Variant': 'ghost', 'Size': 'sm', 'Layout': 'icon', 'Type': 'button', 'AriaLabel': og_s(v_increase)}, 'children': c_2}) }}
{%- endset -%}
{{ og_include('compose/box.html.j2', {'p': {'Class': 'inline-flex h-10 items-center gap-1 rounded bg-background p-1 inset-ring inset-ring-input', 'Attrs': og_attrs(['data-slot', 'number-field'])}, 'children': c_3}) }}

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.

A narrow number field between a minus and a plus ghost icon button, drawn as one control (4px inside its ring). Static markup: the buttons carry no logic; the page wires them.

Props of NumberField
PropTypeDefault Description
value string""
name string""
min string""
label (required)string-accessible name of the number
decrease (required)string-accessible name of the minus button
increase (required)string-accessible name of the plus button

Used in