@widgetic/design-system 0.5.24 → 0.5.26

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.
Files changed (71) hide show
  1. package/dist/components/CopyableHeader.svelte +45 -10
  2. package/dist/components/PasswordInput.svelte +2 -2
  3. package/dist/components/chat/ActivityRow.svelte +6 -6
  4. package/dist/components/chat/ChatHeader.svelte +5 -5
  5. package/dist/components/chat/Composer.svelte +2 -2
  6. package/dist/components/chat/Message.svelte +4 -4
  7. package/dist/components/chat/OptionRow.svelte +1 -1
  8. package/dist/components/chat/PlanCard.svelte +57 -4
  9. package/dist/components/chat/PlanCard.svelte.d.ts +15 -0
  10. package/dist/components/chat/ScrollToBottom.svelte +1 -1
  11. package/dist/components/chat/SuggestionCard.svelte +2 -2
  12. package/dist/components/chat/TaskRow.svelte +3 -3
  13. package/dist/components/index.d.ts +1 -1
  14. package/dist/components/index.js +1 -1
  15. package/dist/components/modals/BaseModal.svelte +1 -1
  16. package/dist/components/search-input/SearchInput.svelte +2 -2
  17. package/dist/components/shell/Banner.svelte +4 -4
  18. package/dist/components/shell/Link.svelte +1 -1
  19. package/dist/components/shell/Link.svelte.d.ts +2 -2
  20. package/dist/components/shell/NavRow.svelte +5 -2
  21. package/dist/components/shell/NavRow.svelte.d.ts +2 -2
  22. package/dist/components/shell/SettingsDialog.svelte +1 -27
  23. package/dist/components/shell/SettingsDialog.svelte.d.ts +0 -4
  24. package/dist/components/shell/WidgetRow.svelte.d.ts +1 -1
  25. package/dist/components/shell/index.d.ts +0 -1
  26. package/dist/components/shell/index.js +0 -1
  27. package/dist/components/toast/ToasterModal.svelte +2 -2
  28. package/dist/components/ui/accordion/accordion-content.svelte +1 -1
  29. package/dist/components/ui/accordion/accordion-trigger.svelte +1 -1
  30. package/dist/components/ui/alert/index.d.ts +2 -2
  31. package/dist/components/ui/alert/index.js +4 -1
  32. package/dist/components/ui/avatar/avatar.svelte +22 -3
  33. package/dist/components/ui/breadcrumb/breadcrumb-ellipsis.svelte +1 -1
  34. package/dist/components/ui/breadcrumb/breadcrumb-separator.svelte +1 -1
  35. package/dist/components/ui/button/button.svelte +1 -1
  36. package/dist/components/ui/button/button.svelte.d.ts +2 -2
  37. package/dist/components/ui/calendar/calendar-next-button.svelte +1 -1
  38. package/dist/components/ui/calendar/calendar-prev-button.svelte +1 -1
  39. package/dist/components/ui/calendar/calendar.svelte.d.ts +1 -1
  40. package/dist/components/ui/checkbox/checkbox.svelte +3 -3
  41. package/dist/components/ui/chip/chip.svelte +1 -1
  42. package/dist/components/ui/command/command-input.svelte +1 -1
  43. package/dist/components/ui/command/command-item.svelte +1 -1
  44. package/dist/components/ui/dialog/dialog-content.svelte +1 -1
  45. package/dist/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte +2 -2
  46. package/dist/components/ui/dropdown-menu/dropdown-menu-item.svelte +1 -1
  47. package/dist/components/ui/dropdown-menu/dropdown-menu-sub-trigger.svelte +2 -2
  48. package/dist/components/ui/icon-button/icon-button.svelte +1 -1
  49. package/dist/components/ui/icon-button/icon-button.svelte.d.ts +2 -2
  50. package/dist/components/ui/input-otp/input-otp-separator.svelte +1 -1
  51. package/dist/components/ui/radio-group/radio-group-item.svelte +1 -1
  52. package/dist/components/ui/range-calendar/range-calendar-next-button.svelte +1 -1
  53. package/dist/components/ui/range-calendar/range-calendar-prev-button.svelte +1 -1
  54. package/dist/components/ui/range-calendar/range-calendar.svelte.d.ts +1 -1
  55. package/dist/components/ui/select/select-content.svelte +134 -4
  56. package/dist/components/ui/select/select-item.svelte +9 -2
  57. package/dist/components/ui/select/select-scroll-down-button.svelte +1 -1
  58. package/dist/components/ui/select/select-scroll-up-button.svelte +1 -1
  59. package/dist/components/ui/select/select-trigger.svelte +3 -2
  60. package/dist/components/ui/stepper-button/stepper-button.svelte +9 -4
  61. package/dist/components/ui/stepper-button/stepper-button.svelte.d.ts +1 -0
  62. package/dist/components/ui/switch/switch.svelte +4 -1
  63. package/dist/components/ui/tag/tag.svelte +1 -1
  64. package/dist/components/ui/toggle/toggle.svelte +1 -1
  65. package/dist/components/ui/toggle/toggle.svelte.d.ts +2 -2
  66. package/dist/styles/tokens.css +25 -3
  67. package/dist/utils/inputModality.d.ts +16 -0
  68. package/dist/utils/inputModality.js +55 -0
  69. package/package.json +1 -1
  70. package/dist/components/shell/messages.d.ts +0 -7
  71. package/dist/components/shell/messages.js +0 -5
