@leap-online/jolt 0.0.0-stage → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +51 -2
- package/THIRD_PARTY_NOTICES.md +25 -0
- package/dist/components/accordion/accordion.svelte +150 -0
- package/dist/components/accordion/accordion.svelte.d.ts +32 -0
- package/dist/components/accordion/index.d.ts +2 -0
- package/dist/components/accordion/index.js +1 -0
- package/dist/components/alert/alert.svelte +75 -0
- package/dist/components/alert/alert.svelte.d.ts +24 -0
- package/dist/components/alert/index.d.ts +1 -0
- package/dist/components/alert/index.js +1 -0
- package/dist/components/app-shell/app-shell.svelte +53 -0
- package/dist/components/app-shell/app-shell.svelte.d.ts +13 -0
- package/dist/components/app-shell/index.d.ts +2 -0
- package/dist/components/app-shell/index.js +1 -0
- package/dist/components/attachment/attachment-list.svelte +77 -0
- package/dist/components/attachment/attachment-list.svelte.d.ts +15 -0
- package/dist/components/attachment/attachment.svelte +119 -0
- package/dist/components/attachment/attachment.svelte.d.ts +14 -0
- package/dist/components/attachment/format.d.ts +1 -0
- package/dist/components/attachment/format.js +9 -0
- package/dist/components/attachment/index.d.ts +3 -0
- package/dist/components/attachment/index.js +2 -0
- package/dist/components/attachment/preview.d.ts +9 -0
- package/dist/components/attachment/preview.js +191 -0
- package/dist/components/attachment/types.d.ts +12 -0
- package/dist/components/attachment/types.js +1 -0
- package/dist/components/avatar/avatar.svelte +115 -0
- package/dist/components/avatar/avatar.svelte.d.ts +18 -0
- package/dist/components/avatar/index.d.ts +1 -0
- package/dist/components/avatar/index.js +1 -0
- package/dist/components/avatar-group/avatar-group.svelte +79 -0
- package/dist/components/avatar-group/avatar-group.svelte.d.ts +19 -0
- package/dist/components/avatar-group/index.d.ts +1 -0
- package/dist/components/avatar-group/index.js +1 -0
- package/dist/components/badge/badge.svelte +45 -0
- package/dist/components/badge/badge.svelte.d.ts +25 -0
- package/dist/components/badge/index.d.ts +1 -0
- package/dist/components/badge/index.js +1 -0
- package/dist/components/breadcrumb/breadcrumb.svelte +165 -0
- package/dist/components/breadcrumb/breadcrumb.svelte.d.ts +24 -0
- package/dist/components/breadcrumb/index.d.ts +2 -0
- package/dist/components/breadcrumb/index.js +1 -0
- package/dist/components/button/button.svelte +77 -0
- package/dist/components/button/button.svelte.d.ts +29 -0
- package/dist/components/button/index.d.ts +1 -0
- package/dist/components/button/index.js +1 -0
- package/dist/components/calendar/calendar.svelte +512 -0
- package/dist/components/calendar/calendar.svelte.d.ts +4 -0
- package/dist/components/calendar/index.d.ts +2 -0
- package/dist/components/calendar/index.js +1 -0
- package/dist/components/calendar/types.d.ts +31 -0
- package/dist/components/calendar/types.js +1 -0
- package/dist/components/card/card.svelte +65 -0
- package/dist/components/card/card.svelte.d.ts +15 -0
- package/dist/components/card/index.d.ts +1 -0
- package/dist/components/card/index.js +1 -0
- package/dist/components/chat/chat-actions.svelte +183 -0
- package/dist/components/chat/chat-actions.svelte.d.ts +21 -0
- package/dist/components/chat/chat-attachments.svelte +41 -0
- package/dist/components/chat/chat-attachments.svelte.d.ts +12 -0
- package/dist/components/chat/chat-composer.svelte +165 -0
- package/dist/components/chat/chat-composer.svelte.d.ts +21 -0
- package/dist/components/chat/chat-loader.svelte +23 -0
- package/dist/components/chat/chat-loader.svelte.d.ts +7 -0
- package/dist/components/chat/chat-markdown.svelte +16 -0
- package/dist/components/chat/chat-markdown.svelte.d.ts +7 -0
- package/dist/components/chat/chat-message.svelte +114 -0
- package/dist/components/chat/chat-message.svelte.d.ts +18 -0
- package/dist/components/chat/chat-reasoning.svelte +52 -0
- package/dist/components/chat/chat-reasoning.svelte.d.ts +11 -0
- package/dist/components/chat/chat-sources.svelte +54 -0
- package/dist/components/chat/chat-sources.svelte.d.ts +10 -0
- package/dist/components/chat/chat-suggestions.svelte +44 -0
- package/dist/components/chat/chat-suggestions.svelte.d.ts +10 -0
- package/dist/components/chat/chat-tool-call.svelte +182 -0
- package/dist/components/chat/chat-tool-call.svelte.d.ts +26 -0
- package/dist/components/chat/chat-viewport.svelte +105 -0
- package/dist/components/chat/chat-viewport.svelte.d.ts +14 -0
- package/dist/components/chat/chat.svelte +113 -0
- package/dist/components/chat/chat.svelte.d.ts +27 -0
- package/dist/components/chat/index.d.ts +16 -0
- package/dist/components/chat/index.js +12 -0
- package/dist/components/chat/types.d.ts +19 -0
- package/dist/components/chat/types.js +1 -0
- package/dist/components/checkbox/checkbox.svelte +99 -0
- package/dist/components/checkbox/checkbox.svelte.d.ts +20 -0
- package/dist/components/checkbox/index.d.ts +1 -0
- package/dist/components/checkbox/index.js +1 -0
- package/dist/components/code-block/code-block.svelte +53 -0
- package/dist/components/code-block/code-block.svelte.d.ts +12 -0
- package/dist/components/code-block/index.d.ts +1 -0
- package/dist/components/code-block/index.js +1 -0
- package/dist/components/collapsible/collapsible.svelte +79 -0
- package/dist/components/collapsible/collapsible.svelte.d.ts +17 -0
- package/dist/components/collapsible/index.d.ts +2 -0
- package/dist/components/collapsible/index.js +1 -0
- package/dist/components/combobox/combobox.svelte +272 -0
- package/dist/components/combobox/combobox.svelte.d.ts +25 -0
- package/dist/components/combobox/index.d.ts +2 -0
- package/dist/components/combobox/index.js +1 -0
- package/dist/components/combobox/types.d.ts +42 -0
- package/dist/components/combobox/types.js +1 -0
- package/dist/components/command-palette/command-palette.svelte +143 -0
- package/dist/components/command-palette/command-palette.svelte.d.ts +31 -0
- package/dist/components/command-palette/index.d.ts +2 -0
- package/dist/components/command-palette/index.js +1 -0
- package/dist/components/confirm-dialog/confirm-dialog.svelte +107 -0
- package/dist/components/confirm-dialog/confirm-dialog.svelte.d.ts +20 -0
- package/dist/components/confirm-dialog/index.d.ts +1 -0
- package/dist/components/confirm-dialog/index.js +1 -0
- package/dist/components/context-menu/context-menu.svelte +175 -0
- package/dist/components/context-menu/context-menu.svelte.d.ts +22 -0
- package/dist/components/context-menu/index.d.ts +1 -0
- package/dist/components/context-menu/index.js +1 -0
- package/dist/components/copy-button/copy-button.svelte +130 -0
- package/dist/components/copy-button/copy-button.svelte.d.ts +19 -0
- package/dist/components/copy-button/index.d.ts +1 -0
- package/dist/components/copy-button/index.js +1 -0
- package/dist/components/data-table/data-table.svelte +146 -0
- package/dist/components/data-table/data-table.svelte.d.ts +43 -0
- package/dist/components/data-table/index.d.ts +2 -0
- package/dist/components/data-table/index.js +1 -0
- package/dist/components/date-picker/date-picker.svelte +95 -0
- package/dist/components/date-picker/date-picker.svelte.d.ts +24 -0
- package/dist/components/date-picker/index.d.ts +2 -0
- package/dist/components/date-picker/index.js +1 -0
- package/dist/components/date-range-picker/date-range-picker.svelte +117 -0
- package/dist/components/date-range-picker/date-range-picker.svelte.d.ts +28 -0
- package/dist/components/date-range-picker/index.d.ts +2 -0
- package/dist/components/date-range-picker/index.js +1 -0
- package/dist/components/dialog/dialog.svelte +98 -0
- package/dist/components/dialog/dialog.svelte.d.ts +16 -0
- package/dist/components/dialog/index.d.ts +1 -0
- package/dist/components/dialog/index.js +1 -0
- package/dist/components/dropdown-menu/dropdown-menu.svelte +197 -0
- package/dist/components/dropdown-menu/dropdown-menu.svelte.d.ts +29 -0
- package/dist/components/dropdown-menu/index.d.ts +1 -0
- package/dist/components/dropdown-menu/index.js +1 -0
- package/dist/components/email-input/email-input.svelte +21 -0
- package/dist/components/email-input/email-input.svelte.d.ts +5 -0
- package/dist/components/email-input/email.d.ts +10 -0
- package/dist/components/email-input/email.js +15 -0
- package/dist/components/email-input/index.d.ts +1 -0
- package/dist/components/email-input/index.js +1 -0
- package/dist/components/empty-state/empty-state.svelte +46 -0
- package/dist/components/empty-state/empty-state.svelte.d.ts +14 -0
- package/dist/components/empty-state/index.d.ts +1 -0
- package/dist/components/empty-state/index.js +1 -0
- package/dist/components/field/checkbox-field.svelte +50 -0
- package/dist/components/field/checkbox-field.svelte.d.ts +4 -0
- package/dist/components/field/field.svelte +71 -0
- package/dist/components/field/field.svelte.d.ts +21 -0
- package/dist/components/field/index.d.ts +5 -0
- package/dist/components/field/index.js +4 -0
- package/dist/components/field/select-field.svelte +55 -0
- package/dist/components/field/select-field.svelte.d.ts +25 -0
- package/dist/components/field/text-field.svelte +48 -0
- package/dist/components/field/text-field.svelte.d.ts +4 -0
- package/dist/components/field/textarea-field.svelte +45 -0
- package/dist/components/field/textarea-field.svelte.d.ts +4 -0
- package/dist/components/field/types.d.ts +74 -0
- package/dist/components/field/types.js +1 -0
- package/dist/components/file-upload/file-upload.svelte +202 -0
- package/dist/components/file-upload/file-upload.svelte.d.ts +15 -0
- package/dist/components/file-upload/index.d.ts +1 -0
- package/dist/components/file-upload/index.js +1 -0
- package/dist/components/hover-card/hover-card.svelte +64 -0
- package/dist/components/hover-card/hover-card.svelte.d.ts +20 -0
- package/dist/components/hover-card/index.d.ts +1 -0
- package/dist/components/hover-card/index.js +1 -0
- package/dist/components/inline-edit/index.d.ts +1 -0
- package/dist/components/inline-edit/index.js +1 -0
- package/dist/components/inline-edit/inline-edit.svelte +207 -0
- package/dist/components/inline-edit/inline-edit.svelte.d.ts +17 -0
- package/dist/components/input/index.d.ts +1 -0
- package/dist/components/input/index.js +1 -0
- package/dist/components/input/input.svelte +36 -0
- package/dist/components/input/input.svelte.d.ts +8 -0
- package/dist/components/kbd/index.d.ts +1 -0
- package/dist/components/kbd/index.js +1 -0
- package/dist/components/kbd/kbd.svelte +33 -0
- package/dist/components/kbd/kbd.svelte.d.ts +10 -0
- package/dist/components/label/index.d.ts +1 -0
- package/dist/components/label/index.js +1 -0
- package/dist/components/label/label.svelte +25 -0
- package/dist/components/label/label.svelte.d.ts +8 -0
- package/dist/components/lightbox/index.d.ts +2 -0
- package/dist/components/lightbox/index.js +1 -0
- package/dist/components/lightbox/lightbox.svelte +264 -0
- package/dist/components/lightbox/lightbox.svelte.d.ts +4 -0
- package/dist/components/lightbox/types.d.ts +41 -0
- package/dist/components/lightbox/types.js +1 -0
- package/dist/components/loader/index.d.ts +1 -0
- package/dist/components/loader/index.js +1 -0
- package/dist/components/loader/loader.svelte +78 -0
- package/dist/components/loader/loader.svelte.d.ts +10 -0
- package/dist/components/markdown/markdown.svelte +52 -0
- package/dist/components/markdown/markdown.svelte.d.ts +7 -0
- package/dist/components/menubar/index.d.ts +3 -0
- package/dist/components/menubar/index.js +1 -0
- package/dist/components/menubar/menubar.svelte +180 -0
- package/dist/components/menubar/menubar.svelte.d.ts +4 -0
- package/dist/components/menubar/types.d.ts +26 -0
- package/dist/components/menubar/types.js +1 -0
- package/dist/components/multi-select/index.d.ts +2 -0
- package/dist/components/multi-select/index.js +1 -0
- package/dist/components/multi-select/multi-select.svelte +273 -0
- package/dist/components/multi-select/multi-select.svelte.d.ts +25 -0
- package/dist/components/multi-select/types.d.ts +32 -0
- package/dist/components/multi-select/types.js +1 -0
- package/dist/components/navigation-menu/index.d.ts +2 -0
- package/dist/components/navigation-menu/index.js +1 -0
- package/dist/components/navigation-menu/navigation-menu.svelte +125 -0
- package/dist/components/navigation-menu/navigation-menu.svelte.d.ts +4 -0
- package/dist/components/navigation-menu/types.d.ts +40 -0
- package/dist/components/navigation-menu/types.js +1 -0
- package/dist/components/page-header/index.d.ts +1 -0
- package/dist/components/page-header/index.js +1 -0
- package/dist/components/page-header/page-header.svelte +44 -0
- package/dist/components/page-header/page-header.svelte.d.ts +11 -0
- package/dist/components/pagination/index.d.ts +2 -0
- package/dist/components/pagination/index.js +1 -0
- package/dist/components/pagination/pagination.svelte +105 -0
- package/dist/components/pagination/pagination.svelte.d.ts +20 -0
- package/dist/components/popover/index.d.ts +2 -0
- package/dist/components/popover/index.js +1 -0
- package/dist/components/popover/popover.svelte +67 -0
- package/dist/components/popover/popover.svelte.d.ts +20 -0
- package/dist/components/progress/index.d.ts +2 -0
- package/dist/components/progress/index.js +1 -0
- package/dist/components/progress/progress.svelte +81 -0
- package/dist/components/progress/progress.svelte.d.ts +16 -0
- package/dist/components/radio-group/index.d.ts +2 -0
- package/dist/components/radio-group/index.js +1 -0
- package/dist/components/radio-group/radio-group.svelte +140 -0
- package/dist/components/radio-group/radio-group.svelte.d.ts +32 -0
- package/dist/components/reaction-bar/index.d.ts +1 -0
- package/dist/components/reaction-bar/index.js +1 -0
- package/dist/components/reaction-bar/reaction-bar.svelte +99 -0
- package/dist/components/reaction-bar/reaction-bar.svelte.d.ts +18 -0
- package/dist/components/scroll-area/index.d.ts +2 -0
- package/dist/components/scroll-area/index.js +1 -0
- package/dist/components/scroll-area/scroll-area.svelte +81 -0
- package/dist/components/scroll-area/scroll-area.svelte.d.ts +15 -0
- package/dist/components/select/index.d.ts +2 -0
- package/dist/components/select/index.js +1 -0
- package/dist/components/select/select.svelte +183 -0
- package/dist/components/select/select.svelte.d.ts +25 -0
- package/dist/components/select/types.d.ts +38 -0
- package/dist/components/select/types.js +1 -0
- package/dist/components/separator/index.d.ts +1 -0
- package/dist/components/separator/index.js +1 -0
- package/dist/components/separator/separator.svelte +25 -0
- package/dist/components/separator/separator.svelte.d.ts +8 -0
- package/dist/components/sheet/index.d.ts +2 -0
- package/dist/components/sheet/index.js +1 -0
- package/dist/components/sheet/sheet.svelte +111 -0
- package/dist/components/sheet/sheet.svelte.d.ts +17 -0
- package/dist/components/sidebar/index.d.ts +2 -0
- package/dist/components/sidebar/index.js +1 -0
- package/dist/components/sidebar/sidebar.svelte +124 -0
- package/dist/components/sidebar/sidebar.svelte.d.ts +4 -0
- package/dist/components/sidebar/types.d.ts +28 -0
- package/dist/components/sidebar/types.js +1 -0
- package/dist/components/skeleton/index.d.ts +1 -0
- package/dist/components/skeleton/index.js +1 -0
- package/dist/components/skeleton/skeleton.svelte +17 -0
- package/dist/components/skeleton/skeleton.svelte.d.ts +6 -0
- package/dist/components/slider/index.d.ts +2 -0
- package/dist/components/slider/index.js +1 -0
- package/dist/components/slider/slider.svelte +194 -0
- package/dist/components/slider/slider.svelte.d.ts +25 -0
- package/dist/components/spinner/index.d.ts +1 -0
- package/dist/components/spinner/index.js +1 -0
- package/dist/components/spinner/spinner.svelte +32 -0
- package/dist/components/spinner/spinner.svelte.d.ts +9 -0
- package/dist/components/split-button/index.d.ts +1 -0
- package/dist/components/split-button/index.js +1 -0
- package/dist/components/split-button/split-button.svelte +87 -0
- package/dist/components/split-button/split-button.svelte.d.ts +21 -0
- package/dist/components/switch/index.d.ts +1 -0
- package/dist/components/switch/index.js +1 -0
- package/dist/components/switch/switch.svelte +78 -0
- package/dist/components/switch/switch.svelte.d.ts +17 -0
- package/dist/components/table/index.d.ts +2 -0
- package/dist/components/table/index.js +1 -0
- package/dist/components/table/table.svelte +71 -0
- package/dist/components/table/table.svelte.d.ts +25 -0
- package/dist/components/table/types.d.ts +19 -0
- package/dist/components/table/types.js +1 -0
- package/dist/components/tabs/index.d.ts +1 -0
- package/dist/components/tabs/index.js +1 -0
- package/dist/components/tabs/tabs.svelte +117 -0
- package/dist/components/tabs/tabs.svelte.d.ts +30 -0
- package/dist/components/tags-input/index.d.ts +2 -0
- package/dist/components/tags-input/index.js +1 -0
- package/dist/components/tags-input/parse.d.ts +6 -0
- package/dist/components/tags-input/parse.js +24 -0
- package/dist/components/tags-input/tags-input.svelte +181 -0
- package/dist/components/tags-input/tags-input.svelte.d.ts +4 -0
- package/dist/components/tags-input/types.d.ts +21 -0
- package/dist/components/tags-input/types.js +1 -0
- package/dist/components/textarea/index.d.ts +2 -0
- package/dist/components/textarea/index.js +1 -0
- package/dist/components/textarea/textarea.svelte +35 -0
- package/dist/components/textarea/textarea.svelte.d.ts +8 -0
- package/dist/components/time-picker/index.d.ts +2 -0
- package/dist/components/time-picker/index.js +1 -0
- package/dist/components/time-picker/time-picker.svelte +255 -0
- package/dist/components/time-picker/time-picker.svelte.d.ts +4 -0
- package/dist/components/time-picker/types.d.ts +23 -0
- package/dist/components/time-picker/types.js +1 -0
- package/dist/components/toast/index.d.ts +4 -0
- package/dist/components/toast/index.js +2 -0
- package/dist/components/toast/toast.svelte +68 -0
- package/dist/components/toast/toast.svelte.d.ts +16 -0
- package/dist/components/toggle/index.d.ts +2 -0
- package/dist/components/toggle/index.js +1 -0
- package/dist/components/toggle/toggle-variants.d.ts +14 -0
- package/dist/components/toggle/toggle-variants.js +19 -0
- package/dist/components/toggle/toggle.svelte +57 -0
- package/dist/components/toggle/toggle.svelte.d.ts +19 -0
- package/dist/components/toggle-group/index.d.ts +2 -0
- package/dist/components/toggle-group/index.js +1 -0
- package/dist/components/toggle-group/toggle-group.svelte +163 -0
- package/dist/components/toggle-group/toggle-group.svelte.d.ts +32 -0
- package/dist/components/tooltip/index.d.ts +1 -0
- package/dist/components/tooltip/index.js +1 -0
- package/dist/components/tooltip/tooltip.svelte +65 -0
- package/dist/components/tooltip/tooltip.svelte.d.ts +18 -0
- package/dist/components/tree-view/index.d.ts +3 -0
- package/dist/components/tree-view/index.js +2 -0
- package/dist/components/tree-view/move-tree-node.d.ts +7 -0
- package/dist/components/tree-view/move-tree-node.js +57 -0
- package/dist/components/tree-view/tree-view.svelte +553 -0
- package/dist/components/tree-view/tree-view.svelte.d.ts +4 -0
- package/dist/components/tree-view/types.d.ts +45 -0
- package/dist/components/tree-view/types.js +1 -0
- package/dist/form/create-form.svelte.d.ts +23 -0
- package/dist/form/create-form.svelte.js +68 -0
- package/dist/form/index.d.ts +4 -0
- package/dist/form/index.js +2 -0
- package/dist/form/superform-errors.d.ts +6 -0
- package/dist/form/superform-errors.js +13 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +67 -0
- package/dist/styles/theme.css +373 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +1 -0
- package/dist/types/menu.d.ts +51 -0
- package/dist/types/menu.js +1 -0
- package/dist/utils/clipboard.d.ts +13 -0
- package/dist/utils/clipboard.js +22 -0
- package/dist/utils/cls.d.ts +5 -0
- package/dist/utils/cls.js +8 -0
- package/dist/utils/highlight.d.ts +4 -0
- package/dist/utils/highlight.js +82 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/package.json +126 -5
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Time } from '@internationalized/date';
|
|
3
|
+
import { ChevronDownIcon, ChevronUpIcon, ClockIcon } from '@lucide/svelte';
|
|
4
|
+
import { TimeField as BitsTimeField } from 'bits-ui';
|
|
5
|
+
import { cls } from '../../utils/index.js';
|
|
6
|
+
import { Button } from '../button/index.js';
|
|
7
|
+
import { Popover } from '../popover/index.js';
|
|
8
|
+
import type { Props } from './types.js';
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
value = $bindable(),
|
|
12
|
+
onValueChange,
|
|
13
|
+
minValue,
|
|
14
|
+
maxValue,
|
|
15
|
+
label,
|
|
16
|
+
ariaLabel,
|
|
17
|
+
hint,
|
|
18
|
+
error,
|
|
19
|
+
disabled,
|
|
20
|
+
readonly,
|
|
21
|
+
required,
|
|
22
|
+
name,
|
|
23
|
+
locale,
|
|
24
|
+
hourCycle,
|
|
25
|
+
granularity,
|
|
26
|
+
class: className,
|
|
27
|
+
inputClass,
|
|
28
|
+
labelClass,
|
|
29
|
+
segmentClass,
|
|
30
|
+
}: Props = $props();
|
|
31
|
+
|
|
32
|
+
const uid = $props.id();
|
|
33
|
+
const inputId = `${uid}-input`;
|
|
34
|
+
const labelId = `${uid}-label`;
|
|
35
|
+
const hintId = `${uid}-hint`;
|
|
36
|
+
const errorId = `${uid}-error`;
|
|
37
|
+
|
|
38
|
+
const hasError = $derived(Boolean(error));
|
|
39
|
+
const describedBy = $derived(
|
|
40
|
+
[hint && !error ? hintId : '', error ? errorId : ''].filter(Boolean).join(' ') || undefined,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const hour = $derived(value?.hour ?? 0);
|
|
44
|
+
const minute = $derived(value?.minute ?? 0);
|
|
45
|
+
const second = $derived(value?.second ?? 0);
|
|
46
|
+
const is12Hour = $derived(hourCycle === 12);
|
|
47
|
+
const showMinutes = $derived(granularity !== 'hour');
|
|
48
|
+
const showSeconds = $derived(granularity === 'second');
|
|
49
|
+
const displayHour = $derived(is12Hour ? (hour % 12 === 0 ? 12 : hour % 12) : hour);
|
|
50
|
+
const period = $derived(hour < 12 ? 'AM' : 'PM');
|
|
51
|
+
|
|
52
|
+
function setTime(nextHour: number, nextMinute: number, nextSecond = second): void {
|
|
53
|
+
const nextValue = new Time(
|
|
54
|
+
(nextHour + 24) % 24,
|
|
55
|
+
(nextMinute + 60) % 60,
|
|
56
|
+
(nextSecond + 60) % 60,
|
|
57
|
+
value?.millisecond ?? 0,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
value = nextValue;
|
|
61
|
+
onValueChange?.(nextValue);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function stepHour(delta: number): void {
|
|
65
|
+
setTime(hour + delta, minute);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function stepMinute(delta: number): void {
|
|
69
|
+
setTime(hour, minute + delta);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function stepSecond(delta: number): void {
|
|
73
|
+
setTime(hour, minute, second + delta);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function togglePeriod(): void {
|
|
77
|
+
setTime(hour < 12 ? hour + 12 : hour - 12, minute);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function formatNumber(next: number): string {
|
|
81
|
+
return String(next).padStart(2, '0');
|
|
82
|
+
}
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<div data-slot="time-picker" class={cls('grid gap-1.5', className)}>
|
|
86
|
+
{#if label}
|
|
87
|
+
<label id={labelId} for={inputId} class={cls('text-sm font-medium', labelClass)}>
|
|
88
|
+
{label}
|
|
89
|
+
</label>
|
|
90
|
+
{/if}
|
|
91
|
+
|
|
92
|
+
<div class="relative">
|
|
93
|
+
<BitsTimeField.Root
|
|
94
|
+
bind:value
|
|
95
|
+
{onValueChange}
|
|
96
|
+
{minValue}
|
|
97
|
+
{maxValue}
|
|
98
|
+
{disabled}
|
|
99
|
+
{readonly}
|
|
100
|
+
{required}
|
|
101
|
+
{locale}
|
|
102
|
+
{hourCycle}
|
|
103
|
+
{granularity}
|
|
104
|
+
errorMessageId={hasError ? errorId : undefined}
|
|
105
|
+
>
|
|
106
|
+
<BitsTimeField.Input
|
|
107
|
+
id={inputId}
|
|
108
|
+
{name}
|
|
109
|
+
aria-labelledby={label ? labelId : undefined}
|
|
110
|
+
aria-label={label ? undefined : (ariaLabel ?? 'Time')}
|
|
111
|
+
aria-describedby={describedBy}
|
|
112
|
+
aria-invalid={hasError || undefined}
|
|
113
|
+
data-slot="time-picker-input"
|
|
114
|
+
class={cls(
|
|
115
|
+
'flex h-9 w-full items-center rounded-md border border-input bg-background px-3 py-2 pe-9 text-sm shadow-xs transition-[color,box-shadow] duration-150 ease-out motion-reduce:transition-none',
|
|
116
|
+
'focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 focus-within:ring-offset-background',
|
|
117
|
+
hasError && 'border-destructive focus-within:ring-destructive',
|
|
118
|
+
disabled && 'cursor-not-allowed opacity-50',
|
|
119
|
+
inputClass,
|
|
120
|
+
)}
|
|
121
|
+
>
|
|
122
|
+
{#snippet children({ segments })}
|
|
123
|
+
{#each segments as segment, index (index)}
|
|
124
|
+
{#if segment.part === 'literal'}
|
|
125
|
+
<span class="text-muted-foreground">{segment.value}</span>
|
|
126
|
+
{:else}
|
|
127
|
+
<BitsTimeField.Segment
|
|
128
|
+
part={segment.part}
|
|
129
|
+
class={cls(
|
|
130
|
+
'rounded-sm px-0.5 text-center tabular-nums outline-hidden focus:bg-accent focus:text-accent-foreground data-[disabled]:opacity-50 data-[focused]:bg-accent data-[focused]:text-accent-foreground',
|
|
131
|
+
segmentClass,
|
|
132
|
+
)}
|
|
133
|
+
>
|
|
134
|
+
{segment.value}
|
|
135
|
+
</BitsTimeField.Segment>
|
|
136
|
+
{/if}
|
|
137
|
+
{/each}
|
|
138
|
+
{/snippet}
|
|
139
|
+
</BitsTimeField.Input>
|
|
140
|
+
</BitsTimeField.Root>
|
|
141
|
+
|
|
142
|
+
<Popover
|
|
143
|
+
align="end"
|
|
144
|
+
contentClass={cls(showSeconds ? 'w-72 p-3' : showMinutes ? 'w-56 p-3' : 'w-48 p-3')}
|
|
145
|
+
>
|
|
146
|
+
{#snippet trigger(props)}
|
|
147
|
+
<Button
|
|
148
|
+
{...props}
|
|
149
|
+
type="button"
|
|
150
|
+
variant="ghost"
|
|
151
|
+
size="icon"
|
|
152
|
+
aria-label="Choose time"
|
|
153
|
+
disabled={disabled || readonly}
|
|
154
|
+
class="absolute end-1 top-1/2 size-7 -translate-y-1/2 text-muted-foreground"
|
|
155
|
+
>
|
|
156
|
+
<ClockIcon class="size-4" />
|
|
157
|
+
</Button>
|
|
158
|
+
{/snippet}
|
|
159
|
+
|
|
160
|
+
<div data-slot="time-picker-popover" class="grid gap-3">
|
|
161
|
+
<p class="text-sm font-medium">Choose time</p>
|
|
162
|
+
<div class="flex items-center justify-center gap-4">
|
|
163
|
+
<div class="grid justify-items-center gap-1">
|
|
164
|
+
<button
|
|
165
|
+
type="button"
|
|
166
|
+
aria-label="Increase hour"
|
|
167
|
+
class="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden"
|
|
168
|
+
onclick={() => stepHour(1)}
|
|
169
|
+
>
|
|
170
|
+
<ChevronUpIcon class="size-4" />
|
|
171
|
+
</button>
|
|
172
|
+
<span class="text-2xl font-semibold tabular-nums">{formatNumber(displayHour)}</span>
|
|
173
|
+
<button
|
|
174
|
+
type="button"
|
|
175
|
+
aria-label="Decrease hour"
|
|
176
|
+
class="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden"
|
|
177
|
+
onclick={() => stepHour(-1)}
|
|
178
|
+
>
|
|
179
|
+
<ChevronDownIcon class="size-4" />
|
|
180
|
+
</button>
|
|
181
|
+
<span class="text-xs text-muted-foreground">Hour</span>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
{#if showMinutes}
|
|
185
|
+
<span class="text-2xl text-muted-foreground">:</span>
|
|
186
|
+
|
|
187
|
+
<div class="grid justify-items-center gap-1">
|
|
188
|
+
<button
|
|
189
|
+
type="button"
|
|
190
|
+
aria-label="Increase minute"
|
|
191
|
+
class="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden"
|
|
192
|
+
onclick={() => stepMinute(1)}
|
|
193
|
+
>
|
|
194
|
+
<ChevronUpIcon class="size-4" />
|
|
195
|
+
</button>
|
|
196
|
+
<span class="text-2xl font-semibold tabular-nums">{formatNumber(minute)}</span>
|
|
197
|
+
<button
|
|
198
|
+
type="button"
|
|
199
|
+
aria-label="Decrease minute"
|
|
200
|
+
class="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden"
|
|
201
|
+
onclick={() => stepMinute(-1)}
|
|
202
|
+
>
|
|
203
|
+
<ChevronDownIcon class="size-4" />
|
|
204
|
+
</button>
|
|
205
|
+
<span class="text-xs text-muted-foreground">Minute</span>
|
|
206
|
+
</div>
|
|
207
|
+
{/if}
|
|
208
|
+
|
|
209
|
+
{#if showSeconds}
|
|
210
|
+
<span class="text-2xl text-muted-foreground">:</span>
|
|
211
|
+
|
|
212
|
+
<div class="grid justify-items-center gap-1">
|
|
213
|
+
<button
|
|
214
|
+
type="button"
|
|
215
|
+
aria-label="Increase second"
|
|
216
|
+
class="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden"
|
|
217
|
+
onclick={() => stepSecond(1)}
|
|
218
|
+
>
|
|
219
|
+
<ChevronUpIcon class="size-4" />
|
|
220
|
+
</button>
|
|
221
|
+
<span class="text-2xl font-semibold tabular-nums">{formatNumber(second)}</span>
|
|
222
|
+
<button
|
|
223
|
+
type="button"
|
|
224
|
+
aria-label="Decrease second"
|
|
225
|
+
class="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden"
|
|
226
|
+
onclick={() => stepSecond(-1)}
|
|
227
|
+
>
|
|
228
|
+
<ChevronDownIcon class="size-4" />
|
|
229
|
+
</button>
|
|
230
|
+
<span class="text-xs text-muted-foreground">Second</span>
|
|
231
|
+
</div>
|
|
232
|
+
{/if}
|
|
233
|
+
|
|
234
|
+
{#if is12Hour}
|
|
235
|
+
<button
|
|
236
|
+
type="button"
|
|
237
|
+
aria-label="Toggle AM/PM"
|
|
238
|
+
class="self-center rounded-md border px-2 py-1 text-xs font-medium transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden"
|
|
239
|
+
onclick={togglePeriod}
|
|
240
|
+
>
|
|
241
|
+
{period}
|
|
242
|
+
</button>
|
|
243
|
+
{/if}
|
|
244
|
+
</div>
|
|
245
|
+
</div>
|
|
246
|
+
</Popover>
|
|
247
|
+
</div>
|
|
248
|
+
|
|
249
|
+
{#if hint && !error}
|
|
250
|
+
<p id={hintId} class="text-xs text-muted-foreground">{hint}</p>
|
|
251
|
+
{/if}
|
|
252
|
+
{#if error}
|
|
253
|
+
<p id={errorId} role="alert" class="text-xs text-destructive">{error}</p>
|
|
254
|
+
{/if}
|
|
255
|
+
</div>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Time } from '@internationalized/date';
|
|
2
|
+
export type TimePickerGranularity = 'hour' | 'minute' | 'second';
|
|
3
|
+
export type Props = {
|
|
4
|
+
value?: Time;
|
|
5
|
+
onValueChange?: (value: Time | undefined) => void;
|
|
6
|
+
minValue?: Time;
|
|
7
|
+
maxValue?: Time;
|
|
8
|
+
label?: string;
|
|
9
|
+
ariaLabel?: string;
|
|
10
|
+
hint?: string;
|
|
11
|
+
error?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
readonly?: boolean;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
name?: string;
|
|
16
|
+
locale?: string;
|
|
17
|
+
hourCycle?: 12 | 24;
|
|
18
|
+
granularity?: TimePickerGranularity;
|
|
19
|
+
class?: string;
|
|
20
|
+
inputClass?: string;
|
|
21
|
+
labelClass?: string;
|
|
22
|
+
segmentClass?: string;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export type ToastTheme = 'light' | 'dark' | 'system';
|
|
3
|
+
export type ToastPosition =
|
|
4
|
+
'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'top-center' | 'bottom-center';
|
|
5
|
+
|
|
6
|
+
export type Props = {
|
|
7
|
+
position?: ToastPosition;
|
|
8
|
+
theme?: ToastTheme;
|
|
9
|
+
duration?: number;
|
|
10
|
+
closeButton?: boolean;
|
|
11
|
+
visibleToasts?: number;
|
|
12
|
+
expand?: boolean;
|
|
13
|
+
offset?: number | string;
|
|
14
|
+
mobileOffset?: number | string;
|
|
15
|
+
class?: string;
|
|
16
|
+
};
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script lang="ts">
|
|
20
|
+
import { Toaster, type ToasterProps } from 'svelte-sonner';
|
|
21
|
+
import { cls } from '../../utils/index.js';
|
|
22
|
+
|
|
23
|
+
let {
|
|
24
|
+
position = 'bottom-right',
|
|
25
|
+
theme = 'system',
|
|
26
|
+
duration = 4000,
|
|
27
|
+
closeButton = true,
|
|
28
|
+
visibleToasts = 3,
|
|
29
|
+
expand = false,
|
|
30
|
+
offset = 24,
|
|
31
|
+
mobileOffset = 16,
|
|
32
|
+
class: className,
|
|
33
|
+
}: Props = $props();
|
|
34
|
+
|
|
35
|
+
const style = $derived(
|
|
36
|
+
[
|
|
37
|
+
'font-family: var(--font-sans)',
|
|
38
|
+
'--normal-bg: var(--popover)',
|
|
39
|
+
'--normal-border: var(--border)',
|
|
40
|
+
'--normal-text: var(--popover-foreground)',
|
|
41
|
+
'--border-radius: var(--radius-lg)',
|
|
42
|
+
'--toast-close-button-start: unset',
|
|
43
|
+
'--toast-close-button-end: 0',
|
|
44
|
+
'--toast-close-button-transform: translate(35%, -35%)',
|
|
45
|
+
].join('; '),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const toastOptions: ToasterProps['toastOptions'] = {
|
|
49
|
+
classes: {
|
|
50
|
+
description: 'text-muted-foreground!',
|
|
51
|
+
closeButton: 'border-border! bg-popover! text-foreground!',
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<Toaster
|
|
57
|
+
{position}
|
|
58
|
+
{theme}
|
|
59
|
+
{duration}
|
|
60
|
+
{closeButton}
|
|
61
|
+
{visibleToasts}
|
|
62
|
+
{expand}
|
|
63
|
+
{offset}
|
|
64
|
+
{mobileOffset}
|
|
65
|
+
{style}
|
|
66
|
+
{toastOptions}
|
|
67
|
+
class={cls('font-sans', className)}
|
|
68
|
+
/>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type ToastTheme = 'light' | 'dark' | 'system';
|
|
2
|
+
export type ToastPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'top-center' | 'bottom-center';
|
|
3
|
+
export type Props = {
|
|
4
|
+
position?: ToastPosition;
|
|
5
|
+
theme?: ToastTheme;
|
|
6
|
+
duration?: number;
|
|
7
|
+
closeButton?: boolean;
|
|
8
|
+
visibleToasts?: number;
|
|
9
|
+
expand?: boolean;
|
|
10
|
+
offset?: number | string;
|
|
11
|
+
mobileOffset?: number | string;
|
|
12
|
+
class?: string;
|
|
13
|
+
};
|
|
14
|
+
declare const Toast: import("svelte").Component<Props, {}, "">;
|
|
15
|
+
type Toast = ReturnType<typeof Toast>;
|
|
16
|
+
export default Toast;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Toggle } from './toggle.svelte';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type VariantProps } from 'tailwind-variants';
|
|
2
|
+
export declare const toggleVariants: import("tailwind-variants").TVReturnType<{
|
|
3
|
+
variant: {
|
|
4
|
+
default: string;
|
|
5
|
+
outline: string;
|
|
6
|
+
};
|
|
7
|
+
size: {
|
|
8
|
+
sm: string;
|
|
9
|
+
default: string;
|
|
10
|
+
lg: string;
|
|
11
|
+
};
|
|
12
|
+
}, undefined, "inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-[color,box-shadow,background-color] duration-150 ease-out motion-reduce:transition-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50", undefined, undefined, undefined>;
|
|
13
|
+
export type ToggleVariant = VariantProps<typeof toggleVariants>['variant'];
|
|
14
|
+
export type ToggleSize = VariantProps<typeof toggleVariants>['size'];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { tv } from 'tailwind-variants';
|
|
2
|
+
export const toggleVariants = tv({
|
|
3
|
+
base: 'inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-[color,box-shadow,background-color] duration-150 ease-out motion-reduce:transition-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50',
|
|
4
|
+
variants: {
|
|
5
|
+
variant: {
|
|
6
|
+
default: 'bg-transparent hover:bg-accent/50 data-[state=on]:bg-primary data-[state=on]:text-primary-foreground data-[state=on]:hover:bg-primary/90',
|
|
7
|
+
outline: 'border border-input bg-transparent hover:bg-accent hover:text-accent-foreground data-[state=on]:border-primary data-[state=on]:bg-primary data-[state=on]:text-primary-foreground data-[state=on]:hover:bg-primary/90',
|
|
8
|
+
},
|
|
9
|
+
size: {
|
|
10
|
+
sm: 'h-8 px-2.5 text-xs',
|
|
11
|
+
default: 'h-9 px-3',
|
|
12
|
+
lg: 'h-10 px-4',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
defaultVariants: {
|
|
16
|
+
variant: 'default',
|
|
17
|
+
size: 'default',
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type {
|
|
4
|
+
ToggleSize as ToggleSizeValue,
|
|
5
|
+
ToggleVariant as ToggleVariantValue,
|
|
6
|
+
} from './toggle-variants.js';
|
|
7
|
+
|
|
8
|
+
export type { ToggleSize, ToggleVariant } from './toggle-variants.js';
|
|
9
|
+
|
|
10
|
+
export type Props = {
|
|
11
|
+
pressed?: boolean;
|
|
12
|
+
onPressedChange?: (pressed: boolean) => void;
|
|
13
|
+
variant?: ToggleVariantValue;
|
|
14
|
+
size?: ToggleSizeValue;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
ariaLabel?: string;
|
|
17
|
+
type?: 'button' | 'submit' | 'reset';
|
|
18
|
+
children?: Snippet;
|
|
19
|
+
class?: string;
|
|
20
|
+
/** Attributes supplied by a tooltip trigger and forwarded to the button. */
|
|
21
|
+
triggerProps?: Record<string, unknown>;
|
|
22
|
+
};
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<script lang="ts">
|
|
26
|
+
import { Toggle as BitsToggle } from 'bits-ui';
|
|
27
|
+
import { cls } from '../../utils/index.js';
|
|
28
|
+
import { toggleVariants } from './toggle-variants.js';
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
pressed = $bindable(false),
|
|
32
|
+
onPressedChange,
|
|
33
|
+
variant = 'default',
|
|
34
|
+
size = 'default',
|
|
35
|
+
disabled,
|
|
36
|
+
ariaLabel,
|
|
37
|
+
type = 'button',
|
|
38
|
+
children,
|
|
39
|
+
class: className,
|
|
40
|
+
triggerProps,
|
|
41
|
+
}: Props = $props();
|
|
42
|
+
|
|
43
|
+
const classes = $derived(cls(toggleVariants({ variant, size }), className));
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<BitsToggle.Root
|
|
47
|
+
{...triggerProps}
|
|
48
|
+
{pressed}
|
|
49
|
+
{onPressedChange}
|
|
50
|
+
{disabled}
|
|
51
|
+
{type}
|
|
52
|
+
aria-label={ariaLabel}
|
|
53
|
+
data-slot="toggle"
|
|
54
|
+
class={classes}
|
|
55
|
+
>
|
|
56
|
+
{@render children?.()}
|
|
57
|
+
</BitsToggle.Root>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { ToggleSize as ToggleSizeValue, ToggleVariant as ToggleVariantValue } from './toggle-variants.js';
|
|
3
|
+
export type { ToggleSize, ToggleVariant } from './toggle-variants.js';
|
|
4
|
+
export type Props = {
|
|
5
|
+
pressed?: boolean;
|
|
6
|
+
onPressedChange?: (pressed: boolean) => void;
|
|
7
|
+
variant?: ToggleVariantValue;
|
|
8
|
+
size?: ToggleSizeValue;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
ariaLabel?: string;
|
|
11
|
+
type?: 'button' | 'submit' | 'reset';
|
|
12
|
+
children?: Snippet;
|
|
13
|
+
class?: string;
|
|
14
|
+
/** Attributes supplied by a tooltip trigger and forwarded to the button. */
|
|
15
|
+
triggerProps?: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
declare const Toggle: import("svelte").Component<Props, {}, "pressed">;
|
|
18
|
+
type Toggle = ReturnType<typeof Toggle>;
|
|
19
|
+
export default Toggle;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ToggleGroup } from './toggle-group.svelte';
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Component } from 'svelte';
|
|
3
|
+
|
|
4
|
+
export type ToggleGroupItem = {
|
|
5
|
+
value: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
ariaLabel?: string;
|
|
8
|
+
icon?: Component<{ class?: string }>;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type ToggleGroupType = 'single' | 'multiple';
|
|
13
|
+
export type ToggleGroupVariant = 'default' | 'outline';
|
|
14
|
+
export type ToggleGroupSize = 'sm' | 'default' | 'lg';
|
|
15
|
+
export type ToggleGroupOrientation = 'horizontal' | 'vertical';
|
|
16
|
+
|
|
17
|
+
export type Props = {
|
|
18
|
+
items: ToggleGroupItem[];
|
|
19
|
+
type?: ToggleGroupType;
|
|
20
|
+
value?: string | string[];
|
|
21
|
+
onValueChange?: (value: string | string[]) => void;
|
|
22
|
+
variant?: ToggleGroupVariant;
|
|
23
|
+
size?: ToggleGroupSize;
|
|
24
|
+
orientation?: ToggleGroupOrientation;
|
|
25
|
+
loop?: boolean;
|
|
26
|
+
rovingFocus?: boolean;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
ariaLabel?: string;
|
|
29
|
+
class?: string;
|
|
30
|
+
itemClass?: string;
|
|
31
|
+
};
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<script lang="ts">
|
|
35
|
+
import { ToggleGroup as BitsToggleGroup } from 'bits-ui';
|
|
36
|
+
import { cls } from '../../utils/index.js';
|
|
37
|
+
import { toggleVariants } from '../toggle/toggle-variants.js';
|
|
38
|
+
|
|
39
|
+
let {
|
|
40
|
+
items,
|
|
41
|
+
type = 'single',
|
|
42
|
+
value = $bindable(),
|
|
43
|
+
onValueChange,
|
|
44
|
+
variant = 'default',
|
|
45
|
+
size = 'default',
|
|
46
|
+
orientation = 'horizontal',
|
|
47
|
+
loop,
|
|
48
|
+
rovingFocus,
|
|
49
|
+
disabled,
|
|
50
|
+
ariaLabel = 'Toggle group',
|
|
51
|
+
class: className,
|
|
52
|
+
itemClass,
|
|
53
|
+
}: Props = $props();
|
|
54
|
+
|
|
55
|
+
const isVertical = $derived(orientation === 'vertical');
|
|
56
|
+
const isOutline = $derived(variant === 'outline');
|
|
57
|
+
const segmentedItemHeights: Record<ToggleGroupSize, string> = {
|
|
58
|
+
sm: 'h-6',
|
|
59
|
+
default: 'h-7',
|
|
60
|
+
lg: 'h-8',
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const singleValue = $derived(typeof value === 'string' ? value : '');
|
|
64
|
+
const multipleValue = $derived(Array.isArray(value) ? value : []);
|
|
65
|
+
|
|
66
|
+
function handleSingleValueChange(next: string): void {
|
|
67
|
+
value = next;
|
|
68
|
+
onValueChange?.(next);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function handleMultipleValueChange(next: string[]): void {
|
|
72
|
+
value = next;
|
|
73
|
+
onValueChange?.(next);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const itemClasses = $derived(
|
|
77
|
+
cls(
|
|
78
|
+
toggleVariants({ variant: 'default', size }),
|
|
79
|
+
!isOutline && segmentedItemHeights[size],
|
|
80
|
+
isOutline &&
|
|
81
|
+
'rounded-none hover:bg-accent hover:text-accent-foreground focus-visible:ring-inset focus-visible:ring-offset-0',
|
|
82
|
+
!isOutline && 'hover:bg-background/70 hover:text-foreground',
|
|
83
|
+
isVertical && 'w-full',
|
|
84
|
+
itemClass,
|
|
85
|
+
),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const rootClasses = $derived(
|
|
89
|
+
cls(
|
|
90
|
+
'inline-flex items-stretch',
|
|
91
|
+
isOutline
|
|
92
|
+
? 'overflow-hidden rounded-lg bg-background ring-1 ring-input'
|
|
93
|
+
: 'gap-1 rounded-lg bg-muted p-1',
|
|
94
|
+
isOutline && isVertical && 'flex-col divide-y divide-input',
|
|
95
|
+
isOutline && !isVertical && 'flex-row divide-x divide-input',
|
|
96
|
+
!isOutline && isVertical && 'flex-col',
|
|
97
|
+
!isOutline && !isVertical && 'flex-row',
|
|
98
|
+
className,
|
|
99
|
+
),
|
|
100
|
+
);
|
|
101
|
+
</script>
|
|
102
|
+
|
|
103
|
+
{#snippet itemContent(item: ToggleGroupItem)}
|
|
104
|
+
{#if item.icon}
|
|
105
|
+
{@const Icon = item.icon}
|
|
106
|
+
<Icon class="size-4" />
|
|
107
|
+
{/if}
|
|
108
|
+
{#if item.label}
|
|
109
|
+
<span>{item.label}</span>
|
|
110
|
+
{/if}
|
|
111
|
+
{/snippet}
|
|
112
|
+
|
|
113
|
+
{#if type === 'multiple'}
|
|
114
|
+
<BitsToggleGroup.Root
|
|
115
|
+
type="multiple"
|
|
116
|
+
value={multipleValue}
|
|
117
|
+
onValueChange={handleMultipleValueChange}
|
|
118
|
+
{orientation}
|
|
119
|
+
{loop}
|
|
120
|
+
{rovingFocus}
|
|
121
|
+
{disabled}
|
|
122
|
+
aria-label={ariaLabel}
|
|
123
|
+
data-slot="toggle-group"
|
|
124
|
+
class={rootClasses}
|
|
125
|
+
>
|
|
126
|
+
{#each items as item (item.value)}
|
|
127
|
+
<BitsToggleGroup.Item
|
|
128
|
+
value={item.value}
|
|
129
|
+
disabled={item.disabled}
|
|
130
|
+
aria-label={!item.label ? (item.ariaLabel ?? item.value) : undefined}
|
|
131
|
+
data-slot="toggle-group-item"
|
|
132
|
+
class={itemClasses}
|
|
133
|
+
>
|
|
134
|
+
{@render itemContent(item)}
|
|
135
|
+
</BitsToggleGroup.Item>
|
|
136
|
+
{/each}
|
|
137
|
+
</BitsToggleGroup.Root>
|
|
138
|
+
{:else}
|
|
139
|
+
<BitsToggleGroup.Root
|
|
140
|
+
type="single"
|
|
141
|
+
value={singleValue}
|
|
142
|
+
onValueChange={handleSingleValueChange}
|
|
143
|
+
{orientation}
|
|
144
|
+
{loop}
|
|
145
|
+
{rovingFocus}
|
|
146
|
+
{disabled}
|
|
147
|
+
aria-label={ariaLabel}
|
|
148
|
+
data-slot="toggle-group"
|
|
149
|
+
class={rootClasses}
|
|
150
|
+
>
|
|
151
|
+
{#each items as item (item.value)}
|
|
152
|
+
<BitsToggleGroup.Item
|
|
153
|
+
value={item.value}
|
|
154
|
+
disabled={item.disabled}
|
|
155
|
+
aria-label={!item.label ? (item.ariaLabel ?? item.value) : undefined}
|
|
156
|
+
data-slot="toggle-group-item"
|
|
157
|
+
class={itemClasses}
|
|
158
|
+
>
|
|
159
|
+
{@render itemContent(item)}
|
|
160
|
+
</BitsToggleGroup.Item>
|
|
161
|
+
{/each}
|
|
162
|
+
</BitsToggleGroup.Root>
|
|
163
|
+
{/if}
|