Hoppa till innehåll
Markdown

NumberSpinner

Wrapper for Sitevision number spinner.

px

This is a field description.

<script>
import { Panel, NumberSpinner } from '@soleil-se/config-svelte';
</script>
<Panel heading="Inställningar">
<NumberSpinner name="height" label="Height" min={0} max={500} step={5} suffix="px" />
</Panel>
PropTypeDescription
label
required
string | Snippet

Field label, a string or Svelte snippet.

value
$bindable
number

Numeric field value.

Default: min ?? 1
name
string

Configuration key and HTML name attribute.

description
string | Snippet

Description shown below the field, a string or Svelte snippet.

min
number

Minimum spinner value.

max
number

Maximum spinner value.

step
number

Increment used by the spinner controls.

Default: 1
decimals
number

Number of decimal places handled by the Sitevision spinner.

Default: 0
suffix
string | [string, string]

Text displayed after the value, or singular and plural forms. For a pair, the first string is used when the value is 1; the second is used otherwise.

disabled
boolean

Disables the spinner.

Default: false
readonly
boolean

Prevents editing while keeping the spinner focusable.

Default: false
show
boolean

Shows or hides the spinner without destroying it.

Default: true
class
string

CSS class added to the form-group wrapper.

children
Snippet

Content rendered after the spinner and validation message.

onInput
function
(value: number, event: JQuery.TriggeredEvent<HTMLInputElement, undefined, HTMLInputElement, HTMLInputElement>) => void

Called for the jQuery input event with the updated numeric value.

onChange
function
(value: number, event: JQuery.TriggeredEvent<HTMLInputElement, undefined, HTMLInputElement, HTMLInputElement>) => void

Called for the jQuery change event with the updated numeric value.

validate
function
(context: ValidationContext<number>) => ValidationResult

Custom validator.

The suffix can be a string, or a pair of strings for singular and plural values. The singular suffix is used when the value is exactly 1.

<NumberSpinner name="height" label="Height" min={1} max={500} suffix="px" />
<NumberSpinner name="hours" label="Hours" min={1} max={24} suffix={['hour', 'hours']} />

By default, the component applies standard required-field validation. A custom validate prop replaces that default and returns { success: boolean, message?: string }.
Validation errors are displayed below the component and prevent saving.

See validation for more details.

label and description accept text or Svelte snippets.
Default child content is rendered after the number spinner and validation message.

App.svelte
<script>
import { NumberSpinner } from '@soleil-se/config-svelte';
</script>
<NumberSpinner name="height">
{#snippet label()}
Ange <strong>höjd</strong>
{/snippet}
{#snippet description()}
Ange höjd i <strong>centimeter</strong>.
{/snippet}
<p>Ytterligare information.</p>
</NumberSpinner>