@@ -1,12 +1,24 @@
1
1
  <script lang="ts">
2
2
  import { Select as SelectPrimitive, type WithoutChild } from "bits-ui";
3
- import SelectScrollUpButton from "./select-scroll-up-button.svelte";
4
- import SelectScrollDownButton from "./select-scroll-down-button.svelte";
3
+ import IconChevronUp from "@tabler/icons-svelte/icons/chevron-up";
4
+ import IconChevronDown from "@tabler/icons-svelte/icons/chevron-down";
5
+ import { onMount, tick } from "svelte";
5
6
  import { cn } from "../../../utils.js";
6
7
  import { useTextDirection } from "../../textDirection.js";
8
+ import { installInputModality } from "../../../utils/inputModality.js";
7
9
 
8
10
  const textDirection = useTextDirection();
9
11
 
12
+ // The rows paint the highlight only while the keyboard drives the list (see select-item.svelte): this is what tells them so
13
+ onMount(() => {
14
+ // Listens once per document and has nothing to take back (it returns nothing)
15
+ installInputModality();
16
+ return () => {
17
+ // A list that closes while an arrow is held must not leave its repeat timer running.
18
+ stopScrollRepeat();
19
+ };
20
+ });
21
+
10
22
  let {
11
23
  ref = $bindable(null),
12
24
  class: className,
@@ -17,6 +29,96 @@
17
29
  }: WithoutChild<SelectPrimitive.ContentProps> & {
18
30
  portalProps?: SelectPrimitive.PortalProps;
19
31
  } = $props();
