@barqjs/aria 0.0.0-stage → 0.2.0-next.1
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/LICENSE +21 -0
- package/README.md +304 -2
- package/package.json +437 -4
- package/src/autocomplete.tsx +581 -0
- package/src/breadcrumbs.tsx +297 -0
- package/src/button.tsx +468 -0
- package/src/calendar.tsx +2316 -0
- package/src/checkbox.tsx +732 -0
- package/src/collections.ts +1059 -0
- package/src/color.ts +2119 -0
- package/src/colorpicker.tsx +2023 -0
- package/src/colorswatchpicker.tsx +240 -0
- package/src/combobox.tsx +3003 -0
- package/src/command.tsx +1203 -0
- package/src/date.ts +674 -0
- package/src/datefield.tsx +2066 -0
- package/src/datepicker.tsx +907 -0
- package/src/dialog.tsx +1077 -0
- package/src/disclosure.tsx +711 -0
- package/src/dnd/clipboard.ts +125 -0
- package/src/dnd/collection.ts +1265 -0
- package/src/dnd/data.ts +409 -0
- package/src/dnd/drag-drop.ts +801 -0
- package/src/dnd/index.ts +133 -0
- package/src/dnd/manager.ts +639 -0
- package/src/dnd/strings.ts +1279 -0
- package/src/dnd/targets.ts +726 -0
- package/src/dnd/types.ts +212 -0
- package/src/dom.ts +703 -0
- package/src/drag-and-drop.tsx +669 -0
- package/src/drawer.ts +674 -0
- package/src/dropzone.tsx +208 -0
- package/src/file-trigger.tsx +103 -0
- package/src/focus.ts +1370 -0
- package/src/form.tsx +94 -0
- package/src/gridlist.tsx +1354 -0
- package/src/group.tsx +146 -0
- package/src/i18n.ts +823 -0
- package/src/index.ts +1672 -0
- package/src/interactions/description.ts +73 -0
- package/src/interactions/flags.ts +35 -0
- package/src/interactions/focus-events.ts +226 -0
- package/src/interactions/focusable.ts +86 -0
- package/src/interactions/hover.ts +213 -0
- package/src/interactions/interact-outside.ts +123 -0
- package/src/interactions/keyboard.ts +298 -0
- package/src/interactions/listeners.ts +78 -0
- package/src/interactions/long-press.ts +160 -0
- package/src/interactions/modality.ts +428 -0
- package/src/interactions/move.ts +257 -0
- package/src/interactions/open-link.ts +226 -0
- package/src/interactions/press.ts +915 -0
- package/src/interactions/prevent-focus.ts +102 -0
- package/src/interactions/scroll-wheel.ts +43 -0
- package/src/interactions/text-selection.ts +77 -0
- package/src/interactions.ts +81 -0
- package/src/label.ts +140 -0
- package/src/link.tsx +477 -0
- package/src/listbox.tsx +1247 -0
- package/src/live.ts +208 -0
- package/src/menu.tsx +2383 -0
- package/src/menubar.tsx +579 -0
- package/src/navigation-tree.tsx +357 -0
- package/src/navigation.ts +735 -0
- package/src/numberfield.tsx +942 -0
- package/src/otp.ts +430 -0
- package/src/overlay-arrow.tsx +157 -0
- package/src/overlays.ts +1549 -0
- package/src/platform.ts +75 -0
- package/src/presence.ts +164 -0
- package/src/preview-trigger.tsx +582 -0
- package/src/progress-bar-context.ts +15 -0
- package/src/questionnaire.tsx +1717 -0
- package/src/radio.tsx +641 -0
- package/src/register-dom.ts +12 -0
- package/src/scroller.ts +1165 -0
- package/src/select.tsx +1745 -0
- package/src/selection-indicator.tsx +74 -0
- package/src/selection.ts +1472 -0
- package/src/shared-element-transition.tsx +316 -0
- package/src/sheet.tsx +1461 -0
- package/src/slider.tsx +1137 -0
- package/src/splitter.ts +1152 -0
- package/src/static-collection.ts +211 -0
- package/src/switch.tsx +212 -0
- package/src/table.tsx +2218 -0
- package/src/tabs.tsx +1127 -0
- package/src/tag.tsx +637 -0
- package/src/textarea.tsx +186 -0
- package/src/textfield.tsx +483 -0
- package/src/toast-components.tsx +589 -0
- package/src/toast.ts +658 -0
- package/src/toggle-button-group.tsx +175 -0
- package/src/toggle-input.tsx +86 -0
- package/src/toggle.ts +384 -0
- package/src/togglegroup.ts +365 -0
- package/src/tokenfield.tsx +1673 -0
- package/src/toolbar.tsx +184 -0
- package/src/tooltip.tsx +674 -0
- package/src/tree.tsx +2075 -0
- package/src/utils.ts +787 -0
- package/src/validation.ts +504 -0
- package/src/virtualizer.tsx +837 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A selection indicator: the bar under the chosen tab, the pill behind the
|
|
3
|
+
* pressed segment, that slides to the new choice rather than blinking.
|
|
4
|
+
*
|
|
5
|
+
* Every item renders one, and only the selected item's is shown. It is a
|
|
6
|
+
* {@link SharedElement} named `SelectionIndicator`, so inside one
|
|
7
|
+
* {@link SharedElementTransition} the indicator leaving the old item and the
|
|
8
|
+
* one arriving at the new item are drawn as one element moving between them.
|
|
9
|
+
*
|
|
10
|
+
* Whether it is shown comes from the item it is in, which offers its selected
|
|
11
|
+
* state with {@link SelectionIndicatorProvider}, or from `isSelected` when the
|
|
12
|
+
* caller knows better.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
type Accessor,
|
|
17
|
+
type Child,
|
|
18
|
+
createContext,
|
|
19
|
+
getContext,
|
|
20
|
+
type Incoming,
|
|
21
|
+
omit,
|
|
22
|
+
provide,
|
|
23
|
+
} from "@barqjs/core";
|
|
24
|
+
import type { RefTarget } from "@barqjs/primitives/refs";
|
|
25
|
+
import { SharedElement } from "./shared-element-transition.tsx";
|
|
26
|
+
import type { StyleProps } from "./utils.ts";
|
|
27
|
+
|
|
28
|
+
export interface SelectionIndicatorValue {
|
|
29
|
+
isSelected: Accessor<boolean>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const SelectionIndicatorContext = createContext<SelectionIndicatorValue | null>(null);
|
|
33
|
+
|
|
34
|
+
/** The enclosing item's selected state, if an item offered it. */
|
|
35
|
+
export function useSelectionIndicator(): SelectionIndicatorValue | null {
|
|
36
|
+
return getContext(SelectionIndicatorContext) ?? null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SelectionIndicatorProviderProps {
|
|
40
|
+
/** Whether the item the children are in is selected. */
|
|
41
|
+
isSelected: boolean;
|
|
42
|
+
children?: Child;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Offer an item's selected state to a {@link SelectionIndicator} among its
|
|
47
|
+
* children. An item component wraps its children in it.
|
|
48
|
+
*/
|
|
49
|
+
export function SelectionIndicatorProvider(props: Incoming<SelectionIndicatorProviderProps>) {
|
|
50
|
+
const value: SelectionIndicatorValue = { isSelected: () => props.isSelected() };
|
|
51
|
+
return provide(
|
|
52
|
+
SelectionIndicatorContext,
|
|
53
|
+
() => value,
|
|
54
|
+
() => props.children as unknown,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface SelectionIndicatorComponentProps extends StyleProps {
|
|
59
|
+
/** @default the enclosing item's selected state */
|
|
60
|
+
isSelected?: boolean;
|
|
61
|
+
children?: Child;
|
|
62
|
+
ref?: RefTarget<HTMLDivElement>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function SelectionIndicator(props: SelectionIndicatorComponentProps) {
|
|
66
|
+
const item = useSelectionIndicator();
|
|
67
|
+
return (
|
|
68
|
+
<SharedElement
|
|
69
|
+
{...omit(props, "isSelected")}
|
|
70
|
+
name="SelectionIndicator"
|
|
71
|
+
isVisible={props.isSelected ?? item?.isSelected() ?? false}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
}
|