Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next: Number Input #644

Draft
wants to merge 5 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/bits-ui/src/lib/bits/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export * as LinkPreview from "./link-preview/index.js";
export * as Listbox from "./listbox/index.js";
export * as Menubar from "./menubar/index.js";
export * as NavigationMenu from "./navigation-menu/index.js";
export * as NumberInput from "./number-input/index.js";
export * as Pagination from "./pagination/index.js";
export * as PinInput from "./pin-input/index.js";
export * as Popover from "./popover/index.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<script lang="ts">
import { box } from "svelte-toolbelt";
import type { NumberInputRootProps } from "../types.js";
import { useNumberInputRoot } from "../number-input.svelte.js";
import { useId } from "$lib/internal/useId.js";
import { noop } from "$lib/internal/callbacks.js";
import { mergeProps } from "$lib/internal/mergeProps.js";

let {
id = useId(),
ref = $bindable(null),
value = $bindable(0),
onValueChange = noop,
format = true,
locale = "en-US",
localeMatcher = "best fit",
mode = "decimal",
prefix,
suffix,
currency,
currencyDisplay = "symbol",
useGrouping = true,
minFractionDigits = 0,
maxFractionDigits = 3,
roundingMode = "halfEven",
min,
max,
step = 1,
allowEmpty = true,
highlightOnFocus = true,
disabled = false,
readonly = false,
...restProps
}: NumberInputRootProps = $props();

const rootState = useNumberInputRoot({
id: box.with(() => id),
ref: box.with(
() => ref as HTMLInputElement,
(v) => (ref = v)
),
value: box.with(
() => value,
(v) => {
value = v;
onValueChange(v);
}
),
format: box.with(() => format),
locale: box.with(() => locale),
localeMatcher: box.with(() => localeMatcher),
mode: box.with(() => mode),
prefix: box.with(() => prefix),
suffix: box.with(() => suffix),
currency: box.with(() => currency),
currencyDisplay: box.with(() => currencyDisplay),
useGrouping: box.with(() => useGrouping),
minFractionDigits: box.with(() => minFractionDigits),
maxFractionDigits: box.with(() => maxFractionDigits),
roundingMode: box.with(() => roundingMode),
min: box.with(() => min),
max: box.with(() => max),
step: box.with(() => step),
allowEmpty: box.with(() => allowEmpty),
highlightOnFocus: box.with(() => highlightOnFocus),
disabled: box.with(() => disabled),
readonly: box.with(() => readonly),
});

const mergedProps = $derived(mergeProps(restProps, rootState.props));
</script>

<input {...mergedProps} />
3 changes: 3 additions & 0 deletions packages/bits-ui/src/lib/bits/number-input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as Root } from "./components/number-input.svelte";

export type { NumberInputRootProps as RootProps } from "./types.js";
Loading
Loading