32
+
33
+ let viewportEl: HTMLElement | null = $state(null);
34
+ let canScrollUp = $state(false);
35
+ let canScrollDown = $state(false);
36
+ let scrollRepeatTimer: ReturnType<typeof setInterval> | null = null;
37
+
38
+ function refreshScrollButtons() {
39
+ if (!viewportEl) {
40
+ canScrollUp = false;
41
+ canScrollDown = false;
42
+ return;
43
+ }
44
+ const paddingTop = Number.parseInt(getComputedStyle(viewportEl).paddingTop, 10) || 0;
45
+ canScrollUp = viewportEl.scrollTop - paddingTop > 0.5;
46
+ canScrollDown =
47
+ viewportEl.scrollTop + viewportEl.clientHeight < viewportEl.scrollHeight - 0.5;
48
+ }
49
+
50
+ function scrollViewportStep(direction: 1 | -1) {
51
+ if (!viewportEl) return;
52
+ const sampleItem = viewportEl.querySelector<HTMLElement>('[data-select-item]');
53
+ const step = sampleItem?.offsetHeight ?? 32;
54
+ viewportEl.scrollTop += direction * step;
55
+ refreshScrollButtons();
56
+ }
57
+
58
+ function stopScrollRepeat() {
59
+ if (scrollRepeatTimer !== null) {
60
+ clearInterval(scrollRepeatTimer);
61
+ scrollRepeatTimer = null;
62
+ }
63
+ }
64
+
65
+ function startScrollRepeat(direction: 1 | -1) {
66
+ stopScrollRepeat();
67
+ scrollViewportStep(direction);
68
+ scrollRepeatTimer = setInterval(() => scrollViewportStep(direction), 80);
69
+ }
70
+
71
+ function handleScrollButtonPointerDown(event: PointerEvent, direction: 1 | -1) {
72
+ event.preventDefault();
73
+ event.stopPropagation();
74
+ startScrollRepeat(direction);
75
+ }
76
+
77
+ function handleScrollButtonPointerUp(event: PointerEvent) {
78
+ event.preventDefault();
79
+ event.stopPropagation();
80
+ stopScrollRepeat();
81
+ }
82
+
83
+ /**
84
+ * Brings the selected row fully into the visible part of the list.
85
+ * Bits UI scrolls the row into view while the list is as tall as it can be; the arrows then show and take room from the
86
+ * viewport, which leaves a row near the end of a long list half behind the down arrow.
87
+ */
88
+ function revealSelectedItem() {
89
+ if (!viewportEl) return;
90
+ const selectedItem =
91
+ viewportEl.querySelector<HTMLElement>('[data-select-item][data-selected]') ??
92
+ viewportEl.querySelector<HTMLElement>('[role="option"][aria-selected="true"]');
93
+ if (!selectedItem) return;
94
+ const viewportRect = viewportEl.getBoundingClientRect();
95
+ const itemRect = selectedItem.getBoundingClientRect();
96
+ const viewportStyle = getComputedStyle(viewportEl);
97
+ const paddingTop = Number.parseInt(viewportStyle.paddingTop, 10) || 0;
98
+ const paddingBottom = Number.parseInt(viewportStyle.paddingBottom, 10) || 0;
99
+ if (itemRect.bottom > viewportRect.bottom - paddingBottom) {
100
+ viewportEl.scrollTop += itemRect.bottom - (viewportRect.bottom - paddingBottom);
101
+ } else if (itemRect.top < viewportRect.top + paddingTop) {
102
+ viewportEl.scrollTop -= viewportRect.top + paddingTop - itemRect.top;
103
+ }
104
+ refreshScrollButtons();
105
+ }
106
+
107
+ $effect(() => {
108
+ if (!viewportEl) return;
109
+ refreshScrollButtons();
110
+ let cancelled = false;
111
+ const frame = requestAnimationFrame(async () => {
112
+ refreshScrollButtons();
113
+ // The arrows are in the DOM after this tick, and only then is the viewport at its final height.
114
+ await tick();
115
+ if (!cancelled) revealSelectedItem();
116
+ });
117
+ return () => {
118
+ cancelled = true;
119
+ cancelAnimationFrame(frame);
120
+ };
121
+ });
20
122
  </script>
21
123
 
22
124
  <SelectPrimitive.Portal {...portalProps}>
@@ -30,14 +132,42 @@
30
132
  )}
31
133
  {...restProps}
32
134
  >
