Range Field
Range Field component
Install
npx ui8kit add range-fieldPulls in: box, compose, inline, input, kit-box, kit-input, kit-text, range, utils
Preview
No static preview for this item: it needs content or a parent that this page cannot supply. The code is below.
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 range-field<!-- 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 from–to pair for numbers or dates (price range, period). Empty means an open end. With numeric bounds two
sliders sit above the inputs. Each control has its own accessible name; every change reports both ends.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type RangeFieldProps = {
type: "number" | "date";
from: string;
to: string;
fromLabel: string;
toLabel: string;
min?: number;
max?: number;
class?: string;
onchange?: (from: string, to: string) => void;
};
</script>
<script lang="ts">
import Box from "../compose/Box.svelte";
import Inline from "../compose/Inline.svelte";
import Input from "../compose/Input.svelte";
import Range from "../compose/Range.svelte";
import { cn } from "../utils";
let {
type,
from,
to,
fromLabel,
toLabel,
min,
max,
class: className,
onchange,
}: RangeFieldProps = $props();
</script>
<Box class={cn("flex flex-col gap-2", className)} data-slot="range-field">
{#if (((type as string) === "number") && (min != null) && (max != null) && (min < max))}
<Range
min={min}
max={max}
aria-label={fromLabel}
value={(((from as string) === "") ? (min == null ? undefined : String(min)) : from)}
data-slot="range-from"
oninput={(event: Event & { currentTarget: HTMLInputElement }) => onchange?.(event.currentTarget.value, to)}
/>
<Range
min={min}
max={max}
aria-label={toLabel}
value={(((to as string) === "") ? (max == null ? undefined : String(max)) : to)}
data-slot="range-to"
oninput={(event: Event & { currentTarget: HTMLInputElement }) => onchange?.(from, event.currentTarget.value)}
/>
{/if}
<Inline class="flex items-center gap-2">
<Input
type={type}
size="sm"
aria-label={fromLabel}
value={from}
min={(min == null ? undefined : String(min))}
max={(max == null ? undefined : String(max))}
oninput={(event: Event & { currentTarget: HTMLInputElement }) => onchange?.(event.currentTarget.value, to)}
/>
<Inline class="text-muted-foreground">
{"–"}
</Inline>
<Input
type={type}
size="sm"
aria-label={toLabel}
value={to}
min={(min == null ? undefined : String(min))}
max={(max == null ? undefined : String(max))}
oninput={(event: Event & { currentTarget: HTMLInputElement }) => onchange?.(from, event.currentTarget.value)}
/>
</Inline>
</Box>
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 range-field// 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 from–to pair for numbers or dates (price range, period). Empty means an open end. With numeric bounds two
* sliders sit above the inputs. Each control has its own accessible name; every change reports both ends.
*/
import { type ChangeEvent, type ReactNode } from "react";
import { Box, Inline, Input, Range } from "../compose";
import { cn } from "../utils";
export type RangeFieldProps = {
type: "number" | "date";
from: string;
to: string;
fromLabel: string;
toLabel: string;
min?: number;
max?: number;
className?: string;
onChange?: (from: string, to: string) => void;
};
export function RangeField({
type,
from,
to,
fromLabel,
toLabel,
min,
max,
className,
onChange,
}: RangeFieldProps) {
return (
<Box className={cn("flex flex-col gap-2", className)} data-slot="range-field">
{(((type as string) === "number") && (min != null) && (max != null) && (min < max)) ? (
<>
<Range
min={min}
max={max}
aria-label={fromLabel}
value={(((from as string) === "") ? (min == null ? undefined : String(min)) : from)}
data-slot="range-from"
onChange={(event: ChangeEvent<HTMLInputElement>) => onChange?.(event.currentTarget.value, to)}
/>
<Range
min={min}
max={max}
aria-label={toLabel}
value={(((to as string) === "") ? (max == null ? undefined : String(max)) : to)}
data-slot="range-to"
onChange={(event: ChangeEvent<HTMLInputElement>) => onChange?.(from, event.currentTarget.value)}
/>
</>
) : null}
<Inline className="flex items-center gap-2">
<Input
type={type}
size="sm"
aria-label={fromLabel}
value={from}
min={(min == null ? undefined : String(min))}
max={(max == null ? undefined : String(max))}
onChange={(event: ChangeEvent<HTMLInputElement>) => onChange?.(event.currentTarget.value, to)}
/>
<Inline className="text-muted-foreground">
{"–"}
</Inline>
<Input
type={type}
size="sm"
aria-label={toLabel}
value={to}
min={(min == null ? undefined : String(min))}
max={(max == null ? undefined : String(max))}
onChange={(event: ChangeEvent<HTMLInputElement>) => onChange?.(from, event.currentTarget.value)}
/>
</Inline>
</Box>
);
}
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 range-field<!-- 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 from–to pair for numbers or dates (price range, period). Empty means an open end. With numeric bounds two
sliders sit above the inputs. Each control has its own accessible name; every change reports both ends.
-->
<script lang="ts">
export type RangeFieldProps = {
type: "number" | "date";
from: string;
to: string;
fromLabel: string;
toLabel: string;
min?: number;
max?: number;
class?: string;
};
</script>
<script setup lang="ts">
import Box from "../compose/Box.vue";
import Inline from "../compose/Inline.vue";
import Input from "../compose/Input.vue";
import Range from "../compose/Range.vue";
import { cn } from "../utils";
const { type, from, to, fromLabel, toLabel, min, max, class: className } = defineProps<RangeFieldProps>();
const emit = defineEmits<{ change: [from: string, to: string] }>();
</script>
<template>
<Box :class="cn('flex flex-col gap-2', className)" data-slot="range-field">
<template v-if="(((type as string) === 'number') && (min != null) && (max != null) && (min < max))">
<Range
:min="min"
:max="max"
:aria-label="fromLabel"
:value="(((from as string) === '') ? (min == null ? undefined : String(min)) : from)"
data-slot="range-from"
@input="(event: Event & { currentTarget: HTMLInputElement }) => emit('change', event.currentTarget.value, to)"
/>
<Range
:min="min"
:max="max"
:aria-label="toLabel"
:value="(((to as string) === '') ? (max == null ? undefined : String(max)) : to)"
data-slot="range-to"
@input="(event: Event & { currentTarget: HTMLInputElement }) => emit('change', from, event.currentTarget.value)"
/>
</template>
<Inline class="flex items-center gap-2">
<Input
:type="type"
size="sm"
:aria-label="fromLabel"
:value="from"
:min="(min == null ? undefined : String(min))"
:max="(max == null ? undefined : String(max))"
@input="(event: Event & { currentTarget: HTMLInputElement }) => emit('change', event.currentTarget.value, to)"
/>
<Inline class="text-muted-foreground">
{{ "–" }}
</Inline>
<Input
:type="type"
size="sm"
:aria-label="toLabel"
:value="to"
:min="(min == null ? undefined : String(min))"
:max="(max == null ? undefined : String(max))"
@input="(event: Event & { currentTarget: HTMLInputElement }) => emit('change', from, event.currentTarget.value)"
/>
</Inline>
</Box>
</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 range-field// 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 from–to pair for numbers or dates (price range, period). Empty means an open end. With numeric bounds two
* sliders sit above the inputs. Each control has its own accessible name; every change reports both ends.
*/
import { type JSX } from "solid-js";
import { Box, Inline, Input, Range } from "../compose";
import { cn } from "../utils";
export type RangeFieldProps = {
type: "number" | "date";
from: string;
to: string;
fromLabel: string;
toLabel: string;
min?: number;
max?: number;
class?: string;
onChange?: (from: string, to: string) => void;
};
export function RangeField({
type,
from,
to,
fromLabel,
toLabel,
min,
max,
class: className,
onChange,
}: RangeFieldProps) {
return (
<Box class={cn("flex flex-col gap-2", className)} data-slot="range-field">
{(((type as string) === "number") && (min != null) && (max != null) && (min < max)) ? (
<>
<Range
min={min}
max={max}
aria-label={fromLabel}
value={(((from as string) === "") ? (min == null ? undefined : String(min)) : from)}
data-slot="range-from"
onInput={(event: InputEvent & { currentTarget: HTMLInputElement }) => onChange?.(event.currentTarget.value, to)}
/>
<Range
min={min}
max={max}
aria-label={toLabel}
value={(((to as string) === "") ? (max == null ? undefined : String(max)) : to)}
data-slot="range-to"
onInput={(event: InputEvent & { currentTarget: HTMLInputElement }) => onChange?.(from, event.currentTarget.value)}
/>
</>
) : null}
<Inline class="flex items-center gap-2">
<Input
type={type}
size="sm"
aria-label={fromLabel}
value={from}
min={(min == null ? undefined : String(min))}
max={(max == null ? undefined : String(max))}
onInput={(event: InputEvent & { currentTarget: HTMLInputElement }) => onChange?.(event.currentTarget.value, to)}
/>
<Inline class="text-muted-foreground">
{"–"}
</Inline>
<Input
type={type}
size="sm"
aria-label={toLabel}
value={to}
min={(min == null ? undefined : String(min))}
max={(max == null ? undefined : String(max))}
onInput={(event: InputEvent & { currentTarget: HTMLInputElement }) => onChange?.(from, event.currentTarget.value)}
/>
</Inline>
</Box>
);
}
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 range-field// 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/parts/range-field.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/input"
"github.com/ui8kit/codegen/generated/templ/ui/text"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// RangeFieldProps are the props of RangeField; the values are the JSON shapes of the TypeScript props.
type RangeFieldProps struct {
Type any `json:"type"`
From any `json:"from"`
To any `json:"to"`
FromLabel any `json:"fromLabel"`
ToLabel any `json:"toLabel"`
Min any `json:"min"`
Max any `json:"max"`
Class string `json:"className"`
}
// A from–to pair for numbers or dates (price range, period). Empty means an open end. With numeric bounds two sliders sit above the inputs. Each control has its own accessible name; every change reports both ends.
templ RangeField(p RangeFieldProps) {
{{ vType := p.Type }}
{{ vFrom := p.From }}
{{ vTo := p.To }}
{{ vFromLabel := p.FromLabel }}
{{ vToLabel := p.ToLabel }}
{{ vMin := p.Min }}
{{ vMax := p.Max }}
@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: uiutils.S(uiutils.Cnv("flex flex-col gap-2", p.Class)), Attrs: uiutils.Attrs("data-slot", "range-field")}}) {
if uiutils.T(uiutils.And(uiutils.Eq(vType, "number"), uiutils.Has(vMin), uiutils.Has(vMax), uiutils.Lt(vMin, vMax))) {
@compose.Range(compose.RangeProps{InputProps: input.InputProps{Min: uiutils.S(vMin), Max: uiutils.S(vMax), Value: uiutils.SP(uiutils.Cond(uiutils.T(uiutils.Eq(vFrom, "")), uiutils.Str(vMin), vFrom)), Attrs: uiutils.Attrs("aria-label", vFromLabel, "data-slot", "range-from")}})
@compose.Range(compose.RangeProps{InputProps: input.InputProps{Min: uiutils.S(vMin), Max: uiutils.S(vMax), Value: uiutils.SP(uiutils.Cond(uiutils.T(uiutils.Eq(vTo, "")), uiutils.Str(vMax), vTo)), Attrs: uiutils.Attrs("aria-label", vToLabel, "data-slot", "range-to")}})
}
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "flex items-center gap-2"}}) {
@compose.Input(compose.InputProps{Size: "sm", InputProps: input.InputProps{Type: uiutils.S(vType), Value: uiutils.SP(vFrom), Min: uiutils.S(uiutils.Str(vMin)), Max: uiutils.S(uiutils.Str(vMax)), Attrs: uiutils.Attrs("aria-label", vFromLabel)}})
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "text-muted-foreground"}}) {
{ uiutils.Text("–") }
}
@compose.Input(compose.InputProps{Size: "sm", InputProps: input.InputProps{Type: uiutils.S(vType), Value: uiutils.SP(vTo), Min: uiutils.S(uiutils.Str(vMin)), Max: uiutils.S(uiutils.Str(vMax)), Attrs: uiutils.Attrs("aria-label", vToLabel)}})
}
}
}
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 range-field{#- 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/parts/range-field.json
A from–to pair for numbers or dates (price range, period). Empty means an open end. With numeric bounds two sliders sit above the inputs. Each control has its own accessible name; every change reports both ends.
Props (p): type, from, to, fromLabel, toLabel, min, max, className. -#}
{%- set v_type = (p.type ?? null) -%}
{%- set v_from = (p.from ?? null) -%}
{%- set v_to = (p.to ?? null) -%}
{%- set v_fromLabel = (p.fromLabel ?? null) -%}
{%- set v_toLabel = (p.toLabel ?? null) -%}
{%- set v_min = (p.min ?? null) -%}
{%- set v_max = (p.max ?? null) -%}
{%- set c_3 -%}
{%- if og_t(og_and([og_eq(v_type, 'number'), og_has(v_min), og_has(v_max), og_lt(v_min, v_max)])) %}
{{ include('compose/Range.html.twig', {'min': og_i(v_min), 'max': og_i(v_max), 'value': og_s((og_t(og_eq(v_from, '')) ? og_str(v_min) : v_from)), 'attrs': og_attrs(['aria-label', v_fromLabel, 'data-slot', 'range-from'])}, with_context = false) }}
{{ include('compose/Range.html.twig', {'min': og_i(v_min), 'max': og_i(v_max), 'value': og_s((og_t(og_eq(v_to, '')) ? og_str(v_max) : v_to)), 'attrs': og_attrs(['aria-label', v_toLabel, 'data-slot', 'range-to'])}, with_context = false) }}
{%- endif %}
{%- set c_2 -%}
{{ include('compose/Input.html.twig', {'type': og_s(v_type), 'size': 'sm', 'value': og_s(v_from), 'min': og_s(og_str(v_min)), 'max': og_s(og_str(v_max)), 'attrs': og_attrs(['aria-label', v_fromLabel])}, with_context = false) }}
{%- set c_1 -%}
{{ og_text('–') }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': 'text-muted-foreground', 'children': c_1}, with_context = false) }}
{{ include('compose/Input.html.twig', {'type': og_s(v_type), 'size': 'sm', 'value': og_s(v_to), 'min': og_s(og_str(v_min)), 'max': og_s(og_str(v_max)), 'attrs': og_attrs(['aria-label', v_toLabel])}, with_context = false) }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': 'flex items-center gap-2', 'children': c_2}, with_context = false) }}
{%- endset -%}
{{ include('compose/Box.html.twig', {'class': og_s(og_cnv(['flex flex-col gap-2', (p.className ?? '')])), 'attrs': og_attrs(['data-slot', 'range-field']), 'children': c_3}, 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 range-field{* 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/parts/range-field.json
A from–to pair for numbers or dates (price range, period). Empty means an open end. With numeric bounds two sliders sit above the inputs. Each control has its own accessible name; every change reports both ends.
Props (p): type, from, to, fromLabel, toLabel, min, max, className. *}
{var $v_type = ($p['type'] ?? null)}
{var $v_from = ($p['from'] ?? null)}
{var $v_to = ($p['to'] ?? null)}
{var $v_fromLabel = ($p['fromLabel'] ?? null)}
{var $v_toLabel = ($p['toLabel'] ?? null)}
{var $v_min = ($p['min'] ?? null)}
{var $v_max = ($p['max'] ?? null)}
{capture $c_3}
{if og_t(og_and([og_eq($v_type, 'number'), og_has($v_min), og_has($v_max), og_lt($v_min, $v_max)]))}
{=og_include('compose/Range.latte', ['min' => og_i($v_min), 'max' => og_i($v_max), 'value' => og_s((og_t(og_eq($v_from, '')) ? og_str($v_min) : $v_from)), 'attrs' => og_attrs(['aria-label', $v_fromLabel, 'data-slot', 'range-from'])])|noescape}
{=og_include('compose/Range.latte', ['min' => og_i($v_min), 'max' => og_i($v_max), 'value' => og_s((og_t(og_eq($v_to, '')) ? og_str($v_max) : $v_to)), 'attrs' => og_attrs(['aria-label', $v_toLabel, 'data-slot', 'range-to'])])|noescape}
{/if}
{capture $c_2}
{=og_include('compose/Input.latte', ['type' => og_s($v_type), 'size' => 'sm', 'value' => og_s($v_from), 'min' => og_s(og_str($v_min)), 'max' => og_s(og_str($v_max)), 'attrs' => og_attrs(['aria-label', $v_fromLabel])])|noescape}
{capture $c_1}
{=og_text('–')}
{/capture}
{=og_include('compose/Inline.latte', ['class' => 'text-muted-foreground', 'children' => (string) $c_1])|noescape}
{=og_include('compose/Input.latte', ['type' => og_s($v_type), 'size' => 'sm', 'value' => og_s($v_to), 'min' => og_s(og_str($v_min)), 'max' => og_s(og_str($v_max)), 'attrs' => og_attrs(['aria-label', $v_toLabel])])|noescape}
{/capture}
{=og_include('compose/Inline.latte', ['class' => 'flex items-center gap-2', 'children' => (string) $c_2])|noescape}
{/capture}
{=og_include('compose/Box.latte', ['class' => og_s(og_cnv(['flex flex-col gap-2', ($p['className'] ?? '')])), 'attrs' => og_attrs(['data-slot', 'range-field']), 'children' => (string) $c_3])|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 range-field{#- 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/parts/range-field.json
A from–to pair for numbers or dates (price range, period). Empty means an open end. With numeric bounds two sliders sit above the inputs. Each control has its own accessible name; every change reports both ends.
Props (p): type, from, to, fromLabel, toLabel, min, max, className. -#}
{%- set v_type = og_def(p['type'], none) -%}
{%- set v_from = og_def(p['from'], none) -%}
{%- set v_to = og_def(p['to'], none) -%}
{%- set v_fromLabel = og_def(p['fromLabel'], none) -%}
{%- set v_toLabel = og_def(p['toLabel'], none) -%}
{%- set v_min = og_def(p['min'], none) -%}
{%- set v_max = og_def(p['max'], none) -%}
{%- set c_3 -%}
{%- if og_t(og_and([og_eq(v_type, 'number'), og_has(v_min), og_has(v_max), og_lt(v_min, v_max)])) %}
{{ og_include('compose/range.html.j2', {'p': {'Min': og_i(v_min), 'Max': og_i(v_max), 'Value': og_s((og_str(v_min) if og_t(og_eq(v_from, '')) else v_from)), 'Attrs': og_attrs(['aria-label', v_fromLabel, 'data-slot', 'range-from'])}}) }}
{{ og_include('compose/range.html.j2', {'p': {'Min': og_i(v_min), 'Max': og_i(v_max), 'Value': og_s((og_str(v_max) if og_t(og_eq(v_to, '')) else v_to)), 'Attrs': og_attrs(['aria-label', v_toLabel, 'data-slot', 'range-to'])}}) }}
{%- endif %}
{%- set c_2 -%}
{{ og_include('compose/input.html.j2', {'p': {'Type': og_s(v_type), 'Size': 'sm', 'Value': og_s(v_from), 'Min': og_s(og_str(v_min)), 'Max': og_s(og_str(v_max)), 'Attrs': og_attrs(['aria-label', v_fromLabel])}}) }}
{%- set c_1 -%}
{{ og_text('–') }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': 'text-muted-foreground'}, 'children': c_1}) }}
{{ og_include('compose/input.html.j2', {'p': {'Type': og_s(v_type), 'Size': 'sm', 'Value': og_s(v_to), 'Min': og_s(og_str(v_min)), 'Max': og_s(og_str(v_max)), 'Attrs': og_attrs(['aria-label', v_toLabel])}}) }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': 'flex items-center gap-2'}, 'children': c_2}) }}
{%- endset -%}
{{ og_include('compose/box.html.j2', {'p': {'Class': og_s(og_cnv(['flex flex-col gap-2', og_def(p['className'], '')])), 'Attrs': og_attrs(['data-slot', 'range-field'])}, 'children': c_3}) }}
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 from–to pair for numbers or dates (price range, period). Empty means an open end. With numeric bounds two sliders sit above the inputs. Each control has its own accessible name; every change reports both ends.
| Prop | Type | Default | Description |
|---|---|---|---|
| type (required) | "number" | "date" | - | |
| from (required) | string | - | |
| to (required) | string | - | |
| fromLabel (required) | string | - | |
| toLabel (required) | string | - | |
| min | number | - | |
| max | number | - |