@lyeve-labs/ui-kit 0.22.2 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { HTMLAnchorAttributes, HTMLButtonAttributes } from 'svelte/elements';
|
|
4
4
|
import Spinner from './Spinner.svelte';
|
|
5
|
+
import Tooltip from './Tooltip.svelte';
|
|
5
6
|
import { safeHref } from '../internal/href.js';
|
|
6
7
|
|
|
7
8
|
type Variant = 'primary' | 'secondary' | 'danger' | 'ghost' | 'outline' | 'violet';
|
|
@@ -25,6 +26,18 @@
|
|
|
25
26
|
type?: 'button' | 'submit' | 'reset';
|
|
26
27
|
href?: string;
|
|
27
28
|
full?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The words shown on hover and focus. Defaults to the button's own
|
|
31
|
+
* aria-label, so an icon-only button names itself to a sighted reader the
|
|
32
|
+
* way it already does to a screen reader; a string replaces those words,
|
|
33
|
+
* and `false` keeps the button silent.
|
|
34
|
+
*
|
|
35
|
+
* Thirty-five icon-only actions across one console had a name and no
|
|
36
|
+
* hint, so a pointer user learned what the trash can did by pressing it.
|
|
37
|
+
* The hint lives here rather than on each caller because the rule that
|
|
38
|
+
* makes a row action icon-only is the kit's, and so is the fix.
|
|
39
|
+
*/
|
|
40
|
+
hint?: string | false;
|
|
28
41
|
class?: string;
|
|
29
42
|
onclick?: (e: MouseEvent) => void;
|
|
30
43
|
children: Snippet;
|
|
@@ -38,12 +51,18 @@
|
|
|
38
51
|
type = 'button',
|
|
39
52
|
href = undefined,
|
|
40
53
|
full = false,
|
|
54
|
+
hint = undefined,
|
|
41
55
|
class: klass = '',
|
|
42
56
|
onclick,
|
|
43
57
|
children,
|
|
44
58
|
...rest
|
|
45
59
|
}: Props = $props();
|
|
46
60
|
|
|
61
|
+
/** The hint text, or nothing: an explicit string, else the aria-label, unless switched off. */
|
|
62
|
+
const hintText = $derived(
|
|
63
|
+
hint === false ? undefined : (hint ?? (rest['aria-label'] || undefined)),
|
|
64
|
+
);
|
|
65
|
+
|
|
47
66
|
/**
|
|
48
67
|
* Colour per variant, in three states: at rest, under a pointer, and held.
|
|
49
68
|
*
|
|
@@ -104,27 +123,40 @@
|
|
|
104
123
|
const inert = $derived(disabled || loading);
|
|
105
124
|
</script>
|
|
106
125
|
|
|
107
|
-
{#
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
126
|
+
{#snippet control()}
|
|
127
|
+
{#if href}
|
|
128
|
+
<a
|
|
129
|
+
href={inert ? undefined : resolvedHref}
|
|
130
|
+
class="{cls} {inert ? 'pointer-events-none opacity-50' : ''}"
|
|
131
|
+
aria-disabled={inert ? 'true' : undefined}
|
|
132
|
+
tabindex={inert ? -1 : undefined}
|
|
133
|
+
{...rest}
|
|
134
|
+
>
|
|
135
|
+
{#if loading}<Spinner size={spinnerSize} />{/if}
|
|
136
|
+
{@render children()}
|
|
137
|
+
</a>
|
|
138
|
+
{:else}
|
|
139
|
+
<button
|
|
140
|
+
{type}
|
|
141
|
+
disabled={disabled || loading}
|
|
142
|
+
aria-busy={loading ? 'true' : undefined}
|
|
143
|
+
{onclick}
|
|
144
|
+
class={cls}
|
|
145
|
+
{...rest}
|
|
146
|
+
>
|
|
147
|
+
{#if loading}<Spinner size={spinnerSize} />{/if}
|
|
148
|
+
{@render children()}
|
|
149
|
+
</button>
|
|
150
|
+
{/if}
|
|
151
|
+
{/snippet}
|
|
152
|
+
|
|
153
|
+
<!-- The hint repeats the name, so it does not describe the control a second
|
|
154
|
+
time; the aria-label already announces it. The wrapper takes the full
|
|
155
|
+
width along with the button, or a full button would shrink to its text. -->
|
|
156
|
+
{#if hintText}
|
|
157
|
+
<Tooltip text={hintText} describe={false} class={full ? 'w-full' : ''}>
|
|
158
|
+
{@render control()}
|
|
159
|
+
</Tooltip>
|
|
118
160
|
{:else}
|
|
119
|
-
|
|
120
|
-
{type}
|
|
121
|
-
disabled={disabled || loading}
|
|
122
|
-
aria-busy={loading ? 'true' : undefined}
|
|
123
|
-
{onclick}
|
|
124
|
-
class={cls}
|
|
125
|
-
{...rest}
|
|
126
|
-
>
|
|
127
|
-
{#if loading}<Spinner size={spinnerSize} />{/if}
|
|
128
|
-
{@render children()}
|
|
129
|
-
</button>
|
|
161
|
+
{@render control()}
|
|
130
162
|
{/if}
|
|
@@ -16,6 +16,18 @@ interface Props extends Forwarded {
|
|
|
16
16
|
type?: 'button' | 'submit' | 'reset';
|
|
17
17
|
href?: string;
|
|
18
18
|
full?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The words shown on hover and focus. Defaults to the button's own
|
|
21
|
+
* aria-label, so an icon-only button names itself to a sighted reader the
|
|
22
|
+
* way it already does to a screen reader; a string replaces those words,
|
|
23
|
+
* and `false` keeps the button silent.
|
|
24
|
+
*
|
|
25
|
+
* Thirty-five icon-only actions across one console had a name and no
|
|
26
|
+
* hint, so a pointer user learned what the trash can did by pressing it.
|
|
27
|
+
* The hint lives here rather than on each caller because the rule that
|
|
28
|
+
* makes a row action icon-only is the kit's, and so is the fix.
|
|
29
|
+
*/
|
|
30
|
+
hint?: string | false;
|
|
19
31
|
class?: string;
|
|
20
32
|
onclick?: (e: MouseEvent) => void;
|
|
21
33
|
children: Snippet;
|
|
@@ -6,11 +6,21 @@
|
|
|
6
6
|
interface Props {
|
|
7
7
|
text: string;
|
|
8
8
|
position?: Position;
|
|
9
|
+
/**
|
|
10
|
+
* Whether the text is the trigger's accessible description.
|
|
11
|
+
*
|
|
12
|
+
* On by default, because a tooltip that nothing points at is read by
|
|
13
|
+
* nobody. Off for a trigger that already carries the same words as its
|
|
14
|
+
* name: an icon-only button named by aria-label would otherwise be
|
|
15
|
+
* announced as "Delete, Delete", so the hint stays visual there and the
|
|
16
|
+
* name does the announcing.
|
|
17
|
+
*/
|
|
18
|
+
describe?: boolean;
|
|
9
19
|
class?: string;
|
|
10
20
|
children: Snippet;
|
|
11
21
|
}
|
|
12
22
|
|
|
13
|
-
let { text, position = 'top', class: cls = '', children }: Props = $props();
|
|
23
|
+
let { text, position = 'top', describe = true, class: cls = '', children }: Props = $props();
|
|
14
24
|
|
|
15
25
|
let visible = $state(false);
|
|
16
26
|
let wrapper = $state<HTMLElement>();
|
|
@@ -32,6 +42,7 @@
|
|
|
32
42
|
* text was visible to a sighted mouse user and to nobody else.
|
|
33
43
|
*/
|
|
34
44
|
$effect(() => {
|
|
45
|
+
if (!describe) return;
|
|
35
46
|
const trigger = wrapper?.querySelector<HTMLElement>(
|
|
36
47
|
'a[href], button, input, select, textarea, [tabindex]:not([tabindex="-1"])',
|
|
37
48
|
);
|
|
@@ -70,7 +81,8 @@
|
|
|
70
81
|
moving onto it does not dismiss it, which SC 1.4.13 also requires. -->
|
|
71
82
|
<span
|
|
72
83
|
{id}
|
|
73
|
-
role=
|
|
84
|
+
role={describe ? 'tooltip' : undefined}
|
|
85
|
+
aria-hidden={describe ? undefined : 'true'}
|
|
74
86
|
hidden={!visible}
|
|
75
87
|
class="absolute {pos[position]} z-tooltip max-w-[min(16rem,calc(100vw-2rem))]
|
|
76
88
|
rounded-lg border border-line bg-surface-2 px-2.5 py-1.5 text-xs text-fg shadow-xl"
|
|
@@ -3,6 +3,16 @@ type Position = 'top' | 'bottom' | 'left' | 'right';
|
|
|
3
3
|
interface Props {
|
|
4
4
|
text: string;
|
|
5
5
|
position?: Position;
|
|
6
|
+
/**
|
|
7
|
+
* Whether the text is the trigger's accessible description.
|
|
8
|
+
*
|
|
9
|
+
* On by default, because a tooltip that nothing points at is read by
|
|
10
|
+
* nobody. Off for a trigger that already carries the same words as its
|
|
11
|
+
* name: an icon-only button named by aria-label would otherwise be
|
|
12
|
+
* announced as "Delete, Delete", so the hint stays visual there and the
|
|
13
|
+
* name does the announcing.
|
|
14
|
+
*/
|
|
15
|
+
describe?: boolean;
|
|
6
16
|
class?: string;
|
|
7
17
|
children: Snippet;
|
|
8
18
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -89,4 +89,4 @@ export type { ConfirmOptions } from './components/dialog/dialog-manager.svelte.j
|
|
|
89
89
|
export type { DialogOptions, DialogEntry, DialogSize } from './components/dialog/types.js';
|
|
90
90
|
export { cn, type ClassValue } from './utils/cn.js';
|
|
91
91
|
export { getTheme, getThemePreference, nextThemePreference, resolveTheme, setTheme, setThemePreference, systemTheme, themeBootScript, toggleTheme, watchSystemTheme, THEME_PREFERENCES, type Theme, type ThemePreference, } from './utils/theme.js';
|
|
92
|
-
export declare const VERSION = "0.
|
|
92
|
+
export declare const VERSION = "0.23.0";
|
package/dist/index.js
CHANGED
|
@@ -96,4 +96,4 @@ export { getTheme, getThemePreference, nextThemePreference, resolveTheme, setThe
|
|
|
96
96
|
// ── Version ────────────────────────────────────────────────────────────────
|
|
97
97
|
// Generated from package.json by `pnpm version:sync`. Bump package.json, never
|
|
98
98
|
// this line; the build and the test suite fail when the two disagree.
|
|
99
|
-
export const VERSION = '0.
|
|
99
|
+
export const VERSION = '0.23.0';
|
package/package.json
CHANGED