@nqmcreative/ui 0.1.0 → 0.2.0
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/README.md +151 -439
- package/cli/index.mjs +67 -30
- package/dist/core/calendar.d.ts +3 -0
- package/dist/core/calendar.js +36 -0
- package/dist/core/dialog.svelte.d.ts +14 -0
- package/dist/core/dialog.svelte.js +23 -0
- package/dist/core/files.d.ts +35 -0
- package/dist/core/files.js +62 -0
- package/dist/core/index.d.ts +37 -0
- package/dist/core/index.js +35 -0
- package/dist/core/list.svelte.d.ts +41 -0
- package/dist/core/list.svelte.js +77 -0
- package/dist/core/number.d.ts +7 -0
- package/dist/core/number.js +17 -0
- package/dist/core/pagination.d.ts +6 -0
- package/dist/core/pagination.js +21 -0
- package/dist/core/password.d.ts +8 -0
- package/dist/core/password.js +23 -0
- package/dist/core/table.d.ts +22 -0
- package/dist/core/table.js +41 -0
- package/dist/core/theme.svelte.d.ts +16 -0
- package/dist/core/theme.svelte.js +34 -0
- package/dist/core/trigger.d.ts +35 -0
- package/dist/core/trigger.js +77 -0
- package/dist/index.d.ts +11 -103
- package/dist/index.js +11 -75
- package/dist/{components → styles/matte}/AccordionItem.svelte +1 -1
- package/dist/{components → styles/matte}/AccordionItem.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Alert.svelte +8 -2
- package/dist/{components → styles/matte}/Alert.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Avatar.svelte +1 -1
- package/dist/{components → styles/matte}/Avatar.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Badge.svelte +8 -3
- package/dist/{components → styles/matte}/Badge.svelte.d.ts +1 -3
- package/dist/{components → styles/matte}/Breadcrumb.svelte +2 -2
- package/dist/{components → styles/matte}/Breadcrumb.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Button.svelte +1 -1
- package/dist/{components → styles/matte}/Button.svelte.d.ts +1 -1
- package/dist/styles/matte/CTASection.svelte +76 -0
- package/dist/styles/matte/CTASection.svelte.d.ts +18 -0
- package/dist/{components → styles/matte}/Calendar.svelte +7 -17
- package/dist/{components → styles/matte}/Calendar.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Card.svelte +1 -1
- package/dist/{components → styles/matte}/Card.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Checkbox.svelte +1 -1
- package/dist/{components → styles/matte}/Checkbox.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/CheckboxGroup.svelte +1 -1
- package/dist/{components → styles/matte}/CheckboxGroup.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Combobox.svelte +31 -42
- package/dist/{components → styles/matte}/Combobox.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/CommandPalette.svelte +26 -41
- package/dist/{components → styles/matte}/CommandPalette.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/ConfirmDialog.svelte +2 -2
- package/dist/{components → styles/matte}/ConfirmDialog.svelte.d.ts +2 -2
- package/dist/{components → styles/matte}/ContextMenu.svelte +5 -7
- package/dist/{components → styles/matte}/DatePicker.svelte +7 -11
- package/dist/{components → styles/matte}/DatePicker.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Drawer.svelte +4 -7
- package/dist/{components → styles/matte}/Dropdown.svelte +18 -36
- package/dist/{components → styles/matte}/Dropdown.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Dropzone.svelte +11 -43
- package/dist/{components → styles/matte}/Dropzone.svelte.d.ts +2 -5
- package/dist/{components → styles/matte}/EmptyState.svelte +1 -1
- package/dist/{components → styles/matte}/EmptyState.svelte.d.ts +1 -1
- package/dist/styles/matte/FeatureCard.svelte +58 -0
- package/dist/styles/matte/FeatureCard.svelte.d.ts +16 -0
- package/dist/styles/matte/FeatureGrid.svelte +62 -0
- package/dist/styles/matte/FeatureGrid.svelte.d.ts +16 -0
- package/dist/{components → styles/matte}/Footer.svelte +1 -1
- package/dist/{components → styles/matte}/Footer.svelte.d.ts +1 -1
- package/dist/styles/matte/HeroSection.svelte +80 -0
- package/dist/styles/matte/HeroSection.svelte.d.ts +21 -0
- package/dist/{components → styles/matte}/Input.svelte +1 -1
- package/dist/{components → styles/matte}/Input.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Link.svelte +1 -1
- package/dist/{components → styles/matte}/Link.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/LocaleProvider.svelte +1 -1
- package/dist/{components → styles/matte}/LocaleProvider.svelte.d.ts +1 -1
- package/dist/styles/matte/LogoCloud.svelte +61 -0
- package/dist/styles/matte/LogoCloud.svelte.d.ts +19 -0
- package/dist/{components → styles/matte}/MenuItem.svelte +1 -1
- package/dist/{components → styles/matte}/MenuItem.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Modal.svelte +4 -7
- package/dist/{components → styles/matte}/MultiSelect.svelte +18 -37
- package/dist/{components → styles/matte}/MultiSelect.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Navbar.svelte +2 -2
- package/dist/{components → styles/matte}/Navbar.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/NumberInput.svelte +4 -8
- package/dist/{components → styles/matte}/NumberInput.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Pagination.svelte +4 -15
- package/dist/{components → styles/matte}/Pagination.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/PasswordInput.svelte +4 -13
- package/dist/{components → styles/matte}/PasswordInput.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Popover.svelte +16 -41
- package/dist/{components → styles/matte}/Popover.svelte.d.ts +1 -1
- package/dist/styles/matte/PricingCard.svelte +107 -0
- package/dist/styles/matte/PricingCard.svelte.d.ts +25 -0
- package/dist/{components → styles/matte}/Progress.svelte +3 -2
- package/dist/{components → styles/matte}/Progress.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Radio.svelte +1 -1
- package/dist/{components → styles/matte}/Radio.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/RadioGroup.svelte +1 -1
- package/dist/{components → styles/matte}/RadioGroup.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/SegmentedControl.svelte +1 -1
- package/dist/{components → styles/matte}/SegmentedControl.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Select.svelte +1 -1
- package/dist/{components → styles/matte}/Select.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Sidebar.svelte +2 -2
- package/dist/{components → styles/matte}/Sidebar.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Slider.svelte +3 -2
- package/dist/{components → styles/matte}/Slider.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Spinner.svelte +2 -2
- package/dist/{components → styles/matte}/Spinner.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Stat.svelte +1 -1
- package/dist/{components → styles/matte}/Stat.svelte.d.ts +1 -1
- package/dist/styles/matte/StatsBand.svelte +57 -0
- package/dist/styles/matte/StatsBand.svelte.d.ts +20 -0
- package/dist/{components → styles/matte}/Steps.svelte +1 -1
- package/dist/{components → styles/matte}/Steps.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Switch.svelte +1 -1
- package/dist/{components → styles/matte}/Switch.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Table.svelte +6 -28
- package/dist/{components → styles/matte}/Table.svelte.d.ts +2 -6
- package/dist/{components → styles/matte}/Tabs.svelte +8 -1
- package/dist/{components → styles/matte}/Tabs.svelte.d.ts +1 -1
- package/dist/styles/matte/Testimonial.svelte +67 -0
- package/dist/styles/matte/Testimonial.svelte.d.ts +19 -0
- package/dist/{components → styles/matte}/Textarea.svelte +1 -1
- package/dist/{components → styles/matte}/Textarea.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/ThemeToggle.svelte +14 -27
- package/dist/{components → styles/matte}/ThemeToggle.svelte.d.ts +2 -6
- package/dist/{components → styles/matte}/Toaster.svelte +4 -4
- package/dist/{fonts.css → styles/matte/fonts.css} +4 -3
- package/dist/styles/matte/index.d.ts +109 -0
- package/dist/styles/matte/index.js +83 -0
- package/dist/{theme.css → styles/matte/theme.css} +0 -1
- package/dist/styles/paper/Accordion.svelte +17 -0
- package/dist/styles/paper/Accordion.svelte.d.ts +8 -0
- package/dist/styles/paper/AccordionItem.svelte +46 -0
- package/dist/styles/paper/AccordionItem.svelte.d.ts +14 -0
- package/dist/styles/paper/Alert.svelte +99 -0
- package/dist/styles/paper/Alert.svelte.d.ts +18 -0
- package/dist/styles/paper/Avatar.svelte +60 -0
- package/dist/styles/paper/Avatar.svelte.d.ts +16 -0
- package/dist/styles/paper/AvatarGroup.svelte +17 -0
- package/dist/styles/paper/AvatarGroup.svelte.d.ts +8 -0
- package/dist/styles/paper/Badge.svelte +58 -0
- package/dist/styles/paper/Badge.svelte.d.ts +16 -0
- package/dist/styles/paper/Breadcrumb.svelte +49 -0
- package/dist/styles/paper/Breadcrumb.svelte.d.ts +14 -0
- package/dist/styles/paper/Button.svelte +96 -0
- package/dist/styles/paper/Button.svelte.d.ts +21 -0
- package/dist/styles/paper/CTASection.svelte +76 -0
- package/dist/styles/paper/CTASection.svelte.d.ts +18 -0
- package/dist/styles/paper/Calendar.svelte +202 -0
- package/dist/styles/paper/Calendar.svelte.d.ts +22 -0
- package/dist/styles/paper/Card.svelte +78 -0
- package/dist/styles/paper/Card.svelte.d.ts +21 -0
- package/dist/styles/paper/Checkbox.svelte +75 -0
- package/dist/styles/paper/Checkbox.svelte.d.ts +15 -0
- package/dist/styles/paper/CheckboxGroup.svelte +111 -0
- package/dist/styles/paper/CheckboxGroup.svelte.d.ts +30 -0
- package/dist/styles/paper/Combobox.svelte +266 -0
- package/dist/styles/paper/Combobox.svelte.d.ts +29 -0
- package/dist/styles/paper/CommandPalette.svelte +209 -0
- package/dist/styles/paper/CommandPalette.svelte.d.ts +32 -0
- package/dist/styles/paper/ConfirmDialog.svelte +97 -0
- package/dist/styles/paper/ConfirmDialog.svelte.d.ts +22 -0
- package/dist/styles/paper/ContextMenu.svelte +88 -0
- package/dist/styles/paper/ContextMenu.svelte.d.ts +15 -0
- package/dist/styles/paper/DatePicker.svelte +192 -0
- package/dist/styles/paper/DatePicker.svelte.d.ts +23 -0
- package/dist/styles/paper/Divider.svelte +30 -0
- package/dist/styles/paper/Divider.svelte.d.ts +10 -0
- package/dist/styles/paper/Drawer.svelte +165 -0
- package/dist/styles/paper/Drawer.svelte.d.ts +20 -0
- package/dist/styles/paper/Dropdown.svelte +94 -0
- package/dist/styles/paper/Dropdown.svelte.d.ts +23 -0
- package/dist/styles/paper/Dropzone.svelte +210 -0
- package/dist/styles/paper/Dropzone.svelte.d.ts +29 -0
- package/dist/styles/paper/EmptyState.svelte +71 -0
- package/dist/styles/paper/EmptyState.svelte.d.ts +18 -0
- package/dist/styles/paper/FeatureCard.svelte +58 -0
- package/dist/styles/paper/FeatureCard.svelte.d.ts +16 -0
- package/dist/styles/paper/FeatureGrid.svelte +62 -0
- package/dist/styles/paper/FeatureGrid.svelte.d.ts +16 -0
- package/dist/styles/paper/Field.svelte +42 -0
- package/dist/styles/paper/Field.svelte.d.ts +16 -0
- package/dist/styles/paper/Footer.svelte +91 -0
- package/dist/styles/paper/Footer.svelte.d.ts +25 -0
- package/dist/styles/paper/HeroSection.svelte +86 -0
- package/dist/styles/paper/HeroSection.svelte.d.ts +21 -0
- package/dist/styles/paper/Input.svelte +60 -0
- package/dist/styles/paper/Input.svelte.d.ts +18 -0
- package/dist/styles/paper/InputGroup.svelte +20 -0
- package/dist/styles/paper/InputGroup.svelte.d.ts +11 -0
- package/dist/styles/paper/Kbd.svelte +17 -0
- package/dist/styles/paper/Kbd.svelte.d.ts +8 -0
- package/dist/styles/paper/Label.svelte +16 -0
- package/dist/styles/paper/Label.svelte.d.ts +9 -0
- package/dist/styles/paper/Link.svelte +44 -0
- package/dist/styles/paper/Link.svelte.d.ts +16 -0
- package/dist/styles/paper/LocaleProvider.svelte +24 -0
- package/dist/styles/paper/LocaleProvider.svelte.d.ts +10 -0
- package/dist/styles/paper/LogoCloud.svelte +61 -0
- package/dist/styles/paper/LogoCloud.svelte.d.ts +19 -0
- package/dist/styles/paper/MenuItem.svelte +64 -0
- package/dist/styles/paper/MenuItem.svelte.d.ts +18 -0
- package/dist/styles/paper/MenuSeparator.svelte +22 -0
- package/dist/styles/paper/MenuSeparator.svelte.d.ts +8 -0
- package/dist/styles/paper/Modal.svelte +118 -0
- package/dist/styles/paper/Modal.svelte.d.ts +21 -0
- package/dist/styles/paper/MultiSelect.svelte +287 -0
- package/dist/styles/paper/MultiSelect.svelte.d.ts +31 -0
- package/dist/styles/paper/Navbar.svelte +201 -0
- package/dist/styles/paper/Navbar.svelte.d.ts +33 -0
- package/dist/styles/paper/NumberInput.svelte +96 -0
- package/dist/styles/paper/NumberInput.svelte.d.ts +15 -0
- package/dist/styles/paper/Pagination.svelte +83 -0
- package/dist/styles/paper/Pagination.svelte.d.ts +15 -0
- package/dist/styles/paper/PasswordInput.svelte +100 -0
- package/dist/styles/paper/PasswordInput.svelte.d.ts +12 -0
- package/dist/styles/paper/Popover.svelte +89 -0
- package/dist/styles/paper/Popover.svelte.d.ts +19 -0
- package/dist/styles/paper/PricingCard.svelte +108 -0
- package/dist/styles/paper/PricingCard.svelte.d.ts +25 -0
- package/dist/styles/paper/Progress.svelte +59 -0
- package/dist/styles/paper/Progress.svelte.d.ts +17 -0
- package/dist/styles/paper/Radio.svelte +55 -0
- package/dist/styles/paper/Radio.svelte.d.ts +15 -0
- package/dist/styles/paper/RadioGroup.svelte +95 -0
- package/dist/styles/paper/RadioGroup.svelte.d.ts +27 -0
- package/dist/styles/paper/SegmentedControl.svelte +88 -0
- package/dist/styles/paper/SegmentedControl.svelte.d.ts +25 -0
- package/dist/styles/paper/Select.svelte +61 -0
- package/dist/styles/paper/Select.svelte.d.ts +20 -0
- package/dist/styles/paper/Sidebar.svelte +206 -0
- package/dist/styles/paper/Sidebar.svelte.d.ts +36 -0
- package/dist/styles/paper/Skeleton.svelte +46 -0
- package/dist/styles/paper/Skeleton.svelte.d.ts +13 -0
- package/dist/styles/paper/Slider.svelte +80 -0
- package/dist/styles/paper/Slider.svelte.d.ts +19 -0
- package/dist/styles/paper/Spinner.svelte +34 -0
- package/dist/styles/paper/Spinner.svelte.d.ts +13 -0
- package/dist/styles/paper/Stat.svelte +51 -0
- package/dist/styles/paper/Stat.svelte.d.ts +16 -0
- package/dist/styles/paper/StatsBand.svelte +63 -0
- package/dist/styles/paper/StatsBand.svelte.d.ts +20 -0
- package/dist/styles/paper/Steps.svelte +141 -0
- package/dist/styles/paper/Steps.svelte.d.ts +24 -0
- package/dist/styles/paper/Switch.svelte +64 -0
- package/dist/styles/paper/Switch.svelte.d.ts +14 -0
- package/dist/styles/paper/Table.svelte +217 -0
- package/dist/styles/paper/Table.svelte.d.ts +66 -0
- package/dist/styles/paper/Tabs.svelte +102 -0
- package/dist/styles/paper/Tabs.svelte.d.ts +23 -0
- package/dist/styles/paper/Testimonial.svelte +64 -0
- package/dist/styles/paper/Testimonial.svelte.d.ts +19 -0
- package/dist/styles/paper/Textarea.svelte +54 -0
- package/dist/styles/paper/Textarea.svelte.d.ts +12 -0
- package/dist/styles/paper/ThemeToggle.svelte +130 -0
- package/dist/styles/paper/ThemeToggle.svelte.d.ts +16 -0
- package/dist/styles/paper/Toaster.svelte +132 -0
- package/dist/styles/paper/Toaster.svelte.d.ts +8 -0
- package/dist/styles/paper/Tooltip.svelte +33 -0
- package/dist/styles/paper/Tooltip.svelte.d.ts +12 -0
- package/dist/styles/paper/fonts.css +46 -0
- package/dist/styles/paper/index.d.ts +109 -0
- package/dist/styles/paper/index.js +83 -0
- package/dist/styles/paper/theme.css +222 -0
- package/package.json +531 -201
- package/registry.json +658 -339
- /package/dist/{actions → core/actions}/anchor.d.ts +0 -0
- /package/dist/{actions → core/actions}/anchor.js +0 -0
- /package/dist/{actions → core/actions}/dismissable.d.ts +0 -0
- /package/dist/{actions → core/actions}/dismissable.js +0 -0
- /package/dist/{date.d.ts → core/date.d.ts} +0 -0
- /package/dist/{date.js → core/date.js} +0 -0
- /package/dist/{locale.svelte.d.ts → core/locale.svelte.d.ts} +0 -0
- /package/dist/{locale.svelte.js → core/locale.svelte.js} +0 -0
- /package/dist/{toast.svelte.d.ts → core/toast.svelte.d.ts} +0 -0
- /package/dist/{toast.svelte.js → core/toast.svelte.js} +0 -0
- /package/dist/{tones.d.ts → core/tones.d.ts} +0 -0
- /package/dist/{tones.js → core/tones.js} +0 -0
- /package/dist/{components → styles/matte}/Accordion.svelte +0 -0
- /package/dist/{components → styles/matte}/Accordion.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/AvatarGroup.svelte +0 -0
- /package/dist/{components → styles/matte}/AvatarGroup.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/ContextMenu.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Divider.svelte +0 -0
- /package/dist/{components → styles/matte}/Divider.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Drawer.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Field.svelte +0 -0
- /package/dist/{components → styles/matte}/Field.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/InputGroup.svelte +0 -0
- /package/dist/{components → styles/matte}/InputGroup.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Kbd.svelte +0 -0
- /package/dist/{components → styles/matte}/Kbd.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Label.svelte +0 -0
- /package/dist/{components → styles/matte}/Label.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/MenuSeparator.svelte +0 -0
- /package/dist/{components → styles/matte}/MenuSeparator.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Modal.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Skeleton.svelte +0 -0
- /package/dist/{components → styles/matte}/Skeleton.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Toaster.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Tooltip.svelte +0 -0
- /package/dist/{components → styles/matte}/Tooltip.svelte.d.ts +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { anchored } from '../../core/actions/anchor.js';
|
|
4
|
+
import { clickOutside, focusTrap, navigateList, portal } from '../../core/actions/dismissable.js';
|
|
5
|
+
import { menuItems } from '../../core/trigger.js';
|
|
6
|
+
import { useLocale } from '../../core/locale.svelte.js';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
/** The region that responds to a right-click. */
|
|
10
|
+
children: Snippet;
|
|
11
|
+
/** Menu contents: `MenuItem`, `MenuSeparator`, anything. */
|
|
12
|
+
menu: Snippet;
|
|
13
|
+
open?: boolean;
|
|
14
|
+
label?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
class?: string;
|
|
17
|
+
menuClass?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let {
|
|
21
|
+
children,
|
|
22
|
+
menu,
|
|
23
|
+
open = $bindable(false),
|
|
24
|
+
label,
|
|
25
|
+
disabled = false,
|
|
26
|
+
class: className = '',
|
|
27
|
+
menuClass = ''
|
|
28
|
+
}: Props = $props();
|
|
29
|
+
|
|
30
|
+
const t = useLocale();
|
|
31
|
+
|
|
32
|
+
let menuEl: HTMLElement | null = $state(null);
|
|
33
|
+
/**
|
|
34
|
+
* A 0×0 element parked at the pointer, so the same `anchored` action that
|
|
35
|
+
* positions dropdowns can flip and clamp this menu too.
|
|
36
|
+
*/
|
|
37
|
+
let cursor: HTMLElement | null = $state(null);
|
|
38
|
+
|
|
39
|
+
function onContextMenu(event: MouseEvent) {
|
|
40
|
+
if (disabled) return;
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
if (!cursor) {
|
|
43
|
+
cursor = document.createElement('div');
|
|
44
|
+
cursor.style.cssText = 'position:fixed;width:0;height:0;pointer-events:none';
|
|
45
|
+
document.body.appendChild(cursor);
|
|
46
|
+
}
|
|
47
|
+
cursor.style.left = `${event.clientX}px`;
|
|
48
|
+
cursor.style.top = `${event.clientY}px`;
|
|
49
|
+
open = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
$effect(() => () => cursor?.remove());
|
|
53
|
+
|
|
54
|
+
function onMenuKeydown(event: KeyboardEvent) {
|
|
55
|
+
if (event.key === 'Escape' || event.key === 'Tab') {
|
|
56
|
+
if (event.key === 'Escape') event.preventDefault();
|
|
57
|
+
event.stopPropagation();
|
|
58
|
+
open = false;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
navigateList(event, menuItems(menuEl));
|
|
62
|
+
}
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
66
|
+
<div oncontextmenu={onContextMenu} class={className}>
|
|
67
|
+
{@render children()}
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
{#if open}
|
|
71
|
+
<div
|
|
72
|
+
bind:this={menuEl}
|
|
73
|
+
use:portal
|
|
74
|
+
use:anchored={{ anchor: cursor, placement: 'bottom-start', offset: 2 }}
|
|
75
|
+
use:clickOutside={{ onoutside: () => (open = false) }}
|
|
76
|
+
use:focusTrap={{ restore: true }}
|
|
77
|
+
onkeydown={onMenuKeydown}
|
|
78
|
+
onclick={(event) => {
|
|
79
|
+
if ((event.target as HTMLElement).closest('[role="menuitem"]:not([disabled])')) open = false;
|
|
80
|
+
}}
|
|
81
|
+
role="menu"
|
|
82
|
+
aria-label={label ?? t.current.menu}
|
|
83
|
+
tabindex="-1"
|
|
84
|
+
class="z-50 flex max-h-[min(24rem,80vh)] min-w-48 flex-col overflow-y-auto rounded-lg border border-hairline bg-bg py-1 font-sans shadow-lg {menuClass}"
|
|
85
|
+
>
|
|
86
|
+
{@render menu()}
|
|
87
|
+
</div>
|
|
88
|
+
{/if}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** The region that responds to a right-click. */
|
|
4
|
+
children: Snippet;
|
|
5
|
+
/** Menu contents: `MenuItem`, `MenuSeparator`, anything. */
|
|
6
|
+
menu: Snippet;
|
|
7
|
+
open?: boolean;
|
|
8
|
+
label?: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
class?: string;
|
|
11
|
+
menuClass?: string;
|
|
12
|
+
}
|
|
13
|
+
declare const ContextMenu: import("svelte").Component<Props, {}, "open">;
|
|
14
|
+
type ContextMenu = ReturnType<typeof ContextMenu>;
|
|
15
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { anchored } from '../../core/actions/anchor.js';
|
|
3
|
+
import { clickOutside, portal } from '../../core/actions/dismissable.js';
|
|
4
|
+
import { dateHint } from '../../core/calendar.js';
|
|
5
|
+
import { formatISO, parseFormatted } from '../../core/date.js';
|
|
6
|
+
import { useLocale } from '../../core/locale.svelte.js';
|
|
7
|
+
import { toneFocusWithinBorder, type Tone } from '../../core/tones.js';
|
|
8
|
+
import Calendar from './Calendar.svelte';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
/** Bindable `YYYY-MM-DD` — the same shape as `<input type="date">`. */
|
|
12
|
+
value?: string;
|
|
13
|
+
/** Inclusive bounds, `YYYY-MM-DD`. */
|
|
14
|
+
min?: string;
|
|
15
|
+
max?: string;
|
|
16
|
+
isDisabled?: (date: Date) => boolean;
|
|
17
|
+
weekStart?: 0 | 1;
|
|
18
|
+
tone?: Tone;
|
|
19
|
+
invalid?: boolean;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
clearable?: boolean;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
id?: string;
|
|
24
|
+
/** Submits the ISO value with a form. */
|
|
25
|
+
name?: string;
|
|
26
|
+
onchange?: (value: string) => void;
|
|
27
|
+
class?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
value = $bindable(''),
|
|
32
|
+
min,
|
|
33
|
+
max,
|
|
34
|
+
isDisabled,
|
|
35
|
+
weekStart = 1,
|
|
36
|
+
tone = 'brand',
|
|
37
|
+
invalid = false,
|
|
38
|
+
disabled = false,
|
|
39
|
+
clearable = true,
|
|
40
|
+
placeholder,
|
|
41
|
+
id,
|
|
42
|
+
name,
|
|
43
|
+
onchange,
|
|
44
|
+
class: className = ''
|
|
45
|
+
}: Props = $props();
|
|
46
|
+
|
|
47
|
+
const t = useLocale();
|
|
48
|
+
|
|
49
|
+
let open = $state(false);
|
|
50
|
+
let text = $state('');
|
|
51
|
+
let editing = $state(false);
|
|
52
|
+
let wrapper: HTMLElement | null = $state(null);
|
|
53
|
+
let inputEl: HTMLInputElement | null = $state(null);
|
|
54
|
+
|
|
55
|
+
/** While typing the field shows the raw text; otherwise the formatted value. */
|
|
56
|
+
const display = $derived(editing ? text : formatISO(value, t.current.dateFormat));
|
|
57
|
+
const hint = $derived(placeholder ?? dateHint(t.current.dateFormat));
|
|
58
|
+
|
|
59
|
+
function commit() {
|
|
60
|
+
editing = false;
|
|
61
|
+
if (!text.trim()) {
|
|
62
|
+
if (value) {
|
|
63
|
+
value = '';
|
|
64
|
+
onchange?.('');
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const parsed = parseFormatted(text, t.current.dateFormat);
|
|
69
|
+
if (parsed && parsed !== value) {
|
|
70
|
+
value = parsed;
|
|
71
|
+
onchange?.(parsed);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function onKeydown(event: KeyboardEvent) {
|
|
76
|
+
if (event.key === 'Escape' && open) {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
event.stopPropagation();
|
|
79
|
+
open = false;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (event.key === 'Enter') {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
commit();
|
|
85
|
+
open = false;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (event.key === 'ArrowDown' && !open) {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
open = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
</script>
|
|
94
|
+
|
|
95
|
+
<div
|
|
96
|
+
bind:this={wrapper}
|
|
97
|
+
class="inline-flex w-full items-center gap-1 rounded-md border bg-bg pr-1 pl-3 shadow-xs transition-colors duration-150 ease-brand-out
|
|
98
|
+
{invalid ? 'border-danger' : `border-hairline-strong ${toneFocusWithinBorder[tone]}`}
|
|
99
|
+
{disabled ? 'pointer-events-none opacity-50' : ''} {className}"
|
|
100
|
+
>
|
|
101
|
+
<input
|
|
102
|
+
bind:this={inputEl}
|
|
103
|
+
{id}
|
|
104
|
+
{disabled}
|
|
105
|
+
type="text"
|
|
106
|
+
inputmode="numeric"
|
|
107
|
+
autocomplete="off"
|
|
108
|
+
role="combobox"
|
|
109
|
+
aria-haspopup="dialog"
|
|
110
|
+
aria-controls="{id ?? 'datepicker'}-calendar"
|
|
111
|
+
aria-invalid={invalid ? 'true' : undefined}
|
|
112
|
+
aria-expanded={open}
|
|
113
|
+
placeholder={hint}
|
|
114
|
+
value={display}
|
|
115
|
+
oninput={(event) => {
|
|
116
|
+
editing = true;
|
|
117
|
+
text = event.currentTarget.value;
|
|
118
|
+
}}
|
|
119
|
+
onblur={commit}
|
|
120
|
+
onkeydown={onKeydown}
|
|
121
|
+
class="h-10 w-full min-w-0 bg-transparent font-sans text-sm text-text tabular-nums placeholder:text-text-muted focus:outline-none"
|
|
122
|
+
/>
|
|
123
|
+
|
|
124
|
+
{#if name}<input type="hidden" {name} {value} />{/if}
|
|
125
|
+
|
|
126
|
+
{#if clearable && value && !disabled}
|
|
127
|
+
<button
|
|
128
|
+
type="button"
|
|
129
|
+
onclick={() => {
|
|
130
|
+
value = '';
|
|
131
|
+
text = '';
|
|
132
|
+
onchange?.('');
|
|
133
|
+
inputEl?.focus();
|
|
134
|
+
}}
|
|
135
|
+
aria-label={t.current.clear}
|
|
136
|
+
class="shrink-0 rounded p-1 text-text-muted transition-colors duration-150 hover:bg-bg-inset hover:text-text focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current"
|
|
137
|
+
>
|
|
138
|
+
<svg class="size-3.5" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
|
139
|
+
<path
|
|
140
|
+
d="m2 2 10 10M12 2 2 12"
|
|
141
|
+
stroke="currentColor"
|
|
142
|
+
stroke-width="1.6"
|
|
143
|
+
stroke-linecap="round"
|
|
144
|
+
/>
|
|
145
|
+
</svg>
|
|
146
|
+
</button>
|
|
147
|
+
{/if}
|
|
148
|
+
|
|
149
|
+
<button
|
|
150
|
+
type="button"
|
|
151
|
+
{disabled}
|
|
152
|
+
onclick={() => (open = !open)}
|
|
153
|
+
aria-label={t.current.selectDate}
|
|
154
|
+
aria-expanded={open}
|
|
155
|
+
class="shrink-0 rounded p-1.5 text-text-muted transition-colors duration-150 hover:bg-bg-inset hover:text-text focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current"
|
|
156
|
+
>
|
|
157
|
+
<svg class="size-4" viewBox="0 0 20 20" fill="none" aria-hidden="true">
|
|
158
|
+
<rect x="3" y="4.5" width="14" height="12" rx="2" stroke="currentColor" stroke-width="1.4" />
|
|
159
|
+
<path
|
|
160
|
+
d="M3 8.5h14M7 3v3M13 3v3"
|
|
161
|
+
stroke="currentColor"
|
|
162
|
+
stroke-width="1.4"
|
|
163
|
+
stroke-linecap="round"
|
|
164
|
+
/>
|
|
165
|
+
</svg>
|
|
166
|
+
</button>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
{#if open}
|
|
170
|
+
<div
|
|
171
|
+
use:portal
|
|
172
|
+
use:anchored={{ anchor: wrapper, placement: 'bottom-start', offset: 4 }}
|
|
173
|
+
use:clickOutside={{ onoutside: () => (open = false), ignore: [wrapper] }}
|
|
174
|
+
id="{id ?? 'datepicker'}-calendar"
|
|
175
|
+
class="z-50 rounded-lg border border-hairline bg-bg shadow-lg"
|
|
176
|
+
>
|
|
177
|
+
<Calendar
|
|
178
|
+
bind:value
|
|
179
|
+
{min}
|
|
180
|
+
{max}
|
|
181
|
+
{isDisabled}
|
|
182
|
+
{weekStart}
|
|
183
|
+
{tone}
|
|
184
|
+
onselect={(next) => {
|
|
185
|
+
editing = false;
|
|
186
|
+
open = false;
|
|
187
|
+
onchange?.(next);
|
|
188
|
+
inputEl?.focus();
|
|
189
|
+
}}
|
|
190
|
+
/>
|
|
191
|
+
</div>
|
|
192
|
+
{/if}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Tone } from '../../core/tones.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** Bindable `YYYY-MM-DD` — the same shape as `<input type="date">`. */
|
|
4
|
+
value?: string;
|
|
5
|
+
/** Inclusive bounds, `YYYY-MM-DD`. */
|
|
6
|
+
min?: string;
|
|
7
|
+
max?: string;
|
|
8
|
+
isDisabled?: (date: Date) => boolean;
|
|
9
|
+
weekStart?: 0 | 1;
|
|
10
|
+
tone?: Tone;
|
|
11
|
+
invalid?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
clearable?: boolean;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
id?: string;
|
|
16
|
+
/** Submits the ISO value with a form. */
|
|
17
|
+
name?: string;
|
|
18
|
+
onchange?: (value: string) => void;
|
|
19
|
+
class?: string;
|
|
20
|
+
}
|
|
21
|
+
declare const DatePicker: import("svelte").Component<Props, {}, "value">;
|
|
22
|
+
type DatePicker = ReturnType<typeof DatePicker>;
|
|
23
|
+
export default DatePicker;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
|
|
4
|
+
export type DividerOrientation = 'horizontal' | 'vertical';
|
|
5
|
+
|
|
6
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
orientation?: DividerOrientation;
|
|
8
|
+
/** Centred caption drawn over a horizontal rule. */
|
|
9
|
+
label?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let { orientation = 'horizontal', label, class: className = '', ...rest }: Props = $props();
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
{#if orientation === 'vertical'}
|
|
16
|
+
<div
|
|
17
|
+
role="separator"
|
|
18
|
+
aria-orientation="vertical"
|
|
19
|
+
class="w-px self-stretch bg-hairline {className}"
|
|
20
|
+
{...rest}
|
|
21
|
+
></div>
|
|
22
|
+
{:else if label}
|
|
23
|
+
<div class="flex items-center gap-3 {className}" {...rest}>
|
|
24
|
+
<span class="h-px flex-1 bg-hairline"></span>
|
|
25
|
+
<span class="font-sans text-xs font-medium text-text-muted">{label}</span>
|
|
26
|
+
<span class="h-px flex-1 bg-hairline"></span>
|
|
27
|
+
</div>
|
|
28
|
+
{:else}
|
|
29
|
+
<div role="separator" class="h-px w-full bg-hairline {className}" {...rest}></div>
|
|
30
|
+
{/if}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
export type DividerOrientation = 'horizontal' | 'vertical';
|
|
3
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
orientation?: DividerOrientation;
|
|
5
|
+
/** Centred caption drawn over a horizontal rule. */
|
|
6
|
+
label?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const Divider: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type Divider = ReturnType<typeof Divider>;
|
|
10
|
+
export default Divider;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLDialogAttributes } from 'svelte/elements';
|
|
4
|
+
import { useLocale } from '../../core/locale.svelte.js';
|
|
5
|
+
import { isBackdropClick, syncDialog } from '../../core/dialog.svelte.js';
|
|
6
|
+
|
|
7
|
+
export type DrawerSide = 'left' | 'right' | 'top' | 'bottom';
|
|
8
|
+
export type DrawerSize = 'sm' | 'md' | 'lg' | 'full';
|
|
9
|
+
|
|
10
|
+
interface Props extends HTMLDialogAttributes {
|
|
11
|
+
/** Bindable. Built on the native `<dialog>`, so it gets the top layer,
|
|
12
|
+
* the backdrop, Escape handling and focus containment for free. */
|
|
13
|
+
open?: boolean;
|
|
14
|
+
side?: DrawerSide;
|
|
15
|
+
size?: DrawerSize;
|
|
16
|
+
title?: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
dismissible?: boolean;
|
|
19
|
+
footer?: Snippet;
|
|
20
|
+
onclose?: () => void;
|
|
21
|
+
children: Snippet;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let {
|
|
25
|
+
open = $bindable(false),
|
|
26
|
+
side = 'right',
|
|
27
|
+
size = 'md',
|
|
28
|
+
title,
|
|
29
|
+
description,
|
|
30
|
+
dismissible = true,
|
|
31
|
+
footer,
|
|
32
|
+
onclose,
|
|
33
|
+
class: className = '',
|
|
34
|
+
children,
|
|
35
|
+
...rest
|
|
36
|
+
}: Props = $props();
|
|
37
|
+
|
|
38
|
+
const t = useLocale();
|
|
39
|
+
let dialog: HTMLDialogElement | null = $state(null);
|
|
40
|
+
|
|
41
|
+
const horizontal = $derived(side === 'left' || side === 'right');
|
|
42
|
+
|
|
43
|
+
const widths: Record<DrawerSize, string> = {
|
|
44
|
+
sm: 'w-[min(20rem,100vw)]',
|
|
45
|
+
md: 'w-[min(28rem,100vw)]',
|
|
46
|
+
lg: 'w-[min(40rem,100vw)]',
|
|
47
|
+
full: 'w-screen'
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const heights: Record<DrawerSize, string> = {
|
|
51
|
+
sm: 'h-[min(16rem,100vh)]',
|
|
52
|
+
md: 'h-[min(24rem,100vh)]',
|
|
53
|
+
lg: 'h-[min(36rem,100vh)]',
|
|
54
|
+
full: 'h-screen'
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const sides: Record<DrawerSide, string> = {
|
|
58
|
+
left: 'mr-auto ml-0 h-screen max-h-screen border-r',
|
|
59
|
+
right: 'mr-0 ml-auto h-screen max-h-screen border-l',
|
|
60
|
+
top: 'mt-0 mb-auto w-screen max-w-screen border-b',
|
|
61
|
+
bottom: 'mt-auto mb-0 w-screen max-w-screen border-t'
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const slide: Record<DrawerSide, string> = {
|
|
65
|
+
left: 'animate-[drawer-left_220ms_cubic-bezier(0,0,0.2,1)]',
|
|
66
|
+
right: 'animate-[drawer-right_220ms_cubic-bezier(0,0,0.2,1)]',
|
|
67
|
+
top: 'animate-[drawer-top_220ms_cubic-bezier(0,0,0.2,1)]',
|
|
68
|
+
bottom: 'animate-[drawer-bottom_220ms_cubic-bezier(0,0,0.2,1)]'
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
$effect(() => syncDialog(dialog, open));
|
|
72
|
+
|
|
73
|
+
function close() {
|
|
74
|
+
open = false;
|
|
75
|
+
onclose?.();
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<dialog
|
|
80
|
+
bind:this={dialog}
|
|
81
|
+
onclose={close}
|
|
82
|
+
onclick={(event) => {
|
|
83
|
+
if (dismissible && isBackdropClick(event, dialog)) close();
|
|
84
|
+
}}
|
|
85
|
+
oncancel={(event) => {
|
|
86
|
+
if (!dismissible) event.preventDefault();
|
|
87
|
+
}}
|
|
88
|
+
class="max-h-none max-w-none border-hairline bg-bg p-0 text-text shadow-2xl backdrop:bg-text/30 backdrop:backdrop-blur-[1px]
|
|
89
|
+
{sides[side]} {horizontal ? widths[size] : heights[size]} {slide[side]} {className}"
|
|
90
|
+
{...rest}
|
|
91
|
+
>
|
|
92
|
+
<div class="flex h-full flex-col">
|
|
93
|
+
{#if title || dismissible}
|
|
94
|
+
<div class="flex items-start gap-4 border-b border-hairline px-5 py-4">
|
|
95
|
+
<div class="flex min-w-0 flex-1 flex-col gap-1">
|
|
96
|
+
{#if title}
|
|
97
|
+
<h2 class="font-heading text-base font-semibold text-text">{title}</h2>
|
|
98
|
+
{/if}
|
|
99
|
+
{#if description}
|
|
100
|
+
<p class="font-sans text-[13px] text-text-muted">{description}</p>
|
|
101
|
+
{/if}
|
|
102
|
+
</div>
|
|
103
|
+
{#if dismissible}
|
|
104
|
+
<button
|
|
105
|
+
type="button"
|
|
106
|
+
onclick={close}
|
|
107
|
+
aria-label={t.current.close}
|
|
108
|
+
class="-m-1 shrink-0 rounded-md p-1 text-text-muted transition-colors duration-150 hover:bg-bg-inset hover:text-text focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand"
|
|
109
|
+
>
|
|
110
|
+
<svg class="size-4" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
|
111
|
+
<path
|
|
112
|
+
d="m2 2 10 10M12 2 2 12"
|
|
113
|
+
stroke="currentColor"
|
|
114
|
+
stroke-width="1.6"
|
|
115
|
+
stroke-linecap="round"
|
|
116
|
+
/>
|
|
117
|
+
</svg>
|
|
118
|
+
</button>
|
|
119
|
+
{/if}
|
|
120
|
+
</div>
|
|
121
|
+
{/if}
|
|
122
|
+
|
|
123
|
+
<div
|
|
124
|
+
class="flex-1 overflow-y-auto px-5 py-4 font-sans text-sm leading-relaxed text-text-secondary"
|
|
125
|
+
>
|
|
126
|
+
{@render children()}
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
{#if footer}
|
|
130
|
+
<div
|
|
131
|
+
class="flex items-center justify-end gap-2 border-t border-hairline bg-bg-alt px-5 py-3.5"
|
|
132
|
+
>
|
|
133
|
+
{@render footer()}
|
|
134
|
+
</div>
|
|
135
|
+
{/if}
|
|
136
|
+
</div>
|
|
137
|
+
</dialog>
|
|
138
|
+
|
|
139
|
+
<style>
|
|
140
|
+
@keyframes -global-drawer-right {
|
|
141
|
+
from {
|
|
142
|
+
transform: translateX(100%);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
@keyframes -global-drawer-left {
|
|
146
|
+
from {
|
|
147
|
+
transform: translateX(-100%);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
@keyframes -global-drawer-top {
|
|
151
|
+
from {
|
|
152
|
+
transform: translateY(-100%);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
@keyframes -global-drawer-bottom {
|
|
156
|
+
from {
|
|
157
|
+
transform: translateY(100%);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
@media (prefers-reduced-motion: reduce) {
|
|
161
|
+
dialog {
|
|
162
|
+
animation: none;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLDialogAttributes } from 'svelte/elements';
|
|
3
|
+
export type DrawerSide = 'left' | 'right' | 'top' | 'bottom';
|
|
4
|
+
export type DrawerSize = 'sm' | 'md' | 'lg' | 'full';
|
|
5
|
+
interface Props extends HTMLDialogAttributes {
|
|
6
|
+
/** Bindable. Built on the native `<dialog>`, so it gets the top layer,
|
|
7
|
+
* the backdrop, Escape handling and focus containment for free. */
|
|
8
|
+
open?: boolean;
|
|
9
|
+
side?: DrawerSide;
|
|
10
|
+
size?: DrawerSize;
|
|
11
|
+
title?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
dismissible?: boolean;
|
|
14
|
+
footer?: Snippet;
|
|
15
|
+
onclose?: () => void;
|
|
16
|
+
children: Snippet;
|
|
17
|
+
}
|
|
18
|
+
declare const Drawer: import("svelte").Component<Props, {}, "open">;
|
|
19
|
+
type Drawer = ReturnType<typeof Drawer>;
|
|
20
|
+
export default Drawer;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { anchored, type Placement } from '../../core/actions/anchor.js';
|
|
4
|
+
import { clickOutside, focusTrap, navigateList, portal } from '../../core/actions/dismissable.js';
|
|
5
|
+
import { describeTrigger, menuItems, popupTrigger } from '../../core/trigger.js';
|
|
6
|
+
import { useLocale } from '../../core/locale.svelte.js';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
/** The control that opens the menu — put a `Button` in here. */
|
|
10
|
+
trigger: Snippet;
|
|
11
|
+
/** Menu contents: `MenuItem`, `MenuSeparator`, or anything else. */
|
|
12
|
+
children: Snippet;
|
|
13
|
+
open?: boolean;
|
|
14
|
+
placement?: Placement;
|
|
15
|
+
offset?: number;
|
|
16
|
+
/** Stretch the menu to the trigger's width. */
|
|
17
|
+
matchWidth?: boolean;
|
|
18
|
+
/** Close as soon as an item inside is activated. Default true. */
|
|
19
|
+
closeOnSelect?: boolean;
|
|
20
|
+
/** Accessible name for the menu. Defaults to the locale's `menu`. */
|
|
21
|
+
label?: string;
|
|
22
|
+
class?: string;
|
|
23
|
+
/** Classes for the wrapper around the trigger. */
|
|
24
|
+
triggerClass?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let {
|
|
28
|
+
trigger,
|
|
29
|
+
children,
|
|
30
|
+
open = $bindable(false),
|
|
31
|
+
placement = 'bottom-start',
|
|
32
|
+
offset = 6,
|
|
33
|
+
matchWidth = false,
|
|
34
|
+
closeOnSelect = true,
|
|
35
|
+
label,
|
|
36
|
+
class: className = '',
|
|
37
|
+
triggerClass = ''
|
|
38
|
+
}: Props = $props();
|
|
39
|
+
|
|
40
|
+
const t = useLocale();
|
|
41
|
+
|
|
42
|
+
let anchorEl: HTMLElement | null = $state(null);
|
|
43
|
+
let menuEl: HTMLElement | null = $state(null);
|
|
44
|
+
|
|
45
|
+
// The ARIA state goes on the consumer's own control, not on our wrapper.
|
|
46
|
+
$effect(() => describeTrigger(anchorEl, 'menu', open));
|
|
47
|
+
|
|
48
|
+
function onMenuKeydown(event: KeyboardEvent) {
|
|
49
|
+
if (event.key === 'Escape' || event.key === 'Tab') {
|
|
50
|
+
if (event.key === 'Escape') event.preventDefault();
|
|
51
|
+
event.stopPropagation();
|
|
52
|
+
open = false;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
navigateList(event, menuItems(menuEl));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function onMenuClick(event: MouseEvent) {
|
|
59
|
+
if (!closeOnSelect) return;
|
|
60
|
+
if ((event.target as HTMLElement).closest('[role="menuitem"]:not([disabled])')) open = false;
|
|
61
|
+
}
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<span
|
|
65
|
+
bind:this={anchorEl}
|
|
66
|
+
use:popupTrigger={{
|
|
67
|
+
toggle: () => (open = !open),
|
|
68
|
+
open: () => (open = true),
|
|
69
|
+
close: () => (open = false),
|
|
70
|
+
arrowOpens: true,
|
|
71
|
+
isOpen: () => open
|
|
72
|
+
}}
|
|
73
|
+
class="inline-flex {triggerClass}"
|
|
74
|
+
>
|
|
75
|
+
{@render trigger()}
|
|
76
|
+
</span>
|
|
77
|
+
|
|
78
|
+
{#if open}
|
|
79
|
+
<div
|
|
80
|
+
bind:this={menuEl}
|
|
81
|
+
use:portal
|
|
82
|
+
use:anchored={{ anchor: anchorEl, placement, offset, matchWidth }}
|
|
83
|
+
use:clickOutside={{ onoutside: () => (open = false), ignore: [anchorEl] }}
|
|
84
|
+
use:focusTrap={{ restore: true }}
|
|
85
|
+
onkeydown={onMenuKeydown}
|
|
86
|
+
onclick={onMenuClick}
|
|
87
|
+
role="menu"
|
|
88
|
+
aria-label={label ?? t.current.menu}
|
|
89
|
+
tabindex="-1"
|
|
90
|
+
class="z-50 flex max-h-[min(24rem,80vh)] min-w-48 flex-col overflow-y-auto rounded-lg border border-hairline bg-bg py-1 font-sans shadow-lg {className}"
|
|
91
|
+
>
|
|
92
|
+
{@render children()}
|
|
93
|
+
</div>
|
|
94
|
+
{/if}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import { type Placement } from '../../core/actions/anchor.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
/** The control that opens the menu — put a `Button` in here. */
|
|
5
|
+
trigger: Snippet;
|
|
6
|
+
/** Menu contents: `MenuItem`, `MenuSeparator`, or anything else. */
|
|
7
|
+
children: Snippet;
|
|
8
|
+
open?: boolean;
|
|
9
|
+
placement?: Placement;
|
|
10
|
+
offset?: number;
|
|
11
|
+
/** Stretch the menu to the trigger's width. */
|
|
12
|
+
matchWidth?: boolean;
|
|
13
|
+
/** Close as soon as an item inside is activated. Default true. */
|
|
14
|
+
closeOnSelect?: boolean;
|
|
15
|
+
/** Accessible name for the menu. Defaults to the locale's `menu`. */
|
|
16
|
+
label?: string;
|
|
17
|
+
class?: string;
|
|
18
|
+
/** Classes for the wrapper around the trigger. */
|
|
19
|
+
triggerClass?: string;
|
|
20
|
+
}
|
|
21
|
+
declare const Dropdown: import("svelte").Component<Props, {}, "open">;
|
|
22
|
+
type Dropdown = ReturnType<typeof Dropdown>;
|
|
23
|
+
export default Dropdown;
|