@alulore/kumiko 0.14.1 → 0.15.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.
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/alert/alert.css +483 -0
- package/dist/alert/alert.d.ts +51 -0
- package/dist/alert/alert.js +40 -0
- package/dist/alert/index.d.ts +1 -0
- package/dist/alert/index.js +1 -0
- package/dist/card/card.css +727 -0
- package/dist/card/card.d.ts +62 -0
- package/dist/card/card.js +48 -0
- package/dist/card/index.d.ts +2 -0
- package/dist/card/index.js +2 -0
- package/dist/card/item-card.d.ts +84 -0
- package/dist/card/item-card.js +73 -0
- package/dist/list-row/index.d.ts +1 -0
- package/dist/list-row/index.js +1 -0
- package/dist/list-row/list-row-motion.d.ts +10 -0
- package/dist/list-row/list-row-motion.js +141 -0
- package/dist/list-row/list-row.css +403 -0
- package/dist/list-row/list-row.d.ts +64 -0
- package/dist/list-row/list-row.js +54 -0
- package/package.json +30 -6
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** How a card is built: a flat panel, a recessed panel, a drop target, a row with a lamp and actions, a button, or an add button. */
|
|
2
|
+
export type CardVariant = "surface" | "inset" | "well" | "banner" | "interactive" | "add";
|
|
3
|
+
/** The surface look: a flat fill, a fill with a hairline edge, a raised soft shadow, or an outline only. */
|
|
4
|
+
export type CardSurface = "flat" | "edge" | "raised" | "outline";
|
|
5
|
+
/** What a pressable card does on hover: grow slightly, lift with a deeper shadow, or only brighten. */
|
|
6
|
+
export type CardHover = "grow" | "lift" | "brighten";
|
|
7
|
+
/** What a pressable card does under a press: squash, sink (a tighter shadow and a darker fill), or nothing. */
|
|
8
|
+
export type CardPress = "squash" | "sink" | "none";
|
|
9
|
+
/** The look of an add card: a dashed outline, a dotted outline, or a soft fill with a plus mark. */
|
|
10
|
+
export type CardAddLook = "dashed" | "dotted" | "plus";
|
|
11
|
+
/** The looks every card shares. Each is a prop, or a word on any container such as `data-kumiko-card="hover-grow"`. */
|
|
12
|
+
export interface CardLooks {
|
|
13
|
+
/**
|
|
14
|
+
* Inset, well and add cards keep their own surface.
|
|
15
|
+
* Word: `surface-flat`, `surface-edge`, `surface-raised` or `surface-outline`.
|
|
16
|
+
* @defaultValue "flat"
|
|
17
|
+
*/
|
|
18
|
+
surface?: CardSurface;
|
|
19
|
+
/**
|
|
20
|
+
* Only a pressable card reacts. Word: `hover-grow`, `hover-lift` or `hover-brighten`.
|
|
21
|
+
* @defaultValue "grow"
|
|
22
|
+
*/
|
|
23
|
+
hover?: CardHover;
|
|
24
|
+
/**
|
|
25
|
+
* Only a pressable card reacts. Word: `press-squash`, `press-sink` or `press-none`.
|
|
26
|
+
* @defaultValue "squash"
|
|
27
|
+
*/
|
|
28
|
+
press?: CardPress;
|
|
29
|
+
}
|
|
30
|
+
/** The data attributes the looks become. A look left out sets nothing, so a word on a container can pick. */
|
|
31
|
+
export declare function lookAttributes(looks: CardLooks): Record<string, string | undefined>;
|
|
32
|
+
export type CardProps = React.HTMLAttributes<HTMLElement> & CardLooks & {
|
|
33
|
+
/** @defaultValue "surface" */
|
|
34
|
+
variant?: CardVariant;
|
|
35
|
+
/**
|
|
36
|
+
* The look of an add card. Word: `add-dashed`, `add-dotted` or `add-plus`.
|
|
37
|
+
* @defaultValue "dashed"
|
|
38
|
+
*/
|
|
39
|
+
addLook?: CardAddLook;
|
|
40
|
+
/** Dimmed, with a not-allowed cursor, and no hover or press. */
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
/** Shown as it is, with no hover, press or pointer cursor, and not dimmed. A button card becomes a plain box. */
|
|
43
|
+
readOnly?: boolean;
|
|
44
|
+
/** A well that a card is being dragged over takes a tint and a ring. */
|
|
45
|
+
over?: boolean;
|
|
46
|
+
/** A well with a solid fill, for use as a drop target on a busy background. */
|
|
47
|
+
solid?: boolean;
|
|
48
|
+
/** The lamp at the start of a banner. */
|
|
49
|
+
lamp?: React.ReactNode;
|
|
50
|
+
/** The actions at the end of a banner. */
|
|
51
|
+
actions?: React.ReactNode;
|
|
52
|
+
/** The card's element: a `div`, or a `button` for a pressable card. */
|
|
53
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
54
|
+
};
|
|
55
|
+
/** An empty data attribute when on, and none when off. */
|
|
56
|
+
export declare function flag(on: boolean | undefined): string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* A panel in six variants. An `interactive` card with an `onClick`, and an `add` card, are buttons: only they
|
|
59
|
+
* (and not `disabled` or `readOnly` ones) react to hover and press. A `banner` shows `lamp`, the children and `actions` in a row.
|
|
60
|
+
* `surface`, `hover`, `press` and `addLook` pick looks; the same words work on any container.
|
|
61
|
+
*/
|
|
62
|
+
export declare function Card({ variant, surface, hover, press, addLook, disabled, readOnly, over, solid, lamp, actions, children, onClick, ref, ...props }: CardProps): React.JSX.Element;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { renderElement } from "@ui-sdk/react/primitive";
|
|
3
|
+
/** The data attributes the looks become. A look left out sets nothing, so a word on a container can pick. */
|
|
4
|
+
export function lookAttributes(looks) {
|
|
5
|
+
return {
|
|
6
|
+
"data-look-surface": looks.surface,
|
|
7
|
+
"data-look-hover": looks.hover,
|
|
8
|
+
"data-look-press": looks.press
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** An empty data attribute when on, and none when off. */
|
|
12
|
+
export function flag(on) {
|
|
13
|
+
return on ? "" : undefined;
|
|
14
|
+
}
|
|
15
|
+
/** A banner's row: the lamp, the body and the actions. */
|
|
16
|
+
function banner(lamp, children, actions) {
|
|
17
|
+
return (_jsxs(_Fragment, { children: [lamp ? _jsx("div", { "data-slot": "card-lamp", children: lamp }) : null, _jsx("div", { "data-slot": "card-body", children: children }), actions ? _jsx("div", { "data-slot": "card-actions", children: actions }) : null] }));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A panel in six variants. An `interactive` card with an `onClick`, and an `add` card, are buttons: only they
|
|
21
|
+
* (and not `disabled` or `readOnly` ones) react to hover and press. A `banner` shows `lamp`, the children and `actions` in a row.
|
|
22
|
+
* `surface`, `hover`, `press` and `addLook` pick looks; the same words work on any container.
|
|
23
|
+
*/
|
|
24
|
+
export function Card({ variant = "surface", surface, hover, press, addLook, disabled = false, readOnly = false, over = false, solid = false, lamp, actions, children, onClick, ref, ...props }) {
|
|
25
|
+
const asButton = !readOnly && (variant === "add" || (variant === "interactive" && onClick !== undefined));
|
|
26
|
+
const common = {
|
|
27
|
+
"data-slot": "card",
|
|
28
|
+
"data-variant": variant,
|
|
29
|
+
...lookAttributes({ surface, hover, press }),
|
|
30
|
+
"data-look-add": addLook,
|
|
31
|
+
"data-over": flag(over),
|
|
32
|
+
"data-solid": flag(solid),
|
|
33
|
+
"data-readonly": flag(readOnly),
|
|
34
|
+
"data-disabled": flag(disabled),
|
|
35
|
+
"data-pressable": flag(asButton && !disabled)
|
|
36
|
+
};
|
|
37
|
+
const kind = asButton
|
|
38
|
+
? { type: "button", disabled, onClick }
|
|
39
|
+
: { "aria-disabled": disabled ? true : undefined };
|
|
40
|
+
const body = variant === "banner" ? banner(lamp, children, actions) : children;
|
|
41
|
+
return renderElement(asButton ? "button" : "div", {
|
|
42
|
+
...common,
|
|
43
|
+
...kind,
|
|
44
|
+
...props,
|
|
45
|
+
ref,
|
|
46
|
+
children: body
|
|
47
|
+
});
|
|
48
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { Card, type CardAddLook, type CardHover, type CardLooks, type CardPress, type CardProps, type CardSurface, type CardVariant } from "./card";
|
|
2
|
+
export { ItemCard, ItemCardEyebrow, ItemCardMedia, ItemCardMeta, ItemCardPolaroid, ItemCardText, ItemCardTitle, type ItemCardDoneLook, type ItemCardDragLook, type ItemCardEyebrowProps, type ItemCardMetaProps, type ItemCardPolaroidProps, type ItemCardPolaroids, type ItemCardProps, type ItemCardSelectLook, type ItemCardTextProps, type ItemCardTone } from "./item-card";
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type CardLooks } from "./card";
|
|
2
|
+
/** The tone of an item card: a dark card or a paper card. */
|
|
3
|
+
export type ItemCardTone = "dark" | "paper";
|
|
4
|
+
/** How a selected item card shows it: a ring outside, a tinted fill with a ring, or a small check badge. */
|
|
5
|
+
export type ItemCardSelectLook = "ring" | "tint" | "check";
|
|
6
|
+
/** How a dragged item card looks: lifted with a bigger shadow, tilted, or grown slightly. */
|
|
7
|
+
export type ItemCardDragLook = "lift" | "tilt" | "grow";
|
|
8
|
+
/** How a done item card looks: struck through, quiet ink only, or a strike that draws across when it becomes done. */
|
|
9
|
+
export type ItemCardDoneLook = "strike" | "quiet" | "draw";
|
|
10
|
+
/** How polaroids sit: a tilted fan that stays, a fan that straightens on hover, or no tilt. */
|
|
11
|
+
export type ItemCardPolaroids = "fan" | "straighten" | "flat";
|
|
12
|
+
export type ItemCardProps = React.HTMLAttributes<HTMLElement> & CardLooks & {
|
|
13
|
+
/** @defaultValue "dark" */
|
|
14
|
+
tone?: ItemCardTone;
|
|
15
|
+
selected?: boolean;
|
|
16
|
+
done?: boolean;
|
|
17
|
+
dragging?: boolean;
|
|
18
|
+
/** Dimmed, with a not-allowed cursor, and no hover or press. */
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
/** Shown as it is, with no hover, press or pointer cursor, and not dimmed. */
|
|
21
|
+
readOnly?: boolean;
|
|
22
|
+
/** Draws the card on its only child, which receives the props. */
|
|
23
|
+
asChild?: boolean;
|
|
24
|
+
/** The card's element. With `asChild` it goes to the child. */
|
|
25
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
26
|
+
/**
|
|
27
|
+
* Word: `select-ring`, `select-tint` or `select-check`.
|
|
28
|
+
* @defaultValue "ring"
|
|
29
|
+
*/
|
|
30
|
+
selectLook?: ItemCardSelectLook;
|
|
31
|
+
/**
|
|
32
|
+
* Word: `drag-lift`, `drag-tilt` or `drag-grow`.
|
|
33
|
+
* @defaultValue "lift"
|
|
34
|
+
*/
|
|
35
|
+
dragLook?: ItemCardDragLook;
|
|
36
|
+
/**
|
|
37
|
+
* Word: `done-strike`, `done-quiet` or `done-draw`.
|
|
38
|
+
* @defaultValue "draw"
|
|
39
|
+
*/
|
|
40
|
+
doneLook?: ItemCardDoneLook;
|
|
41
|
+
/**
|
|
42
|
+
* Word: `polaroid-fan`, `polaroid-straighten` or `polaroid-flat`.
|
|
43
|
+
* @defaultValue "straighten"
|
|
44
|
+
*/
|
|
45
|
+
polaroids?: ItemCardPolaroids;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* A card for one item, as a button when it has an `onClick` and a plain box otherwise; `asChild` draws it on your own element.
|
|
49
|
+
* Only a pressable card (not `disabled` or `readOnly`) reacts to hover and press.
|
|
50
|
+
* The looks are props, and the same words work on any container, such as `data-kumiko-card="select-check done-draw"`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function ItemCard({ asChild, onClick, children, ref, ...props }: ItemCardProps): React.JSX.Element;
|
|
53
|
+
export type ItemCardEyebrowProps = React.ComponentPropsWithoutRef<"span"> & {
|
|
54
|
+
/** The colour of the small diamond, any CSS colour. */
|
|
55
|
+
dot?: string;
|
|
56
|
+
};
|
|
57
|
+
/** A small line above the title, led by a coloured diamond. */
|
|
58
|
+
export declare function ItemCardEyebrow({ dot, children, ...props }: ItemCardEyebrowProps): React.JSX.Element;
|
|
59
|
+
/** The title. A done card shows it quiet, and struck through or drawn through, by its look. */
|
|
60
|
+
export declare function ItemCardTitle({ children, ...props }: React.ComponentPropsWithoutRef<"span">): React.JSX.Element;
|
|
61
|
+
export type ItemCardTextProps = React.ComponentPropsWithoutRef<"span"> & {
|
|
62
|
+
/**
|
|
63
|
+
* How many lines show before the text is cut.
|
|
64
|
+
* @defaultValue 2
|
|
65
|
+
*/
|
|
66
|
+
lines?: number;
|
|
67
|
+
};
|
|
68
|
+
/** A few lines of quiet text, cut after `lines`. */
|
|
69
|
+
export declare function ItemCardText({ lines, style, ...props }: ItemCardTextProps): React.JSX.Element;
|
|
70
|
+
/** A row that holds up to three polaroids. */
|
|
71
|
+
export declare function ItemCardMedia({ children, ...props }: React.ComponentPropsWithoutRef<"span">): React.JSX.Element;
|
|
72
|
+
export type ItemCardPolaroidProps = React.ComponentPropsWithoutRef<"span"> & {
|
|
73
|
+
/** An image address. Without it the children (an inline SVG, say) fill the photo. */
|
|
74
|
+
src?: string;
|
|
75
|
+
alt?: string;
|
|
76
|
+
};
|
|
77
|
+
/** One photo with a white border. */
|
|
78
|
+
export declare function ItemCardPolaroid({ src, alt, children, ...props }: ItemCardPolaroidProps): React.JSX.Element;
|
|
79
|
+
export type ItemCardMetaProps = React.ComponentPropsWithoutRef<"span"> & {
|
|
80
|
+
/** A number or text shown in a count badge at the end. */
|
|
81
|
+
count?: React.ReactNode;
|
|
82
|
+
};
|
|
83
|
+
/** A row for small facts, with a count badge pushed to the end. It needs the badge styles (`badge.css`, which `card.css` imports). */
|
|
84
|
+
export declare function ItemCardMeta({ count, children, ...props }: ItemCardMetaProps): React.JSX.Element;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { mergeProps, renderElement } from "@ui-sdk/react/primitive";
|
|
3
|
+
import { Children, isValidElement } from "react";
|
|
4
|
+
import { Badge } from "../badge/badge";
|
|
5
|
+
import { flag, lookAttributes } from "./card";
|
|
6
|
+
/** Splits the props into the data attributes that carry the state and looks, and the rest for the element. */
|
|
7
|
+
function splitProps(props) {
|
|
8
|
+
const { tone, selected, done, dragging, disabled, readOnly, ...more } = props;
|
|
9
|
+
const { selectLook, dragLook, doneLook, polaroids, surface, hover, press, ...dom } = more;
|
|
10
|
+
const state = {
|
|
11
|
+
"data-slot": "item-card",
|
|
12
|
+
"data-tone": tone === "paper" ? "paper" : undefined,
|
|
13
|
+
"data-selected": flag(selected),
|
|
14
|
+
"data-done": flag(done),
|
|
15
|
+
"data-dragging": flag(dragging),
|
|
16
|
+
"data-readonly": flag(readOnly),
|
|
17
|
+
"data-disabled": flag(disabled),
|
|
18
|
+
"data-look-select": selectLook,
|
|
19
|
+
"data-look-drag": dragLook,
|
|
20
|
+
"data-look-done": doneLook,
|
|
21
|
+
"data-look-polaroid": polaroids,
|
|
22
|
+
"aria-disabled": disabled ? true : undefined,
|
|
23
|
+
...lookAttributes({ surface, hover, press })
|
|
24
|
+
};
|
|
25
|
+
return { state, dom, disabled: disabled === true, readOnly: readOnly === true };
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A card for one item, as a button when it has an `onClick` and a plain box otherwise; `asChild` draws it on your own element.
|
|
29
|
+
* Only a pressable card (not `disabled` or `readOnly`) reacts to hover and press.
|
|
30
|
+
* The looks are props, and the same words work on any container, such as `data-kumiko-card="select-check done-draw"`.
|
|
31
|
+
*/
|
|
32
|
+
export function ItemCard({ asChild = false, onClick, children, ref, ...props }) {
|
|
33
|
+
const { state, dom, disabled, readOnly } = splitProps(props);
|
|
34
|
+
const clickable = onClick !== undefined && !readOnly;
|
|
35
|
+
const pressable = { ...state, "data-pressable": flag(clickable && !disabled) };
|
|
36
|
+
if (asChild && isValidElement(children)) {
|
|
37
|
+
const own = { onClick: clickable && !disabled ? onClick : undefined, ref };
|
|
38
|
+
return renderElement("div", mergeProps(dom, own, pressable), children);
|
|
39
|
+
}
|
|
40
|
+
const button = clickable ? { type: "button", disabled, onClick } : {};
|
|
41
|
+
return renderElement(clickable ? "button" : "div", {
|
|
42
|
+
...dom,
|
|
43
|
+
...pressable,
|
|
44
|
+
...button,
|
|
45
|
+
ref,
|
|
46
|
+
children
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** A small line above the title, led by a coloured diamond. */
|
|
50
|
+
export function ItemCardEyebrow({ dot, children, ...props }) {
|
|
51
|
+
return (_jsxs("span", { "data-slot": "item-card-eyebrow", ...props, children: [_jsx("i", { "aria-hidden": "true", style: dot ? { background: dot } : undefined }), children] }));
|
|
52
|
+
}
|
|
53
|
+
/** The title. A done card shows it quiet, and struck through or drawn through, by its look. */
|
|
54
|
+
export function ItemCardTitle({ children, ...props }) {
|
|
55
|
+
return (_jsx("span", { "data-slot": "item-card-title", ...props, children: _jsx("span", { "data-slot": "item-card-title-text", children: children }) }));
|
|
56
|
+
}
|
|
57
|
+
/** A few lines of quiet text, cut after `lines`. */
|
|
58
|
+
export function ItemCardText({ lines = 2, style, ...props }) {
|
|
59
|
+
const clamp = { WebkitLineClamp: lines, maxBlockSize: `${lines * 1.5}em` };
|
|
60
|
+
return _jsx("span", { "data-slot": "item-card-text", style: { ...style, ...clamp }, ...props });
|
|
61
|
+
}
|
|
62
|
+
/** A row that holds up to three polaroids. */
|
|
63
|
+
export function ItemCardMedia({ children, ...props }) {
|
|
64
|
+
return (_jsx("span", { "data-slot": "item-card-media", "data-count": Children.count(children), ...props, children: children }));
|
|
65
|
+
}
|
|
66
|
+
/** One photo with a white border. */
|
|
67
|
+
export function ItemCardPolaroid({ src, alt = "", children, ...props }) {
|
|
68
|
+
return (_jsx("span", { "data-slot": "item-card-polaroid", ...props, children: _jsx("span", { "data-slot": "item-card-photo", children: src ? _jsx("img", { src: src, alt: alt, draggable: false }) : children }) }));
|
|
69
|
+
}
|
|
70
|
+
/** A row for small facts, with a count badge pushed to the end. It needs the badge styles (`badge.css`, which `card.css` imports). */
|
|
71
|
+
export function ItemCardMeta({ count, children, ...props }) {
|
|
72
|
+
return (_jsxs("span", { "data-slot": "item-card-meta", ...props, children: [children, count !== undefined && count !== null ? (_jsx(Badge, { variant: "count", size: "md", children: count })) : null] }));
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InfoRow, ListRow, RowList, type CurrentLook, type InfoRowProps, type ListRowProps, type RowHover, type RowListProps, type RowPress, type RowSize } from "./list-row";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InfoRow, ListRow, RowList } from "./list-row";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ComponentProps, type RefObject } from "react";
|
|
2
|
+
export declare const ROW = "[data-slot=\"list-row\"]:not([data-static]):not(:disabled)";
|
|
3
|
+
export declare function isRoving(list: HTMLElement): boolean;
|
|
4
|
+
export declare function show(glider: HTMLElement | null, row: HTMLElement | null): void;
|
|
5
|
+
export declare function followFocus(list: HTMLElement, row: HTMLElement): void;
|
|
6
|
+
export declare function targetRow(list: HTMLElement, row: HTMLElement, key: string): HTMLElement | null;
|
|
7
|
+
type Handlers = Pick<ComponentProps<"div">, "onPointerOver" | "onPointerLeave" | "onFocus" | "onKeyDown">;
|
|
8
|
+
export declare function useListHandlers(app: Handlers, list: RefObject<HTMLElement | null>, hoverGlide: RefObject<HTMLElement | null>, stop: RefObject<HTMLElement | null>): Handlers;
|
|
9
|
+
export declare function useListSync(list: RefObject<HTMLElement | null>, glider: RefObject<HTMLElement | null>, stop: RefObject<HTMLElement | null>): void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { useLayoutEffect } from "react";
|
|
2
|
+
/* The rows a person can reach: not static, not disabled. */
|
|
3
|
+
export const ROW = '[data-slot="list-row"]:not([data-static]):not(:disabled)';
|
|
4
|
+
const OWNER = '[data-kumiko-list-row~="roving"], [data-kumiko-list-row~="no-roving"]';
|
|
5
|
+
/* Roving is on unless the nearest container that says anything about it says no-roving. */
|
|
6
|
+
export function isRoving(list) {
|
|
7
|
+
const owner = list.closest(OWNER);
|
|
8
|
+
return owner === null || !owner.dataset.kumikoListRow?.split(" ").includes("no-roving");
|
|
9
|
+
}
|
|
10
|
+
/* Puts a glider over a row and copies the row's look onto it. */
|
|
11
|
+
function place(glider, row) {
|
|
12
|
+
const style = glider.style;
|
|
13
|
+
const computed = getComputedStyle(row);
|
|
14
|
+
const name = glider.dataset.kind === "current" ? "--_cur-bg" : "--_hover-bg";
|
|
15
|
+
style.setProperty("--_x", `${row.offsetLeft}px`);
|
|
16
|
+
style.setProperty("--_y", `${row.offsetTop}px`);
|
|
17
|
+
style.setProperty("--_w", `${row.offsetWidth}px`);
|
|
18
|
+
style.setProperty("--_h", `${row.offsetHeight}px`);
|
|
19
|
+
style.setProperty("--_r", computed.borderRadius);
|
|
20
|
+
style.setProperty("--_bg", computed.getPropertyValue(name));
|
|
21
|
+
style.setProperty("--_bar", computed.getPropertyValue("--_bar"));
|
|
22
|
+
}
|
|
23
|
+
/* Shows a glider at a row, or hides it. It lands without sliding the first time it appears. */
|
|
24
|
+
export function show(glider, row) {
|
|
25
|
+
if (!glider) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!row) {
|
|
29
|
+
delete glider.dataset.visible;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
place(glider, row);
|
|
33
|
+
if (!Object.hasOwn(glider.dataset, "visible")) {
|
|
34
|
+
void glider.offsetWidth;
|
|
35
|
+
glider.dataset.visible = "";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/* Gives the Tab stop to one row when the list is roving, and takes every stop back when it is not. */
|
|
39
|
+
function syncRoving(list, stop) {
|
|
40
|
+
const rows = [...list.querySelectorAll(ROW)];
|
|
41
|
+
if (!isRoving(list)) {
|
|
42
|
+
for (const row of rows) {
|
|
43
|
+
if (Object.hasOwn(row.dataset, "roving")) {
|
|
44
|
+
row.removeAttribute("tabindex");
|
|
45
|
+
delete row.dataset.roving;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const kept = stop && rows.includes(stop) ? stop : null;
|
|
51
|
+
const start = kept ?? rows.find((row) => Object.hasOwn(row.dataset, "current")) ?? rows[0];
|
|
52
|
+
for (const row of rows) {
|
|
53
|
+
row.dataset.roving = "";
|
|
54
|
+
row.tabIndex = row === start ? 0 : -1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/* Moves the Tab stop to the row that has focus. */
|
|
58
|
+
export function followFocus(list, row) {
|
|
59
|
+
for (const other of list.querySelectorAll("[data-roving]")) {
|
|
60
|
+
other.tabIndex = other === row ? 0 : -1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/* The row an arrow key or Home or End moves to, or null when the key is not one of them. */
|
|
64
|
+
export function targetRow(list, row, key) {
|
|
65
|
+
const rows = [...list.querySelectorAll(ROW)];
|
|
66
|
+
const last = rows.length - 1;
|
|
67
|
+
const at = rows.indexOf(row);
|
|
68
|
+
const to = new Map([
|
|
69
|
+
["Home", 0],
|
|
70
|
+
["End", last],
|
|
71
|
+
["ArrowDown", Math.min(last, at + 1)],
|
|
72
|
+
["ArrowUp", Math.max(0, at - 1)]
|
|
73
|
+
]).get(key);
|
|
74
|
+
return to === undefined ? null : (rows[to] ?? null);
|
|
75
|
+
}
|
|
76
|
+
/* The list's own handlers: the hover wash follows the mouse, focus moves the Tab stop and the arrows move focus. Each also calls the app's handler first. */
|
|
77
|
+
export function useListHandlers(app, list, hoverGlide, stop) {
|
|
78
|
+
const rowOf = (target) => {
|
|
79
|
+
const row = target instanceof Element ? target.closest(ROW) : null;
|
|
80
|
+
return row && list.current?.contains(row) ? row : null;
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
onPointerOver: (event) => {
|
|
84
|
+
app.onPointerOver?.(event);
|
|
85
|
+
if (event.pointerType === "mouse") {
|
|
86
|
+
show(hoverGlide.current, rowOf(event.target));
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
onPointerLeave: (event) => {
|
|
90
|
+
app.onPointerLeave?.(event);
|
|
91
|
+
show(hoverGlide.current, null);
|
|
92
|
+
},
|
|
93
|
+
onFocus: (event) => {
|
|
94
|
+
app.onFocus?.(event);
|
|
95
|
+
const row = rowOf(event.target);
|
|
96
|
+
if (row && list.current && isRoving(list.current)) {
|
|
97
|
+
stop.current = row;
|
|
98
|
+
followFocus(list.current, row);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
onKeyDown: (event) => {
|
|
102
|
+
app.onKeyDown?.(event);
|
|
103
|
+
const row = rowOf(event.target);
|
|
104
|
+
if (!list.current || !row || event.defaultPrevented || !isRoving(list.current)) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const to = targetRow(list.current, row, event.key);
|
|
108
|
+
if (to) {
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
to.focus();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/* After every render and every change of the rows: place the current glider and set the Tab stop. */
|
|
116
|
+
export function useListSync(list, glider, stop) {
|
|
117
|
+
useLayoutEffect(() => {
|
|
118
|
+
const element = list.current;
|
|
119
|
+
if (!element) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
const sync = () => {
|
|
123
|
+
show(glider.current, element.querySelector("[data-current]"));
|
|
124
|
+
syncRoving(element, stop.current);
|
|
125
|
+
};
|
|
126
|
+
sync();
|
|
127
|
+
const mutations = new MutationObserver(sync);
|
|
128
|
+
mutations.observe(element, {
|
|
129
|
+
subtree: true,
|
|
130
|
+
childList: true,
|
|
131
|
+
attributes: true,
|
|
132
|
+
attributeFilter: ["data-current", "disabled"]
|
|
133
|
+
});
|
|
134
|
+
const sizes = new ResizeObserver(sync);
|
|
135
|
+
sizes.observe(element);
|
|
136
|
+
return () => {
|
|
137
|
+
mutations.disconnect();
|
|
138
|
+
sizes.disconnect();
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
}
|