Skip to content

Commit

Permalink
[ScrollingValue] Add single prop to enable individual number displa…
Browse files Browse the repository at this point in the history
…y (proper handling of 9)
  • Loading branch information
techniq committed Nov 12, 2023
1 parent 32c1e88 commit a730969
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-mangos-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': patch
---

[ScrollingValue] Add `single` prop to enable individual number display (proper handling of 9)
3 changes: 2 additions & 1 deletion packages/svelte-ux/src/lib/components/ScrollingValue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { getComponentTheme } from './theme';
export let value = 0;
export let single = false;
export let format: (value: number) => string | number = (value) => value;
export let classes: {
Expand Down Expand Up @@ -33,7 +34,7 @@
class={cls('col-span-full row-span-full', theme.value, classes.value)}
style:transform="translateY({-100 + 100 * offset}%)"
>
{format(Math.floor($displayValue + 1))}
{format(Math.floor(single && $displayValue >= 9 ? 0 : $displayValue + 1))}
</div>
<div
class={cls('col-span-full row-span-full', theme.value, classes.value)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
<ScrollingValue bind:value />
</Preview>

<h2>Individual numbers</h2>

<Preview>
{#each Math.abs(value).toString().split('') as num}
<ScrollingValue value={Number(num)} single class="text-3xl tabular-nums" />
{/each}
</Preview>

<h2>Formatted</h2>

<Preview>
Expand All @@ -86,12 +94,6 @@
</span>
</Preview>

<h2>Font-size</h2>

<Preview>
<ScrollingValue bind:value class="text-6xl" />
</Preview>

<h2>Field</h2>
<h3>With label and appended actions</h3>

Expand Down

1 comment on commit a730969

@vercel
Copy link

@vercel vercel bot commented on a730969 Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.