@openwarelabs/ui 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.
Files changed (33) hide show
  1. package/README.md +5 -5
  2. package/dist/components/InlineEdit/InlineEdit.d.cts +8 -0
  3. package/dist/components/InlineEdit/InlineEdit.d.ts +8 -0
  4. package/dist/components/InlineEdit/InlineEdit.types.d.cts +74 -0
  5. package/dist/components/InlineEdit/InlineEdit.types.d.ts +74 -0
  6. package/dist/components/NavigationMenu/NavigationMenu.d.cts +14 -0
  7. package/dist/components/NavigationMenu/NavigationMenu.d.ts +14 -0
  8. package/dist/components/NavigationMenu/NavigationMenu.types.d.cts +84 -0
  9. package/dist/components/NavigationMenu/NavigationMenu.types.d.ts +84 -0
  10. package/dist/components/SortableList/SortableList.d.cts +7 -0
  11. package/dist/components/SortableList/SortableList.d.ts +7 -0
  12. package/dist/components/SortableList/SortableList.types.d.cts +82 -0
  13. package/dist/components/SortableList/SortableList.types.d.ts +82 -0
  14. package/dist/components/TreeView/TreeView.d.cts +8 -0
  15. package/dist/components/TreeView/TreeView.d.ts +8 -0
  16. package/dist/components/TreeView/TreeView.types.d.cts +88 -0
  17. package/dist/components/TreeView/TreeView.types.d.ts +88 -0
  18. package/dist/components/VirtualList/VirtualList.d.cts +9 -0
  19. package/dist/components/VirtualList/VirtualList.d.ts +9 -0
  20. package/dist/components/VirtualList/VirtualList.types.d.cts +80 -0
  21. package/dist/components/VirtualList/VirtualList.types.d.ts +80 -0
  22. package/dist/components/VirtualList/useVirtualizer.d.cts +60 -0
  23. package/dist/components/VirtualList/useVirtualizer.d.ts +60 -0
  24. package/dist/components.css +637 -0
  25. package/dist/index.cjs +2732 -1328
  26. package/dist/index.cjs.map +4 -4
  27. package/dist/index.d.cts +12 -0
  28. package/dist/index.d.ts +12 -0
  29. package/dist/index.js +2695 -1267
  30. package/dist/index.js.map +4 -4
  31. package/dist/openware-ui.iife.js +9 -8
  32. package/dist/styles.css +637 -0
  33. package/package.json +1 -1
