@widgetic/design-system 0.5.35 → 0.5.36
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/dist/components/chat/Composer.svelte +62 -13
- package/dist/components/chat/Composer.svelte.d.ts +6 -0
- package/dist/components/filters/FilterByButton.svelte +82 -0
- package/dist/components/filters/FilterByButton.svelte.d.ts +20 -0
- package/dist/components/filters/SortDirectionButton.svelte +61 -0
- package/dist/components/filters/SortDirectionButton.svelte.d.ts +12 -0
- package/dist/components/filters/index.d.ts +2 -0
- package/dist/components/filters/index.js +2 -0
- package/dist/components/ic/browser/BrowserInputController.svelte +2 -2
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +3 -0
- package/dist/components/navigation/Breadcrumbs.svelte +36 -4
- package/dist/components/navigation/breadcrumbSlideIn.d.ts +21 -0
- package/dist/components/navigation/breadcrumbSlideIn.js +44 -0
- package/dist/components/shell/AppShell.svelte +1 -1
- package/dist/components/shell/WidgetRow.svelte +10 -1
- package/dist/components/toast/ToasterModal.svelte +1 -1
- package/dist/components/tooltip/HintTooltip.svelte +48 -0
- package/dist/components/tooltip/HintTooltip.svelte.d.ts +18 -0
- package/dist/components/ui/number-stepper/index.d.ts +3 -0
- package/dist/components/ui/number-stepper/index.js +3 -0
- package/dist/components/ui/number-stepper/number-stepper.svelte +212 -0
- package/dist/components/ui/number-stepper/number-stepper.svelte.d.ts +24 -0
- package/dist/components/ui/number-stepper/numberStepperSteps.d.ts +26 -0
- package/dist/components/ui/number-stepper/numberStepperSteps.js +45 -0
- package/dist/components/ui/tooltip/tooltip-content.svelte +13 -2
- package/dist/components/ui/tooltip/tooltip-content.svelte.d.ts +5 -1
- package/package.json +1 -1
|
@@ -38,6 +38,12 @@
|
|
|
38
38
|
leading?: Snippet;
|
|
39
39
|
trailing?: Snippet;
|
|
40
40
|
attachments?: Snippet;
|
|
41
|
+
/** Bounce + white tooltip on the send control (publish-before-send nudge). */
|
|
42
|
+
sendAttention?: {
|
|
43
|
+
bounce: boolean;
|
|
44
|
+
hintOpen: boolean;
|
|
45
|
+
hintText: string;
|
|
46
|
+
};
|
|
41
47
|
};
|
|
42
48
|
</script>
|
|
43
49
|
|
|
@@ -50,6 +56,7 @@
|
|
|
50
56
|
import { cn } from '../../utils.js';
|
|
51
57
|
import { Button } from '../ui/button/index.js';
|
|
52
58
|
import { IconButton } from '../ui/icon-button/index.js';
|
|
59
|
+
import HintTooltip from '../tooltip/HintTooltip.svelte';
|
|
53
60
|
import * as DropdownMenu from '../ui/dropdown-menu';
|
|
54
61
|
import { canSendText, clampTextareaHeight, shouldSendOnKeyDown } from './composerLogic.js';
|
|
55
62
|
import {
|
|
@@ -84,6 +91,7 @@
|
|
|
84
91
|
leading,
|
|
85
92
|
trailing,
|
|
86
93
|
attachments,
|
|
94
|
+
sendAttention,
|
|
87
95
|
...restProps
|
|
88
96
|
}: ComposerProps = $props();
|
|
89
97
|
|
|
@@ -217,19 +225,60 @@
|
|
|
217
225
|
{#if trailing}
|
|
218
226
|
{@render trailing()}
|
|
219
227
|
{/if}
|
|
220
|
-
<
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
228
|
+
<HintTooltip
|
|
229
|
+
content={sendAttention?.hintOpen && sendAttention.hintText ? sendAttention.hintText : ' '}
|
|
230
|
+
side="top"
|
|
231
|
+
align="end"
|
|
232
|
+
delayDuration={0}
|
|
233
|
+
open={sendAttention?.hintOpen === true}
|
|
225
234
|
>
|
|
226
|
-
{#
|
|
227
|
-
<
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
235
|
+
{#snippet trigger({ props })}
|
|
236
|
+
<IconButton
|
|
237
|
+
{...props}
|
|
238
|
+
variant="primary"
|
|
239
|
+
data-testid="composer-send"
|
|
240
|
+
class={sendAttention?.bounce ? 'wc-composer-send-bounce' : undefined}
|
|
241
|
+
label={busy ? messages.stop : messages.send}
|
|
242
|
+
disabled={!sendEnabled}
|
|
243
|
+
onclick={handleSend}
|
|
244
|
+
>
|
|
245
|
+
{#if busy}
|
|
246
|
+
<IconPlayerStop class="size-4 stroke-2" aria-hidden="true" />
|
|
247
|
+
{:else if sendIcon === 'arrow-up'}
|
|
248
|
+
<IconArrowUp class="size-4 stroke-2" aria-hidden="true" />
|
|
249
|
+
{:else}
|
|
250
|
+
<IconSend class="size-4 stroke-2" aria-hidden="true" />
|
|
251
|
+
{/if}
|
|
252
|
+
</IconButton>
|
|
253
|
+
{/snippet}
|
|
254
|
+
</HintTooltip>
|
|
234
255
|
</div>
|
|
235
256
|
</div>
|
|
257
|
+
|
|
258
|
+
<style>
|
|
259
|
+
@keyframes wc-composer-send-bounce-keyframes {
|
|
260
|
+
0%,
|
|
261
|
+
100% {
|
|
262
|
+
transform: translateY(0);
|
|
263
|
+
}
|
|
264
|
+
30% {
|
|
265
|
+
transform: translateY(-6px);
|
|
266
|
+
}
|
|
267
|
+
55% {
|
|
268
|
+
transform: translateY(0);
|
|
269
|
+
}
|
|
270
|
+
75% {
|
|
271
|
+
transform: translateY(-3px);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
:global(.wc-composer-send-bounce) {
|
|
276
|
+
animation: wc-composer-send-bounce-keyframes 700ms ease-out 1;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
@media (prefers-reduced-motion: reduce) {
|
|
280
|
+
:global(.wc-composer-send-bounce) {
|
|
281
|
+
animation: none;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
</style>
|
|
@@ -31,6 +31,12 @@ export type ComposerProps = HTMLAttributes<HTMLDivElement> & {
|
|
|
31
31
|
leading?: Snippet;
|
|
32
32
|
trailing?: Snippet;
|
|
33
33
|
attachments?: Snippet;
|
|
34
|
+
/** Bounce + white tooltip on the send control (publish-before-send nudge). */
|
|
35
|
+
sendAttention?: {
|
|
36
|
+
bounce: boolean;
|
|
37
|
+
hintOpen: boolean;
|
|
38
|
+
hintText: string;
|
|
39
|
+
};
|
|
34
40
|
};
|
|
35
41
|
declare const Composer: import("svelte").Component<ComposerProps, {}, "ref" | "value" | "busy">;
|
|
36
42
|
type Composer = ReturnType<typeof Composer>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Figma: Files / Root (291:1973) — filter and sort triggers are outline pills h-32, 8px radius; menus 292:2741 / 292:2948.
|
|
3
|
+
Shared by file browser (filter/sort) and dashboard project filter (feat/r12 dash/fb).
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import type { Component } from 'svelte';
|
|
7
|
+
import IconChevronDown from '@tabler/icons-svelte/icons/chevron-down';
|
|
8
|
+
import IconCheck from '@tabler/icons-svelte/icons/check';
|
|
9
|
+
import { cn } from '../../utils.js';
|
|
10
|
+
import * as DropdownMenu from '../ui/dropdown-menu';
|
|
11
|
+
|
|
12
|
+
export type FilterByOption = { value: string; label: string; icon?: Component };
|
|
13
|
+
|
|
14
|
+
let {
|
|
15
|
+
label,
|
|
16
|
+
options,
|
|
17
|
+
value = $bindable(''),
|
|
18
|
+
onValueChange,
|
|
19
|
+
disabled = false,
|
|
20
|
+
class: className,
|
|
21
|
+
menuClass,
|
|
22
|
+
contentAlign = 'start'
|
|
23
|
+
}: {
|
|
24
|
+
label: string;
|
|
25
|
+
options: FilterByOption[];
|
|
26
|
+
value?: string;
|
|
27
|
+
onValueChange?: (next: string) => void;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
class?: string;
|
|
30
|
+
/** Classes on the dropdown panel (width, etc.). */
|
|
31
|
+
menuClass?: string;
|
|
32
|
+
contentAlign?: 'start' | 'center' | 'end';
|
|
33
|
+
} = $props();
|
|
34
|
+
|
|
35
|
+
const selectedLabel = $derived(
|
|
36
|
+
options.find((option) => option.value === value)?.label ?? options[0]?.label ?? ''
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
function handleSelect(next: string) {
|
|
40
|
+
if (next === value) return;
|
|
41
|
+
value = next;
|
|
42
|
+
onValueChange?.(next);
|
|
43
|
+
}
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<DropdownMenu.Root>
|
|
47
|
+
<DropdownMenu.Trigger
|
|
48
|
+
{disabled}
|
|
49
|
+
class={cn(
|
|
50
|
+
'group flex h-8 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-lg border border-input bg-background px-3 text-start transition-colors duration-fast hover:bg-accent focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',
|
|
51
|
+
className
|
|
52
|
+
)}
|
|
53
|
+
>
|
|
54
|
+
<span class="text-body text-muted-foreground whitespace-nowrap">{label}</span>
|
|
55
|
+
<span class="whitespace-nowrap text-body-medium text-foreground">{selectedLabel}</span>
|
|
56
|
+
<IconChevronDown
|
|
57
|
+
class="size-4 shrink-0 stroke-2 opacity-50 transition-transform duration-base group-data-[state=open]:rotate-180"
|
|
58
|
+
aria-hidden="true"
|
|
59
|
+
/>
|
|
60
|
+
</DropdownMenu.Trigger>
|
|
61
|
+
<DropdownMenu.Content side="bottom" align={contentAlign} class={cn('w-[12.5rem] min-w-0', menuClass)}>
|
|
62
|
+
{#each options as option (option.value)}
|
|
63
|
+
{@const OptionIcon = option.icon}
|
|
64
|
+
<DropdownMenu.Item
|
|
65
|
+
class="relative flex w-full items-center gap-2 rounded-lg px-2 py-1.5 ps-8 {value === option.value
|
|
66
|
+
? 'bg-brand-subtle'
|
|
67
|
+
: ''} data-highlighted:bg-accent"
|
|
68
|
+
onclick={() => handleSelect(option.value)}
|
|
69
|
+
>
|
|
70
|
+
<span class="absolute start-2 flex size-4 items-center justify-center">
|
|
71
|
+
{#if value === option.value}
|
|
72
|
+
<IconCheck class="size-4 stroke-2 text-foreground" aria-hidden="true" />
|
|
73
|
+
{/if}
|
|
74
|
+
</span>
|
|
75
|
+
{#if OptionIcon}
|
|
76
|
+
<OptionIcon class="size-4 shrink-0 stroke-2" aria-hidden="true" />
|
|
77
|
+
{/if}
|
|
78
|
+
<span class="text-body min-w-0 flex-1 truncate">{option.label}</span>
|
|
79
|
+
</DropdownMenu.Item>
|
|
80
|
+
{/each}
|
|
81
|
+
</DropdownMenu.Content>
|
|
82
|
+
</DropdownMenu.Root>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Component } from 'svelte';
|
|
2
|
+
export type FilterByOption = {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
icon?: Component;
|
|
6
|
+
};
|
|
7
|
+
type $$ComponentProps = {
|
|
8
|
+
label: string;
|
|
9
|
+
options: FilterByOption[];
|
|
10
|
+
value?: string;
|
|
11
|
+
onValueChange?: (next: string) => void;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
class?: string;
|
|
14
|
+
/** Classes on the dropdown panel (width, etc.). */
|
|
15
|
+
menuClass?: string;
|
|
16
|
+
contentAlign?: 'start' | 'center' | 'end';
|
|
17
|
+
};
|
|
18
|
+
declare const FilterByButton: Component<$$ComponentProps, {}, "value">;
|
|
19
|
+
type FilterByButton = ReturnType<typeof FilterByButton>;
|
|
20
|
+
export default FilterByButton;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Figma: Files / Root — 32×32 outline icon button beside sort (291:1973, x1088); tooltip is the white HintTooltip (A18).
|
|
3
|
+
-->
|
|
4
|
+
<script lang="ts">
|
|
5
|
+
import IconArrowDown from '@tabler/icons-svelte/icons/arrow-down';
|
|
6
|
+
import IconArrowUp from '@tabler/icons-svelte/icons/arrow-up';
|
|
7
|
+
import { cn } from '../../utils.js';
|
|
8
|
+
import { IconButton } from '../ui/icon-button';
|
|
9
|
+
import HintTooltip from '../tooltip/HintTooltip.svelte';
|
|
10
|
+
|
|
11
|
+
export type SortDirection = 'asc' | 'desc';
|
|
12
|
+
|
|
13
|
+
let {
|
|
14
|
+
direction,
|
|
15
|
+
onDirectionChange,
|
|
16
|
+
disabled = false,
|
|
17
|
+
ariaLabel,
|
|
18
|
+
tooltipLabel,
|
|
19
|
+
class: className
|
|
20
|
+
}: {
|
|
21
|
+
direction: SortDirection;
|
|
22
|
+
onDirectionChange?: (next: SortDirection) => void;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
ariaLabel?: string;
|
|
25
|
+
tooltipLabel?: string;
|
|
26
|
+
class?: string;
|
|
27
|
+
} = $props();
|
|
28
|
+
|
|
29
|
+
const resolvedAriaLabel = $derived(ariaLabel ?? tooltipLabel ?? (direction === 'asc' ? 'Sort descending' : 'Sort ascending'));
|
|
30
|
+
const resolvedTooltip = $derived(
|
|
31
|
+
tooltipLabel ?? (direction === 'asc' ? 'Sort descending' : 'Sort ascending')
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
function handleClick() {
|
|
35
|
+
const next: SortDirection = direction === 'asc' ? 'desc' : 'asc';
|
|
36
|
+
onDirectionChange?.(next);
|
|
37
|
+
}
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<HintTooltip content={resolvedTooltip} side="top" align="end" sideOffset={8}>
|
|
41
|
+
{#snippet trigger({ props })}
|
|
42
|
+
<IconButton
|
|
43
|
+
{...props}
|
|
44
|
+
variant="outline"
|
|
45
|
+
size="default"
|
|
46
|
+
class={cn('size-8', className)}
|
|
47
|
+
label={resolvedAriaLabel}
|
|
48
|
+
{disabled}
|
|
49
|
+
onclick={(event: MouseEvent) => {
|
|
50
|
+
(props.onclick as ((event: MouseEvent) => void) | undefined)?.(event);
|
|
51
|
+
handleClick();
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
{#if direction === 'asc'}
|
|
55
|
+
<IconArrowUp class="size-4 stroke-2" aria-hidden="true" />
|
|
56
|
+
{:else}
|
|
57
|
+
<IconArrowDown class="size-4 stroke-2" aria-hidden="true" />
|
|
58
|
+
{/if}
|
|
59
|
+
</IconButton>
|
|
60
|
+
{/snippet}
|
|
61
|
+
</HintTooltip>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type SortDirection = 'asc' | 'desc';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
direction: SortDirection;
|
|
4
|
+
onDirectionChange?: (next: SortDirection) => void;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
ariaLabel?: string;
|
|
7
|
+
tooltipLabel?: string;
|
|
8
|
+
class?: string;
|
|
9
|
+
};
|
|
10
|
+
declare const SortDirectionButton: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
11
|
+
type SortDirectionButton = ReturnType<typeof SortDirectionButton>;
|
|
12
|
+
export default SortDirectionButton;
|
|
@@ -287,10 +287,10 @@
|
|
|
287
287
|
<Tooltip.Content
|
|
288
288
|
side={/* rtl-ok: the help text is put where the pointer is, by the style below */ 'right'}
|
|
289
289
|
sideOffset={5}
|
|
290
|
-
class="
|
|
290
|
+
class="z-[99999]"
|
|
291
291
|
style="position: fixed; left: {mouseX + 20}px; top: {mouseY}px; z-index: 999999; /* rtl-ok: the help text follows the pointer, measured from the left edge of the page */"
|
|
292
292
|
>
|
|
293
|
-
<p class="text-
|
|
293
|
+
<p class="text-caption">{header.helpText}</p>
|
|
294
294
|
</Tooltip.Content>
|
|
295
295
|
</Tooltip.Root>
|
|
296
296
|
</Tooltip.Provider>
|
|
@@ -8,6 +8,8 @@ export { Composer, type ComposerMessages, type ComposerProps, Message, type Mess
|
|
|
8
8
|
export { CreatorBar, CanvasBoardStatusChip } from './creator';
|
|
9
9
|
export type { CanvasBoardStatusChipVariant } from './creator';
|
|
10
10
|
export { ColorPicker, type ColorPickerMessages, type ColorPickerProps, normalizeHex, hexToHsv, hsvToHex, type Hsv } from './color-picker';
|
|
11
|
+
export { FilterByButton, SortDirectionButton, type FilterByOption, type SortDirection } from './filters';
|
|
12
|
+
export { default as HintTooltip } from './tooltip/HintTooltip.svelte';
|
|
11
13
|
export { default as DebugGrid } from './debug-grid/DebugGrid.svelte';
|
|
12
14
|
export { FontPicker, type FontPickerMessages, type FontPickerProps, filterFonts, fontFamilyCss, type FontPickerFont } from './font-picker';
|
|
13
15
|
export { default as BrowserInputController } from './ic/browser/BrowserInputController.svelte';
|
|
@@ -54,6 +56,7 @@ export { Skeleton } from './ui/skeleton';
|
|
|
54
56
|
export { Slider, type SliderProps } from './ui/slider';
|
|
55
57
|
export { Toaster, toast } from './ui/sonner';
|
|
56
58
|
export { StepperButton } from './ui/stepper-button';
|
|
59
|
+
export { NumberStepper } from './ui/number-stepper';
|
|
57
60
|
export { Switch } from './ui/switch';
|
|
58
61
|
export * as Table from './ui/table';
|
|
59
62
|
export * as Tabs from './ui/tabs';
|
package/dist/components/index.js
CHANGED
|
@@ -8,6 +8,8 @@ export { default as WScrollArea } from './WScrollArea.svelte';
|
|
|
8
8
|
export { Composer, Message, ActivityRow, OptionRow, TaskRow, ScrollToBottom, canSendText, clampTextareaHeight, shouldSendOnKeyDown, ChatHeader, PlanCard, QuestionCard, canSubmitQuestion, formatQuestionStep, isFirstQuestion, isLastQuestion, moveFocusedIndex, optionItemRole, primaryQuestionLabel, selectionRole, toggleOption, SuggestionCard } from './chat';
|
|
9
9
|
export { CreatorBar, CanvasBoardStatusChip } from './creator';
|
|
10
10
|
export { ColorPicker, normalizeHex, hexToHsv, hsvToHex } from './color-picker';
|
|
11
|
+
export { FilterByButton, SortDirectionButton } from './filters';
|
|
12
|
+
export { default as HintTooltip } from './tooltip/HintTooltip.svelte';
|
|
11
13
|
export { default as DebugGrid } from './debug-grid/DebugGrid.svelte';
|
|
12
14
|
export { FontPicker, filterFonts, fontFamilyCss } from './font-picker';
|
|
13
15
|
export { default as BrowserInputController } from './ic/browser/BrowserInputController.svelte';
|
|
@@ -54,6 +56,7 @@ export { Skeleton } from './ui/skeleton';
|
|
|
54
56
|
export { Slider } from './ui/slider';
|
|
55
57
|
export { Toaster, toast } from './ui/sonner';
|
|
56
58
|
export { StepperButton } from './ui/stepper-button';
|
|
59
|
+
export { NumberStepper } from './ui/number-stepper';
|
|
57
60
|
export { Switch } from './ui/switch';
|
|
58
61
|
export * as Table from './ui/table';
|
|
59
62
|
export * as Tabs from './ui/tabs';
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import type { BreadcrumbsProps } from './types.js';
|
|
17
17
|
import { dirForUserText, useTextDirection } from '../textDirection.js';
|
|
18
18
|
import { breadcrumbsAvailableWidthPx } from './breadcrumbsAvailableWidth.js';
|
|
19
|
+
import { slideInFromStart } from './breadcrumbSlideIn.js';
|
|
19
20
|
|
|
20
21
|
// Environment Import
|
|
21
22
|
// import { browser } from '$app/environment';
|
|
@@ -74,6 +75,19 @@
|
|
|
74
75
|
let breadcrumbsContainer: HTMLElement;
|
|
75
76
|
let breadcrumbsPositioned = false;
|
|
76
77
|
let showLogs = false;
|
|
78
|
+
// The crumb of a folder just entered slides in a little. `slideTargetLength` is the path length that still owes
|
|
79
|
+
// the slide: the crumbs are drawn again once the folder has loaded, so the slide waits for its crumb.
|
|
80
|
+
let previousPathLength = -1;
|
|
81
|
+
let slideTargetLength = 0;
|
|
82
|
+
$: {
|
|
83
|
+
const pathLength = currentPath?.length ?? 0;
|
|
84
|
+
if (previousPathLength >= 0 && pathLength > previousPathLength) slideTargetLength = pathLength;
|
|
85
|
+
else if (pathLength < previousPathLength) slideTargetLength = 0;
|
|
86
|
+
previousPathLength = pathLength;
|
|
87
|
+
}
|
|
88
|
+
function markSlidePlayed() {
|
|
89
|
+
slideTargetLength = 0;
|
|
90
|
+
}
|
|
77
91
|
let showBackTooltip = false;
|
|
78
92
|
let showForwardTooltip = false;
|
|
79
93
|
// The text style and the gap between crumbs come from the Figma size of the crumbs
|
|
@@ -245,9 +259,10 @@
|
|
|
245
259
|
otherwise clips the tooltip at the header's bottom edge. -->
|
|
246
260
|
<Tooltip.Portal>
|
|
247
261
|
<Tooltip.Content
|
|
262
|
+
variant="inverse"
|
|
248
263
|
side="bottom"
|
|
249
264
|
sideOffset={6}
|
|
250
|
-
class="
|
|
265
|
+
class="text-caption z-[200000] rounded-lg px-2 py-1"
|
|
251
266
|
>
|
|
252
267
|
{backLabel}
|
|
253
268
|
</Tooltip.Content>
|
|
@@ -275,9 +290,10 @@
|
|
|
275
290
|
{#if showForwardTooltip}
|
|
276
291
|
<Tooltip.Portal>
|
|
277
292
|
<Tooltip.Content
|
|
293
|
+
variant="inverse"
|
|
278
294
|
side="bottom"
|
|
279
295
|
sideOffset={6}
|
|
280
|
-
class="
|
|
296
|
+
class="text-caption z-[200000] rounded-lg px-2 py-1"
|
|
281
297
|
>
|
|
282
298
|
{forwardLabel}
|
|
283
299
|
</Tooltip.Content>
|
|
@@ -355,7 +371,15 @@
|
|
|
355
371
|
<Breadcrumb.Separator class="text-muted-foreground shrink-0 [&>svg]:size-4" />
|
|
356
372
|
<Breadcrumb.Item class="shrink-0">
|
|
357
373
|
{#if index === itemsToShow - 2}
|
|
358
|
-
<span
|
|
374
|
+
<span
|
|
375
|
+
dir={nameDirection}
|
|
376
|
+
class="{crumbTextClass} text-foreground"
|
|
377
|
+
aria-current="page"
|
|
378
|
+
use:slideInFromStart={{
|
|
379
|
+
play: slideTargetLength === currentPath.length,
|
|
380
|
+
onPlayed: markSlidePlayed
|
|
381
|
+
}}
|
|
382
|
+
>
|
|
359
383
|
{currentPathNames[currentPath.length - 1]}
|
|
360
384
|
</span>
|
|
361
385
|
{:else}
|
|
@@ -384,7 +408,15 @@
|
|
|
384
408
|
<Breadcrumb.Separator class="text-muted-foreground shrink-0 [&>svg]:size-4" />
|
|
385
409
|
<Breadcrumb.Item class="shrink-0">
|
|
386
410
|
{#if index === currentPath.length - 1}
|
|
387
|
-
<span
|
|
411
|
+
<span
|
|
412
|
+
dir={nameDirection}
|
|
413
|
+
class="{crumbTextClass} text-foreground"
|
|
414
|
+
aria-current="page"
|
|
415
|
+
use:slideInFromStart={{
|
|
416
|
+
play: slideTargetLength === currentPath.length,
|
|
417
|
+
onPlayed: markSlidePlayed
|
|
418
|
+
}}
|
|
419
|
+
>
|
|
388
420
|
{currentPathNames[index]}
|
|
389
421
|
</span>
|
|
390
422
|
{:else}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The crumb that appears when a folder is entered slides in a little, from the side the path starts on,
|
|
3
|
+
* the way a panel slides into a screen. It is the one to click to go back, so it should be noticed.
|
|
4
|
+
*/
|
|
5
|
+
/** How far the crumb starts from its place, in px. "Just a bit": it is a nudge, not a ride across the header. */
|
|
6
|
+
export declare const CRUMB_SLIDE_DISTANCE_PX = 16;
|
|
7
|
+
/** Long enough to be seen, short enough to stay out of the way (the overlays of the system use 200ms). */
|
|
8
|
+
export declare const CRUMB_SLIDE_DURATION_MS = 280;
|
|
9
|
+
export declare const CRUMB_SLIDE_EASING = "cubic-bezier(0.2, 0.7, 0.2, 1)";
|
|
10
|
+
export type CrumbSlideParams = {
|
|
11
|
+
/** Only the crumb of a folder just entered plays; every other crumb that appears stays still. */
|
|
12
|
+
play: boolean;
|
|
13
|
+
/** Called once the slide was started, so the page can forget it (a later redraw must not play it again). */
|
|
14
|
+
onPlayed?: () => void;
|
|
15
|
+
};
|
|
16
|
+
/** True when the person asked their system for less motion. */
|
|
17
|
+
export declare function prefersReducedMotion(): boolean;
|
|
18
|
+
/** The keyframes of the slide: from the start side of the path (left in English, right in Arabic) to the place. */
|
|
19
|
+
export declare function crumbSlideKeyframes(direction: 'ltr' | 'rtl'): Keyframe[];
|
|
20
|
+
/** Svelte action: slide the crumb in when `play` is true and motion is allowed. */
|
|
21
|
+
export declare function slideInFromStart(node: HTMLElement, params: CrumbSlideParams): {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The crumb that appears when a folder is entered slides in a little, from the side the path starts on,
|
|
3
|
+
* the way a panel slides into a screen. It is the one to click to go back, so it should be noticed.
|
|
4
|
+
*/
|
|
5
|
+
/** How far the crumb starts from its place, in px. "Just a bit": it is a nudge, not a ride across the header. */
|
|
6
|
+
export const CRUMB_SLIDE_DISTANCE_PX = 16;
|
|
7
|
+
/** Long enough to be seen, short enough to stay out of the way (the overlays of the system use 200ms). */
|
|
8
|
+
export const CRUMB_SLIDE_DURATION_MS = 280;
|
|
9
|
+
export const CRUMB_SLIDE_EASING = 'cubic-bezier(0.2, 0.7, 0.2, 1)';
|
|
10
|
+
/** True when the person asked their system for less motion. */
|
|
11
|
+
export function prefersReducedMotion() {
|
|
12
|
+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
|
|
13
|
+
return false;
|
|
14
|
+
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
15
|
+
}
|
|
16
|
+
/** The keyframes of the slide: from the start side of the path (left in English, right in Arabic) to the place. */
|
|
17
|
+
export function crumbSlideKeyframes(direction) {
|
|
18
|
+
const startOffset = direction === 'rtl' ? CRUMB_SLIDE_DISTANCE_PX : -CRUMB_SLIDE_DISTANCE_PX;
|
|
19
|
+
return [
|
|
20
|
+
{ transform: `translateX(${startOffset}px)`, opacity: 0 },
|
|
21
|
+
{ transform: 'translateX(0)', opacity: 1 }
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
/** Svelte action: slide the crumb in when `play` is true and motion is allowed. */
|
|
25
|
+
export function slideInFromStart(node, params) {
|
|
26
|
+
try {
|
|
27
|
+
if (params?.play) {
|
|
28
|
+
params.onPlayed?.();
|
|
29
|
+
if (!prefersReducedMotion() && typeof node.animate === 'function') {
|
|
30
|
+
const direction = getComputedStyle(node).direction === 'rtl' ? 'rtl' : 'ltr';
|
|
31
|
+
node.animate(crumbSlideKeyframes(direction), {
|
|
32
|
+
duration: CRUMB_SLIDE_DURATION_MS,
|
|
33
|
+
easing: CRUMB_SLIDE_EASING,
|
|
34
|
+
fill: 'backwards'
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
// A missing animation must never break the path.
|
|
41
|
+
console.warn('[Breadcrumbs] The slide-in of the new crumb could not start', error);
|
|
42
|
+
}
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
const contentSurfaceClass = $derived(
|
|
30
30
|
contentSurface === 'plain'
|
|
31
31
|
? 'border-transparent bg-transparent shadow-none rounded-none'
|
|
32
|
-
: 'rounded-panel
|
|
32
|
+
: 'rounded-panel bg-background shadow-none'
|
|
33
33
|
);
|
|
34
34
|
</script>
|
|
35
35
|
|
|
@@ -113,7 +113,16 @@
|
|
|
113
113
|
|
|
114
114
|
{#if showBadge}
|
|
115
115
|
{#if badgeTone === 'draft'}
|
|
116
|
-
|
|
116
|
+
<!-- Selected: the row is light green, so the grey chip would stand out. It takes the green of the selection ring. -->
|
|
117
|
+
<Badge
|
|
118
|
+
variant="default"
|
|
119
|
+
class={cn(
|
|
120
|
+
'shrink-0 max-sm:hidden',
|
|
121
|
+
isSelected
|
|
122
|
+
? 'border-brand text-brand-foreground bg-transparent'
|
|
123
|
+
: 'bg-muted text-muted-foreground'
|
|
124
|
+
)}>{badgeLabel}</Badge
|
|
125
|
+
>
|
|
117
126
|
{:else}
|
|
118
127
|
<Badge variant="secondary" showDot class="shrink-0 max-sm:hidden">{badgeLabel}</Badge>
|
|
119
128
|
{/if}
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
'-close-button !absolute !end-1.5 !top-1/2 !z-10 !-translate-y-1/2 !flex !size-7 !shrink-0 !items-center !justify-center !rounded-full !border-0 !bg-transparent !p-0 !text-inherit !transition-colors hover:!bg-current/20 focus-visible:!bg-current/20 focus-visible:!outline-hidden [&_svg]:!size-3.5 [&_svg]:!stroke-2',
|
|
140
140
|
info: '!border-border !bg-popover !text-popover-foreground',
|
|
141
141
|
success:
|
|
142
|
-
'!border-transparent !bg-
|
|
142
|
+
'!border-transparent !bg-brand !text-brand-foreground [&>[data-icon]]:!hidden',
|
|
143
143
|
warning: '!border-transparent !bg-warning !text-primary-foreground [&>[data-icon]]:!hidden',
|
|
144
144
|
error:
|
|
145
145
|
'!border-transparent !bg-destructive !text-destructive-foreground [&>[data-icon]]:!hidden'
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
White tooltip wrapper for icon buttons (upload help, sort direction, editor hints).
|
|
3
|
+
Provides Tooltip.Provider + Portal so callers only supply the trigger snippet and the copy.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import type { Snippet } from 'svelte';
|
|
7
|
+
import * as Tooltip from '../ui/tooltip';
|
|
8
|
+
import { cn } from '../../utils.js';
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
content,
|
|
12
|
+
side = 'top',
|
|
13
|
+
align = 'center',
|
|
14
|
+
sideOffset = 8,
|
|
15
|
+
delayDuration = 200,
|
|
16
|
+
/** When set, controls visibility (e.g. programmatic nudge on Send). */
|
|
17
|
+
open,
|
|
18
|
+
class: className,
|
|
19
|
+
contentClass,
|
|
20
|
+
trigger
|
|
21
|
+
}: {
|
|
22
|
+
content: string;
|
|
23
|
+
side?: 'top' | 'right' | 'bottom' | 'left';
|
|
24
|
+
align?: 'start' | 'center' | 'end';
|
|
25
|
+
sideOffset?: number;
|
|
26
|
+
delayDuration?: number;
|
|
27
|
+
open?: boolean;
|
|
28
|
+
class?: string;
|
|
29
|
+
contentClass?: string;
|
|
30
|
+
/** Receives bits-ui trigger props (spread onto IconButton / Button). */
|
|
31
|
+
trigger: Snippet<[{ props: Record<string, unknown> }]>;
|
|
32
|
+
} = $props();
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<Tooltip.Provider {delayDuration}>
|
|
36
|
+
<Tooltip.Root open={open}>
|
|
37
|
+
<Tooltip.Trigger class={cn('inline-flex', className)}>
|
|
38
|
+
{#snippet child({ props }: { props: Record<string, unknown> })}
|
|
39
|
+
{@render trigger({ props })}
|
|
40
|
+
{/snippet}
|
|
41
|
+
</Tooltip.Trigger>
|
|
42
|
+
<Tooltip.Portal>
|
|
43
|
+
<Tooltip.Content {side} {align} {sideOffset} class={contentClass}>
|
|
44
|
+
<p class="text-caption whitespace-pre-line break-words">{content}</p>
|
|
45
|
+
</Tooltip.Content>
|
|
46
|
+
</Tooltip.Portal>
|
|
47
|
+
</Tooltip.Root>
|
|
48
|
+
</Tooltip.Provider>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
content: string;
|
|
4
|
+
side?: 'top' | 'right' | 'bottom' | 'left';
|
|
5
|
+
align?: 'start' | 'center' | 'end';
|
|
6
|
+
sideOffset?: number;
|
|
7
|
+
delayDuration?: number;
|
|
8
|
+
open?: boolean;
|
|
9
|
+
class?: string;
|
|
10
|
+
contentClass?: string;
|
|
11
|
+
/** Receives bits-ui trigger props (spread onto IconButton / Button). */
|
|
12
|
+
trigger: Snippet<[{
|
|
13
|
+
props: Record<string, unknown>;
|
|
14
|
+
}]>;
|
|
15
|
+
};
|
|
16
|
+
declare const HintTooltip: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
17
|
+
type HintTooltip = ReturnType<typeof HintTooltip>;
|
|
18
|
+
export default HintTooltip;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
<!-- Figma: IC Number (Editor / Input controls): an accent surface, the value at the start (12 px in), the minus and the plus at the end.
|
|
2
|
+
The editor's `NumberControls` is the same control with more behaviour (angle wrap, drag in the value area); this is the part
|
|
3
|
+
that other packages need (the canvas panel), so that they stop drawing a plain number beside two loose stepper buttons.
|
|
4
|
+
|
|
5
|
+
The value can be typed (it is kept inside min and max when the field loses the focus or Enter is pressed, Escape puts the
|
|
6
|
+
old number back), stepped with the arrow keys, or stepped with the two buttons, which repeat while they are held.
|
|
7
|
+
`value` is `null` when the things selected disagree: the field then shows `mixedText` and the first step starts from `fallbackValue`. -->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { onDestroy } from "svelte";
|
|
10
|
+
import { cn } from "../../../utils.js";
|
|
11
|
+
import { StepperButton } from "../stepper-button";
|
|
12
|
+
import { clampToLimits, decimalsOf, parseTypedNumber, steppedNumber } from "./numberStepperSteps.js";
|
|
13
|
+
|
|
14
|
+
/** The pause before a held button starts to repeat, and the time between two repeats (ms): the editor's numbers. */
|
|
15
|
+
const HOLD_DELAY_MS = 400;
|
|
16
|
+
const REPEAT_INTERVAL_MS = 80;
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
/** The current number, or `null` when the selection has no single value (the field shows `mixedText`). */
|
|
20
|
+
value: number | null;
|
|
21
|
+
/** Called with the new number each time it changes: a step, a typed number committed, an arrow key. */
|
|
22
|
+
onChange: (nextValue: number) => void;
|
|
23
|
+
min?: number;
|
|
24
|
+
max?: number;
|
|
25
|
+
/** How far one press moves the value. Its decimals are the decimals the value is kept to. */
|
|
26
|
+
step?: number;
|
|
27
|
+
/** The name of the field, for screen readers ("Stroke width"). */
|
|
28
|
+
label: string;
|
|
29
|
+
/** The names of the two buttons ("Decrease", "Increase"); they are announced with the name of the field. */
|
|
30
|
+
decreaseLabel: string;
|
|
31
|
+
increaseLabel: string;
|
|
32
|
+
/** What the field shows when `value` is `null`. */
|
|
33
|
+
mixedText?: string;
|
|
34
|
+
/** Where the first step starts from when `value` is `null`. */
|
|
35
|
+
fallbackValue?: number;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
class?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let {
|
|
41
|
+
value,
|
|
42
|
+
onChange,
|
|
43
|
+
min,
|
|
44
|
+
max,
|
|
45
|
+
step = 1,
|
|
46
|
+
label,
|
|
47
|
+
decreaseLabel,
|
|
48
|
+
increaseLabel,
|
|
49
|
+
mixedText = "–",
|
|
50
|
+
fallbackValue = 0,
|
|
51
|
+
disabled = false,
|
|
52
|
+
class: className
|
|
53
|
+
}: Props = $props();
|
|
54
|
+
|
|
55
|
+
/** The text in the field while the person types; `null` when the field shows the value itself. */
|
|
56
|
+
let typedText = $state<string | null>(null);
|
|
57
|
+
let pressedStepper = $state<"increment" | "decrement" | null>(null);
|
|
58
|
+
|
|
59
|
+
let autoRepeatTimer: ReturnType<typeof setTimeout> | null = null;
|
|
60
|
+
let autoRepeatInterval: ReturnType<typeof setInterval> | null = null;
|
|
61
|
+
|
|
62
|
+
const decimals = $derived(decimalsOf(step));
|
|
63
|
+
const shownText = $derived(typedText ?? (value === null ? mixedText : String(value)));
|
|
64
|
+
const isAtMin = $derived(value !== null && min !== undefined && value <= min);
|
|
65
|
+
const isAtMax = $derived(value !== null && max !== undefined && value >= max);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* One step. Returns false when nothing was applied because the value is at a limit, so that a held button stops there.
|
|
69
|
+
*/
|
|
70
|
+
function applyStep(direction: 1 | -1): boolean {
|
|
71
|
+
try {
|
|
72
|
+
const current = value ?? fallbackValue;
|
|
73
|
+
const next = steppedNumber(current, direction * step, { min, max }, step);
|
|
74
|
+
typedText = null;
|
|
75
|
+
if (next === value) {
|
|
76
|
+
stopAutoRepeat();
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
onChange(next);
|
|
80
|
+
return true;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error("[NumberStepper] a step could not be applied", error);
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function startAutoRepeat(direction: 1 | -1, event: MouseEvent): void {
|
|
88
|
+
// Only the main button steps: a right or middle click must not
|
|
89
|
+
if (event.button !== 0 || disabled) return;
|
|
90
|
+
stopAutoRepeat();
|
|
91
|
+
pressedStepper = direction === 1 ? "increment" : "decrement";
|
|
92
|
+
|
|
93
|
+
// A button that turns disabled at a limit gets no mouseup: the release is watched on the window too
|
|
94
|
+
window.addEventListener("mouseup", stopAutoRepeat);
|
|
95
|
+
window.addEventListener("blur", stopAutoRepeat);
|
|
96
|
+
|
|
97
|
+
// At a limit there is nothing to hold
|
|
98
|
+
if (!applyStep(direction)) return;
|
|
99
|
+
|
|
100
|
+
autoRepeatTimer = setTimeout(() => {
|
|
101
|
+
if (pressedStepper === null) return;
|
|
102
|
+
autoRepeatInterval = setInterval(() => {
|
|
103
|
+
if (pressedStepper !== null) applyStep(direction);
|
|
104
|
+
}, REPEAT_INTERVAL_MS);
|
|
105
|
+
}, HOLD_DELAY_MS);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** A button pressed with the keyboard (Enter or Space) clicks without a mouse down: `detail` is 0 then. */
|
|
109
|
+
function handleStepperClick(direction: 1 | -1, event: MouseEvent): void {
|
|
110
|
+
if (event.detail !== 0) return;
|
|
111
|
+
applyStep(direction);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function stopAutoRepeat(): void {
|
|
115
|
+
if (typeof window !== "undefined") {
|
|
116
|
+
window.removeEventListener("mouseup", stopAutoRepeat);
|
|
117
|
+
window.removeEventListener("blur", stopAutoRepeat);
|
|
118
|
+
}
|
|
119
|
+
if (autoRepeatTimer !== null) clearTimeout(autoRepeatTimer);
|
|
120
|
+
if (autoRepeatInterval !== null) clearInterval(autoRepeatInterval);
|
|
121
|
+
autoRepeatTimer = null;
|
|
122
|
+
autoRepeatInterval = null;
|
|
123
|
+
pressedStepper = null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Keeps what was typed to the characters of a number; the number itself is read when the field is committed. */
|
|
127
|
+
function handleInput(event: Event): void {
|
|
128
|
+
const input = event.currentTarget as HTMLInputElement;
|
|
129
|
+
const allowed = min !== undefined && min >= 0 ? /[^\d.,]/g : /[^\d.,-]/g;
|
|
130
|
+
const cleaned = input.value.replace(allowed, "");
|
|
131
|
+
if (cleaned !== input.value) input.value = cleaned;
|
|
132
|
+
typedText = cleaned;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Reads what was typed: a number inside the limits becomes the value, anything else puts the old value back. */
|
|
136
|
+
function commitTypedText(): void {
|
|
137
|
+
if (typedText === null) return;
|
|
138
|
+
try {
|
|
139
|
+
const parsed = parseTypedNumber(typedText, { min, max }, decimals);
|
|
140
|
+
typedText = null;
|
|
141
|
+
if (parsed !== null && parsed !== value) onChange(clampToLimits(parsed, { min, max }));
|
|
142
|
+
} catch (error) {
|
|
143
|
+
typedText = null;
|
|
144
|
+
console.error("[NumberStepper] the typed number could not be read", error);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function handleKeyDown(event: KeyboardEvent): void {
|
|
149
|
+
if (event.metaKey || event.ctrlKey || event.altKey) return;
|
|
150
|
+
// The page around the field has shortcuts of its own (delete, the arrow keys move the selection): the field keeps its keys
|
|
151
|
+
event.stopPropagation();
|
|
152
|
+
if (event.key === "ArrowUp") {
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
applyStep(1);
|
|
155
|
+
} else if (event.key === "ArrowDown") {
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
applyStep(-1);
|
|
158
|
+
} else if (event.key === "Enter") {
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
commitTypedText();
|
|
161
|
+
(event.currentTarget as HTMLInputElement).blur();
|
|
162
|
+
} else if (event.key === "Escape") {
|
|
163
|
+
typedText = null;
|
|
164
|
+
(event.currentTarget as HTMLInputElement).blur();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
onDestroy(stopAutoRepeat);
|
|
169
|
+
</script>
|
|
170
|
+
|
|
171
|
+
<!-- The group gives the two buttons the name of their row ("Stroke width: Decrease"). -->
|
|
172
|
+
<div
|
|
173
|
+
role="group"
|
|
174
|
+
aria-label={label}
|
|
175
|
+
data-disabled={disabled ? "true" : undefined}
|
|
176
|
+
class={cn(
|
|
177
|
+
"flex h-9 min-w-0 items-center gap-1 rounded-lg bg-accent pe-1 transition-colors duration-fast hover:bg-accent-hover focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 focus-within:ring-offset-background data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50",
|
|
178
|
+
className
|
|
179
|
+
)}
|
|
180
|
+
>
|
|
181
|
+
<input
|
|
182
|
+
type="text"
|
|
183
|
+
inputmode={decimals > 0 ? "decimal" : "numeric"}
|
|
184
|
+
autocomplete="off"
|
|
185
|
+
aria-label={label}
|
|
186
|
+
{disabled}
|
|
187
|
+
value={shownText}
|
|
188
|
+
oninput={handleInput}
|
|
189
|
+
onblur={commitTypedText}
|
|
190
|
+
onfocus={(event) => event.currentTarget.select()}
|
|
191
|
+
onkeydown={handleKeyDown}
|
|
192
|
+
class="h-full min-w-0 flex-1 bg-transparent ps-3 text-body tabular-nums outline-hidden"
|
|
193
|
+
/>
|
|
194
|
+
<StepperButton
|
|
195
|
+
kind="minus"
|
|
196
|
+
label={decreaseLabel}
|
|
197
|
+
disabled={disabled || isAtMin}
|
|
198
|
+
data-pressed={pressedStepper === "decrement" ? "true" : undefined}
|
|
199
|
+
onmousedown={(event) => startAutoRepeat(-1, event)}
|
|
200
|
+
onmouseup={stopAutoRepeat}
|
|
201
|
+
onclick={(event) => handleStepperClick(-1, event)}
|
|
202
|
+
/>
|
|
203
|
+
<StepperButton
|
|
204
|
+
kind="plus"
|
|
205
|
+
label={increaseLabel}
|
|
206
|
+
disabled={disabled || isAtMax}
|
|
207
|
+
data-pressed={pressedStepper === "increment" ? "true" : undefined}
|
|
208
|
+
onmousedown={(event) => startAutoRepeat(1, event)}
|
|
209
|
+
onmouseup={stopAutoRepeat}
|
|
210
|
+
onclick={(event) => handleStepperClick(1, event)}
|
|
211
|
+
/>
|
|
212
|
+
</div>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** The current number, or `null` when the selection has no single value (the field shows `mixedText`). */
|
|
3
|
+
value: number | null;
|
|
4
|
+
/** Called with the new number each time it changes: a step, a typed number committed, an arrow key. */
|
|
5
|
+
onChange: (nextValue: number) => void;
|
|
6
|
+
min?: number;
|
|
7
|
+
max?: number;
|
|
8
|
+
/** How far one press moves the value. Its decimals are the decimals the value is kept to. */
|
|
9
|
+
step?: number;
|
|
10
|
+
/** The name of the field, for screen readers ("Stroke width"). */
|
|
11
|
+
label: string;
|
|
12
|
+
/** The names of the two buttons ("Decrease", "Increase"); they are announced with the name of the field. */
|
|
13
|
+
decreaseLabel: string;
|
|
14
|
+
increaseLabel: string;
|
|
15
|
+
/** What the field shows when `value` is `null`. */
|
|
16
|
+
mixedText?: string;
|
|
17
|
+
/** Where the first step starts from when `value` is `null`. */
|
|
18
|
+
fallbackValue?: number;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
class?: string;
|
|
21
|
+
}
|
|
22
|
+
declare const NumberStepper: import("svelte").Component<Props, {}, "">;
|
|
23
|
+
type NumberStepper = ReturnType<typeof NumberStepper>;
|
|
24
|
+
export default NumberStepper;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic of the number stepper (`number-stepper.svelte`), kept apart from the component so Node can test it.
|
|
3
|
+
*
|
|
4
|
+
* Same rules as the editor's `NumberControls`: one press moves the value by one step and keeps it inside the limits, and at a
|
|
5
|
+
* limit the result is the value itself, which tells the caller that there is nothing to apply (and nothing to repeat).
|
|
6
|
+
*/
|
|
7
|
+
export interface NumberStepLimits {
|
|
8
|
+
/** The lowest value; no limit when left out. */
|
|
9
|
+
min?: number;
|
|
10
|
+
/** The highest value; no limit when left out. */
|
|
11
|
+
max?: number;
|
|
12
|
+
}
|
|
13
|
+
/** How many decimals a step has (0.1 → 1, 5 → 0), so that 0.1 + 0.2 shows as 0.3 and not 0.30000000000000004. */
|
|
14
|
+
export declare function decimalsOf(step: number): number;
|
|
15
|
+
/** `value` kept between `min` and `max` (either may be left out). */
|
|
16
|
+
export declare function clampToLimits(value: number, { min, max }?: NumberStepLimits): number;
|
|
17
|
+
/**
|
|
18
|
+
* The value after one press of a stepper button (or one arrow key): `currentValue` moved by `adjustment`, rounded to the
|
|
19
|
+
* decimals of `precisionStep`, then kept inside the limits.
|
|
20
|
+
*/
|
|
21
|
+
export declare function steppedNumber(currentValue: number, adjustment: number, limits?: NumberStepLimits, precisionStep?: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* What a person typed in the field, as a number inside the limits, or `null` when it is not a number (an empty field, a lone
|
|
24
|
+
* minus sign, letters): the field then goes back to the value it had.
|
|
25
|
+
*/
|
|
26
|
+
export declare function parseTypedNumber(text: string, limits?: NumberStepLimits, decimals?: number): number | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic of the number stepper (`number-stepper.svelte`), kept apart from the component so Node can test it.
|
|
3
|
+
*
|
|
4
|
+
* Same rules as the editor's `NumberControls`: one press moves the value by one step and keeps it inside the limits, and at a
|
|
5
|
+
* limit the result is the value itself, which tells the caller that there is nothing to apply (and nothing to repeat).
|
|
6
|
+
*/
|
|
7
|
+
/** How many decimals a step has (0.1 → 1, 5 → 0), so that 0.1 + 0.2 shows as 0.3 and not 0.30000000000000004. */
|
|
8
|
+
export function decimalsOf(step) {
|
|
9
|
+
if (!Number.isFinite(step))
|
|
10
|
+
return 0;
|
|
11
|
+
const text = String(step);
|
|
12
|
+
const dot = text.indexOf('.');
|
|
13
|
+
return dot === -1 ? 0 : text.length - dot - 1;
|
|
14
|
+
}
|
|
15
|
+
/** `value` kept between `min` and `max` (either may be left out). */
|
|
16
|
+
export function clampToLimits(value, { min, max } = {}) {
|
|
17
|
+
let clamped = value;
|
|
18
|
+
if (min !== undefined && clamped < min)
|
|
19
|
+
clamped = min;
|
|
20
|
+
if (max !== undefined && clamped > max)
|
|
21
|
+
clamped = max;
|
|
22
|
+
return clamped;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The value after one press of a stepper button (or one arrow key): `currentValue` moved by `adjustment`, rounded to the
|
|
26
|
+
* decimals of `precisionStep`, then kept inside the limits.
|
|
27
|
+
*/
|
|
28
|
+
export function steppedNumber(currentValue, adjustment, limits = {}, precisionStep = Math.abs(adjustment)) {
|
|
29
|
+
const decimals = decimalsOf(precisionStep);
|
|
30
|
+
const moved = Number((currentValue + adjustment).toFixed(decimals));
|
|
31
|
+
return clampToLimits(moved, limits);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* What a person typed in the field, as a number inside the limits, or `null` when it is not a number (an empty field, a lone
|
|
35
|
+
* minus sign, letters): the field then goes back to the value it had.
|
|
36
|
+
*/
|
|
37
|
+
export function parseTypedNumber(text, limits = {}, decimals = 0) {
|
|
38
|
+
const trimmed = text.trim().replace(',', '.');
|
|
39
|
+
if (trimmed === '' || trimmed === '-' || trimmed === '.')
|
|
40
|
+
return null;
|
|
41
|
+
const parsed = Number(trimmed);
|
|
42
|
+
if (!Number.isFinite(parsed))
|
|
43
|
+
return null;
|
|
44
|
+
return clampToLimits(Number(parsed.toFixed(decimals)), limits);
|
|
45
|
+
}
|
|
@@ -16,8 +16,18 @@
|
|
|
16
16
|
ref = $bindable(null),
|
|
17
17
|
class: className,
|
|
18
18
|
sideOffset = 4,
|
|
19
|
+
variant = 'default',
|
|
19
20
|
...restProps
|
|
20
|
-
}: TooltipContentProps
|
|
21
|
+
}: TooltipContentProps & {
|
|
22
|
+
/** `default` is the white popover surface (editors, upload help). `inverse` is the dark pill (breadcrumbs nav). */
|
|
23
|
+
variant?: 'default' | 'inverse';
|
|
24
|
+
} = $props();
|
|
25
|
+
|
|
26
|
+
const variantClasses = {
|
|
27
|
+
default:
|
|
28
|
+
'bg-popover text-popover-foreground border border-border shadow-sm',
|
|
29
|
+
inverse: 'bg-inverse text-inverse-foreground border-transparent'
|
|
30
|
+
};
|
|
21
31
|
</script>
|
|
22
32
|
|
|
23
33
|
<TooltipPrimitive.Content
|
|
@@ -25,7 +35,8 @@
|
|
|
25
35
|
{sideOffset}
|
|
26
36
|
dir={$textDirection}
|
|
27
37
|
class={cn(
|
|
28
|
-
'
|
|
38
|
+
'text-caption animate-in fade-in-0 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 max-w-[min(18rem,calc(100vw-2rem))] overflow-hidden rounded-lg px-3 py-1.5 text-balance whitespace-normal',
|
|
39
|
+
variantClasses[variant],
|
|
29
40
|
overlayFloatingContentZClass,
|
|
30
41
|
className
|
|
31
42
|
)}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Tooltip as TooltipPrimitive } from "bits-ui";
|
|
2
2
|
export type TooltipContentProps = TooltipPrimitive.ContentProps;
|
|
3
|
-
|
|
3
|
+
type $$ComponentProps = TooltipContentProps & {
|
|
4
|
+
/** `default` is the white popover surface (editors, upload help). `inverse` is the dark pill (breadcrumbs nav). */
|
|
5
|
+
variant?: 'default' | 'inverse';
|
|
6
|
+
};
|
|
7
|
+
declare const TooltipContent: import("svelte").Component<$$ComponentProps, {}, "ref">;
|
|
4
8
|
type TooltipContent = ReturnType<typeof TooltipContent>;
|
|
5
9
|
export default TooltipContent;
|