diff --git a/src/docs/cards/extras/CardPhone.svelte b/src/docs/cards/extras/CardPhone.svelte new file mode 100644 index 0000000..7dfb124 --- /dev/null +++ b/src/docs/cards/extras/CardPhone.svelte @@ -0,0 +1,11 @@ + + +
+ +
+
Hello there
+
+
+
\ No newline at end of file diff --git a/src/docs/cards/extras/CardStopwatch.svelte b/src/docs/cards/extras/CardStopwatch.svelte new file mode 100644 index 0000000..4a3a819 --- /dev/null +++ b/src/docs/cards/extras/CardStopwatch.svelte @@ -0,0 +1,16 @@ + + + + + diff --git a/src/docs/cards/extras/CardTimer.svelte b/src/docs/cards/extras/CardTimer.svelte new file mode 100644 index 0000000..b28121e --- /dev/null +++ b/src/docs/cards/extras/CardTimer.svelte @@ -0,0 +1,16 @@ + + + + + diff --git a/src/docs/site-components/components_extra.ts b/src/docs/site-components/components_extra.ts index af7d8ad..03bcf74 100644 --- a/src/docs/site-components/components_extra.ts +++ b/src/docs/site-components/components_extra.ts @@ -2,6 +2,9 @@ import CardExcalidraw from '$docs/cards/extras/CardExcalidraw.svelte'; import CardUndraw from '$docs/cards/extras/CardUndraw.svelte'; import CardColorPicker from '$docs/cards/extras/CardColorPicker.svelte'; import CardColorSelect from '$docs/cards/extras/CardColorSelect.svelte'; +import CardStopwatch from '$docs/cards/extras/CardStopwatch.svelte'; +import CardTimer from '$docs/cards/extras/CardTimer.svelte'; +import CardPhone from '$docs/cards/extras/CardPhone.svelte'; export const extraComponents = [ { @@ -27,5 +30,23 @@ export const extraComponents = [ className: '', label: 'Color Select', href: 'color-select' + }, + { + component: CardStopwatch, + className: '', + label: 'Stopwatch', + href: 'stopwatch' + }, + { + component: CardTimer, + className: '', + label: 'Timer', + href: 'timer' + }, + { + component: CardPhone, + className: '', + label: 'Phone', + href: 'phone' } ].sort((a, b) => a.label.localeCompare(b.label)); diff --git a/src/lib/components/base/scroll-area/BodyScrollArea.svelte b/src/lib/components/base/scroll-area/BodyScrollArea.svelte index 10d50df..3b1ff2e 100644 --- a/src/lib/components/base/scroll-area/BodyScrollArea.svelte +++ b/src/lib/components/base/scroll-area/BodyScrollArea.svelte @@ -1,43 +1,3 @@ - + \ No newline at end of file diff --git a/src/lib/components/base/scroll-area/style.css b/src/lib/components/base/scroll-area/style.css new file mode 100644 index 0000000..93ef704 --- /dev/null +++ b/src/lib/components/base/scroll-area/style.css @@ -0,0 +1,41 @@ +.body::-webkit-scrollbar-track { + background-color: transparent; +} + +@supports (scrollbar-width: auto) { + body { + scrollbar-color: var(--color-base-400) transparent; + scrollbar-width: thin; + } + + .dark body { + scrollbar-color: var(--color-base-800) transparent; + } +} + +@supports not (scrollbar-width: auto) { + body::-webkit-scrollbar { + width: 14px; + height: 14px; + } +} + +body::-webkit-scrollbar-thumb { + background-color: var(--color-base-400); + border-radius: 20px; + border: 4px solid transparent; + background-clip: content-box; +} + +body::-webkit-scrollbar-thumb:hover { + background-color: var(--color-base-500); +} + +/* Dark mode rules */ +.dark body::-webkit-scrollbar-thumb { + background-color: var(--color-base-800); +} + +.dark body::-webkit-scrollbar-thumb:hover { + background-color: var(--color-base-700); +} \ No newline at end of file diff --git a/src/lib/components/extra/phone/Phone.svelte b/src/lib/components/extra/phone/Phone.svelte index e1c6f50..793cf4b 100644 --- a/src/lib/components/extra/phone/Phone.svelte +++ b/src/lib/components/extra/phone/Phone.svelte @@ -1,8 +1,16 @@ -
+
diff --git a/src/lib/components/extra/stopwatch/Stopwatch.svelte b/src/lib/components/extra/stopwatch/Stopwatch.svelte new file mode 100644 index 0000000..54e7d87 --- /dev/null +++ b/src/lib/components/extra/stopwatch/Stopwatch.svelte @@ -0,0 +1,66 @@ + + + +
+ {#if showHours} + + {/if} + + {#if showMinutes} + + {/if} + + {#if showSeconds} + + {/if} +
+
diff --git a/src/lib/components/extra/stopwatch/StopwatchState.svelte.ts b/src/lib/components/extra/stopwatch/StopwatchState.svelte.ts new file mode 100644 index 0000000..7818748 --- /dev/null +++ b/src/lib/components/extra/stopwatch/StopwatchState.svelte.ts @@ -0,0 +1,90 @@ +// adopted from https://github.com/joshnuss/svelte-reactive-timer + +type Status = 'running' | 'paused' | 'stopped'; +type Options = { + precision?: number; +}; + +export class StopwatchState { + status = $state('stopped'); + duration = $state(0); + elapsed = $state(0); + startAt = $state(null); + + time = $state(null); + precision: number; + #interval: number | null = null; + + constructor(options: Options = {}) { + this.precision = options.precision ?? 1000 / 60; + } + + get isRunning() { + return this.status == 'running'; + } + + get isStopped() { + return this.status == 'stopped'; + } + + get isPaused() { + return this.status == 'paused'; + } + + start() { + if (this.isRunning) { + this.stop(); + } + + this.time = new Date(); + this.startAt = this.time; + this.status = 'running'; + this.elapsed = 0; + this.#schedule(); + } + + stop() { + this.#dispose(); + this.status = 'stopped'; + } + + pause() { + this.#dispose(); + this.status = 'paused'; + } + + resume() { + this.time = new Date(); + this.status = 'running'; + this.#schedule(); + } + + reset(duration?: number) { + if (duration) { + this.duration = duration; + } + this.#dispose(); + + this.time = new Date(); + this.startAt = this.time; + this.elapsed = 0; + } + + #schedule() { + this.time = new Date(); + this.#interval = setInterval(() => this.#onInterval(), this.precision); + } + + #dispose() { + if (this.#interval) { + clearInterval(this.#interval); + } + } + + #onInterval() { + const now = new Date(); + + this.elapsed += now.getTime() - this.time!.getTime(); + this.time = now; + } +} diff --git a/src/lib/components/extra/timer/Timer.svelte b/src/lib/components/extra/timer/Timer.svelte index 9f40cff..b7a9864 100644 --- a/src/lib/components/extra/timer/Timer.svelte +++ b/src/lib/components/extra/timer/Timer.svelte @@ -6,14 +6,24 @@ import { cn } from '$lib/utils.js'; let { - timer = $bindable(new TimerState(1000 * 60 * 60)), + timer = $bindable(), class: className, ref = $bindable(null), + showHours = false, + showMinutes = true, + showSeconds = true, ...restProps }: WithElementRef>> & { timer?: TimerState; + showHours?: boolean; + showMinutes?: boolean; + showSeconds?: boolean; } = $props(); + if (!timer) { + timer = new TimerState(1000 * 60 * 10); + } + const hh = $derived(Math.floor(timer.remaining / 3600000)); const mm = $derived(Math.floor((timer.remaining % 3600000) / 60000)); const ss = $derived(Math.floor((timer.remaining % 60000) / 1000)); @@ -29,21 +39,28 @@ style="font-variant-numeric: tabular-nums;" {...restProps} > - + {#if showHours} + + {/if} + + {#if showMinutes} + + {/if} - - + {#if showSeconds} + + {/if}
diff --git a/src/lib/components/extra/timer/TimerState.svelte.ts b/src/lib/components/extra/timer/TimerState.svelte.ts index dee3395..3b172ba 100644 --- a/src/lib/components/extra/timer/TimerState.svelte.ts +++ b/src/lib/components/extra/timer/TimerState.svelte.ts @@ -69,14 +69,11 @@ export class TimerState { } this.#dispose(); - if (!this.isStopped) { - this.start(); - } else { - this.time = new Date(); - this.startAt = this.time; - this.endAt = new Date(this.time.getTime() + this.duration); - this.elapsed = 0; - } + this.status = 'stopped'; + this.time = new Date(); + this.startAt = this.time; + this.endAt = new Date(this.time.getTime() + this.duration); + this.elapsed = 0; } #schedule() { diff --git a/src/lib/index.ts b/src/lib/index.ts index 61221a8..eb574cb 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -6,6 +6,7 @@ export { Alert, AlertDescription, AlertTitle } from '$lib/components/base/alert' export { Avatar, AvatarGroup } from '$lib/components/base/avatar'; export { Badge } from '$lib/components/base/badge'; export { Button } from '$lib/components/base/button'; +export { default as Box } from '$lib/components/base/box/Box.svelte'; export { default as ImageCard } from '$lib/components/base/card/ImageCard.svelte'; export { default as ChatBubble } from '$lib/components/base/chat-bubble/ChatBubble.svelte'; export { Checkbox } from '$lib/components/base/checkbox'; @@ -34,6 +35,11 @@ export { ColorPicker, PopoverColorPicker } from '$lib/components/extra/color-pic export { default as Excalidraw } from '$lib/components/extra/excalidraw/Excalidraw.svelte'; export { default as Undraw } from '$lib/components/extra/undraw/Undraw.svelte'; export { ColorSelect } from '$lib/components/extra/color-select'; +export { default as Stopwatch } from '$lib/components/extra/stopwatch/Stopwatch.svelte'; +export { default as Timer } from '$lib/components/extra/timer/Timer.svelte'; +export { StopwatchState } from '$lib/components/extra/stopwatch/StopwatchState.svelte'; +export { TimerState } from '$lib/components/extra/timer/TimerState.svelte'; +export { default as Phone } from '$lib/components/extra/phone/Phone.svelte'; // 3d components export { default as ModelPicker } from '$lib/components/3d/model-picker/ModelPicker.svelte'; diff --git a/src/routes/components/base/number-input/NumberInput.md b/src/routes/components/base/number-input/NumberInput.md index c049858..815bedc 100644 --- a/src/routes/components/base/number-input/NumberInput.md +++ b/src/routes/components/base/number-input/NumberInput.md @@ -20,3 +20,7 @@ ``` + +## Credits + +- Adapted from an example of [number-flow](https://number-flow.barvian.me/) \ No newline at end of file diff --git a/src/routes/components/extras/color-picker/ColorPicker.md b/src/routes/components/extras/color-picker/ColorPicker.md index c10d68f..4517eb2 100644 --- a/src/routes/components/extras/color-picker/ColorPicker.md +++ b/src/routes/components/extras/color-picker/ColorPicker.md @@ -30,4 +30,4 @@ ### Credits -Adapted from [svelte-color-select](https://github.com/CaptainCodeman/svelte-color-select). \ No newline at end of file +- Adapted from [svelte-color-select](https://github.com/CaptainCodeman/svelte-color-select). \ No newline at end of file diff --git a/src/routes/components/extras/phone/+page.svelte b/src/routes/components/extras/phone/+page.svelte index ae7d1db..f2a2026 100644 --- a/src/routes/components/extras/phone/+page.svelte +++ b/src/routes/components/extras/phone/+page.svelte @@ -1,5 +1,8 @@ - - + + + diff --git a/src/routes/components/extras/phone/Example.svelte b/src/routes/components/extras/phone/Example.svelte new file mode 100644 index 0000000..fcf9aa4 --- /dev/null +++ b/src/routes/components/extras/phone/Example.svelte @@ -0,0 +1,11 @@ + + + +
+
Hello there
+
+
diff --git a/src/routes/components/extras/phone/Phone.md b/src/routes/components/extras/phone/Phone.md new file mode 100644 index 0000000..971560b --- /dev/null +++ b/src/routes/components/extras/phone/Phone.md @@ -0,0 +1,23 @@ + + +# Phone + +## Example + + + +## Usage + +```svelte + + + +
+
Hello there
+
+
+``` \ No newline at end of file diff --git a/src/routes/components/extras/stopwatch/+page.svelte b/src/routes/components/extras/stopwatch/+page.svelte new file mode 100644 index 0000000..a7e65ff --- /dev/null +++ b/src/routes/components/extras/stopwatch/+page.svelte @@ -0,0 +1,8 @@ + + + + + diff --git a/src/routes/components/extras/stopwatch/Example.svelte b/src/routes/components/extras/stopwatch/Example.svelte new file mode 100644 index 0000000..d0fb16b --- /dev/null +++ b/src/routes/components/extras/stopwatch/Example.svelte @@ -0,0 +1,27 @@ + + + + + + +
+ + +
diff --git a/src/routes/components/extras/stopwatch/Stopwatch.md b/src/routes/components/extras/stopwatch/Stopwatch.md new file mode 100644 index 0000000..e2c597a --- /dev/null +++ b/src/routes/components/extras/stopwatch/Stopwatch.md @@ -0,0 +1,28 @@ + + +# Stopwatch + +## Example + + + +## Usage + +```svelte + + + + + +``` + +## Credits + +- Stopwatch state based on [svelte-reactive-timer](https://github.com/joshnuss/svelte-reactive-timer) +- Moving numbers component from [number-flow](https://number-flow.barvian.me/) \ No newline at end of file diff --git a/src/routes/components/extras/timer/+page.svelte b/src/routes/components/extras/timer/+page.svelte index f7acb62..c2b8263 100644 --- a/src/routes/components/extras/timer/+page.svelte +++ b/src/routes/components/extras/timer/+page.svelte @@ -1,5 +1,8 @@ - - + + + diff --git a/src/routes/components/extras/timer/Example.svelte b/src/routes/components/extras/timer/Example.svelte new file mode 100644 index 0000000..b542d63 --- /dev/null +++ b/src/routes/components/extras/timer/Example.svelte @@ -0,0 +1,27 @@ + + + + + + +
+ + +
diff --git a/src/routes/components/extras/timer/Timer.md b/src/routes/components/extras/timer/Timer.md new file mode 100644 index 0000000..b071910 --- /dev/null +++ b/src/routes/components/extras/timer/Timer.md @@ -0,0 +1,28 @@ + + +# Timer + +## Example + + + +## Usage + +```svelte + + + + + +``` + +## Credits + +- Timer state based on [svelte-reactive-timer](https://github.com/joshnuss/svelte-reactive-timer) +- Moving numbers component from [number-flow](https://number-flow.barvian.me/) \ No newline at end of file