@w5-ui/svelte 0.1.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 +8 -0
- package/package.json +57 -0
- package/src/lib/components/Accordion.svelte +3 -0
- package/src/lib/components/AccordionItem.svelte +40 -0
- package/src/lib/components/ActionMenu.svelte +96 -0
- package/src/lib/components/ActivityFeed.svelte +60 -0
- package/src/lib/components/Alert.svelte +19 -0
- package/src/lib/components/AnnotatedTimeSeries.svelte +90 -0
- package/src/lib/components/ArcDiagram.svelte +74 -0
- package/src/lib/components/AreaChart.svelte +64 -0
- package/src/lib/components/Avatar.svelte +30 -0
- package/src/lib/components/AvatarGroup.svelte +35 -0
- package/src/lib/components/Badge.svelte +25 -0
- package/src/lib/components/Banner.svelte +37 -0
- package/src/lib/components/BarChart.svelte +52 -0
- package/src/lib/components/BeeswarmChart.svelte +88 -0
- package/src/lib/components/BoxPlot.svelte +66 -0
- package/src/lib/components/Breadcrumb.svelte +31 -0
- package/src/lib/components/BubbleChart.svelte +69 -0
- package/src/lib/components/BulletChart.svelte +70 -0
- package/src/lib/components/BumpChart.svelte +109 -0
- package/src/lib/components/Button.svelte +25 -0
- package/src/lib/components/CIDRInput.svelte +142 -0
- package/src/lib/components/CalendarHeatmap.svelte +86 -0
- package/src/lib/components/Callout.svelte +38 -0
- package/src/lib/components/CandlestickChart.svelte +66 -0
- package/src/lib/components/Card.svelte +11 -0
- package/src/lib/components/Carousel.svelte +64 -0
- package/src/lib/components/Checkbox.svelte +45 -0
- package/src/lib/components/ChordDiagram.svelte +90 -0
- package/src/lib/components/CirclePacking.svelte +119 -0
- package/src/lib/components/CodeBlock.svelte +49 -0
- package/src/lib/components/ColorPicker.svelte +91 -0
- package/src/lib/components/ColumnToggle.svelte +96 -0
- package/src/lib/components/Combobox.svelte +138 -0
- package/src/lib/components/CommandPalette.svelte +152 -0
- package/src/lib/components/ConfirmDialog.svelte +84 -0
- package/src/lib/components/ContextMenu.svelte +107 -0
- package/src/lib/components/ContextualHelp.svelte +73 -0
- package/src/lib/components/ContourPlot.svelte +164 -0
- package/src/lib/components/CopyButton.svelte +33 -0
- package/src/lib/components/CorrelationMatrix.svelte +90 -0
- package/src/lib/components/CountUp.svelte +49 -0
- package/src/lib/components/CumulativeDistribution.svelte +67 -0
- package/src/lib/components/DatePicker.svelte +201 -0
- package/src/lib/components/DateRangePicker.svelte +249 -0
- package/src/lib/components/Dendrogram.svelte +128 -0
- package/src/lib/components/Donut.svelte +49 -0
- package/src/lib/components/DotPlot.svelte +121 -0
- package/src/lib/components/Drawer.svelte +60 -0
- package/src/lib/components/DualAxisChart.svelte +80 -0
- package/src/lib/components/DumbbellChart.svelte +56 -0
- package/src/lib/components/DurationInput.svelte +118 -0
- package/src/lib/components/EmptyState.svelte +21 -0
- package/src/lib/components/ErrorBandChart.svelte +69 -0
- package/src/lib/components/ExpandableRow.svelte +42 -0
- package/src/lib/components/Field.svelte +40 -0
- package/src/lib/components/FileUpload.svelte +96 -0
- package/src/lib/components/FilterBuilder.svelte +160 -0
- package/src/lib/components/FlameGraph.svelte +88 -0
- package/src/lib/components/ForceGraph.svelte +104 -0
- package/src/lib/components/FunnelChart.svelte +50 -0
- package/src/lib/components/GanttChart.svelte +49 -0
- package/src/lib/components/Gauge.svelte +53 -0
- package/src/lib/components/GroupedList.svelte +87 -0
- package/src/lib/components/HealthBar.svelte +19 -0
- package/src/lib/components/HeatMap.svelte +64 -0
- package/src/lib/components/HexbinChart.svelte +100 -0
- package/src/lib/components/Histogram.svelte +93 -0
- package/src/lib/components/HorizonChart.svelte +71 -0
- package/src/lib/components/HoverCard.svelte +45 -0
- package/src/lib/components/IPInput.svelte +103 -0
- package/src/lib/components/IcicleChart.svelte +87 -0
- package/src/lib/components/IconButton.svelte +19 -0
- package/src/lib/components/InlineEdit.svelte +72 -0
- package/src/lib/components/Input.svelte +18 -0
- package/src/lib/components/InputGroup.svelte +14 -0
- package/src/lib/components/JsonViewer.svelte +15 -0
- package/src/lib/components/JsonViewerNode.svelte +59 -0
- package/src/lib/components/KVTable.svelte +18 -0
- package/src/lib/components/KanbanBoard.svelte +141 -0
- package/src/lib/components/Kbd.svelte +16 -0
- package/src/lib/components/LineChart.svelte +67 -0
- package/src/lib/components/LogViewer.svelte +84 -0
- package/src/lib/components/LollipopChart.svelte +79 -0
- package/src/lib/components/MACInput.svelte +98 -0
- package/src/lib/components/MarimekkoChart.svelte +108 -0
- package/src/lib/components/MatrixChart.svelte +55 -0
- package/src/lib/components/Menubar.svelte +131 -0
- package/src/lib/components/MirroredBarChart.svelte +120 -0
- package/src/lib/components/Modal.svelte +90 -0
- package/src/lib/components/MultiSelect.svelte +165 -0
- package/src/lib/components/NightingaleChart.svelte +63 -0
- package/src/lib/components/NotificationPanel.svelte +170 -0
- package/src/lib/components/NumberInput.svelte +93 -0
- package/src/lib/components/OTPInput.svelte +94 -0
- package/src/lib/components/Pagination.svelte +58 -0
- package/src/lib/components/ParallelCoordinates.svelte +98 -0
- package/src/lib/components/ParetoChart.svelte +88 -0
- package/src/lib/components/PasswordInput.svelte +62 -0
- package/src/lib/components/PieChart.svelte +91 -0
- package/src/lib/components/Pill.svelte +12 -0
- package/src/lib/components/PolarHeatmap.svelte +85 -0
- package/src/lib/components/Popover.svelte +89 -0
- package/src/lib/components/ProgressBar.svelte +29 -0
- package/src/lib/components/PunchCard.svelte +73 -0
- package/src/lib/components/QuadrantChart.svelte +122 -0
- package/src/lib/components/RadarChart.svelte +71 -0
- package/src/lib/components/RadialBarChart.svelte +76 -0
- package/src/lib/components/RadioGroup.svelte +48 -0
- package/src/lib/components/RangeSlider.svelte +68 -0
- package/src/lib/components/RankedList.svelte +49 -0
- package/src/lib/components/ResizablePanel.svelte +77 -0
- package/src/lib/components/RidgelinePlot.svelte +103 -0
- package/src/lib/components/RowToggle.svelte +19 -0
- package/src/lib/components/SankeyDiagram.svelte +100 -0
- package/src/lib/components/ScatterPlot.svelte +54 -0
- package/src/lib/components/SearchBox.svelte +11 -0
- package/src/lib/components/SegmentedControl.svelte +51 -0
- package/src/lib/components/Select.svelte +110 -0
- package/src/lib/components/SelectionToolbar.svelte +42 -0
- package/src/lib/components/Sidebar.svelte +44 -0
- package/src/lib/components/Signal.svelte +12 -0
- package/src/lib/components/Skeleton.svelte +23 -0
- package/src/lib/components/SkipLink.svelte +9 -0
- package/src/lib/components/Slider.svelte +48 -0
- package/src/lib/components/SlopeChart.svelte +91 -0
- package/src/lib/components/SortHeader.svelte +19 -0
- package/src/lib/components/SortableList.svelte +87 -0
- package/src/lib/components/Sparkline.svelte +32 -0
- package/src/lib/components/SparklineMatrix.svelte +84 -0
- package/src/lib/components/Spinner.svelte +6 -0
- package/src/lib/components/SplitButton.svelte +102 -0
- package/src/lib/components/Spoiler.svelte +41 -0
- package/src/lib/components/StackedBarChart.svelte +83 -0
- package/src/lib/components/StackedProgress.svelte +32 -0
- package/src/lib/components/StarRating.svelte +64 -0
- package/src/lib/components/Stat.svelte +24 -0
- package/src/lib/components/StatusIndicator.svelte +10 -0
- package/src/lib/components/StepChart.svelte +74 -0
- package/src/lib/components/Stepper.svelte +40 -0
- package/src/lib/components/StreamGraph.svelte +93 -0
- package/src/lib/components/StripeChart.svelte +52 -0
- package/src/lib/components/SunburstChart.svelte +80 -0
- package/src/lib/components/SwitchPortGrid.svelte +45 -0
- package/src/lib/components/TabPanel.svelte +17 -0
- package/src/lib/components/Tabs.svelte +45 -0
- package/src/lib/components/Tag.svelte +19 -0
- package/src/lib/components/TagInput.svelte +92 -0
- package/src/lib/components/Textarea.svelte +31 -0
- package/src/lib/components/ThresholdAreaChart.svelte +72 -0
- package/src/lib/components/TimePicker.svelte +116 -0
- package/src/lib/components/TimeRange.svelte +104 -0
- package/src/lib/components/Timeline.svelte +32 -0
- package/src/lib/components/Toast.svelte +52 -0
- package/src/lib/components/Toggle.svelte +23 -0
- package/src/lib/components/ToggleGroup.svelte +32 -0
- package/src/lib/components/Tooltip.svelte +16 -0
- package/src/lib/components/Topbar.svelte +63 -0
- package/src/lib/components/TransferList.svelte +184 -0
- package/src/lib/components/TreeItem.svelte +61 -0
- package/src/lib/components/TreeMap.svelte +90 -0
- package/src/lib/components/TreeView.svelte +130 -0
- package/src/lib/components/UptimeTimeline.svelte +86 -0
- package/src/lib/components/VennDiagram.svelte +91 -0
- package/src/lib/components/ViolinPlot.svelte +114 -0
- package/src/lib/components/VirtualList.svelte +38 -0
- package/src/lib/components/WaffleChart.svelte +68 -0
- package/src/lib/components/WaterfallChart.svelte +96 -0
- package/src/lib/components/WordCloud.svelte +103 -0
- package/src/lib/icons/AlarmIcon.svelte +5 -0
- package/src/lib/icons/BellIcon.svelte +6 -0
- package/src/lib/icons/CaretIcon.svelte +8 -0
- package/src/lib/icons/ClientsIcon.svelte +5 -0
- package/src/lib/icons/CloseIcon.svelte +6 -0
- package/src/lib/icons/DashboardIcon.svelte +7 -0
- package/src/lib/icons/DevicesIcon.svelte +5 -0
- package/src/lib/icons/DownloadIcon.svelte +6 -0
- package/src/lib/icons/HelpIcon.svelte +7 -0
- package/src/lib/icons/InfraIcon.svelte +7 -0
- package/src/lib/icons/IntegrationsIcon.svelte +5 -0
- package/src/lib/icons/LogsIcon.svelte +6 -0
- package/src/lib/icons/PlusIcon.svelte +6 -0
- package/src/lib/icons/PortsIcon.svelte +6 -0
- package/src/lib/icons/SearchIcon.svelte +10 -0
- package/src/lib/icons/SecurityIcon.svelte +4 -0
- package/src/lib/icons/SettingsIcon.svelte +5 -0
- package/src/lib/icons/TopologyIcon.svelte +7 -0
- package/src/lib/icons/UpdatesIcon.svelte +6 -0
- package/src/lib/icons/VpnIcon.svelte +5 -0
- package/src/lib/icons/WifiIcon.svelte +5 -0
- package/src/lib/icons/WirelessIcon.svelte +4 -0
- package/src/lib/icons.ts +22 -0
- package/src/lib/index.ts +275 -0
- package/src/lib/styles.css +2 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from 'svelte';
|
|
3
|
+
|
|
4
|
+
export interface ColumnDef {
|
|
5
|
+
key: string;
|
|
6
|
+
label: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export let columns: ColumnDef[] = [];
|
|
11
|
+
export let visible: Set<string> = new Set();
|
|
12
|
+
export let onChange: (visible: Set<string>) => void = () => {};
|
|
13
|
+
|
|
14
|
+
let open = false;
|
|
15
|
+
let btnEl: HTMLButtonElement;
|
|
16
|
+
let panelEl: HTMLDivElement;
|
|
17
|
+
const panelId = `col-toggle-${Math.random().toString(36).slice(2)}`;
|
|
18
|
+
|
|
19
|
+
function close() {
|
|
20
|
+
open = false;
|
|
21
|
+
btnEl?.focus();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function toggle(key: string) {
|
|
25
|
+
const next = new Set(visible);
|
|
26
|
+
if (next.has(key)) next.delete(key);
|
|
27
|
+
else next.add(key);
|
|
28
|
+
onChange(next);
|
|
29
|
+
visible = next;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function onKey(e: KeyboardEvent) {
|
|
33
|
+
if (open && e.key === 'Escape') close();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function onDown(e: MouseEvent) {
|
|
37
|
+
if (open && !panelEl?.contains(e.target as Node) && !btnEl?.contains(e.target as Node)) {
|
|
38
|
+
close();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
onMount(() => {
|
|
43
|
+
document.addEventListener('keydown', onKey);
|
|
44
|
+
document.addEventListener('mousedown', onDown);
|
|
45
|
+
return () => {
|
|
46
|
+
document.removeEventListener('keydown', onKey);
|
|
47
|
+
document.removeEventListener('mousedown', onDown);
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<div class="col-toggle">
|
|
53
|
+
<button
|
|
54
|
+
bind:this={btnEl}
|
|
55
|
+
type="button"
|
|
56
|
+
class="col-toggle__btn{open ? ' col-toggle__btn--active' : ''}"
|
|
57
|
+
aria-haspopup="dialog"
|
|
58
|
+
aria-expanded={open}
|
|
59
|
+
aria-controls={panelId}
|
|
60
|
+
on:click={() => (open = !open)}
|
|
61
|
+
>
|
|
62
|
+
<svg viewBox="0 0 14 14" width="14" height="14" fill="none" aria-hidden="true" focusable="false">
|
|
63
|
+
<rect x="1" y="2" width="3" height="10" rx="1" stroke="currentColor" stroke-width="1.3" />
|
|
64
|
+
<rect x="5.5" y="2" width="3" height="10" rx="1" stroke="currentColor" stroke-width="1.3" />
|
|
65
|
+
<rect x="10" y="2" width="3" height="10" rx="1" stroke="currentColor" stroke-width="1.3" />
|
|
66
|
+
</svg>
|
|
67
|
+
<span>Columns</span>
|
|
68
|
+
</button>
|
|
69
|
+
{#if open}
|
|
70
|
+
<div
|
|
71
|
+
bind:this={panelEl}
|
|
72
|
+
id={panelId}
|
|
73
|
+
class="col-toggle__panel"
|
|
74
|
+
role="dialog"
|
|
75
|
+
aria-label="Toggle columns"
|
|
76
|
+
>
|
|
77
|
+
<div class="col-toggle__header">Columns</div>
|
|
78
|
+
<ul class="col-toggle__list" role="list">
|
|
79
|
+
{#each columns as col (col.key)}
|
|
80
|
+
<li class="col-toggle__item">
|
|
81
|
+
<label class="col-toggle__label">
|
|
82
|
+
<input
|
|
83
|
+
type="checkbox"
|
|
84
|
+
class="col-toggle__check"
|
|
85
|
+
checked={visible.has(col.key)}
|
|
86
|
+
disabled={col.required}
|
|
87
|
+
on:change={() => { if (!col.required) toggle(col.key); }}
|
|
88
|
+
/>
|
|
89
|
+
<span>{col.label}</span>
|
|
90
|
+
</label>
|
|
91
|
+
</li>
|
|
92
|
+
{/each}
|
|
93
|
+
</ul>
|
|
94
|
+
</div>
|
|
95
|
+
{/if}
|
|
96
|
+
</div>
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
let counter = 0;
|
|
3
|
+
export interface ComboboxOption { value: string; label: string; }
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import { createEventDispatcher, onMount, onDestroy } from 'svelte';
|
|
8
|
+
|
|
9
|
+
export let options: ComboboxOption[] = [];
|
|
10
|
+
export let value: string | undefined = undefined;
|
|
11
|
+
export let label: string | undefined = undefined;
|
|
12
|
+
export let placeholder: string = 'Search…';
|
|
13
|
+
export let id: string | undefined = undefined;
|
|
14
|
+
export let disabled: boolean = false;
|
|
15
|
+
let className = '';
|
|
16
|
+
export { className as class };
|
|
17
|
+
|
|
18
|
+
const uid = `dash-ui-cb-${++counter}`;
|
|
19
|
+
$: inputId = id ?? uid;
|
|
20
|
+
$: listboxId = `${inputId}-lb`;
|
|
21
|
+
|
|
22
|
+
const dispatch = createEventDispatcher<{ change: string }>();
|
|
23
|
+
|
|
24
|
+
let open = false;
|
|
25
|
+
let query = '';
|
|
26
|
+
let activeIdx = -1;
|
|
27
|
+
let inputEl: HTMLInputElement;
|
|
28
|
+
let wrapperEl: HTMLDivElement;
|
|
29
|
+
|
|
30
|
+
$: selectedOption = options.find((o) => o.value === value);
|
|
31
|
+
|
|
32
|
+
$: filtered = query.trim() === ''
|
|
33
|
+
? options
|
|
34
|
+
: options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase()));
|
|
35
|
+
|
|
36
|
+
$: activeOptionId = activeIdx >= 0 && filtered[activeIdx]
|
|
37
|
+
? `${listboxId}-opt-${activeIdx}`
|
|
38
|
+
: undefined;
|
|
39
|
+
|
|
40
|
+
$: displayValue = open ? query : (selectedOption?.label ?? '');
|
|
41
|
+
|
|
42
|
+
function openList() {
|
|
43
|
+
if (disabled) return;
|
|
44
|
+
query = selectedOption?.label ?? '';
|
|
45
|
+
activeIdx = options.findIndex((o) => o.value === value);
|
|
46
|
+
open = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function pick(opt: ComboboxOption) {
|
|
50
|
+
dispatch('change', opt.value);
|
|
51
|
+
open = false;
|
|
52
|
+
query = '';
|
|
53
|
+
inputEl?.focus();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function onInputChange(e: Event) {
|
|
57
|
+
query = (e.target as HTMLInputElement).value;
|
|
58
|
+
activeIdx = -1;
|
|
59
|
+
if (!open) open = true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function onKeyDown(e: KeyboardEvent) {
|
|
63
|
+
if (disabled) return;
|
|
64
|
+
if (e.key === 'Escape') { open = false; query = ''; return; }
|
|
65
|
+
if (!open) {
|
|
66
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); openList(); }
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (e.key === 'ArrowDown') { e.preventDefault(); activeIdx = Math.min(activeIdx + 1, filtered.length - 1); }
|
|
70
|
+
else if (e.key === 'ArrowUp') { e.preventDefault(); activeIdx = Math.max(activeIdx - 1, 0); }
|
|
71
|
+
else if (e.key === 'Home') { e.preventDefault(); activeIdx = 0; }
|
|
72
|
+
else if (e.key === 'End') { e.preventDefault(); activeIdx = filtered.length - 1; }
|
|
73
|
+
else if (e.key === 'Enter') { e.preventDefault(); if (activeIdx >= 0 && filtered[activeIdx]) pick(filtered[activeIdx]); }
|
|
74
|
+
else if (e.key === 'Tab') { open = false; query = ''; }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function handleOutside(e: MouseEvent) {
|
|
78
|
+
if (open && !wrapperEl?.contains(e.target as Node)) { open = false; query = ''; }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
onMount(() => document.addEventListener('mousedown', handleOutside));
|
|
82
|
+
onDestroy(() => document.removeEventListener('mousedown', handleOutside));
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<div class="combobox-wrapper {className}" bind:this={wrapperEl}>
|
|
86
|
+
{#if label}<label for={inputId} class="sr-only">{label}</label>{/if}
|
|
87
|
+
<div class="combobox-field">
|
|
88
|
+
<input
|
|
89
|
+
bind:this={inputEl}
|
|
90
|
+
id={inputId}
|
|
91
|
+
role="combobox"
|
|
92
|
+
aria-expanded={open}
|
|
93
|
+
aria-controls={listboxId}
|
|
94
|
+
aria-autocomplete="list"
|
|
95
|
+
aria-activedescendant={activeOptionId}
|
|
96
|
+
aria-label={label}
|
|
97
|
+
autocomplete="off"
|
|
98
|
+
spellcheck="false"
|
|
99
|
+
{disabled}
|
|
100
|
+
{placeholder}
|
|
101
|
+
value={displayValue}
|
|
102
|
+
on:input={onInputChange}
|
|
103
|
+
on:focus={openList}
|
|
104
|
+
on:keydown={onKeyDown}
|
|
105
|
+
class="combobox-input"
|
|
106
|
+
/>
|
|
107
|
+
<button
|
|
108
|
+
type="button"
|
|
109
|
+
tabindex="-1"
|
|
110
|
+
aria-hidden="true"
|
|
111
|
+
class="combobox-chevron-btn"
|
|
112
|
+
on:click={() => { if (open) { open = false; query = ''; } else { inputEl?.focus(); openList(); } }}
|
|
113
|
+
>
|
|
114
|
+
<svg class="select-chevron{open ? ' combobox-chevron-open' : ''}" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
|
|
115
|
+
<path d="M4 6l4 4 4-4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" fill="none" />
|
|
116
|
+
</svg>
|
|
117
|
+
</button>
|
|
118
|
+
</div>
|
|
119
|
+
{#if open}
|
|
120
|
+
<ul id={listboxId} role="listbox" aria-label={label} class="select-listbox combobox-listbox">
|
|
121
|
+
{#if filtered.length === 0}
|
|
122
|
+
<li class="combobox-empty">No results</li>
|
|
123
|
+
{:else}
|
|
124
|
+
{#each filtered as opt, idx (opt.value)}
|
|
125
|
+
<li
|
|
126
|
+
id="{listboxId}-opt-{idx}"
|
|
127
|
+
role="option"
|
|
128
|
+
aria-selected={opt.value === value}
|
|
129
|
+
data-active={idx === activeIdx ? 'true' : undefined}
|
|
130
|
+
class="select-option"
|
|
131
|
+
on:mousedown|preventDefault={() => pick(opt)}
|
|
132
|
+
on:mouseenter={() => { activeIdx = idx; }}
|
|
133
|
+
>{opt.label}</li>
|
|
134
|
+
{/each}
|
|
135
|
+
{/if}
|
|
136
|
+
</ul>
|
|
137
|
+
{/if}
|
|
138
|
+
</div>
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
export interface CommandItem {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
group?: string;
|
|
6
|
+
shortcut?: string;
|
|
7
|
+
}
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import { createEventDispatcher, tick } from 'svelte';
|
|
12
|
+
import Kbd from './Kbd.svelte';
|
|
13
|
+
|
|
14
|
+
export let open: boolean = false;
|
|
15
|
+
export let items: CommandItem[] = [];
|
|
16
|
+
export let placeholder: string = 'Search pages and actions…';
|
|
17
|
+
|
|
18
|
+
const dispatch = createEventDispatcher<{ select: string; close: void }>();
|
|
19
|
+
|
|
20
|
+
let query = '';
|
|
21
|
+
let activeIdx = 0;
|
|
22
|
+
let inputEl: HTMLInputElement;
|
|
23
|
+
const listboxId = `cp-list-${Math.random().toString(36).slice(2)}`;
|
|
24
|
+
|
|
25
|
+
$: filtered =
|
|
26
|
+
query.trim() === ''
|
|
27
|
+
? items
|
|
28
|
+
: items.filter((i) => i.label.toLowerCase().includes(query.toLowerCase()));
|
|
29
|
+
|
|
30
|
+
$: grouped = filtered.reduce(
|
|
31
|
+
(acc, item) => {
|
|
32
|
+
const g = item.group ?? '';
|
|
33
|
+
const found = acc.find((a: { group: string }) => a.group === g);
|
|
34
|
+
if (found) found.items.push(item);
|
|
35
|
+
else acc.push({ group: g, items: [item] });
|
|
36
|
+
return acc;
|
|
37
|
+
},
|
|
38
|
+
[] as { group: string; items: CommandItem[] }[],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
$: if (open) {
|
|
42
|
+
query = '';
|
|
43
|
+
activeIdx = 0;
|
|
44
|
+
tick().then(() => inputEl?.focus());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
$: if (query !== undefined) activeIdx = 0;
|
|
48
|
+
|
|
49
|
+
function handleKey(e: KeyboardEvent) {
|
|
50
|
+
if (e.key === 'ArrowDown') {
|
|
51
|
+
e.preventDefault();
|
|
52
|
+
activeIdx = Math.min(activeIdx + 1, filtered.length - 1);
|
|
53
|
+
} else if (e.key === 'ArrowUp') {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
activeIdx = Math.max(activeIdx - 1, 0);
|
|
56
|
+
} else if (e.key === 'Enter') {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
const item = filtered[activeIdx];
|
|
59
|
+
if (item) commit(item.id);
|
|
60
|
+
} else if (e.key === 'Escape') {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
dispatch('close');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function commit(id: string) {
|
|
67
|
+
dispatch('select', id);
|
|
68
|
+
dispatch('close');
|
|
69
|
+
query = '';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function handleBackdrop(e: MouseEvent) {
|
|
73
|
+
if (e.target === e.currentTarget) dispatch('close');
|
|
74
|
+
}
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
{#if open}
|
|
78
|
+
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
|
79
|
+
<div class="cp-backdrop" role="presentation" on:click={handleBackdrop} on:keydown={handleKey}>
|
|
80
|
+
<div
|
|
81
|
+
role="dialog"
|
|
82
|
+
aria-modal="true"
|
|
83
|
+
aria-label="Command palette"
|
|
84
|
+
class="cp-panel"
|
|
85
|
+
>
|
|
86
|
+
<div class="cp-search">
|
|
87
|
+
<svg
|
|
88
|
+
class="cp-search-icon"
|
|
89
|
+
width="16"
|
|
90
|
+
height="16"
|
|
91
|
+
viewBox="0 0 16 16"
|
|
92
|
+
fill="none"
|
|
93
|
+
stroke="currentColor"
|
|
94
|
+
stroke-width="1.5"
|
|
95
|
+
stroke-linecap="round"
|
|
96
|
+
stroke-linejoin="round"
|
|
97
|
+
aria-hidden="true"
|
|
98
|
+
focusable="false"
|
|
99
|
+
>
|
|
100
|
+
<circle cx="6.5" cy="6.5" r="4.5" />
|
|
101
|
+
<path d="M10.5 10.5l3 3" />
|
|
102
|
+
</svg>
|
|
103
|
+
<input
|
|
104
|
+
bind:this={inputEl}
|
|
105
|
+
class="cp-input"
|
|
106
|
+
type="text"
|
|
107
|
+
role="combobox"
|
|
108
|
+
aria-expanded={filtered.length > 0}
|
|
109
|
+
aria-autocomplete="list"
|
|
110
|
+
aria-controls={listboxId}
|
|
111
|
+
{placeholder}
|
|
112
|
+
bind:value={query}
|
|
113
|
+
on:keydown={handleKey}
|
|
114
|
+
/>
|
|
115
|
+
<span class="cp-kbd">Esc</span>
|
|
116
|
+
</div>
|
|
117
|
+
<ul id={listboxId} role="listbox" aria-label="Results" class="cp-list">
|
|
118
|
+
{#if filtered.length === 0}
|
|
119
|
+
<li class="cp-empty">No results for “{query}”</li>
|
|
120
|
+
{:else}
|
|
121
|
+
{#each grouped as { group, items: groupItems }}
|
|
122
|
+
<li role="presentation">
|
|
123
|
+
{#if group}
|
|
124
|
+
<div class="cp-group-label">{group}</div>
|
|
125
|
+
{/if}
|
|
126
|
+
{#each groupItems as item}
|
|
127
|
+
{@const idx = filtered.indexOf(item)}
|
|
128
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
129
|
+
<div
|
|
130
|
+
role="option"
|
|
131
|
+
tabindex="-1"
|
|
132
|
+
aria-selected={idx === activeIdx}
|
|
133
|
+
data-active={idx === activeIdx ? 'true' : undefined}
|
|
134
|
+
class="cp-item"
|
|
135
|
+
on:click={() => commit(item.id)}
|
|
136
|
+
on:mouseenter={() => (activeIdx = idx)}
|
|
137
|
+
>
|
|
138
|
+
{item.label}
|
|
139
|
+
{#if item.shortcut}
|
|
140
|
+
<span class="cp-item-shortcut" aria-label={item.shortcut.replace(/\+/g, ' then ')}>
|
|
141
|
+
<Kbd keys={item.shortcut} />
|
|
142
|
+
</span>
|
|
143
|
+
{/if}
|
|
144
|
+
</div>
|
|
145
|
+
{/each}
|
|
146
|
+
</li>
|
|
147
|
+
{/each}
|
|
148
|
+
{/if}
|
|
149
|
+
</ul>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
{/if}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy, afterUpdate } from 'svelte';
|
|
3
|
+
|
|
4
|
+
export let open = false;
|
|
5
|
+
export let title = '';
|
|
6
|
+
export let description: string | undefined = undefined;
|
|
7
|
+
export let confirmLabel = 'Confirm';
|
|
8
|
+
export let cancelLabel = 'Cancel';
|
|
9
|
+
export let variant: 'danger' | 'warning' | 'info' = 'info';
|
|
10
|
+
export let onConfirm: () => void = () => {};
|
|
11
|
+
export let onCancel: () => void = () => {};
|
|
12
|
+
|
|
13
|
+
const FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
|
14
|
+
|
|
15
|
+
const VARIANT_CLASS: Record<string, string> = {
|
|
16
|
+
danger: 'btn cd-confirm cd-confirm--danger',
|
|
17
|
+
warning: 'btn cd-confirm cd-confirm--warning',
|
|
18
|
+
info: 'btn cd-confirm cd-confirm--info',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
let dialogEl: HTMLDivElement;
|
|
22
|
+
let prev: HTMLElement | null = null;
|
|
23
|
+
let prevOverflow = '';
|
|
24
|
+
|
|
25
|
+
function onKey(e: KeyboardEvent) {
|
|
26
|
+
if (e.key === 'Escape') { onCancel(); return; }
|
|
27
|
+
if (e.key !== 'Tab' || !dialogEl) return;
|
|
28
|
+
const els = Array.from(dialogEl.querySelectorAll<HTMLElement>(FOCUSABLE));
|
|
29
|
+
if (!els.length) { e.preventDefault(); return; }
|
|
30
|
+
const first = els[0]!;
|
|
31
|
+
const last = els[els.length - 1]!;
|
|
32
|
+
const active = document.activeElement;
|
|
33
|
+
if (e.shiftKey && active === first) { e.preventDefault(); last.focus(); }
|
|
34
|
+
else if (!e.shiftKey && active === last) { e.preventDefault(); first.focus(); }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
$: if (open) {
|
|
38
|
+
prev = document.activeElement as HTMLElement | null;
|
|
39
|
+
prevOverflow = document.body.style.overflow;
|
|
40
|
+
document.body.style.overflow = 'hidden';
|
|
41
|
+
window.addEventListener('keydown', onKey);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
afterUpdate(() => {
|
|
45
|
+
if (open && dialogEl) {
|
|
46
|
+
const first = dialogEl.querySelector<HTMLElement>(FOCUSABLE);
|
|
47
|
+
(first ?? dialogEl).focus();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
$: if (!open) {
|
|
52
|
+
window.removeEventListener('keydown', onKey);
|
|
53
|
+
document.body.style.overflow = prevOverflow;
|
|
54
|
+
prev?.focus?.();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
onDestroy(() => {
|
|
58
|
+
window.removeEventListener('keydown', onKey);
|
|
59
|
+
document.body.style.overflow = prevOverflow;
|
|
60
|
+
});
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<div class="backdrop {open ? 'show' : ''}" role="presentation" on:click={(e) => { if (e.target === e.currentTarget) onCancel(); }}>
|
|
64
|
+
<div
|
|
65
|
+
bind:this={dialogEl}
|
|
66
|
+
class="modal cd-dialog"
|
|
67
|
+
role="alertdialog"
|
|
68
|
+
aria-modal="true"
|
|
69
|
+
aria-labelledby="cd-title"
|
|
70
|
+
aria-describedby={description ? 'cd-desc' : undefined}
|
|
71
|
+
tabindex="-1"
|
|
72
|
+
>
|
|
73
|
+
<div class="modal-h">
|
|
74
|
+
<h2 id="cd-title">{title}</h2>
|
|
75
|
+
</div>
|
|
76
|
+
{#if description}
|
|
77
|
+
<div id="cd-desc" class="cd-body">{description}</div>
|
|
78
|
+
{/if}
|
|
79
|
+
<div class="modal-f">
|
|
80
|
+
<button type="button" class="btn btn-ghost" on:click={onCancel}>{cancelLabel}</button>
|
|
81
|
+
<button type="button" class={VARIANT_CLASS[variant]} on:click={onConfirm}>{confirmLabel}</button>
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<script lang="ts" context="module">
|
|
2
|
+
export interface ContextMenuItem {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
danger?: boolean;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type ContextMenuEntry = ContextMenuItem | { separator: true };
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import { onDestroy, tick, createEventDispatcher } from 'svelte';
|
|
13
|
+
|
|
14
|
+
export let items: ContextMenuEntry[] = [];
|
|
15
|
+
export let x = 0;
|
|
16
|
+
export let y = 0;
|
|
17
|
+
export let open = false;
|
|
18
|
+
export let label = 'Context menu';
|
|
19
|
+
|
|
20
|
+
const dispatch = createEventDispatcher<{ close: void; action: string }>();
|
|
21
|
+
|
|
22
|
+
let menuEl: HTMLUListElement;
|
|
23
|
+
let activeIdx = 0;
|
|
24
|
+
|
|
25
|
+
$: actionItems = items.reduce<ContextMenuItem[]>((acc, e) => {
|
|
26
|
+
if (!('separator' in e)) acc.push(e);
|
|
27
|
+
return acc;
|
|
28
|
+
}, []);
|
|
29
|
+
|
|
30
|
+
const menuW = 168;
|
|
31
|
+
$: menuH = items.length * 30 + 8;
|
|
32
|
+
$: cx = Math.min(x, (typeof window !== 'undefined' ? window.innerWidth : 1200) - menuW - 8);
|
|
33
|
+
$: cy = Math.min(y, (typeof window !== 'undefined' ? window.innerHeight : 800) - menuH - 8);
|
|
34
|
+
|
|
35
|
+
function activate(id: string) {
|
|
36
|
+
dispatch('action', id);
|
|
37
|
+
dispatch('close');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
41
|
+
if (e.key === 'Escape') { e.preventDefault(); dispatch('close'); }
|
|
42
|
+
else if (e.key === 'ArrowDown') { e.preventDefault(); activeIdx = Math.min(activeIdx + 1, actionItems.length - 1); }
|
|
43
|
+
else if (e.key === 'ArrowUp') { e.preventDefault(); activeIdx = Math.max(activeIdx - 1, 0); }
|
|
44
|
+
else if (e.key === 'Home') { e.preventDefault(); activeIdx = 0; }
|
|
45
|
+
else if (e.key === 'End') { e.preventDefault(); activeIdx = actionItems.length - 1; }
|
|
46
|
+
else if (e.key === 'Enter' || e.key === ' ') {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
const item = actionItems[activeIdx];
|
|
49
|
+
if (item && !item.disabled) activate(item.id);
|
|
50
|
+
}
|
|
51
|
+
else if (e.key === 'Tab') { dispatch('close'); }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function handleOutside(e: MouseEvent) {
|
|
55
|
+
if (!menuEl?.contains(e.target as Node)) dispatch('close');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
$: if (open) {
|
|
59
|
+
activeIdx = 0;
|
|
60
|
+
tick().then(() => menuEl?.focus());
|
|
61
|
+
document.addEventListener('mousedown', handleOutside);
|
|
62
|
+
} else {
|
|
63
|
+
document.removeEventListener('mousedown', handleOutside);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
onDestroy(() => {
|
|
67
|
+
document.removeEventListener('mousedown', handleOutside);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
function actionIndex(entry: ContextMenuEntry): number {
|
|
71
|
+
if ('separator' in entry) return -1;
|
|
72
|
+
return actionItems.indexOf(entry as ContextMenuItem);
|
|
73
|
+
}
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
{#if open}
|
|
77
|
+
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
|
78
|
+
<ul
|
|
79
|
+
bind:this={menuEl}
|
|
80
|
+
role="menu"
|
|
81
|
+
aria-label={label}
|
|
82
|
+
tabindex="-1"
|
|
83
|
+
class="ctx-menu"
|
|
84
|
+
style="left:{cx}px;top:{cy}px"
|
|
85
|
+
on:keydown={handleKeyDown}
|
|
86
|
+
>
|
|
87
|
+
{#each items as entry, i (i)}
|
|
88
|
+
{#if 'separator' in entry}
|
|
89
|
+
<li role="separator" class="ctx-menu-sep"></li>
|
|
90
|
+
{:else}
|
|
91
|
+
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
|
92
|
+
<li
|
|
93
|
+
role="menuitem"
|
|
94
|
+
tabindex="-1"
|
|
95
|
+
aria-disabled={entry.disabled || undefined}
|
|
96
|
+
data-active={actionIndex(entry) === activeIdx ? 'true' : undefined}
|
|
97
|
+
data-danger={entry.danger || undefined}
|
|
98
|
+
class="ctx-menu-item"
|
|
99
|
+
on:mouseenter={() => (activeIdx = actionIndex(entry))}
|
|
100
|
+
on:mousedown|preventDefault={() => { if (!entry.disabled) activate(entry.id); }}
|
|
101
|
+
>
|
|
102
|
+
{entry.label}
|
|
103
|
+
</li>
|
|
104
|
+
{/if}
|
|
105
|
+
{/each}
|
|
106
|
+
</ul>
|
|
107
|
+
{/if}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
let counter = 0;
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { onMount, onDestroy, tick } from 'svelte';
|
|
7
|
+
|
|
8
|
+
export let title: string;
|
|
9
|
+
export let body: string;
|
|
10
|
+
export let placement: 'top' | 'bottom' = 'top';
|
|
11
|
+
|
|
12
|
+
const uid = `dash-ui-ch-${++counter}`;
|
|
13
|
+
const titleId = `${uid}-title`;
|
|
14
|
+
|
|
15
|
+
let open = false;
|
|
16
|
+
let rootEl: HTMLSpanElement;
|
|
17
|
+
let triggerEl: HTMLButtonElement;
|
|
18
|
+
let panelEl: HTMLDivElement;
|
|
19
|
+
|
|
20
|
+
async function toggle() {
|
|
21
|
+
open = !open;
|
|
22
|
+
if (open) {
|
|
23
|
+
await tick();
|
|
24
|
+
panelEl?.focus();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function onKey(e: KeyboardEvent) {
|
|
29
|
+
if (!open) return;
|
|
30
|
+
if (e.key === 'Escape') {
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
open = false;
|
|
33
|
+
triggerEl?.focus();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function onPointer(e: PointerEvent) {
|
|
38
|
+
if (open && !rootEl?.contains(e.target as Node)) open = false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onMount(() => {
|
|
42
|
+
window.addEventListener('keydown', onKey);
|
|
43
|
+
document.addEventListener('pointerdown', onPointer);
|
|
44
|
+
});
|
|
45
|
+
onDestroy(() => {
|
|
46
|
+
window.removeEventListener('keydown', onKey);
|
|
47
|
+
document.removeEventListener('pointerdown', onPointer);
|
|
48
|
+
});
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<span class="ch-root" bind:this={rootEl}>
|
|
52
|
+
<button
|
|
53
|
+
bind:this={triggerEl}
|
|
54
|
+
type="button"
|
|
55
|
+
class="ch-trigger"
|
|
56
|
+
aria-label="Help"
|
|
57
|
+
aria-haspopup="dialog"
|
|
58
|
+
aria-expanded={open}
|
|
59
|
+
on:click={toggle}
|
|
60
|
+
>?</button>
|
|
61
|
+
{#if open}
|
|
62
|
+
<div
|
|
63
|
+
bind:this={panelEl}
|
|
64
|
+
role="dialog"
|
|
65
|
+
aria-labelledby={titleId}
|
|
66
|
+
class="ch-panel ch-panel--{placement}"
|
|
67
|
+
tabindex="-1"
|
|
68
|
+
>
|
|
69
|
+
<div id={titleId} class="ch-title">{title}</div>
|
|
70
|
+
<div class="ch-body">{body}</div>
|
|
71
|
+
</div>
|
|
72
|
+
{/if}
|
|
73
|
+
</span>
|