@human-kit/ui 1.0.0-beta.7 → 1.0.0-beta.8
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/FOCUS_STATE_CONTRACT.md +15 -4
- package/dist/FOCUS_STATE_REVIEW_TEMPLATE.md +8 -8
- package/dist/avatar/README.md +52 -0
- package/dist/avatar/count/avatar-count.svelte +56 -0
- package/dist/avatar/count/avatar-count.svelte.d.ts +4 -0
- package/dist/avatar/fallback/avatar-fallback.svelte +67 -0
- package/dist/avatar/fallback/avatar-fallback.svelte.d.ts +4 -0
- package/dist/avatar/group/avatar-group.svelte +65 -0
- package/dist/avatar/group/avatar-group.svelte.d.ts +4 -0
- package/dist/avatar/group/context.d.ts +15 -0
- package/dist/avatar/group/context.js +15 -0
- package/dist/avatar/image/avatar-image.svelte +104 -0
- package/dist/avatar/image/avatar-image.svelte.d.ts +4 -0
- package/dist/avatar/index.d.ts +22 -0
- package/dist/avatar/index.js +10 -0
- package/dist/avatar/index.parts.d.ts +5 -0
- package/dist/avatar/index.parts.js +5 -0
- package/dist/avatar/root/avatar-root.svelte +79 -0
- package/dist/avatar/root/avatar-root.svelte.d.ts +4 -0
- package/dist/avatar/root/context.d.ts +14 -0
- package/dist/avatar/root/context.js +15 -0
- package/dist/avatar/types.d.ts +84 -0
- package/dist/avatar/types.js +1 -0
- package/dist/breadcrumbs/README.md +65 -0
- package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte +62 -0
- package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte.d.ts +4 -0
- package/dist/breadcrumbs/index.d.ts +23 -0
- package/dist/breadcrumbs/index.js +10 -0
- package/dist/breadcrumbs/index.parts.d.ts +6 -0
- package/dist/breadcrumbs/index.parts.js +6 -0
- package/dist/breadcrumbs/item/breadcrumbs-item.svelte +42 -0
- package/dist/breadcrumbs/item/breadcrumbs-item.svelte.d.ts +4 -0
- package/dist/breadcrumbs/link/breadcrumbs-link.svelte +47 -0
- package/dist/breadcrumbs/link/breadcrumbs-link.svelte.d.ts +4 -0
- package/dist/breadcrumbs/list/breadcrumbs-list.svelte +31 -0
- package/dist/breadcrumbs/list/breadcrumbs-list.svelte.d.ts +4 -0
- package/dist/breadcrumbs/root/breadcrumbs-root.svelte +112 -0
- package/dist/breadcrumbs/root/breadcrumbs-root.svelte.d.ts +4 -0
- package/dist/breadcrumbs/root/context.d.ts +19 -0
- package/dist/breadcrumbs/root/context.js +15 -0
- package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte +35 -0
- package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte.d.ts +4 -0
- package/dist/breadcrumbs/types.d.ts +80 -0
- package/dist/breadcrumbs/types.js +1 -0
- package/dist/combobox/popover/combobox-popover.svelte +4 -56
- package/dist/dialog/root/dialog-root.svelte +15 -2
- package/dist/drawer/root/drawer-root.svelte +15 -2
- package/dist/index.d.ts +14 -0
- package/dist/index.js +13 -0
- package/dist/internal/localized-strings.d.ts +48 -0
- package/dist/internal/localized-strings.js +48 -0
- package/dist/internal/number-precision.d.ts +9 -0
- package/dist/internal/number-precision.js +27 -0
- package/dist/menu/root/focus-state.d.ts +2 -2
- package/dist/menu/root/focus-state.js +8 -32
- package/dist/menu/root/menu-state.svelte.js +5 -1
- package/dist/numberfield/root/number-utils.js +1 -20
- package/dist/popover/root/focus-state.d.ts +2 -2
- package/dist/popover/root/focus-state.js +7 -34
- package/dist/primitives/contain-wheel.d.ts +9 -0
- package/dist/primitives/contain-wheel.js +41 -0
- package/dist/primitives/floating.d.ts +6 -0
- package/dist/primitives/floating.js +26 -5
- package/dist/primitives/keyboard-navigation.d.ts +6 -0
- package/dist/primitives/keyboard-navigation.js +2 -1
- package/dist/primitives/trigger-focus-state.d.ts +29 -0
- package/dist/primitives/trigger-focus-state.js +57 -0
- package/dist/progress/README.md +54 -0
- package/dist/progress/index.d.ts +21 -0
- package/dist/progress/index.js +9 -0
- package/dist/progress/index.parts.d.ts +5 -0
- package/dist/progress/index.parts.js +5 -0
- package/dist/progress/indicator/progress-indicator.svelte +37 -0
- package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
- package/dist/progress/label/progress-label.svelte +34 -0
- package/dist/progress/label/progress-label.svelte.d.ts +4 -0
- package/dist/progress/root/context.d.ts +26 -0
- package/dist/progress/root/context.js +15 -0
- package/dist/progress/root/progress-root.svelte +136 -0
- package/dist/progress/root/progress-root.svelte.d.ts +4 -0
- package/dist/progress/root/progress-utils.d.ts +12 -0
- package/dist/progress/root/progress-utils.js +41 -0
- package/dist/progress/track/progress-track.svelte +27 -0
- package/dist/progress/track/progress-track.svelte.d.ts +4 -0
- package/dist/progress/types.d.ts +81 -0
- package/dist/progress/types.js +1 -0
- package/dist/progress/value/progress-value.svelte +36 -0
- package/dist/progress/value/progress-value.svelte.d.ts +4 -0
- package/dist/select/README.md +129 -0
- package/dist/select/index.d.ts +30 -0
- package/dist/select/index.js +16 -0
- package/dist/select/index.parts.d.ts +8 -0
- package/dist/select/index.parts.js +9 -0
- package/dist/select/item/select-item.svelte +68 -0
- package/dist/select/item/select-item.svelte.d.ts +10 -0
- package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
- package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
- package/dist/select/label/select-label.svelte +46 -0
- package/dist/select/label/select-label.svelte.d.ts +4 -0
- package/dist/select/list/select-list.svelte +241 -0
- package/dist/select/list/select-list.svelte.d.ts +62 -0
- package/dist/select/popover/select-popover.svelte +80 -0
- package/dist/select/popover/select-popover.svelte.d.ts +9 -0
- package/dist/select/root/context.d.ts +106 -0
- package/dist/select/root/context.js +22 -0
- package/dist/select/root/select-root.svelte +544 -0
- package/dist/select/root/select-root.svelte.d.ts +25 -0
- package/dist/select/trigger/select-trigger.svelte +192 -0
- package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
- package/dist/select/types.d.ts +133 -0
- package/dist/select/types.js +1 -0
- package/dist/select/value/select-value.svelte +61 -0
- package/dist/select/value/select-value.svelte.d.ts +4 -0
- package/dist/separator/README.md +35 -0
- package/dist/separator/index.d.ts +7 -0
- package/dist/separator/index.js +3 -0
- package/dist/separator/separator.svelte +254 -0
- package/dist/separator/separator.svelte.d.ts +45 -0
- package/dist/separator/types.d.ts +1 -0
- package/dist/separator/types.js +1 -0
- package/dist/slider/README.md +61 -0
- package/dist/slider/fill/slider-fill.svelte +40 -0
- package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
- package/dist/slider/index.d.ts +9 -0
- package/dist/slider/index.js +8 -0
- package/dist/slider/index.parts.d.ts +6 -0
- package/dist/slider/index.parts.js +6 -0
- package/dist/slider/label/slider-label.svelte +44 -0
- package/dist/slider/label/slider-label.svelte.d.ts +4 -0
- package/dist/slider/output/slider-output.svelte +46 -0
- package/dist/slider/output/slider-output.svelte.d.ts +4 -0
- package/dist/slider/root/context.d.ts +106 -0
- package/dist/slider/root/context.js +15 -0
- package/dist/slider/root/slider-root.svelte +545 -0
- package/dist/slider/root/slider-root.svelte.d.ts +4 -0
- package/dist/slider/root/slider-utils.d.ts +57 -0
- package/dist/slider/root/slider-utils.js +88 -0
- package/dist/slider/thumb/slider-thumb.svelte +276 -0
- package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
- package/dist/slider/track/slider-track.svelte +60 -0
- package/dist/slider/track/slider-track.svelte.d.ts +4 -0
- package/dist/slider/types.d.ts +144 -0
- package/dist/slider/types.js +1 -0
- package/dist/tooltip/README.md +53 -0
- package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
- package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
- package/dist/tooltip/content/tooltip-content.svelte +148 -0
- package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
- package/dist/tooltip/index.d.ts +8 -0
- package/dist/tooltip/index.js +7 -0
- package/dist/tooltip/index.parts.d.ts +5 -0
- package/dist/tooltip/index.parts.js +5 -0
- package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
- package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
- package/dist/tooltip/root/context.d.ts +46 -0
- package/dist/tooltip/root/context.js +22 -0
- package/dist/tooltip/root/safe-polygon.d.ts +26 -0
- package/dist/tooltip/root/safe-polygon.js +66 -0
- package/dist/tooltip/root/tooltip-group.d.ts +26 -0
- package/dist/tooltip/root/tooltip-group.js +41 -0
- package/dist/tooltip/root/tooltip-root.svelte +454 -0
- package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
- package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
- package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
- package/dist/tooltip/types.d.ts +105 -0
- package/dist/tooltip/types.js +1 -0
- package/package.json +36 -1
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
delete trigger.dataset.focused;
|
|
4
|
-
delete trigger.dataset.focusVisible;
|
|
5
|
-
}
|
|
1
|
+
import { applyTriggerCloseFocusState as applyTriggerCloseFocusStateShared, addTriggerBlurCleanup, clearTriggerFocusState, focusFellToBody } from '../../primitives/trigger-focus-state';
|
|
2
|
+
export { addTriggerBlurCleanup, clearTriggerFocusState, focusFellToBody };
|
|
6
3
|
// Per APG/React Aria/Radix, focus returns to the trigger only for keyboard or
|
|
7
4
|
// imperative closes. User-directed dismissals ('outside-press', 'focus-out',
|
|
8
5
|
// 'scroll') must leave focus where the user just put it (e.g. the caret in an
|
|
9
|
-
// outside input, or the element tabbed to).
|
|
6
|
+
// outside input, or the element tabbed to). The one exception, an outside press
|
|
7
|
+
// that left the focus on nothing, lives in the shared primitive.
|
|
10
8
|
const TRIGGER_REFOCUS_CLOSE_REASONS = new Set([
|
|
11
9
|
'escape-key',
|
|
12
10
|
'close-press',
|
|
@@ -16,32 +14,7 @@ export function shouldRefocusTriggerOnClose(reason) {
|
|
|
16
14
|
return TRIGGER_REFOCUS_CLOSE_REASONS.has(reason);
|
|
17
15
|
}
|
|
18
16
|
export function applyTriggerCloseFocusState(trigger, reason, event) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
if (reason === 'outside-press' || reason === 'escape-key') {
|
|
24
|
-
trigger.dataset.focused = 'true';
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
delete trigger.dataset.focused;
|
|
28
|
-
}
|
|
29
|
-
if (closeModality === 'keyboard') {
|
|
30
|
-
trigger.dataset.focusVisible = 'true';
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
delete trigger.dataset.focusVisible;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
export function addTriggerBlurCleanup(trigger, once = false) {
|
|
37
|
-
const handleBlur = () => {
|
|
38
|
-
clearTriggerFocusState(trigger);
|
|
39
|
-
if (once) {
|
|
40
|
-
trigger.removeEventListener('blur', handleBlur);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
trigger.addEventListener('blur', handleBlur);
|
|
44
|
-
return () => {
|
|
45
|
-
trigger.removeEventListener('blur', handleBlur);
|
|
46
|
-
};
|
|
17
|
+
applyTriggerCloseFocusStateShared(trigger, reason, event, {
|
|
18
|
+
refocus: shouldRefocusTriggerOnClose(reason)
|
|
19
|
+
});
|
|
47
20
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps a wheel event inside a floating panel.
|
|
3
|
+
*
|
|
4
|
+
* A non-modal popover closes when the page scrolls under it, and a wheel over a list that
|
|
5
|
+
* has reached its end would scroll the page. So the event scrolls the panel, or a scrollable
|
|
6
|
+
* element inside it, while one of them can still move in that direction, and it is consumed
|
|
7
|
+
* otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export declare function containWheel(event: WheelEvent, panel: HTMLElement): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function canElementScrollInDirection(element, deltaY) {
|
|
2
|
+
const isScrollingDown = deltaY > 0;
|
|
3
|
+
const isScrollingUp = deltaY < 0;
|
|
4
|
+
const canScrollDown = element.scrollTop < element.scrollHeight - element.clientHeight;
|
|
5
|
+
const canScrollUp = element.scrollTop > 0;
|
|
6
|
+
return (isScrollingDown && canScrollDown) || (isScrollingUp && canScrollUp);
|
|
7
|
+
}
|
|
8
|
+
function isScrollableElement(element) {
|
|
9
|
+
const { overflowY } = getComputedStyle(element);
|
|
10
|
+
return (['auto', 'scroll', 'overlay'].includes(overflowY) && element.scrollHeight > element.clientHeight);
|
|
11
|
+
}
|
|
12
|
+
function hasScrollableDescendantForWheel(boundary, target, deltaY) {
|
|
13
|
+
let current = target instanceof HTMLElement ? target : target instanceof Node ? target.parentElement : null;
|
|
14
|
+
while (current) {
|
|
15
|
+
if (isScrollableElement(current) && canElementScrollInDirection(current, deltaY)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (current === boundary) {
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
current = current.parentElement;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Keeps a wheel event inside a floating panel.
|
|
27
|
+
*
|
|
28
|
+
* A non-modal popover closes when the page scrolls under it, and a wheel over a list that
|
|
29
|
+
* has reached its end would scroll the page. So the event scrolls the panel, or a scrollable
|
|
30
|
+
* element inside it, while one of them can still move in that direction, and it is consumed
|
|
31
|
+
* otherwise.
|
|
32
|
+
*/
|
|
33
|
+
export function containWheel(event, panel) {
|
|
34
|
+
if (hasScrollableDescendantForWheel(panel, event.target, event.deltaY) ||
|
|
35
|
+
(isScrollableElement(panel) && canElementScrollInDirection(panel, event.deltaY))) {
|
|
36
|
+
event.stopPropagation();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
event.stopPropagation();
|
|
41
|
+
}
|
|
@@ -55,6 +55,12 @@ export type FloatingOptions = {
|
|
|
55
55
|
* so a panel that shrinks to fit still leaves the gutter visible.
|
|
56
56
|
*/
|
|
57
57
|
collisionPadding?: number;
|
|
58
|
+
/**
|
|
59
|
+
* An arrow element inside the floating element. The action moves it along the edge that faces
|
|
60
|
+
* the anchor, with `left` or `top`, and it writes the side in `data-placement`. The offset from
|
|
61
|
+
* that edge is for the CSS of the arrow.
|
|
62
|
+
*/
|
|
63
|
+
arrow?: HTMLElement | null;
|
|
58
64
|
/** Callback when position is updated. */
|
|
59
65
|
onPositionUpdate?: (x: number, y: number, placement: FloatingPlacement) => void;
|
|
60
66
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computePosition, flip, shift, limitShift, offset as offsetMiddleware, size, autoUpdate } from '@floating-ui/dom';
|
|
1
|
+
import { arrow as arrowMiddleware, computePosition, flip, shift, limitShift, offset as offsetMiddleware, size, autoUpdate } from '@floating-ui/dom';
|
|
2
2
|
/**
|
|
3
3
|
* A zero-size anchor at a viewport point, for panels that follow the pointer
|
|
4
4
|
* instead of an element — a context menu at the cursor, a toolbar at a text
|
|
@@ -24,6 +24,9 @@ export function createPointAnchor(x, y, contextElement) {
|
|
|
24
24
|
...(contextElement ? { contextElement } : {})
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
+
function isVirtualAnchor(anchor) {
|
|
28
|
+
return anchor !== null && !(anchor instanceof Element);
|
|
29
|
+
}
|
|
27
30
|
/** Viewport gutter applied when no `collisionPadding` is given. */
|
|
28
31
|
const DEFAULT_COLLISION_PADDING = 8;
|
|
29
32
|
/**
|
|
@@ -166,14 +169,21 @@ export function floating(floatingElement, options) {
|
|
|
166
169
|
floatingEl.style.maxWidth = `${clampedAvailableWidth}px`;
|
|
167
170
|
floatingEl.style.maxHeight = `${clampedAvailableHeight}px`;
|
|
168
171
|
}
|
|
169
|
-
})
|
|
172
|
+
}),
|
|
173
|
+
...(currentOptions.arrow ? [arrowMiddleware({ element: currentOptions.arrow })] : [])
|
|
170
174
|
];
|
|
171
175
|
}
|
|
176
|
+
function applyArrowPosition(arrowElement, data, finalPlacement) {
|
|
177
|
+
const side = finalPlacement.split('-')[0];
|
|
178
|
+
arrowElement.dataset.placement = side;
|
|
179
|
+
arrowElement.style.left = data?.x !== undefined ? `${data.x}px` : '';
|
|
180
|
+
arrowElement.style.top = data?.y !== undefined ? `${data.y}px` : '';
|
|
181
|
+
}
|
|
172
182
|
async function updatePosition() {
|
|
173
183
|
const anchor = currentOptions.anchor;
|
|
174
184
|
if (!anchor || !floatingElement)
|
|
175
185
|
return;
|
|
176
|
-
const { x, y, placement: finalPlacement } = await computePosition(anchor, floatingElement, {
|
|
186
|
+
const { x, y, placement: finalPlacement, middlewareData } = await computePosition(anchor, floatingElement, {
|
|
177
187
|
placement: normalizeExtendedPlacement(currentOptions.placement || 'bottom'),
|
|
178
188
|
middleware: buildMiddleware(),
|
|
179
189
|
strategy: 'fixed' // Use fixed strategy for portal-rendered elements
|
|
@@ -182,6 +192,9 @@ export function floating(floatingElement, options) {
|
|
|
182
192
|
left: `${x}px`,
|
|
183
193
|
top: `${y}px`
|
|
184
194
|
});
|
|
195
|
+
if (currentOptions.arrow) {
|
|
196
|
+
applyArrowPosition(currentOptions.arrow, middlewareData.arrow, finalPlacement);
|
|
197
|
+
}
|
|
185
198
|
currentOptions.onPositionUpdate?.(x, y, finalPlacement);
|
|
186
199
|
}
|
|
187
200
|
function stop() {
|
|
@@ -199,13 +212,21 @@ export function floating(floatingElement, options) {
|
|
|
199
212
|
return {
|
|
200
213
|
update(newOptions) {
|
|
201
214
|
const anchorChanged = newOptions.anchor !== currentOptions.anchor;
|
|
215
|
+
// Two virtual anchors on the same context element are two points on one surface: a
|
|
216
|
+
// panel that follows the pointer makes one per move. The listeners of `autoUpdate`
|
|
217
|
+
// are on the context element, thus they stay, and only the position runs again.
|
|
218
|
+
const sameSurface = anchorChanged &&
|
|
219
|
+
isVirtualAnchor(newOptions.anchor) &&
|
|
220
|
+
isVirtualAnchor(currentOptions.anchor) &&
|
|
221
|
+
newOptions.anchor.contextElement !== undefined &&
|
|
222
|
+
newOptions.anchor.contextElement === currentOptions.anchor.contextElement;
|
|
202
223
|
currentOptions = newOptions;
|
|
203
|
-
if (anchorChanged) {
|
|
224
|
+
if (anchorChanged && !(sameSurface && cleanup)) {
|
|
204
225
|
// Re-subscribe autoUpdate to the new anchor (or stop when it's gone).
|
|
205
226
|
start();
|
|
206
227
|
}
|
|
207
228
|
else if (cleanup) {
|
|
208
|
-
// Same anchor, new placement/offset/boundary: reposition immediately.
|
|
229
|
+
// Same anchor, new placement/offset/boundary/arrow: reposition immediately.
|
|
209
230
|
void updatePosition();
|
|
210
231
|
}
|
|
211
232
|
},
|
|
@@ -79,6 +79,12 @@ export type KeyboardNavigationReturn = {
|
|
|
79
79
|
setCurrentId: (id: string | number | null) => void;
|
|
80
80
|
/** Update items (call after DOM changes) */
|
|
81
81
|
updateItems: () => void;
|
|
82
|
+
/**
|
|
83
|
+
* Searches with a printable character, the same as a key press on the container. For a
|
|
84
|
+
* widget that opens on a character typed outside the container, such as a select: the
|
|
85
|
+
* character is applied once the items exist.
|
|
86
|
+
*/
|
|
87
|
+
typeahead: (char: string) => void;
|
|
82
88
|
};
|
|
83
89
|
/**
|
|
84
90
|
* Creates a keyboard navigation controller for list-like components.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The focus state of a trigger after its floating panel closes.
|
|
3
|
+
*
|
|
4
|
+
* Shared by Popover and Menu, whose close reasons differ only in which of them return the
|
|
5
|
+
* focus to the trigger. The rule for the attributes is the same for both: the trigger shows
|
|
6
|
+
* `data-focused` and `data-focus-visible` only while it holds the focus. Written by hand for
|
|
7
|
+
* a trigger that does not hold it, they would clear only on a blur of the trigger — and a
|
|
8
|
+
* trigger that never took the focus never blurs.
|
|
9
|
+
*/
|
|
10
|
+
export declare function clearTriggerFocusState(trigger: HTMLElement): void;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the last interaction left the focus on nothing: the body, or no element at all.
|
|
13
|
+
*
|
|
14
|
+
* An outside press on a heading, on a paragraph or on the background moves the focus to the
|
|
15
|
+
* body, and a keyboard user then has nowhere to continue from — Space and Enter open nothing.
|
|
16
|
+
* The focus returns to the trigger in that case, and only in that case: a press on a button or
|
|
17
|
+
* an input keeps the focus the user just gave it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function focusFellToBody(): boolean;
|
|
20
|
+
export type ApplyTriggerCloseFocusStateOptions = {
|
|
21
|
+
/**
|
|
22
|
+
* Whether the close reason returns the focus to the trigger on its own. An outside press
|
|
23
|
+
* never does, and it is handled here: the focus returns only when the press left it on
|
|
24
|
+
* nothing.
|
|
25
|
+
*/
|
|
26
|
+
refocus: boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare function applyTriggerCloseFocusState(trigger: HTMLElement, reason: string, event: Event | undefined, options: ApplyTriggerCloseFocusStateOptions): void;
|
|
29
|
+
export declare function addTriggerBlurCleanup(trigger: HTMLElement, once?: boolean): () => void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { focusWithModality, resolveCloseInteractionModality } from './input-modality.js';
|
|
2
|
+
/**
|
|
3
|
+
* The focus state of a trigger after its floating panel closes.
|
|
4
|
+
*
|
|
5
|
+
* Shared by Popover and Menu, whose close reasons differ only in which of them return the
|
|
6
|
+
* focus to the trigger. The rule for the attributes is the same for both: the trigger shows
|
|
7
|
+
* `data-focused` and `data-focus-visible` only while it holds the focus. Written by hand for
|
|
8
|
+
* a trigger that does not hold it, they would clear only on a blur of the trigger — and a
|
|
9
|
+
* trigger that never took the focus never blurs.
|
|
10
|
+
*/
|
|
11
|
+
export function clearTriggerFocusState(trigger) {
|
|
12
|
+
delete trigger.dataset.focused;
|
|
13
|
+
delete trigger.dataset.focusVisible;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether the last interaction left the focus on nothing: the body, or no element at all.
|
|
17
|
+
*
|
|
18
|
+
* An outside press on a heading, on a paragraph or on the background moves the focus to the
|
|
19
|
+
* body, and a keyboard user then has nowhere to continue from — Space and Enter open nothing.
|
|
20
|
+
* The focus returns to the trigger in that case, and only in that case: a press on a button or
|
|
21
|
+
* an input keeps the focus the user just gave it.
|
|
22
|
+
*/
|
|
23
|
+
export function focusFellToBody() {
|
|
24
|
+
const active = document.activeElement;
|
|
25
|
+
return !active || active === document.body || active === document.documentElement;
|
|
26
|
+
}
|
|
27
|
+
export function applyTriggerCloseFocusState(trigger, reason, event, options) {
|
|
28
|
+
const closeModality = resolveCloseInteractionModality(reason, event);
|
|
29
|
+
if (options.refocus || (reason === 'outside-press' && focusFellToBody())) {
|
|
30
|
+
focusWithModality(trigger, closeModality);
|
|
31
|
+
}
|
|
32
|
+
const holdsFocus = document.activeElement === trigger;
|
|
33
|
+
if (holdsFocus) {
|
|
34
|
+
trigger.dataset.focused = 'true';
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
delete trigger.dataset.focused;
|
|
38
|
+
}
|
|
39
|
+
if (holdsFocus && closeModality === 'keyboard') {
|
|
40
|
+
trigger.dataset.focusVisible = 'true';
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
delete trigger.dataset.focusVisible;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function addTriggerBlurCleanup(trigger, once = false) {
|
|
47
|
+
const handleBlur = () => {
|
|
48
|
+
clearTriggerFocusState(trigger);
|
|
49
|
+
if (once) {
|
|
50
|
+
trigger.removeEventListener('blur', handleBlur);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
trigger.addEventListener('blur', handleBlur);
|
|
54
|
+
return () => {
|
|
55
|
+
trigger.removeEventListener('blur', handleBlur);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Progress
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`Progress` shows the status of a task that takes time. It holds a value between `min` and `max`, or no value while the end of the task is not known. A screen reader reads its name and its value.
|
|
6
|
+
|
|
7
|
+
## Anatomy
|
|
8
|
+
|
|
9
|
+
- `Progress.Root`
|
|
10
|
+
- `Progress.Label`
|
|
11
|
+
- `Progress.Track`
|
|
12
|
+
- `Progress.Indicator`
|
|
13
|
+
- `Progress.Value`
|
|
14
|
+
|
|
15
|
+
```svelte
|
|
16
|
+
<Progress.Root value={31}>
|
|
17
|
+
<Progress.Label>Export data</Progress.Label>
|
|
18
|
+
<Progress.Value />
|
|
19
|
+
<Progress.Track>
|
|
20
|
+
<Progress.Indicator />
|
|
21
|
+
</Progress.Track>
|
|
22
|
+
</Progress.Root>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage guidelines
|
|
26
|
+
|
|
27
|
+
- Give the bar a name with `Progress.Label`, or with `aria-label` on the root.
|
|
28
|
+
- Give `value={null}` while the end of the task is not known. Animate the indicator with CSS on `data-indeterminate`.
|
|
29
|
+
- Give `format` to show the value in a unit. Without it, the text is the position in the range as a percentage.
|
|
30
|
+
- Read `percent` and `status` from `bind:context` for a shape of your own, such as a ring.
|
|
31
|
+
- Put `aria-busy="true"` on the region that the task fills. The bar says how far the task is; it does not say what the task changes.
|
|
32
|
+
|
|
33
|
+
## API reference
|
|
34
|
+
|
|
35
|
+
- `Progress.Root`
|
|
36
|
+
- `value: number | null`
|
|
37
|
+
- `min?: number` (0), `max?: number` (100)
|
|
38
|
+
- `format?: Intl.NumberFormatOptions`
|
|
39
|
+
- `getValueText?: (formattedValue, value) => string`
|
|
40
|
+
- `aria-valuetext?: string`
|
|
41
|
+
- `orientation?: 'horizontal' | 'vertical'` (horizontal)
|
|
42
|
+
- `element?`, `context?`
|
|
43
|
+
- `Progress.Value`
|
|
44
|
+
- `children?: Snippet<[{ formattedValue, value, status }]>`
|
|
45
|
+
|
|
46
|
+
## Accessibility
|
|
47
|
+
|
|
48
|
+
- `Progress.Root` has `role="progressbar"` with `aria-valuemin`, `aria-valuemax`, `aria-valuenow` and `aria-valuetext`.
|
|
49
|
+
- An indeterminate progress has no `aria-valuenow` and no `aria-valuetext`. A number for a task with no known end would be false.
|
|
50
|
+
- `Progress.Label` writes `aria-labelledby` on the bar. An `aria-labelledby` that you give stands.
|
|
51
|
+
- `Progress.Value` is `aria-hidden`: the bar already gives the value to the screen reader.
|
|
52
|
+
- The value follows the locale of `LocaleProvider`, and the runtime locale without one.
|
|
53
|
+
- The bar takes no focus, and it has no focus state. It is not in the focus contract.
|
|
54
|
+
- The indicator fills from the start edge of the text direction: a right-to-left page fills from the right.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ComponentProps } from 'svelte';
|
|
2
|
+
import type ProgressIndicatorComponent from './indicator/progress-indicator.svelte';
|
|
3
|
+
import type ProgressLabelComponent from './label/progress-label.svelte';
|
|
4
|
+
import type ProgressRootComponent from './root/progress-root.svelte';
|
|
5
|
+
import type ProgressTrackComponent from './track/progress-track.svelte';
|
|
6
|
+
import type ProgressValueComponent from './value/progress-value.svelte';
|
|
7
|
+
export * as Progress from './index.parts.js';
|
|
8
|
+
export { default as ProgressRoot } from './root/progress-root.svelte';
|
|
9
|
+
export { default as ProgressLabel } from './label/progress-label.svelte';
|
|
10
|
+
export { default as ProgressTrack } from './track/progress-track.svelte';
|
|
11
|
+
export { default as ProgressIndicator } from './indicator/progress-indicator.svelte';
|
|
12
|
+
export { default as ProgressValue } from './value/progress-value.svelte';
|
|
13
|
+
export type ProgressRootProps = ComponentProps<typeof ProgressRootComponent>;
|
|
14
|
+
export type ProgressLabelProps = ComponentProps<typeof ProgressLabelComponent>;
|
|
15
|
+
export type ProgressTrackProps = ComponentProps<typeof ProgressTrackComponent>;
|
|
16
|
+
export type ProgressIndicatorProps = ComponentProps<typeof ProgressIndicatorComponent>;
|
|
17
|
+
export type ProgressValueProps = ComponentProps<typeof ProgressValueComponent>;
|
|
18
|
+
export type { ProgressValueState } from './types.js';
|
|
19
|
+
export { getProgressContext, setProgressContext, useProgressContext, type ProgressContext, type ProgressOrientation, type ProgressStatus } from './root/context.js';
|
|
20
|
+
import * as ProgressParts from './index.parts.js';
|
|
21
|
+
export default ProgressParts;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * as Progress from './index.parts.js';
|
|
2
|
+
export { default as ProgressRoot } from './root/progress-root.svelte';
|
|
3
|
+
export { default as ProgressLabel } from './label/progress-label.svelte';
|
|
4
|
+
export { default as ProgressTrack } from './track/progress-track.svelte';
|
|
5
|
+
export { default as ProgressIndicator } from './indicator/progress-indicator.svelte';
|
|
6
|
+
export { default as ProgressValue } from './value/progress-value.svelte';
|
|
7
|
+
export { getProgressContext, setProgressContext, useProgressContext } from './root/context.js';
|
|
8
|
+
import * as ProgressParts from './index.parts.js';
|
|
9
|
+
export default ProgressParts;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as Root } from './root/progress-root.svelte';
|
|
2
|
+
export { default as Label } from './label/progress-label.svelte';
|
|
3
|
+
export { default as Track } from './track/progress-track.svelte';
|
|
4
|
+
export { default as Indicator } from './indicator/progress-indicator.svelte';
|
|
5
|
+
export { default as Value } from './value/progress-value.svelte';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as Root } from './root/progress-root.svelte';
|
|
2
|
+
export { default as Label } from './label/progress-label.svelte';
|
|
3
|
+
export { default as Track } from './track/progress-track.svelte';
|
|
4
|
+
export { default as Indicator } from './indicator/progress-indicator.svelte';
|
|
5
|
+
export { default as Value } from './value/progress-value.svelte';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ProgressIndicatorProps } from '../types.js';
|
|
3
|
+
import { useProgressContext } from '../root/context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Progress.Indicator — the part of the track that the task has done.
|
|
7
|
+
*
|
|
8
|
+
* It sizes itself to the percentage: the width from the start edge of a horizontal track, and
|
|
9
|
+
* the height from the bottom of a vertical one. The start edge follows the direction of the
|
|
10
|
+
* text, thus a right-to-left page fills from the right. An indeterminate progress gets no
|
|
11
|
+
* size: your CSS animates it.
|
|
12
|
+
*/
|
|
13
|
+
let { children, class: className = '', style, ...restProps }: ProgressIndicatorProps = $props();
|
|
14
|
+
|
|
15
|
+
const progress = useProgressContext('Progress.Indicator');
|
|
16
|
+
|
|
17
|
+
const sizeStyle = $derived.by(() => {
|
|
18
|
+
if (progress.percent === null) return '';
|
|
19
|
+
if (progress.orientation === 'vertical') {
|
|
20
|
+
return `position: absolute; inset-inline: 0; bottom: 0; height: ${progress.percent}%;`;
|
|
21
|
+
}
|
|
22
|
+
return `position: absolute; inset-block: 0; inset-inline-start: 0; width: ${progress.percent}%;`;
|
|
23
|
+
});
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<div
|
|
27
|
+
{...restProps}
|
|
28
|
+
class={className}
|
|
29
|
+
style="{sizeStyle}{style ? ` ${style}` : ''}"
|
|
30
|
+
data-progress-indicator="true"
|
|
31
|
+
data-orientation={progress.orientation}
|
|
32
|
+
data-progressing={progress.status === 'progressing' || undefined}
|
|
33
|
+
data-complete={progress.status === 'complete' || undefined}
|
|
34
|
+
data-indeterminate={progress.status === 'indeterminate' || undefined}
|
|
35
|
+
>
|
|
36
|
+
{@render children?.()}
|
|
37
|
+
</div>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ProgressLabelProps } from '../types.js';
|
|
3
|
+
import { useProgressContext } from '../root/context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Progress.Label — the name of the task.
|
|
7
|
+
*
|
|
8
|
+
* It registers its id with the root, which gives it to the progress bar as `aria-labelledby`.
|
|
9
|
+
* A bare text beside the bar leaves the bar unnamed: a `role="progressbar"` takes its name
|
|
10
|
+
* from `aria-labelledby` or `aria-label`, never from the text near it. It renders a `<span>`
|
|
11
|
+
* and not a `<label>`, because a `<label>` names a form control, and a progress bar is none.
|
|
12
|
+
*/
|
|
13
|
+
let { children, class: className = '', id: idProp, ...restProps }: ProgressLabelProps = $props();
|
|
14
|
+
|
|
15
|
+
const progress = useProgressContext('Progress.Label');
|
|
16
|
+
const generatedId = $props.id();
|
|
17
|
+
const id = $derived(idProp ?? generatedId);
|
|
18
|
+
|
|
19
|
+
// The returned unregister runs on destroy, and again whenever the id changes.
|
|
20
|
+
$effect(() => progress.registerLabel(id));
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<span
|
|
24
|
+
{...restProps}
|
|
25
|
+
{id}
|
|
26
|
+
class={className}
|
|
27
|
+
data-progress-label="true"
|
|
28
|
+
data-orientation={progress.orientation}
|
|
29
|
+
data-progressing={progress.status === 'progressing' || undefined}
|
|
30
|
+
data-complete={progress.status === 'complete' || undefined}
|
|
31
|
+
data-indeterminate={progress.status === 'indeterminate' || undefined}
|
|
32
|
+
>
|
|
33
|
+
{@render children?.()}
|
|
34
|
+
</span>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ProgressStatus } from './progress-utils';
|
|
2
|
+
export type ProgressOrientation = 'horizontal' | 'vertical';
|
|
3
|
+
export type ProgressContext = {
|
|
4
|
+
/** The id of the root element. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** The value, held in the range. `null` while the progress is indeterminate. */
|
|
7
|
+
value: number | null;
|
|
8
|
+
min: number;
|
|
9
|
+
max: number;
|
|
10
|
+
/** The position in the range, from 0 to 100. `null` while the progress is indeterminate. */
|
|
11
|
+
percent: number | null;
|
|
12
|
+
status: ProgressStatus;
|
|
13
|
+
orientation: ProgressOrientation;
|
|
14
|
+
/** The value as text, for the user. Empty while the progress is indeterminate. */
|
|
15
|
+
formattedValue: string;
|
|
16
|
+
/** The text a screen reader gets for the value. */
|
|
17
|
+
valueText: string | undefined;
|
|
18
|
+
/** The ids of the registered labels, for `aria-labelledby`. */
|
|
19
|
+
labelledBy: string | undefined;
|
|
20
|
+
/** Registers a label id; the returned function unregisters it. */
|
|
21
|
+
registerLabel: (id: string) => () => void;
|
|
22
|
+
};
|
|
23
|
+
export declare function setProgressContext(context: ProgressContext): void;
|
|
24
|
+
export declare function getProgressContext(): ProgressContext | undefined;
|
|
25
|
+
export declare function useProgressContext(part?: string): ProgressContext;
|
|
26
|
+
export type { ProgressStatus };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
const KEY = Symbol('progress');
|
|
3
|
+
export function setProgressContext(context) {
|
|
4
|
+
setContext(KEY, context);
|
|
5
|
+
}
|
|
6
|
+
export function getProgressContext() {
|
|
7
|
+
return getContext(KEY);
|
|
8
|
+
}
|
|
9
|
+
export function useProgressContext(part = 'Progress') {
|
|
10
|
+
const context = getProgressContext();
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error(`${part} must be used within Progress.Root.`);
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|