33
- <SelectScrollUpButton />
135
+ {#if canScrollUp}
136
+ <button
137
+ type="button"
138
+ tabindex={-1}
139
+ aria-hidden="true"
140
+ class="select-scroll-step select-scroll-step-up flex w-full cursor-default items-center justify-center py-1"
141
+ onpointerdown={(event) => handleScrollButtonPointerDown(event, -1)}
142
+ onpointerup={handleScrollButtonPointerUp}
143
+ onpointerleave={handleScrollButtonPointerUp}
144
+ onpointercancel={handleScrollButtonPointerUp}
145
+ >
146
+ <IconChevronUp class="size-4 stroke-2" aria-hidden="true" />
147
+ </button>
148
+ {/if}
34
149
  <SelectPrimitive.Viewport
150
+ bind:ref={viewportEl}
151
+ onscroll={refreshScrollButtons}
35
152
  class={cn(
36
153
  "h-[var(--bits-select-anchor-height)] w-full min-w-[var(--bits-select-anchor-width)] p-1"
37
154
  )}
38
155
  >
39
156
  {@render children?.()}
40
157
  </SelectPrimitive.Viewport>
41
- <SelectScrollDownButton />
158
+ {#if canScrollDown}
159
+ <button
160
+ type="button"
161
+ tabindex={-1}
162
+ aria-hidden="true"
163
+ class="select-scroll-step select-scroll-step-down flex w-full cursor-default items-center justify-center py-1"
164
+ onpointerdown={(event) => handleScrollButtonPointerDown(event, 1)}
165
+ onpointerup={handleScrollButtonPointerUp}
166
+ onpointerleave={handleScrollButtonPointerUp}
167
+ onpointercancel={handleScrollButtonPointerUp}
168
+ >
169
+ <IconChevronDown class="size-4 stroke-2" aria-hidden="true" />
170
+ </button>
171
+ {/if}
42
172
  </SelectPrimitive.Content>
43
173
  </SelectPrimitive.Portal>
@@ -18,11 +18,18 @@
18
18
  }: SelectItemProps = $props();
19
19
  </script>
20
20
 
21
+ <!--
22
+ Which row is painted. bits-ui highlights the row the pointer moves over and never takes the highlight back when the pointer
23
+ leaves, so painting `data-highlighted` left the last row crossed lit after the pointer had gone. So:
24
+ - the pointer paints with :hover, which ends when the pointer does (a selected row keeps its own look);
25
+ - the keyboard paints `data-highlighted`, while the last input was a key press (data-input-modality="keyboard", set by
26
+ utils/inputModality.ts), and the hover of a pointer that is resting somewhere does not paint a second row then.
27
+ -->
21
28
  <SelectPrimitive.Item
22
29
  bind:ref
23
30
  {value}
24
31
  class={cn(
25
- "relative flex h-8 w-full cursor-pointer select-none items-center gap-2 rounded-lg px-2 py-1.5 ps-8 text-body outline-hidden data-[highlighted]:bg-accent data-[selected]:bg-brand-subtle data-[disabled]:pointer-events-none data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50",
32
+ "relative flex h-8 w-full cursor-pointer select-none items-center gap-2 rounded-lg px-2 py-1.5 ps-8 text-body outline-hidden data-[selected]:bg-brand-subtle hover:not-data-[selected]:bg-accent [[data-input-modality=keyboard]_&]:not-data-[selected]:data-[highlighted]:bg-accent [[data-input-modality=keyboard]_&]:not-data-[selected]:not-data-[highlighted]:hover:bg-transparent data-[disabled]:pointer-events-none data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50",
26
33
  className
27
34
  )}
28
35
  {...restProps}
@@ -30,7 +37,7 @@
30
37
  {#snippet children({ selected, highlighted })}
31
38
  <span class="absolute start-2 flex size-3.5 items-center justify-center">
32
39
  {#if selected}
33
- <IconCheck class="size-4 stroke-[1.333]" aria-hidden="true" />
40
+ <IconCheck class="size-4 stroke-2" aria-hidden="true" />
34
41
  {/if}
35
42
  </span>
36
43
  {#if childrenProp}
@@ -19,5 +19,5 @@
19
19
  class={cn("flex cursor-default items-center justify-center py-1", className)}
20
20
  {...restProps}
21
21
  >
22
- <IconChevronDown class="size-4 stroke-[1.333]" aria-hidden="true" />
22
+ <IconChevronDown class="size-4 stroke-2" aria-hidden="true" />
23
23
  </SelectPrimitive.ScrollDownButton>
@@ -19,5 +19,5 @@
19
19
  class={cn("flex cursor-default items-center justify-center py-1", className)}
20
20
  {...restProps}
21
21
  >
22
- <IconChevronUp class="size-4 stroke-[1.333]" aria-hidden="true" />
22
+ <IconChevronUp class="size-4 stroke-2" aria-hidden="true" />
23
23
  </SelectPrimitive.ScrollUpButton>
@@ -19,11 +19,12 @@
19
19
  <SelectPrimitive.Trigger
20
20
  bind:ref
21
21
  class={cn(
22
- "flex h-9 w-full items-center justify-between gap-2 rounded-lg border border-input bg-background px-3 py-2 text-start text-body 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:opacity-50 data-[placeholder]:text-muted-foreground aria-invalid:border-destructive [&>span]:line-clamp-1",
22
+ "flex h-9 w-full items-center justify-between gap-2 rounded-lg border border-input bg-background px-3 py-2 text-start text-body 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:opacity-50 data-[placeholder]:text-muted-foreground aria-invalid:border-destructive [&>span]:line-clamp-1 [&[data-state=open]>svg:last-child]:rotate-180",
23
23
  className
24
24
  )}
25
25
  {...restProps}
26
26
  >
27
27
  {@render children?.()}
28
- <IconChevronDown class="size-4 shrink-0 stroke-[1.333] opacity-50" aria-hidden="true" />
28
+ <!-- Figma: the open trigger shows the arrow up. It turns with the motion of the accordion's arrow (transition-transform duration-base). -->
29
+ <IconChevronDown class="size-4 shrink-0 stroke-2 opacity-50 transition-transform duration-base" aria-hidden="true" />
29
30
  </SelectPrimitive.Trigger>
@@ -1,4 +1,6 @@
1
- <!-- Figma: Stepper Button (Editor / Atoms 171:81). -->
1
+ <!-- Figma: Stepper Button (Editor / Atoms 171:81).
2
+ The plus and the minus are 14 px icons drawn with the 1.333 px stroke of every Figma icon: `size-3.5` with `stroke-[2.286]`
3
+ (the stroke width is counted in the 24-unit viewBox of the icon: 1.333 * 24 / 14). At 16 px they were bigger than in the design. -->
2
4
  <script lang="ts">
3
5
  import type { HTMLButtonAttributes } from "svelte/elements";
4
6
  import IconMinus from "@tabler/icons-svelte/icons/minus";
@@ -12,10 +14,12 @@
12
14
  kind = "plus",
13
15
  label,
14
16
  disabled = false,
17
+ "data-pressed": dataPressed,
15
18
  ...restProps
16
19
  }: HTMLButtonAttributes & {
17
20
  kind?: StepperKind;
18
21
  label: string;
22
+ "data-pressed"?: "true";
19
23
  } = $props();
20
24
  </script>
21
25
 
@@ -23,15 +27,16 @@
23
27
  type="button"
24
28
  aria-label={label}
25
29
  {disabled}
30
+ data-pressed={dataPressed}
26
31
  class={cn(
27
- "inline-flex size-6 shrink-0 items-center justify-center rounded-lg bg-transparent text-foreground 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:opacity-50 press-feedback",
32
+ "inline-flex size-6 shrink-0 items-center justify-center rounded-lg bg-transparent text-foreground 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:opacity-50 press-feedback [&_svg]:pointer-events-none",
28
33
  className
29
34
  )}
30
35
  {...restProps}
31
36
  >
32
37
  {#if kind === "minus"}
33
- <IconMinus class="size-4 stroke-[1.333]" aria-hidden="true" />
38
+ <IconMinus class="size-3.5 stroke-[2.286]" aria-hidden="true" />
34
39
  {:else}
35
- <IconPlus class="size-4 stroke-[1.333]" aria-hidden="true" />
40
+ <IconPlus class="size-3.5 stroke-[2.286]" aria-hidden="true" />
36
41
  {/if}
37
42
  </button>
@@ -3,6 +3,7 @@ export type StepperKind = "plus" | "minus";
3
3
  type $$ComponentProps = HTMLButtonAttributes & {
4
4
  kind?: StepperKind;
5
5
  label: string;
6
+ "data-pressed"?: "true";
6
7
  };
7
8
  declare const StepperButton: import("svelte").Component<$$ComponentProps, {}, "">;
8
9
  type StepperButton = ReturnType<typeof StepperButton>;
@@ -18,12 +18,15 @@
18
18
  <!--
19
19
  The track is 36x20. `relative before:absolute before:inset-x-0 before:-inset-y-0.5` adds an invisible 2px above and below,
20
20
  so the tap target is 36x24 (the minimum height of a target). Figma keeps the same 24px frame around the 20px track.
21
+ The thumb (the "scrub") is 16x16 and sits 2px from every edge of the track, as Figma's track pads it (2/2/2/2). The track has no
22
+ border of its own: a transparent 1px border here would add a pixel of padding on every side, which left the thumb 3px from the
23
+ start and 1px from the end.
21
24
  -->
22
25
  <SwitchPrimitive.Root
23
26
  bind:ref
24
27
  bind:checked
25
28
  class={cn(
26
- "peer relative inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border border-transparent bg-input p-0.5 transition-colors duration-base ease-out before:absolute before:inset-x-0 before:-inset-y-0.5 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:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:hover:bg-primary/90",
29
+ "peer relative inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full bg-input p-0.5 transition-colors duration-base ease-out before:absolute before:inset-x-0 before:-inset-y-0.5 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:opacity-50 data-[state=checked]:bg-primary",
27
30
  className
28
31
  )}
29
32
  {...restProps}
@@ -36,7 +36,7 @@
36
36
  {disabled}
37
37
  onclick={onRemove}
38
38
  >
39
- <IconX class="size-4 stroke-[1.333]" aria-hidden="true" />
39
+ <IconX class="size-4 stroke-2" aria-hidden="true" />
40
40
  </button>
41
41
  {/if}
42
42
  </span>
@@ -3,7 +3,7 @@
3
3
  import type { VariantProps } from "tailwind-variants";
4
4
 
5
5
  export const toggleVariants = tv({
6
- base: "inline-flex items-center justify-center gap-2 rounded-lg text-label 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 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-brand-subtle data-[state=on]:text-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:stroke-[1.333] hover:bg-accent",
6
+ base: "inline-flex items-center justify-center gap-2 rounded-lg text-label 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 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-brand-subtle data-[state=on]:text-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:stroke-2 hover:bg-accent",
7
7
  variants: {
8
8
  variant: {
9
9
  default: "bg-transparent text-foreground",
@@ -9,7 +9,7 @@ export declare const toggleVariants: import("tailwind-variants").TVReturnType<{
9
9
  sm: string;
10
10
  lg: string;
11
11
  };
12
- }, undefined, "inline-flex items-center justify-center gap-2 rounded-lg text-label 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 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-brand-subtle data-[state=on]:text-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:stroke-[1.333] hover:bg-accent", {
12
+ }, undefined, "inline-flex items-center justify-center gap-2 rounded-lg text-label 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 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-brand-subtle data-[state=on]:text-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:stroke-2 hover:bg-accent", {
13
13
  responsiveVariants?: boolean | (string | number | symbol)[] | {
14
14
  size?: boolean | (string | number | symbol)[] | undefined;
15
15
  variant?: boolean | (string | number | symbol)[] | undefined;
@@ -42,7 +42,7 @@ export declare const toggleVariants: import("tailwind-variants").TVReturnType<{
42
42
  sm: string;
43
43
  lg: string;
44
44
  };
45
- }, undefined, "inline-flex items-center justify-center gap-2 rounded-lg text-label 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 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-brand-subtle data-[state=on]:text-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:stroke-[1.333] hover:bg-accent", import("tailwind-variants/dist/config.js").TVConfig<{
45
+ }, undefined, "inline-flex items-center justify-center gap-2 rounded-lg text-label 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 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-brand-subtle data-[state=on]:text-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:stroke-2 hover:bg-accent", import("tailwind-variants/dist/config.js").TVConfig<{
46
46
  variant: {
47
47
  default: string;
48
48
  outline: string;
@@ -238,15 +238,37 @@
238
238
  transition-timing-function: var(--ease-drawer);
239
239
  }
240
240
 
241
+ /*
242
+ * A pressable control shrinks to `--scale-press` while it is pressed and goes back to 100% when it is released
243
+ * (Figma: the Pressed variants of Button and Icon Button are 0.97 of the Default size).
244
+ *
245
+ * The utility owns the whole transition of the control: the colours that hover changes and the transform of the press.
246
+ * `transition-colors` sets `transition-property` too, with the same specificity, so whichever of the two came last in the
247
+ * stylesheet won, and when that was `transition-colors` the press had no transition at all: the control snapped in and
248
+ * snapped back. `:not([data-no-press])` raises the specificity above `transition-colors` and `duration-*`, so they compose
249
+ * in any order, and `data-no-press` is the way to opt one control out.
250
+ */
241
251
  @utility press-feedback {
242
- transition: transform var(--duration-base) var(--ease-out);
252
+ &:not([data-no-press]) {
253
+ transition:
254
+ color var(--duration-fast) cubic-bezier(0.4, 0, 0.2, 1),
255
+ background-color var(--duration-fast) cubic-bezier(0.4, 0, 0.2, 1),
256
+ border-color var(--duration-fast) cubic-bezier(0.4, 0, 0.2, 1),
257
+ outline-color var(--duration-fast) cubic-bezier(0.4, 0, 0.2, 1),
258
+ text-decoration-color var(--duration-fast) cubic-bezier(0.4, 0, 0.2, 1),
259
+ fill var(--duration-fast) cubic-bezier(0.4, 0, 0.2, 1),
260
+ stroke var(--duration-fast) cubic-bezier(0.4, 0, 0.2, 1),
261
+ transform var(--duration-base) var(--ease-out);
262
+ }
243
263
 
244
- &:active:not(:disabled):not([aria-disabled='true']) {
264
+ &:active:not(:disabled):not([aria-disabled='true']),
265
+ &[data-pressed='true']:not(:disabled):not([aria-disabled='true']) {
245
266
  transform: scale(var(--scale-press));
246
267
  }
247
268
 
248
269
  @media (prefers-reduced-motion: reduce) {
249
- &:active:not(:disabled):not([aria-disabled='true']) {
270
+ &:active:not(:disabled):not([aria-disabled='true']),
271
+ &[data-pressed='true']:not(:disabled):not([aria-disabled='true']) {
250
272
  transform: none;
251
273
  }
252
274
  }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Tells the styles whether the last thing a person did was press a key or use the pointer.
3
+ *
4
+ * The root element carries `data-input-modality="keyboard"` after a key press and `data-input-modality="pointer"` after the
5
+ * pointer moved or pressed. A list can then paint the row that the keyboard highlighted without painting, for ever, the row
6
+ * the pointer happened to cross last: bits-ui's Select never takes the highlight back when the pointer leaves, so what the
7
+ * pointer highlighted stayed painted after it had gone (Figma Select Option has Default, Hover and Selected looks, not a
8
+ * "was hovered" one).
9
+ *
10
+ * `installInputModality` is safe to call as often as needed: it listens once per document.
11
+ */
12
+ /** The attribute on the root element that carries the modality. */
13
+ export declare const inputModalityAttribute = "data-input-modality";
14
+ export type InputModality = 'keyboard' | 'pointer';
15
+ /** Start listening in `doc` (the page by default). Does nothing on the server. */
16
+ export declare function installInputModality(doc?: Document | undefined): void;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Tells the styles whether the last thing a person did was press a key or use the pointer.
3
+ *
4
+ * The root element carries `data-input-modality="keyboard"` after a key press and `data-input-modality="pointer"` after the
5
+ * pointer moved or pressed. A list can then paint the row that the keyboard highlighted without painting, for ever, the row
6
+ * the pointer happened to cross last: bits-ui's Select never takes the highlight back when the pointer leaves, so what the
7
+ * pointer highlighted stayed painted after it had gone (Figma Select Option has Default, Hover and Selected looks, not a
8
+ * "was hovered" one).
9
+ *
10
+ * `installInputModality` is safe to call as often as needed: it listens once per document.
11
+ */
12
+ /** The attribute on the root element that carries the modality. */
13
+ export const inputModalityAttribute = 'data-input-modality';
14
+ /** The documents that already listen, so that a second call does nothing. */
15
+ const listeningDocuments = new WeakSet();
16
+ /**
17
+ * Keys that act on a list. A modifier on its own (Shift, Meta…) or a shortcut (Cmd+C) is not the keyboard driving a list:
18
+ * a person who opens a menu with the pointer and then presses Shift must not see the highlight appear.
19
+ */
20
+ function isListNavigationKey(event) {
21
+ if (event.metaKey || event.ctrlKey || event.altKey)
22
+ return false;
23
+ return (event.key === 'ArrowUp' ||
24
+ event.key === 'ArrowDown' ||
25
+ event.key === 'ArrowLeft' ||
26
+ event.key === 'ArrowRight' ||
27
+ event.key === 'Home' ||
28
+ event.key === 'End' ||
29
+ event.key === 'PageUp' ||
30
+ event.key === 'PageDown' ||
31
+ event.key === 'Enter' ||
32
+ event.key === ' ' ||
33
+ event.key === 'Tab' ||
34
+ // Type-ahead: a single character moves the highlight to the row that starts with it
35
+ event.key.length === 1);
36
+ }
37
+ /** Start listening in `doc` (the page by default). Does nothing on the server. */
38
+ export function installInputModality(doc = typeof document === 'undefined' ? undefined : document) {
39
+ if (!doc || listeningDocuments.has(doc))
40
+ return;
41
+ listeningDocuments.add(doc);
42
+ const root = doc.documentElement;
43
+ const setModality = (modality) => {
44
+ // Compared first: the pointer moves hundreds of times a second and nothing has to be written for that
45
+ if (root.getAttribute(inputModalityAttribute) !== modality) {
46
+ root.setAttribute(inputModalityAttribute, modality);
47
+ }
48
+ };
49
+ doc.addEventListener('keydown', (event) => {
50
+ if (isListNavigationKey(event))
51
+ setModality('keyboard');
52
+ }, true);
53
+ doc.addEventListener('pointermove', () => setModality('pointer'), { capture: true, passive: true });
54
+ doc.addEventListener('pointerdown', () => setModality('pointer'), { capture: true, passive: true });
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/design-system",
3
- "version": "0.5.24",
3
+ "version": "0.5.26",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",
@@ -1,7 +0,0 @@
1
- /** Footer links in SettingsDialog (Figma Settings Dialog 107:618). */
2
- export interface SettingsDialogMessages {
3
- privacyPolicy: string;
4
- termsOfService: string;
5
- cookieSettings: string;
6
- }
7
- export declare const defaultSettingsDialogMessages: SettingsDialogMessages;
@@ -1,5 +0,0 @@
1
- export const defaultSettingsDialogMessages = {
2
- privacyPolicy: 'Privacy policy',
3
- termsOfService: 'Terms of service',
4
- cookieSettings: 'Cookie settings'
5
- };