@widgetic/design-system 0.5.40 → 0.5.42
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 +73 -0
- package/dist/components/ContentRefreshOverlay.svelte +103 -0
- package/dist/components/ContentRefreshOverlay.svelte.d.ts +18 -0
- package/dist/components/EmptyState.svelte +6 -2
- package/dist/components/chat/Composer.svelte +380 -19
- package/dist/components/chat/Composer.svelte.d.ts +88 -1
- package/dist/components/chat/PlanCard.svelte +218 -88
- package/dist/components/chat/PlanCard.svelte.d.ts +11 -0
- package/dist/components/chat/QuestionCard.svelte +180 -70
- package/dist/components/chat/QuestionCard.svelte.d.ts +28 -2
- package/dist/components/chat/QuestionCardSummary.svelte +96 -0
- package/dist/components/chat/QuestionCardSummary.svelte.d.ts +20 -0
- package/dist/components/chat/QueueCard.svelte +185 -0
- package/dist/components/chat/QueueCard.svelte.d.ts +40 -0
- package/dist/components/chat/composerLogic.d.ts +31 -0
- package/dist/components/chat/composerLogic.js +37 -0
- package/dist/components/chat/composerReferences.d.ts +28 -0
- package/dist/components/chat/composerReferences.js +23 -0
- package/dist/components/chat/index.d.ts +8 -3
- package/dist/components/chat/index.js +10 -2
- package/dist/components/chat/questionCardLogic.d.ts +40 -3
- package/dist/components/chat/questionCardLogic.js +54 -3
- package/dist/components/chat/queueCardLogic.d.ts +7 -0
- package/dist/components/chat/queueCardLogic.js +5 -0
- package/dist/components/creator/CreatorBar.svelte +54 -1
- package/dist/components/creator/CreatorBar.svelte.d.ts +5 -0
- package/dist/components/creator/index.d.ts +1 -2
- package/dist/components/creator/index.js +2 -0
- package/dist/components/index.d.ts +8 -7
- package/dist/components/index.js +8 -6
- package/dist/components/modals/BaseModal.svelte +23 -4
- package/dist/components/modals/BaseModal.svelte.d.ts +5 -0
- package/dist/components/navigation/breadcrumbSlideIn.d.ts +6 -2
- package/dist/components/navigation/breadcrumbSlideIn.js +6 -6
- package/dist/components/search-input/SearchInput.svelte +317 -14
- package/dist/components/search-input/SearchInput.svelte.d.ts +3 -0
- package/dist/components/search-input/index.d.ts +1 -0
- package/dist/components/search-input/index.js +1 -0
- package/dist/components/search-input/index2.d.ts +4 -0
- package/dist/components/search-input/recentSearches.d.ts +16 -0
- package/dist/components/search-input/recentSearches.js +141 -0
- package/dist/components/shell/NavRow.svelte +53 -10
- package/dist/components/shell/NavRow.svelte.d.ts +23 -2
- package/dist/components/shell/NotificationRow.svelte +3 -2
- package/dist/components/shell/ProfileRow.svelte +6 -4
- package/dist/components/shell/ProfileRow.svelte.d.ts +2 -2
- package/dist/components/shell/SettingsDialog.svelte +23 -1
- package/dist/components/shell/WidgetRow.svelte +4 -3
- package/dist/components/shell/WidgetRow.svelte.d.ts +2 -2
- package/dist/components/toast/ToasterModal.svelte +8 -3
- package/dist/components/toast/ToasterModal.svelte.d.ts +2 -0
- package/dist/components/ui/accordion/accordion-trigger.svelte +19 -0
- package/dist/components/ui/button/button.svelte +4 -2
- package/dist/components/ui/chip/chip.svelte +39 -1
- package/dist/components/ui/chip/chip.svelte.d.ts +8 -0
- package/dist/components/ui/chip/chipProgress.d.ts +14 -0
- package/dist/components/ui/chip/chipProgress.js +21 -0
- package/dist/components/ui/dialog/dialog-content.svelte +24 -2
- package/dist/components/ui/dropdown-menu/dropdown-menu-content.svelte +2 -1
- package/dist/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte +2 -1
- package/dist/components/ui/hover-card/hover-card-content.svelte +2 -1
- package/dist/components/ui/icon-button/icon-button.svelte +2 -0
- package/dist/components/ui/icon-button/icon-button.svelte.d.ts +5 -0
- package/dist/components/ui/number-controls/index.d.ts +2 -0
- package/dist/components/ui/number-controls/index.js +2 -0
- package/dist/components/ui/number-controls/number-controls.svelte +530 -0
- package/dist/components/ui/number-controls/number-controls.svelte.d.ts +46 -0
- package/dist/components/ui/number-controls/numberControlsSteps.d.ts +17 -0
- package/dist/components/ui/number-controls/numberControlsSteps.js +23 -0
- package/dist/components/ui/number-controls/numberControlsValueArea.d.ts +29 -0
- package/dist/components/ui/number-controls/numberControlsValueArea.js +51 -0
- package/dist/components/ui/popover/popover-content.svelte +2 -1
- package/dist/components/ui/select/select-content.svelte +2 -1
- package/dist/components/ui/text-flip/index.d.ts +1 -0
- package/dist/components/ui/text-flip/index.js +1 -0
- package/dist/components/ui/text-flip/text-flip.svelte +103 -0
- package/dist/components/ui/text-flip/text-flip.svelte.d.ts +15 -0
- package/dist/components/ui/text-flip/textFlipLogic.d.ts +49 -0
- package/dist/components/ui/text-flip/textFlipLogic.js +151 -0
- package/dist/components/ui/tooltip/tooltip-content.svelte +1 -1
- package/dist/inline-completion/completionAnswer.d.ts +11 -0
- package/dist/inline-completion/completionAnswer.js +49 -0
- package/dist/inline-completion/completionCache.d.ts +24 -0
- package/dist/inline-completion/completionCache.js +47 -0
- package/dist/inline-completion/completionController.d.ts +61 -0
- package/dist/inline-completion/completionController.js +280 -0
- package/dist/inline-completion/completionKeys.d.ts +21 -0
- package/dist/inline-completion/completionKeys.js +19 -0
- package/dist/inline-completion/completionText.d.ts +53 -0
- package/dist/inline-completion/completionText.js +79 -0
- package/dist/inline-completion/completionTypes.d.ts +71 -0
- package/dist/inline-completion/completionTypes.js +5 -0
- package/dist/inline-completion/gatewayCompletion.d.ts +37 -0
- package/dist/inline-completion/gatewayCompletion.js +77 -0
- package/dist/inline-completion/ghostTap.d.ts +19 -0
- package/dist/inline-completion/ghostTap.js +20 -0
- package/dist/inline-completion/hintMemory.d.ts +43 -0
- package/dist/inline-completion/hintMemory.js +90 -0
- package/dist/inline-completion/httpSource.d.ts +40 -0
- package/dist/inline-completion/httpSource.js +149 -0
- package/dist/inline-completion/index.d.ts +30 -0
- package/dist/inline-completion/index.js +20 -0
- package/dist/inline-completion/inlineCompletionAction.d.ts +54 -0
- package/dist/inline-completion/inlineCompletionAction.js +310 -0
- package/dist/inline-completion/outcomeReporter.d.ts +49 -0
- package/dist/inline-completion/outcomeReporter.js +139 -0
- package/dist/inline-completion/promiseLike.d.ts +9 -0
- package/dist/inline-completion/promiseLike.js +9 -0
- package/dist/prompt-references/ReferenceMenu.svelte +344 -0
- package/dist/prompt-references/ReferenceMenu.svelte.d.ts +26 -0
- package/dist/prompt-references/index.d.ts +27 -0
- package/dist/prompt-references/index.js +20 -0
- package/dist/prompt-references/neutralizingSource.d.ts +21 -0
- package/dist/prompt-references/neutralizingSource.js +29 -0
- package/dist/prompt-references/promptReferences.d.ts +28 -0
- package/dist/prompt-references/promptReferences.js +766 -0
- package/dist/prompt-references/referenceBadge.d.ts +61 -0
- package/dist/prompt-references/referenceBadge.js +82 -0
- package/dist/prompt-references/referenceBadgePainter.d.ts +31 -0
- package/dist/prompt-references/referenceBadgePainter.js +106 -0
- package/dist/prompt-references/referenceEditing.d.ts +60 -0
- package/dist/prompt-references/referenceEditing.js +135 -0
- package/dist/prompt-references/referenceLabels.d.ts +56 -0
- package/dist/prompt-references/referenceLabels.js +215 -0
- package/dist/prompt-references/referenceMeasure.d.ts +12 -0
- package/dist/prompt-references/referenceMeasure.js +63 -0
- package/dist/prompt-references/referenceMenuHost.svelte.d.ts +29 -0
- package/dist/prompt-references/referenceMenuHost.svelte.js +43 -0
- package/dist/prompt-references/referenceMenuKeys.d.ts +26 -0
- package/dist/prompt-references/referenceMenuKeys.js +49 -0
- package/dist/prompt-references/referenceMenuPlacement.d.ts +63 -0
- package/dist/prompt-references/referenceMenuPlacement.js +66 -0
- package/dist/prompt-references/referenceTokens.d.ts +175 -0
- package/dist/prompt-references/referenceTokens.js +332 -0
- package/dist/prompt-references/referenceTrigger.d.ts +52 -0
- package/dist/prompt-references/referenceTrigger.js +100 -0
- package/dist/prompt-references/referenceTypes.d.ts +38 -0
- package/dist/prompt-references/referenceTypes.js +4 -0
- package/dist/prompt-references/sentReferences.d.ts +50 -0
- package/dist/prompt-references/sentReferences.js +122 -0
- package/dist/styles/tokens.css +126 -1
- package/dist/textarea-overlay/index.d.ts +9 -0
- package/dist/textarea-overlay/index.js +7 -0
- package/dist/textarea-overlay/mirrorSegments.d.ts +31 -0
- package/dist/textarea-overlay/mirrorSegments.js +47 -0
- package/dist/textarea-overlay/mirrorSizing.d.ts +39 -0
- package/dist/textarea-overlay/mirrorSizing.js +40 -0
- package/dist/textarea-overlay/textareaOverlay.d.ts +25 -0
- package/dist/textarea-overlay/textareaOverlay.js +277 -0
- package/dist/utils/modalEnterKey.d.ts +139 -0
- package/dist/utils/modalEnterKey.js +276 -0
- package/dist/utils/modalFocusTrap.d.ts +7 -0
- package/dist/utils/modalFocusTrap.js +22 -0
- package/dist/utils/overlayMotion.d.ts +10 -0
- package/dist/utils/overlayMotion.js +12 -3
- package/dist/utils/reducedMotion.d.ts +9 -0
- package/dist/utils/reducedMotion.js +13 -0
- package/dist/utils/revealOpeningSection.d.ts +51 -0
- package/dist/utils/revealOpeningSection.js +109 -0
- package/package.json +16 -1
- package/dist/components/ui/number-stepper/index.d.ts +0 -3
- package/dist/components/ui/number-stepper/index.js +0 -3
- package/dist/components/ui/number-stepper/number-stepper.svelte +0 -212
- package/dist/components/ui/number-stepper/number-stepper.svelte.d.ts +0 -24
- package/dist/components/ui/number-stepper/numberStepperSteps.d.ts +0 -26
- package/dist/components/ui/number-stepper/numberStepperSteps.js +0 -45
|
@@ -2,10 +2,28 @@
|
|
|
2
2
|
Figma: Search Field (component set 189:1138, node 189:1138).
|
|
3
3
|
The same field works as a plain search control and as the textbox of a combobox: pass `inputAttributes` (role, aria-*,
|
|
4
4
|
autocomplete) from the parent; `type`, `value`, and the input `class` always come from this component so the look stays one.
|
|
5
|
+
|
|
6
|
+
Optional `recentSearchesKey` (a host-built localStorage key) shows up to three recent searches under the field when it is
|
|
7
|
+
focused and empty. With `recentSearchesKey` left at `''` the field matches the original Search Field (no recents panel).
|
|
8
|
+
|
|
9
|
+
Once a person has searched and then cleared the field (the clear button, or deleting every character), the list is not shown
|
|
10
|
+
again for the rest of that session (the life of the page, per key): they just did that search, so the list would only repeat
|
|
11
|
+
it. A reload starts a new session.
|
|
5
12
|
-->
|
|
6
13
|
<script lang="ts">
|
|
14
|
+
import { tick } from 'svelte';
|
|
7
15
|
import IconSearch from '@tabler/icons-svelte/icons/search';
|
|
8
16
|
import IconX from '@tabler/icons-svelte/icons/x';
|
|
17
|
+
import IconClock from '@tabler/icons-svelte/icons/clock';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
MIN_RECENT_SEARCH_LENGTH,
|
|
21
|
+
areRecentSearchesHiddenForSession,
|
|
22
|
+
clearRecentSearches,
|
|
23
|
+
hideRecentSearchesForSession,
|
|
24
|
+
readRecentSearches,
|
|
25
|
+
rememberRecentSearch
|
|
26
|
+
} from './recentSearches.js';
|
|
9
27
|
|
|
10
28
|
export let placeholder = 'Search…';
|
|
11
29
|
export let value = '';
|
|
@@ -24,9 +42,254 @@
|
|
|
24
42
|
export let inputElement: HTMLInputElement | null = null;
|
|
25
43
|
/** Spread first; this component’s `type`, `value`, and `class` are set after so they override clashing keys from the spread. */
|
|
26
44
|
export let inputAttributes: Record<string, unknown> = {};
|
|
45
|
+
/** localStorage key for recent searches; `''` keeps the field as today (no recents UI). */
|
|
46
|
+
export let recentSearchesKey = '';
|
|
47
|
+
export let recentSearchesLabel = 'Recent searches';
|
|
48
|
+
export let clearRecentSearchesLabel = 'Clear';
|
|
49
|
+
|
|
50
|
+
const instanceUid =
|
|
51
|
+
typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'
|
|
52
|
+
? crypto.randomUUID()
|
|
53
|
+
: `search-input-${Math.random().toString(36).slice(2)}`;
|
|
54
|
+
const recentListboxId = `search-input-recent-listbox-${instanceUid}`;
|
|
55
|
+
|
|
56
|
+
let recentPanelOpen = false;
|
|
57
|
+
let recentItems: string[] = [];
|
|
58
|
+
let activeRecentIndex = -1;
|
|
59
|
+
let recentPanelEl: HTMLDivElement | null = null;
|
|
60
|
+
let pointerHoverEnabled = true;
|
|
61
|
+
let clearButtonPressed = false;
|
|
62
|
+
|
|
63
|
+
function recentOptionId(index: number): string {
|
|
64
|
+
return `${recentListboxId}-opt-${index}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function openRecentPanelIfApplicable(): void {
|
|
68
|
+
// A person who searched and then cleared the field does not get the list back in this session: they just did the search
|
|
69
|
+
if (!recentSearchesKey || value.trim() || areRecentSearchesHiddenForSession(recentSearchesKey)) {
|
|
70
|
+
recentPanelOpen = false;
|
|
71
|
+
activeRecentIndex = -1;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
recentItems = readRecentSearches(recentSearchesKey);
|
|
75
|
+
recentPanelOpen = recentItems.length > 0;
|
|
76
|
+
activeRecentIndex = -1;
|
|
77
|
+
pointerHoverEnabled = true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function closeRecentPanel(): void {
|
|
81
|
+
recentPanelOpen = false;
|
|
82
|
+
activeRecentIndex = -1;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function chooseRecentTerm(term: string): void {
|
|
86
|
+
if (!inputElement) return;
|
|
87
|
+
inputElement.value = term;
|
|
88
|
+
value = term;
|
|
89
|
+
inputElement.dispatchEvent(new Event('input', { bubbles: true }));
|
|
90
|
+
rememberRecentSearch(recentSearchesKey, term);
|
|
91
|
+
closeRecentPanel();
|
|
92
|
+
inputElement.focus();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function handleRecentPointerMove(event: PointerEvent): void {
|
|
96
|
+
if (!pointerHoverEnabled) return;
|
|
97
|
+
const target = event.target as HTMLElement | null;
|
|
98
|
+
const row = target?.closest?.('[data-recent-index]') as HTMLElement | null;
|
|
99
|
+
if (!row || !recentPanelEl?.contains(row)) return;
|
|
100
|
+
const index = Number(row.dataset.recentIndex);
|
|
101
|
+
if (!Number.isNaN(index)) activeRecentIndex = index;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function handleRecentPanelPointerDown(event: PointerEvent): void {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function handleClearRecent(event: MouseEvent): void {
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
event.stopPropagation();
|
|
111
|
+
clearRecentSearches(recentSearchesKey);
|
|
112
|
+
recentItems = [];
|
|
113
|
+
closeRecentPanel();
|
|
114
|
+
inputElement?.focus();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function recordSearchIfEligible(term: string): void {
|
|
118
|
+
if (!recentSearchesKey) return;
|
|
119
|
+
const trimmed = term.trim();
|
|
120
|
+
if (trimmed.length < MIN_RECENT_SEARCH_LENGTH) return;
|
|
121
|
+
rememberRecentSearch(recentSearchesKey, trimmed);
|
|
122
|
+
if (recentPanelOpen) {
|
|
123
|
+
recentItems = readRecentSearches(recentSearchesKey);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function handleFocusInternal(event: FocusEvent): void {
|
|
128
|
+
openRecentPanelIfApplicable();
|
|
129
|
+
onFocus(event);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function handleBlurInternal(event: FocusEvent): void {
|
|
133
|
+
const related = event.relatedTarget as Node | null;
|
|
134
|
+
const focusStayedInRecents =
|
|
135
|
+
recentPanelEl && related != null && recentPanelEl.contains(related);
|
|
136
|
+
|
|
137
|
+
if (!clearButtonPressed && !focusStayedInRecents) {
|
|
138
|
+
recordSearchIfEligible(value);
|
|
139
|
+
}
|
|
140
|
+
if (!focusStayedInRecents) {
|
|
141
|
+
closeRecentPanel();
|
|
142
|
+
}
|
|
143
|
+
clearButtonPressed = false;
|
|
144
|
+
onBlur(event);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** What the field held when it was last looked at: going from words to nothing is a search that is over. */
|
|
148
|
+
let lastObservedValue = value;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Looks at the words of the field. When there were words and now there are none (the clear button, the keyboard, or a host that
|
|
152
|
+
* empties the field), the search is over, so the recent searches are hidden for the rest of the session and the open card closes.
|
|
153
|
+
* It runs from the input event and from the reactive statement below; the second look of the same change finds nothing new.
|
|
154
|
+
*/
|
|
155
|
+
function observeValue(nextValue: string): void {
|
|
156
|
+
const hadWords = lastObservedValue.trim().length > 0;
|
|
157
|
+
lastObservedValue = nextValue;
|
|
158
|
+
if (!recentSearchesKey) return;
|
|
159
|
+
if (hadWords && !nextValue.trim()) {
|
|
160
|
+
hideRecentSearchesForSession(recentSearchesKey);
|
|
161
|
+
closeRecentPanel();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function handleInputInternal(event: Event): void {
|
|
166
|
+
void onInput(event);
|
|
167
|
+
if (!recentSearchesKey) return;
|
|
168
|
+
observeValue(value);
|
|
169
|
+
if (value.trim()) {
|
|
170
|
+
closeRecentPanel();
|
|
171
|
+
} else if (typeof document !== 'undefined' && document.activeElement === inputElement) {
|
|
172
|
+
openRecentPanelIfApplicable();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function moveActiveRecent(delta: number, jump: 'start' | 'end' | null): void {
|
|
177
|
+
if (!recentItems.length) return;
|
|
178
|
+
if (jump === 'start') {
|
|
179
|
+
activeRecentIndex = 0;
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (jump === 'end') {
|
|
183
|
+
activeRecentIndex = recentItems.length - 1;
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (activeRecentIndex < 0) {
|
|
187
|
+
activeRecentIndex = delta > 0 ? 0 : recentItems.length - 1;
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const next = activeRecentIndex + delta;
|
|
191
|
+
if (next < 0) activeRecentIndex = recentItems.length - 1;
|
|
192
|
+
else if (next >= recentItems.length) activeRecentIndex = 0;
|
|
193
|
+
else activeRecentIndex = next;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function handleKeydownInternal(event: KeyboardEvent): void {
|
|
197
|
+
const trimmed = value.trim();
|
|
198
|
+
|
|
199
|
+
if (recentSearchesKey && recentPanelOpen) {
|
|
200
|
+
if (event.key === 'Escape') {
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
event.stopPropagation();
|
|
203
|
+
closeRecentPanel();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (event.key === 'Tab') {
|
|
207
|
+
closeRecentPanel();
|
|
208
|
+
} else if (event.key === 'ArrowDown') {
|
|
209
|
+
event.preventDefault();
|
|
210
|
+
pointerHoverEnabled = false;
|
|
211
|
+
moveActiveRecent(1, null);
|
|
212
|
+
return;
|
|
213
|
+
} else if (event.key === 'ArrowUp') {
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
pointerHoverEnabled = false;
|
|
216
|
+
moveActiveRecent(-1, null);
|
|
217
|
+
return;
|
|
218
|
+
} else if (event.key === 'Home') {
|
|
219
|
+
event.preventDefault();
|
|
220
|
+
pointerHoverEnabled = false;
|
|
221
|
+
moveActiveRecent(0, 'start');
|
|
222
|
+
return;
|
|
223
|
+
} else if (event.key === 'End') {
|
|
224
|
+
event.preventDefault();
|
|
225
|
+
pointerHoverEnabled = false;
|
|
226
|
+
moveActiveRecent(0, 'end');
|
|
227
|
+
return;
|
|
228
|
+
} else if (event.key === 'Enter' && activeRecentIndex >= 0) {
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
chooseRecentTerm(recentItems[activeRecentIndex]);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (event.key === 'Backspace' && !value) {
|
|
236
|
+
event.preventDefault();
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (event.key === 'Enter' && recentSearchesKey && trimmed.length >= MIN_RECENT_SEARCH_LENGTH) {
|
|
241
|
+
recordSearchIfEligible(value);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
onKeydown(event);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function handleClearClick(): Promise<void> {
|
|
248
|
+
// The button only exists while there are words: this is a search that is over, so the list of recent searches stays hidden for
|
|
249
|
+
// the rest of the session. It is hidden before the host empties the field, so that nothing can open it in between.
|
|
250
|
+
if (recentSearchesKey) {
|
|
251
|
+
hideRecentSearchesForSession(recentSearchesKey);
|
|
252
|
+
closeRecentPanel();
|
|
253
|
+
}
|
|
254
|
+
onClear();
|
|
255
|
+
try {
|
|
256
|
+
if (!recentSearchesKey) return;
|
|
257
|
+
// The clear button leaves with the words and would take the focus with it: the field takes the focus back, so the keyboard
|
|
258
|
+
// keeps working and a new search can start at once. The list stays closed (see above). A field without recent searches is
|
|
259
|
+
// left as it was.
|
|
260
|
+
await tick();
|
|
261
|
+
inputElement?.focus();
|
|
262
|
+
} catch (error) {
|
|
263
|
+
console.warn('[SearchInput] Could not give the field the focus back after clearing it', error);
|
|
264
|
+
} finally {
|
|
265
|
+
// This press is over: the next time the field loses the focus, its words count as a search again
|
|
266
|
+
clearButtonPressed = false;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
$: effectiveInputAttributes =
|
|
271
|
+
recentSearchesKey && recentPanelOpen
|
|
272
|
+
? {
|
|
273
|
+
...inputAttributes,
|
|
274
|
+
role: 'combobox',
|
|
275
|
+
'aria-expanded': true,
|
|
276
|
+
'aria-controls': recentListboxId,
|
|
277
|
+
'aria-autocomplete': 'list',
|
|
278
|
+
...(activeRecentIndex >= 0
|
|
279
|
+
? { 'aria-activedescendant': recentOptionId(activeRecentIndex) }
|
|
280
|
+
: {})
|
|
281
|
+
}
|
|
282
|
+
: inputAttributes;
|
|
283
|
+
|
|
284
|
+
$: if (recentSearchesKey && value.trim() && recentPanelOpen) {
|
|
285
|
+
closeRecentPanel();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// A host can change the words too (restoring a search from the address, emptying the field): every change is looked at
|
|
289
|
+
$: observeValue(value);
|
|
27
290
|
</script>
|
|
28
291
|
|
|
29
|
-
<div class="w-full {containerClass}">
|
|
292
|
+
<div class="w-full {recentSearchesKey ? 'relative' : ''} {containerClass}">
|
|
30
293
|
<div
|
|
31
294
|
class="group bg-accent duration-fast focus-within:bg-accent hover:bg-accent-hover relative flex h-9 w-full items-center gap-2 rounded-lg px-3 transition-colors"
|
|
32
295
|
>
|
|
@@ -37,22 +300,16 @@
|
|
|
37
300
|
aria-hidden="true"
|
|
38
301
|
/>
|
|
39
302
|
<input
|
|
40
|
-
{...
|
|
303
|
+
{...effectiveInputAttributes}
|
|
41
304
|
type="search"
|
|
42
305
|
bind:this={inputElement}
|
|
43
306
|
{placeholder}
|
|
44
307
|
bind:value
|
|
45
|
-
oninput={
|
|
46
|
-
onkeydown={
|
|
47
|
-
if (e.key === 'Backspace' && !value) {
|
|
48
|
-
e.preventDefault();
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
onKeydown(e);
|
|
52
|
-
}}
|
|
308
|
+
oninput={handleInputInternal}
|
|
309
|
+
onkeydown={handleKeydownInternal}
|
|
53
310
|
onpaste={onPaste}
|
|
54
|
-
onfocus={
|
|
55
|
-
onblur={
|
|
311
|
+
onfocus={handleFocusInternal}
|
|
312
|
+
onblur={handleBlurInternal}
|
|
56
313
|
class="text-body text-foreground placeholder:text-muted-foreground min-w-0 flex-1 border-0 bg-transparent focus:outline-hidden [&::-webkit-search-cancel-button]:hidden [&::-webkit-search-decoration]:hidden {inputClass}"
|
|
57
314
|
/>
|
|
58
315
|
{#if value}
|
|
@@ -60,10 +317,56 @@
|
|
|
60
317
|
type="button"
|
|
61
318
|
class="text-muted-foreground duration-fast hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background inline-flex size-4 shrink-0 items-center justify-center transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden"
|
|
62
319
|
aria-label={clearLabel}
|
|
63
|
-
|
|
320
|
+
onmousedown={() => {
|
|
321
|
+
clearButtonPressed = true;
|
|
322
|
+
}}
|
|
323
|
+
onclick={handleClearClick}
|
|
64
324
|
>
|
|
65
325
|
<IconX class="size-4 stroke-2" aria-hidden="true" />
|
|
66
326
|
</button>
|
|
67
327
|
{/if}
|
|
68
328
|
</div>
|
|
69
|
-
|
|
329
|
+
|
|
330
|
+
{#if recentSearchesKey && recentPanelOpen}
|
|
331
|
+
<!-- The card: a title with Clear on top, then the list of terms. Only the list is the listbox (its children are the options);
|
|
332
|
+
the Clear button sits outside it. A press on the card never takes the focus from the field. -->
|
|
333
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
334
|
+
<div
|
|
335
|
+
bind:this={recentPanelEl}
|
|
336
|
+
class="border-border bg-popover text-popover-foreground absolute start-0 top-full z-50 mt-1 w-full overflow-hidden rounded-xl border p-1 shadow-md"
|
|
337
|
+
onpointerdown={handleRecentPanelPointerDown}
|
|
338
|
+
onpointermove={handleRecentPointerMove}
|
|
339
|
+
>
|
|
340
|
+
<div class="flex items-center justify-between gap-2 px-2 py-1.5">
|
|
341
|
+
<span class="text-caption text-muted-foreground" aria-hidden="true">{recentSearchesLabel}</span>
|
|
342
|
+
<button
|
|
343
|
+
type="button"
|
|
344
|
+
class="text-caption text-muted-foreground hover:text-foreground rounded-md px-1.5 py-0.5 transition-colors focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-hidden"
|
|
345
|
+
onclick={handleClearRecent}
|
|
346
|
+
>
|
|
347
|
+
{clearRecentSearchesLabel}
|
|
348
|
+
</button>
|
|
349
|
+
</div>
|
|
350
|
+
<div id={recentListboxId} role="listbox" aria-label={recentSearchesLabel}>
|
|
351
|
+
{#each recentItems as term, index (term.toLowerCase())}
|
|
352
|
+
<button
|
|
353
|
+
type="button"
|
|
354
|
+
role="option"
|
|
355
|
+
id={recentOptionId(index)}
|
|
356
|
+
data-recent-index={index}
|
|
357
|
+
aria-selected={index === activeRecentIndex}
|
|
358
|
+
tabindex="-1"
|
|
359
|
+
class="flex min-h-9 w-full cursor-pointer items-center gap-2 rounded-lg px-2 text-start transition-colors duration-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background {index ===
|
|
360
|
+
activeRecentIndex
|
|
361
|
+
? 'bg-accent'
|
|
362
|
+
: 'hover:bg-accent'}"
|
|
363
|
+
onclick={() => chooseRecentTerm(term)}
|
|
364
|
+
>
|
|
365
|
+
<IconClock class="text-muted-foreground size-4 shrink-0 stroke-2" aria-hidden="true" />
|
|
366
|
+
<span class="text-body truncate">{term}</span>
|
|
367
|
+
</button>
|
|
368
|
+
{/each}
|
|
369
|
+
</div>
|
|
370
|
+
</div>
|
|
371
|
+
{/if}
|
|
372
|
+
</div>
|
|
@@ -25,6 +25,9 @@ declare const SearchInput: $$__sveltets_2_IsomorphicComponent<{
|
|
|
25
25
|
clearLabel?: string;
|
|
26
26
|
/** Bindable ref to the native input (e.g. combobox controllers call focus()). */ inputElement?: HTMLInputElement | null;
|
|
27
27
|
/** Spread first; this component’s `type`, `value`, and `class` are set after so they override clashing keys from the spread. */ inputAttributes?: Record<string, unknown>;
|
|
28
|
+
/** localStorage key for recent searches; `''` keeps the field as today (no recents UI). */ recentSearchesKey?: string;
|
|
29
|
+
recentSearchesLabel?: string;
|
|
30
|
+
clearRecentSearchesLabel?: string;
|
|
28
31
|
}, {
|
|
29
32
|
[evt: string]: CustomEvent<any>;
|
|
30
33
|
}, {}, {}, string>;
|
|
@@ -14,6 +14,10 @@ export interface SearchInputProps {
|
|
|
14
14
|
clearLabel?: string;
|
|
15
15
|
inputElement?: HTMLInputElement | null;
|
|
16
16
|
inputAttributes?: Record<string, unknown>;
|
|
17
|
+
/** localStorage key for recent searches; empty string disables the feature. */
|
|
18
|
+
recentSearchesKey?: string;
|
|
19
|
+
recentSearchesLabel?: string;
|
|
20
|
+
clearRecentSearchesLabel?: string;
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
export default class SearchInput extends SvelteComponent<SearchInputProps> {}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** How many recent terms we keep per storage key. */
|
|
2
|
+
export declare const RECENT_SEARCHES_LIMIT = 3;
|
|
3
|
+
/** Shorter trimmed terms are not stored or shown. */
|
|
4
|
+
export declare const MIN_RECENT_SEARCH_LENGTH = 2;
|
|
5
|
+
/** Returns the stored list for `key`, newest first. Never throws. */
|
|
6
|
+
export declare function readRecentSearches(key: string): string[];
|
|
7
|
+
/** Adds `term` to the stored list (newest first, case-insensitive dedupe). Returns the new list. Never throws. */
|
|
8
|
+
export declare function rememberRecentSearch(key: string, term: string): string[];
|
|
9
|
+
/** Clears the stored list for `key`. Never throws. */
|
|
10
|
+
export declare function clearRecentSearches(key: string): void;
|
|
11
|
+
/** Hides the recent searches of `key` for the rest of this session (they stay stored). Never throws. */
|
|
12
|
+
export declare function hideRecentSearchesForSession(key: string): void;
|
|
13
|
+
/** True while the recent searches of `key` are hidden for this session. */
|
|
14
|
+
export declare function areRecentSearchesHiddenForSession(key: string): boolean;
|
|
15
|
+
/** Test-only: reset in-memory fallback, the keys hidden for the session, and log latch. */
|
|
16
|
+
export declare function __resetRecentSearchesTestState(): void;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/** How many recent terms we keep per storage key. */
|
|
2
|
+
export const RECENT_SEARCHES_LIMIT = 3;
|
|
3
|
+
/** Shorter trimmed terms are not stored or shown. */
|
|
4
|
+
export const MIN_RECENT_SEARCH_LENGTH = 2;
|
|
5
|
+
const STORAGE_VERSION = 1;
|
|
6
|
+
const MAX_TERM_LENGTH = 80;
|
|
7
|
+
/** When localStorage is unusable, fall back to memory for the rest of the page. */
|
|
8
|
+
const memoryFallback = new Map();
|
|
9
|
+
let loggedStorageFailure = false;
|
|
10
|
+
function logStorageFailureOnce(error) {
|
|
11
|
+
if (loggedStorageFailure)
|
|
12
|
+
return;
|
|
13
|
+
loggedStorageFailure = true;
|
|
14
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
15
|
+
console.warn(`[SearchInput] recent searches storage unavailable: ${detail}`);
|
|
16
|
+
}
|
|
17
|
+
function normalizeTerm(raw) {
|
|
18
|
+
const trimmed = raw.trim();
|
|
19
|
+
if (trimmed.length < MIN_RECENT_SEARCH_LENGTH)
|
|
20
|
+
return null;
|
|
21
|
+
if (trimmed.length <= MAX_TERM_LENGTH)
|
|
22
|
+
return trimmed;
|
|
23
|
+
return trimmed.slice(0, MAX_TERM_LENGTH);
|
|
24
|
+
}
|
|
25
|
+
function sanitizeItems(items) {
|
|
26
|
+
if (!Array.isArray(items))
|
|
27
|
+
return [];
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const entry of items) {
|
|
30
|
+
if (typeof entry !== 'string')
|
|
31
|
+
continue;
|
|
32
|
+
const normalized = normalizeTerm(entry);
|
|
33
|
+
if (normalized)
|
|
34
|
+
out.push(normalized);
|
|
35
|
+
}
|
|
36
|
+
return out.slice(0, RECENT_SEARCHES_LIMIT);
|
|
37
|
+
}
|
|
38
|
+
function parseStored(raw) {
|
|
39
|
+
if (!raw)
|
|
40
|
+
return [];
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(raw);
|
|
43
|
+
if (!parsed || typeof parsed !== 'object' || parsed.v !== STORAGE_VERSION)
|
|
44
|
+
return [];
|
|
45
|
+
return sanitizeItems(parsed.items);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function readFromLocalStorage(key) {
|
|
52
|
+
if (typeof window === 'undefined')
|
|
53
|
+
return null;
|
|
54
|
+
try {
|
|
55
|
+
return parseStored(window.localStorage.getItem(key));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logStorageFailureOnce(error);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function writeToLocalStorage(key, items) {
|
|
63
|
+
if (typeof window === 'undefined')
|
|
64
|
+
return false;
|
|
65
|
+
try {
|
|
66
|
+
const payload = { v: STORAGE_VERSION, items };
|
|
67
|
+
window.localStorage.setItem(key, JSON.stringify(payload));
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
logStorageFailureOnce(error);
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function removeFromLocalStorage(key) {
|
|
76
|
+
if (typeof window === 'undefined')
|
|
77
|
+
return;
|
|
78
|
+
try {
|
|
79
|
+
window.localStorage.removeItem(key);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
logStorageFailureOnce(error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function dedupeMoveToFront(items, term) {
|
|
86
|
+
const lower = term.toLowerCase();
|
|
87
|
+
const without = items.filter((item) => item.toLowerCase() !== lower);
|
|
88
|
+
return [term, ...without].slice(0, RECENT_SEARCHES_LIMIT);
|
|
89
|
+
}
|
|
90
|
+
/** Returns the stored list for `key`, newest first. Never throws. */
|
|
91
|
+
export function readRecentSearches(key) {
|
|
92
|
+
if (!key || typeof window === 'undefined')
|
|
93
|
+
return [];
|
|
94
|
+
const fromStorage = readFromLocalStorage(key);
|
|
95
|
+
if (fromStorage !== null)
|
|
96
|
+
return fromStorage;
|
|
97
|
+
return [...(memoryFallback.get(key) ?? [])];
|
|
98
|
+
}
|
|
99
|
+
/** Adds `term` to the stored list (newest first, case-insensitive dedupe). Returns the new list. Never throws. */
|
|
100
|
+
export function rememberRecentSearch(key, term) {
|
|
101
|
+
if (!key || typeof window === 'undefined')
|
|
102
|
+
return [];
|
|
103
|
+
const normalized = normalizeTerm(term);
|
|
104
|
+
if (!normalized)
|
|
105
|
+
return readRecentSearches(key);
|
|
106
|
+
const current = readRecentSearches(key);
|
|
107
|
+
const next = dedupeMoveToFront(current, normalized);
|
|
108
|
+
if (!writeToLocalStorage(key, next)) {
|
|
109
|
+
memoryFallback.set(key, next);
|
|
110
|
+
}
|
|
111
|
+
return next;
|
|
112
|
+
}
|
|
113
|
+
/** Clears the stored list for `key`. Never throws. */
|
|
114
|
+
export function clearRecentSearches(key) {
|
|
115
|
+
if (!key || typeof window === 'undefined')
|
|
116
|
+
return;
|
|
117
|
+
removeFromLocalStorage(key);
|
|
118
|
+
memoryFallback.delete(key);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The keys whose recent searches stay hidden for the rest of this session. A session is the life of the page: the set lives in
|
|
122
|
+
* memory only, so a reload (or a new tab) starts a new one. It is filled when a person searched and then cleared the field:
|
|
123
|
+
* a list of what they searched would only repeat what they just did.
|
|
124
|
+
*/
|
|
125
|
+
const keysHiddenForSession = new Set();
|
|
126
|
+
/** Hides the recent searches of `key` for the rest of this session (they stay stored). Never throws. */
|
|
127
|
+
export function hideRecentSearchesForSession(key) {
|
|
128
|
+
if (!key)
|
|
129
|
+
return;
|
|
130
|
+
keysHiddenForSession.add(key);
|
|
131
|
+
}
|
|
132
|
+
/** True while the recent searches of `key` are hidden for this session. */
|
|
133
|
+
export function areRecentSearchesHiddenForSession(key) {
|
|
134
|
+
return Boolean(key) && keysHiddenForSession.has(key);
|
|
135
|
+
}
|
|
136
|
+
/** Test-only: reset in-memory fallback, the keys hidden for the session, and log latch. */
|
|
137
|
+
export function __resetRecentSearchesTestState() {
|
|
138
|
+
memoryFallback.clear();
|
|
139
|
+
keysHiddenForSession.clear();
|
|
140
|
+
loggedStorageFailure = false;
|
|
141
|
+
}
|
|
@@ -3,15 +3,19 @@
|
|
|
3
3
|
import type { WithElementRef } from 'bits-ui';
|
|
4
4
|
import type { HTMLAnchorAttributes, HTMLButtonAttributes } from 'svelte/elements';
|
|
5
5
|
|
|
6
|
+
// Keyboard focus is drawn as the hover fill, with no ring (owner, 18 Nov 2026: "remove the focus ring around the sidebar
|
|
7
|
+
// elements"). The ring showed up on a row the moment a page was reloaded with the settings dialog open, because the dialog
|
|
8
|
+
// put the focus on its first row. A row that has the focus still looks different from its neighbours, so a person who
|
|
9
|
+
// moves with the keyboard can see where they are, but nothing is drawn around it.
|
|
6
10
|
export const navRowVariants = tv({
|
|
7
|
-
base: 'group/nav-row relative before:absolute before:inset-x-0 before:-inset-y-px flex h-8 w-full min-w-0 items-center gap-2 rounded-lg py-1.5 ps-2 pe-2 text-start transition-colors duration-fast focus-visible:outline-hidden
|
|
11
|
+
base: 'group/nav-row relative before:absolute before:inset-x-0 before:-inset-y-px flex h-8 w-full min-w-0 items-center gap-2 rounded-lg py-1.5 ps-2 pe-2 text-start transition-colors duration-fast focus-visible:outline-hidden active:bg-accent-hover disabled:pointer-events-none disabled:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:stroke-2',
|
|
8
12
|
variants: {
|
|
9
13
|
active: {
|
|
10
14
|
true: 'bg-sidebar-accent text-sidebar-accent-foreground text-body-medium active:bg-accent-hover',
|
|
11
15
|
// The inactive row carries its own type style (14/20 regular, Figma Nav Row): without it the label took the size
|
|
12
16
|
// of whatever it sat in (16px in a dialog), bigger than the active row's 14/20 medium.
|
|
13
17
|
false:
|
|
14
|
-
'text-body text-muted-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-accent-hover active:text-sidebar-accent-foreground'
|
|
18
|
+
'text-body text-muted-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:bg-sidebar-accent focus-visible:text-sidebar-accent-foreground active:bg-accent-hover active:text-sidebar-accent-foreground'
|
|
15
19
|
}
|
|
16
20
|
},
|
|
17
21
|
defaultVariants: {
|
|
@@ -19,8 +23,23 @@
|
|
|
19
23
|
}
|
|
20
24
|
});
|
|
21
25
|
|
|
26
|
+
/**
|
|
27
|
+
* The filled pill of `trailingVariant="badge"`: the badge a phone draws on an app icon. A solid destructive (red) fill with the
|
|
28
|
+
* number in white, a circle for one digit (`min-w-5` is as wide as the 20px height) and a pill for more (`px-1.5`). It is
|
|
29
|
+
* the design system's Badge (`destructive`) at the size of a counter, so a count that wants attention stands out from the
|
|
30
|
+
* muted text of a count that only informs.
|
|
31
|
+
*/
|
|
32
|
+
export const navRowBadgeClass =
|
|
33
|
+
'inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full bg-destructive px-1.5 text-label-small text-destructive-foreground tabular-nums';
|
|
34
|
+
|
|
35
|
+
/** The muted count to the right of a row (the default): it informs, it does not ask for attention. */
|
|
36
|
+
export const navRowTrailingTextClass = 'text-caption text-muted-foreground shrink-0 tabular-nums';
|
|
37
|
+
|
|
22
38
|
export type NavRowVisualState = 'default' | 'hover' | 'pressed' | 'active' | 'focus' | 'disabled';
|
|
23
39
|
|
|
40
|
+
/** How the text on the right of the row is drawn: muted text (a count that informs) or a filled badge (a count that asks for attention). */
|
|
41
|
+
export type NavRowTrailingVariant = 'text' | 'badge';
|
|
42
|
+
|
|
24
43
|
export type NavRowProps = WithElementRef<HTMLButtonAttributes> &
|
|
25
44
|
WithElementRef<HTMLAnchorAttributes> & {
|
|
26
45
|
ref?: HTMLAnchorElement | HTMLButtonElement | null;
|
|
@@ -32,6 +51,16 @@
|
|
|
32
51
|
showIcon?: boolean;
|
|
33
52
|
showTrailing?: boolean;
|
|
34
53
|
trailing?: string;
|
|
54
|
+
/**
|
|
55
|
+
* `text` (default): muted caption. `badge`: a filled pill like the unread count on a phone's app icon, for a number that
|
|
56
|
+
* wants to be noticed (the unread count of the Inbox).
|
|
57
|
+
*/
|
|
58
|
+
trailingVariant?: NavRowTrailingVariant;
|
|
59
|
+
/**
|
|
60
|
+
* What a screen reader says for the trailing text when the text alone says too little: a badge that shows "3" is "3 unread".
|
|
61
|
+
* When it is set the visible text is hidden from assistive technology and this is read instead.
|
|
62
|
+
*/
|
|
63
|
+
trailingAccessibleLabel?: string;
|
|
35
64
|
/** Showcase-only forced visual state (CSS `:hover` / `:focus-visible` otherwise). */
|
|
36
65
|
visualState?: NavRowVisualState;
|
|
37
66
|
};
|
|
@@ -52,6 +81,8 @@
|
|
|
52
81
|
showIcon = true,
|
|
53
82
|
showTrailing = false,
|
|
54
83
|
trailing = '',
|
|
84
|
+
trailingVariant = 'text',
|
|
85
|
+
trailingAccessibleLabel = undefined,
|
|
55
86
|
visualState = undefined,
|
|
56
87
|
icon,
|
|
57
88
|
iconComponent = undefined,
|
|
@@ -73,12 +104,28 @@
|
|
|
73
104
|
if (!visualState || visualState === 'default' || visualState === 'active') return '';
|
|
74
105
|
if (visualState === 'hover') return 'bg-sidebar-accent text-sidebar-accent-foreground';
|
|
75
106
|
if (visualState === 'pressed') return 'bg-accent-hover text-sidebar-accent-foreground';
|
|
76
|
-
|
|
77
|
-
|
|
107
|
+
// Keyboard focus is the hover fill: no ring is drawn around a sidebar row (see the note above `navRowVariants`)
|
|
108
|
+
if (visualState === 'focus') return 'bg-sidebar-accent text-sidebar-accent-foreground';
|
|
78
109
|
return '';
|
|
79
110
|
});
|
|
80
111
|
</script>
|
|
81
112
|
|
|
113
|
+
<!-- The text on the right of the row, in both the link and the button form of the row -->
|
|
114
|
+
{#snippet trailingContent()}
|
|
115
|
+
{#if showTrailing && trailing}
|
|
116
|
+
{#if trailingVariant === 'badge'}
|
|
117
|
+
<span class={navRowBadgeClass} data-nav-row-badge="">
|
|
118
|
+
<span aria-hidden={trailingAccessibleLabel ? 'true' : undefined}>{trailing}</span>
|
|
119
|
+
{#if trailingAccessibleLabel}
|
|
120
|
+
<span class="sr-only">{trailingAccessibleLabel}</span>
|
|
121
|
+
{/if}
|
|
122
|
+
</span>
|
|
123
|
+
{:else}
|
|
124
|
+
<span class={navRowTrailingTextClass}>{trailing}</span>
|
|
125
|
+
{/if}
|
|
126
|
+
{/if}
|
|
127
|
+
{/snippet}
|
|
128
|
+
|
|
82
129
|
{#if href && !isDisabled}
|
|
83
130
|
<a
|
|
84
131
|
bind:this={ref}
|
|
@@ -99,9 +146,7 @@
|
|
|
99
146
|
</span>
|
|
100
147
|
{/if}
|
|
101
148
|
<span class="min-w-0 flex-1 truncate">{label}</span>
|
|
102
|
-
{
|
|
103
|
-
<span class="text-caption text-muted-foreground shrink-0 tabular-nums">{trailing}</span>
|
|
104
|
-
{/if}
|
|
149
|
+
{@render trailingContent()}
|
|
105
150
|
{@render children?.()}
|
|
106
151
|
</a>
|
|
107
152
|
{:else}
|
|
@@ -124,9 +169,7 @@
|
|
|
124
169
|
</span>
|
|
125
170
|
{/if}
|
|
126
171
|
<span class="min-w-0 flex-1 truncate">{label}</span>
|
|
127
|
-
{
|
|
128
|
-
<span class="text-caption text-muted-foreground shrink-0 tabular-nums">{trailing}</span>
|
|
129
|
-
{/if}
|
|
172
|
+
{@render trailingContent()}
|
|
130
173
|
{@render children?.()}
|
|
131
174
|
</button>
|
|
132
175
|
{/if}
|