@@ -0,0 +1,88 @@
1
+ import type { ReactNode } from "react";
2
+ /** One row of the tree, and the rows under it. */
3
+ export interface TreeItem {
4
+ /** Unique in the whole tree: it's what `expanded` and `selected` hold. */
5
+ id: string;
6
+ /** The row's text. It names the row for screen readers and is what type-ahead matches. */
7
+ label: string;
8
+ /** A 16px icon before the label. */
9
+ icon?: ReactNode;
10
+ /** A muted line under the label. */
11
+ description?: ReactNode;
12
+ /** Muted content at the end of the row: a count, a badge, a status. Keep it non-interactive. */
13
+ end?: ReactNode;
14
+ /** It can be focused and opened, but not selected, checked or activated. */
15
+ disabled?: boolean;
16
+ /** The rows under this one. */
17
+ children?: TreeItem[];
18
+ /** It has children that `loadChildren` fetches the first time it opens. */
19
+ hasChildren?: boolean;
20
+ }
21
+ export type TreeViewSelectionMode = "none" | "single" | "multiple";
22
+ export interface TreeViewLabels {
23
+ /** The row shown while children load.
24
+ * @default "Loading…" */
25
+ loading?: string;
26
+ /** The row shown when they couldn't load, before the retry text.
27
+ * @default "Couldn't load." */
28
+ error?: string;
29
+ /** The retry text in that row; activating the row tries again.
30
+ * @default "Retry" */
31
+ retry?: string;
32
+ }
33
+ export interface TreeViewProps {
34
+ /** The top-level rows. */
35
+ items: TreeItem[];
36
+ /** Names the tree for screen readers: "Categories", "Permissions". */
37
+ label?: string;
38
+ /** Names the tree by another element's id instead, such as a heading's. */
39
+ "aria-labelledby"?: string;
40
+ /** The ids of the open rows, when you control them. */
41
+ expanded?: string[];
42
+ /** The ids open at first when uncontrolled.
43
+ * @default [] */
44
+ defaultExpanded?: string[];
45
+ /** Called with the open ids when a row opens or closes. */
46
+ onExpandedChange?(expanded: string[]): void;
47
+ /** `single` selects one row; `multiple` any number (Shift extends a range); `none` makes rows only activate.
48
+ * @default "single" */
49
+ selectionMode?: TreeViewSelectionMode;
50
+ /** The selected (or checked) ids, when you control them. */
51
+ selected?: string[];
52
+ /** The ids selected at first when uncontrolled.
53
+ * @default [] */
54
+ defaultSelected?: string[];
55
+ /** Called with the selected (or checked) ids, in the tree's order. */
56
+ onSelectedChange?(selected: string[]): void;
57
+ /** Shows a checkbox on each row for picking several. Checking a row checks the loaded rows under it, and a row whose
58
+ * rows are partly checked shows a dash. `selected` then holds every fully checked id. Implies multiple selection.
59
+ * @default false */
60
+ checkboxes?: boolean;
61
+ /** Fetches a row's children the first time it opens, for rows with `hasChildren`. A loading row shows meanwhile,
62
+ * and if it rejects, a row to retry. */
63
+ loadChildren?(item: TreeItem): Promise<TreeItem[]>;
64
+ /** Called when a row is activated: Enter, a double-click, or a click when `selectionMode` is `none`. */
65
+ onAction?(item: TreeItem): void;
66
+ /** Draws each row's label instead of the plain text, e.g. to highlight a search match. */
67
+ renderLabel?(item: TreeItem): ReactNode;
68
+ /** The words it shows, for other languages. */
69
+ labels?: TreeViewLabels;
70
+ className?: string;
71
+ }
72
+ /** A row's checkbox: checked, not, or partly (some of the rows under it). Internal. */
73
+ export type TreeViewChecked = boolean | "mixed";
74
+ /** A visible row: an item, or the loading or error row under an item whose children are being fetched. Internal. */
75
+ export interface TreeViewRow {
76
+ id: string;
77
+ item?: TreeItem;
78
+ status?: "loading" | "error";
79
+ parent?: TreeViewRow;
80
+ /** Its place in the visible rows. */
81
+ index: number;
82
+ level: number;
83
+ pos: number;
84
+ size: number;
85
+ expandable: boolean;
86
+ open: boolean;
87
+ kids: TreeViewRow[];
88
+ }
@@ -0,0 +1,88 @@
1
+ import type { ReactNode } from "react";
2
+ /** One row of the tree, and the rows under it. */
3
+ export interface TreeItem {
4
+ /** Unique in the whole tree: it's what `expanded` and `selected` hold. */
5
+ id: string;
6
+ /** The row's text. It names the row for screen readers and is what type-ahead matches. */
7
+ label: string;
8
+ /** A 16px icon before the label. */
9
+ icon?: ReactNode;
10
+ /** A muted line under the label. */
11
+ description?: ReactNode;
12
+ /** Muted content at the end of the row: a count, a badge, a status. Keep it non-interactive. */
13
+ end?: ReactNode;
14
+ /** It can be focused and opened, but not selected, checked or activated. */
15
+ disabled?: boolean;
16
+ /** The rows under this one. */
17
+ children?: TreeItem[];
18
+ /** It has children that `loadChildren` fetches the first time it opens. */
19
+ hasChildren?: boolean;
20
+ }
21
+ export type TreeViewSelectionMode = "none" | "single" | "multiple";
22
+ export interface TreeViewLabels {
23
+ /** The row shown while children load.
24
+ * @default "Loading…" */
25
+ loading?: string;
26
+ /** The row shown when they couldn't load, before the retry text.
27
+ * @default "Couldn't load." */
28
+ error?: string;
29
+ /** The retry text in that row; activating the row tries again.
30
+ * @default "Retry" */
31
+ retry?: string;
32
+ }
33
+ export interface TreeViewProps {
34
+ /** The top-level rows. */
35
+ items: TreeItem[];
36
+ /** Names the tree for screen readers: "Categories", "Permissions". */
37
+ label?: string;
38
+ /** Names the tree by another element's id instead, such as a heading's. */
39
+ "aria-labelledby"?: string;
40
+ /** The ids of the open rows, when you control them. */
41
+ expanded?: string[];
42
+ /** The ids open at first when uncontrolled.
43
+ * @default [] */
44
+ defaultExpanded?: string[];
45
+ /** Called with the open ids when a row opens or closes. */
46
+ onExpandedChange?(expanded: string[]): void;
47
+ /** `single` selects one row; `multiple` any number (Shift extends a range); `none` makes rows only activate.
48
+ * @default "single" */
49
+ selectionMode?: TreeViewSelectionMode;
50
+ /** The selected (or checked) ids, when you control them. */
51
+ selected?: string[];
52
+ /** The ids selected at first when uncontrolled.
53
+ * @default [] */
54
+ defaultSelected?: string[];
55
+ /** Called with the selected (or checked) ids, in the tree's order. */
56
+ onSelectedChange?(selected: string[]): void;
57
+ /** Shows a checkbox on each row for picking several. Checking a row checks the loaded rows under it, and a row whose
58
+ * rows are partly checked shows a dash. `selected` then holds every fully checked id. Implies multiple selection.
59
+ * @default false */
60
+ checkboxes?: boolean;
61
+ /** Fetches a row's children the first time it opens, for rows with `hasChildren`. A loading row shows meanwhile,
62
+ * and if it rejects, a row to retry. */
63
+ loadChildren?(item: TreeItem): Promise<TreeItem[]>;
64
+ /** Called when a row is activated: Enter, a double-click, or a click when `selectionMode` is `none`. */
65
+ onAction?(item: TreeItem): void;
66
+ /** Draws each row's label instead of the plain text, e.g. to highlight a search match. */
67
+ renderLabel?(item: TreeItem): ReactNode;
68
+ /** The words it shows, for other languages. */
69
+ labels?: TreeViewLabels;
70
+ className?: string;
71
+ }
72
+ /** A row's checkbox: checked, not, or partly (some of the rows under it). Internal. */
73
+ export type TreeViewChecked = boolean | "mixed";
74
+ /** A visible row: an item, or the loading or error row under an item whose children are being fetched. Internal. */
75
+ export interface TreeViewRow {
76
+ id: string;
77
+ item?: TreeItem;
78
+ status?: "loading" | "error";
79
+ parent?: TreeViewRow;
80
+ /** Its place in the visible rows. */
81
+ index: number;
82
+ level: number;
83
+ pos: number;
84
+ size: number;
85
+ expandable: boolean;
86
+ open: boolean;
87
+ kids: TreeViewRow[];
88
+ }
@@ -0,0 +1,9 @@
1
+ import { type ReactElement, type RefAttributes } from "react";
2
+ import type { VirtualListHandle, VirtualListProps } from "./VirtualList.types.cjs";
3
+ export type { VirtualListHandle, VirtualListLabels, VirtualListProps } from "./VirtualList.types.cjs";
4
+ /**
5
+ * A scrolling list that renders only the rows in view, for long logs, chat histories and big datasets: 10,000 rows
6
+ * cost what 20 do. Rows have a fixed `itemSize`, or are measured as they render. `onEndReached` loads more as the
7
+ * reader nears the end, `followOutput` keeps a log's newest line in view, and a ref scrolls to any row.
8
+ */
9
+ export declare const VirtualList: <T = unknown>(props: VirtualListProps<T> & RefAttributes<VirtualListHandle>) => ReactElement | null;
@@ -0,0 +1,9 @@
1
+ import { type ReactElement, type RefAttributes } from "react";
2
+ import type { VirtualListHandle, VirtualListProps } from "./VirtualList.types.js";
3
+ export type { VirtualListHandle, VirtualListLabels, VirtualListProps } from "./VirtualList.types.js";
4
+ /**
5
+ * A scrolling list that renders only the rows in view, for long logs, chat histories and big datasets: 10,000 rows
6
+ * cost what 20 do. Rows have a fixed `itemSize`, or are measured as they render. `onEndReached` loads more as the
7
+ * reader nears the end, `followOutput` keeps a log's newest line in view, and a ref scrolls to any row.
8
+ */
9
+ export declare const VirtualList: <T = unknown>(props: VirtualListProps<T> & RefAttributes<VirtualListHandle>) => ReactElement | null;
@@ -0,0 +1,80 @@
1
+ import type { CSSProperties, Key, ReactNode } from "react";
2
+ import type { ScrollToIndexOptions } from "./useVirtualizer.cjs";
3
+ export interface VirtualListLabels {
4
+ /** Announced to screen readers while more rows load.
5
+ * @default "Loading more" */
6
+ loading?: string;
7
+ }
8
+ export interface VirtualListProps<T = unknown> {
9
+ /** The rows' data. Leave it out and pass `count` to render rows from their index alone. */
10
+ items?: readonly T[];
11
+ /** How many rows there are.
12
+ * @default items.length */
13
+ count?: number;
14
+ /** Renders one row. With `count` alone, `item` is undefined: use the index. */
15
+ renderItem(item: T, index: number): ReactNode;
16
+ /** A stable key for each row, such as its id. Give one when rows can be added at the top (older messages), so
17
+ * the view stays where it was, and so measured heights follow their row.
18
+ * @default (item, index) => index */
19
+ getKey?(item: T, index: number): Key;
20
+ /** Every row's height in pixels, when they're all the same. The fastest: nothing is measured. */
21
+ itemSize?: number;
22
+ /** A guess at a row's height in pixels when they vary. Each row is measured once it renders, and replaces the
23
+ * guess without the view jumping; the closer the guess, the steadier the scrollbar.
24
+ * @default 48 */
25
+ estimateSize?: number | ((index: number) => number);
26
+ /** How many rows to render beyond each edge of the view, so fast scrolling doesn't show blank space.
27
+ * @default 4 */
28
+ overscan?: number;
29
+ /** Space between rows, in pixels.
30
+ * @default 0 */
31
+ gap?: number;
32
+ /** The list's height. Without `height` or `maxHeight`, it fills its parent, which needs a height. */
33
+ height?: number | string;
34
+ /** Lets the list grow with its rows up to this height, then scroll. */
35
+ maxHeight?: number | string;
36
+ /** Called when the reader scrolls near the end, to load more rows. Called once per number of rows, and not
37
+ * while `loading` or once `hasMore` is false. */
38
+ onEndReached?(): void;
39
+ /** Called when the reader scrolls near the start, to load older rows (a chat's history). Rows added at the top
40
+ * keep the view where it was, as long as `getKey` gives real keys. */
41
+ onStartReached?(): void;
42
+ /** How close to either end, in pixels, calls `onEndReached` or `onStartReached`.
43
+ * @default 200 */
44
+ endReachedThreshold?: number;
45
+ /** Shows a spinner after the last row and tells screen readers more is loading.
46
+ * @default false */
47
+ loading?: boolean;
48
+ /** Whether there are more rows to load at the end; false stops `onEndReached`.
49
+ * @default true */
50
+ hasMore?: boolean;
51
+ /** Opens at the end and keeps the newest row in view as rows are added or grow, while the reader is at the end:
52
+ * for logs and chats. Scrolling up to read stops it; scrolling back down starts it again.
53
+ * @default false */
54
+ followOutput?: boolean;
55
+ /** `list` for a list of rows. `feed` for an endless stream of articles people read one by one (posts, news):
56
+ * each row is a focusable article, and Page Down and Page Up move between them.
57
+ * @default "list" */
58
+ role?: "list" | "feed";
59
+ /** Names the list for screen readers. */
60
+ label?: string;
61
+ /** The id of a visible heading that names the list, in place of `label`. */
62
+ "aria-labelledby"?: string;
63
+ /** Shown in place of the rows when there are none and nothing is loading. */
64
+ empty?: ReactNode;
65
+ /** The words it uses, for other languages. */
66
+ labels?: VirtualListLabels;
67
+ /** A class for each row's wrapper. */
68
+ itemClassName?: string;
69
+ id?: string;
70
+ className?: string;
71
+ style?: CSSProperties;
72
+ }
73
+ export interface VirtualListHandle {
74
+ /** Scrolls a row into view, rendering it first. `behavior: "smooth"` animates, except under reduced motion. */
75
+ scrollToIndex(index: number, options?: ScrollToIndexOptions): void;
76
+ /** Scrolls to the last row, and follows new rows again with `followOutput`. */
77
+ scrollToEnd(options?: Pick<ScrollToIndexOptions, "behavior">): void;
78
+ /** The element that scrolls. */
79
+ readonly element: HTMLDivElement | null;
80
+ }
@@ -0,0 +1,80 @@
1
+ import type { CSSProperties, Key, ReactNode } from "react";
2
+ import type { ScrollToIndexOptions } from "./useVirtualizer.js";
3
+ export interface VirtualListLabels {
4
+ /** Announced to screen readers while more rows load.
5
+ * @default "Loading more" */
6
+ loading?: string;
7
+ }
8
+ export interface VirtualListProps<T = unknown> {
9
+ /** The rows' data. Leave it out and pass `count` to render rows from their index alone. */
10
+ items?: readonly T[];
11
+ /** How many rows there are.
12
+ * @default items.length */
13
+ count?: number;
14
+ /** Renders one row. With `count` alone, `item` is undefined: use the index. */
15
+ renderItem(item: T, index: number): ReactNode;
16
+ /** A stable key for each row, such as its id. Give one when rows can be added at the top (older messages), so
17
+ * the view stays where it was, and so measured heights follow their row.
18
+ * @default (item, index) => index */
19
+ getKey?(item: T, index: number): Key;
20
+ /** Every row's height in pixels, when they're all the same. The fastest: nothing is measured. */
21
+ itemSize?: number;
22
+ /** A guess at a row's height in pixels when they vary. Each row is measured once it renders, and replaces the
23
+ * guess without the view jumping; the closer the guess, the steadier the scrollbar.
24
+ * @default 48 */
25
+ estimateSize?: number | ((index: number) => number);
26
+ /** How many rows to render beyond each edge of the view, so fast scrolling doesn't show blank space.
27
+ * @default 4 */
28
+ overscan?: number;
29
+ /** Space between rows, in pixels.
30
+ * @default 0 */
31
+ gap?: number;
32
+ /** The list's height. Without `height` or `maxHeight`, it fills its parent, which needs a height. */
33
+ height?: number | string;
34
+ /** Lets the list grow with its rows up to this height, then scroll. */
35
+ maxHeight?: number | string;
36
+ /** Called when the reader scrolls near the end, to load more rows. Called once per number of rows, and not
37
+ * while `loading` or once `hasMore` is false. */
38
+ onEndReached?(): void;
39
+ /** Called when the reader scrolls near the start, to load older rows (a chat's history). Rows added at the top
40
+ * keep the view where it was, as long as `getKey` gives real keys. */
41
+ onStartReached?(): void;
42
+ /** How close to either end, in pixels, calls `onEndReached` or `onStartReached`.
43
+ * @default 200 */
44
+ endReachedThreshold?: number;
45
+ /** Shows a spinner after the last row and tells screen readers more is loading.
46
+ * @default false */
47
+ loading?: boolean;
48
+ /** Whether there are more rows to load at the end; false stops `onEndReached`.
49
+ * @default true */
50
+ hasMore?: boolean;
51
+ /** Opens at the end and keeps the newest row in view as rows are added or grow, while the reader is at the end:
52
+ * for logs and chats. Scrolling up to read stops it; scrolling back down starts it again.
53
+ * @default false */
54
+ followOutput?: boolean;
55
+ /** `list` for a list of rows. `feed` for an endless stream of articles people read one by one (posts, news):
56
+ * each row is a focusable article, and Page Down and Page Up move between them.
57
+ * @default "list" */
58
+ role?: "list" | "feed";
59
+ /** Names the list for screen readers. */
60
+ label?: string;
61
+ /** The id of a visible heading that names the list, in place of `label`. */
62
+ "aria-labelledby"?: string;
63
+ /** Shown in place of the rows when there are none and nothing is loading. */
64
+ empty?: ReactNode;
65
+ /** The words it uses, for other languages. */
66
+ labels?: VirtualListLabels;
67
+ /** A class for each row's wrapper. */
68
+ itemClassName?: string;
69
+ id?: string;
70
+ className?: string;
71
+ style?: CSSProperties;
72
+ }
73
+ export interface VirtualListHandle {
74
+ /** Scrolls a row into view, rendering it first. `behavior: "smooth"` animates, except under reduced motion. */
75
+ scrollToIndex(index: number, options?: ScrollToIndexOptions): void;
76
+ /** Scrolls to the last row, and follows new rows again with `followOutput`. */
77
+ scrollToEnd(options?: Pick<ScrollToIndexOptions, "behavior">): void;
78
+ /** The element that scrolls. */
79
+ readonly element: HTMLDivElement | null;
80
+ }
@@ -0,0 +1,60 @@
1
+ import { type Key } from "react";
2
+ /** One row that's rendered: where it goes and how tall it is. */
3
+ export interface VirtualItem {
4
+ index: number;
5
+ /** The row's key, from `getKey`: use it as the React key. */
6
+ key: Key;
7
+ /** Its top, in pixels from the top of the scrolling content. */
8
+ start: number;
9
+ /** Its height in pixels: `itemSize`, or measured, or the estimate until it's measured. */
10
+ size: number;
11
+ }
12
+ export interface ScrollToIndexOptions {
13
+ /** Where the row ends up: at the `start` (top) of the view, the `center`, the `end`, or `auto`, scrolling only as
14
+ * far as needed to show it.
15
+ * @default "auto" */
16
+ align?: "start" | "center" | "end" | "auto";
17
+ /** `smooth` animates the scroll, except for people who prefer reduced motion.
18
+ * @default "auto" */
19
+ behavior?: ScrollBehavior;
20
+ }
21
+ export interface UseVirtualizerOptions {
22
+ /** How many rows there are. */
23
+ count: number;
24
+ /** Returns the element that scrolls. It must be there once the component has mounted. */
25
+ getScrollElement(): HTMLElement | null;
26
+ /** Every row's height in pixels, when they're all the same: the fastest, as nothing is measured. */
27
+ itemSize?: number;
28
+ /** A guess at a row's height in pixels, before it's measured. Rows are measured as they render, and the view
29
+ * doesn't jump when a row above it turns out taller or shorter than the guess.
30
+ * @default 48 */
31
+ estimateSize?: number | ((index: number) => number);
32
+ /** How many rows to render beyond each edge of the view, so fast scrolling doesn't show gaps.
33
+ * @default 4 */
34
+ overscan?: number;
35
+ /** Space between rows, in pixels.
36
+ * @default 0 */
37
+ gap?: number;
38
+ /** A stable key for each row. With real keys (not the index), measured heights follow their row, and rows
39
+ * added at the top keep the view where it was.
40
+ * @default (index) => index */
41
+ getKey?(index: number): Key;
42
+ /** A row to keep rendered even out of view, such as the one that has focus, so it isn't lost. */
43
+ keepMounted?: number | null;
44
+ }
45
+ export interface Virtualizer {
46
+ /** The rows to render: those in view and the overscan around them. */
47
+ items: VirtualItem[];
48
+ /** The height of all the rows together: give the content inside the scrolling element this height. */
49
+ totalSize: number;
50
+ /** Pass as the `ref` of each rendered row, with `data-index` on it, so its height is measured. */
51
+ measureElement(element: HTMLElement | null): void;
52
+ /** Scrolls a row into view. */
53
+ scrollToIndex(index: number, options?: ScrollToIndexOptions): void;
54
+ }
55
+ /**
56
+ * Windowing for long lists: works out which rows of `count` are in view of a scrolling element, where each one goes,
57
+ * and how tall the whole list is, so you render only those rows. Rows have a fixed `itemSize`, or are measured with
58
+ * ResizeObserver as they render. VirtualList is built on it; use it for your own virtualized table or list box.
59
+ */
60
+ export declare function useVirtualizer({ count, getScrollElement, itemSize, estimateSize, overscan, gap, getKey, keepMounted, }: UseVirtualizerOptions): Virtualizer;
@@ -0,0 +1,60 @@
1
+ import { type Key } from "react";
2
+ /** One row that's rendered: where it goes and how tall it is. */
3
+ export interface VirtualItem {
4
+ index: number;
5
+ /** The row's key, from `getKey`: use it as the React key. */
6
+ key: Key;
7
+ /** Its top, in pixels from the top of the scrolling content. */
8
+ start: number;
9
+ /** Its height in pixels: `itemSize`, or measured, or the estimate until it's measured. */
10
+ size: number;
11
+ }
12
+ export interface ScrollToIndexOptions {
13
+ /** Where the row ends up: at the `start` (top) of the view, the `center`, the `end`, or `auto`, scrolling only as
14
+ * far as needed to show it.
15
+ * @default "auto" */
16
+ align?: "start" | "center" | "end" | "auto";
17
+ /** `smooth` animates the scroll, except for people who prefer reduced motion.
18
+ * @default "auto" */
19
+ behavior?: ScrollBehavior;
20
+ }
21
+ export interface UseVirtualizerOptions {
22
+ /** How many rows there are. */
23
+ count: number;
24
+ /** Returns the element that scrolls. It must be there once the component has mounted. */
25
+ getScrollElement(): HTMLElement | null;
26
+ /** Every row's height in pixels, when they're all the same: the fastest, as nothing is measured. */
27
+ itemSize?: number;
28
+ /** A guess at a row's height in pixels, before it's measured. Rows are measured as they render, and the view
29
+ * doesn't jump when a row above it turns out taller or shorter than the guess.
30
+ * @default 48 */
31
+ estimateSize?: number | ((index: number) => number);
32
+ /** How many rows to render beyond each edge of the view, so fast scrolling doesn't show gaps.
33
+ * @default 4 */
34
+ overscan?: number;
35
+ /** Space between rows, in pixels.
36
+ * @default 0 */
37
+ gap?: number;
38
+ /** A stable key for each row. With real keys (not the index), measured heights follow their row, and rows
39
+ * added at the top keep the view where it was.
40
+ * @default (index) => index */
41
+ getKey?(index: number): Key;
42
+ /** A row to keep rendered even out of view, such as the one that has focus, so it isn't lost. */
43
+ keepMounted?: number | null;
44
+ }
45
+ export interface Virtualizer {
46
+ /** The rows to render: those in view and the overscan around them. */
47
+ items: VirtualItem[];
48
+ /** The height of all the rows together: give the content inside the scrolling element this height. */
49
+ totalSize: number;
50
+ /** Pass as the `ref` of each rendered row, with `data-index` on it, so its height is measured. */
51
+ measureElement(element: HTMLElement | null): void;
52
+ /** Scrolls a row into view. */
53
+ scrollToIndex(index: number, options?: ScrollToIndexOptions): void;
54
+ }
55
+ /**
56
+ * Windowing for long lists: works out which rows of `count` are in view of a scrolling element, where each one goes,
57
+ * and how tall the whole list is, so you render only those rows. Rows have a fixed `itemSize`, or are measured with
58
+ * ResizeObserver as they render. VirtualList is built on it; use it for your own virtualized table or list box.
59
+ */
60
+ export declare function useVirtualizer({ count, getScrollElement, itemSize, estimateSize, overscan, gap, getKey, keepMounted, }: UseVirtualizerOptions): Virtualizer;