@talogic/react 0.8.1 → 0.10.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.
@@ -0,0 +1,28 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { Selection } from './selection.hook';
3
+ /** Props of {@link SelectAllCheckbox}. */
4
+ export interface SelectAllCheckboxProps {
5
+ /** The selection of the list. */
6
+ selection: Selection;
7
+ /** Extra menu rows after "All" and "None", for example a `DropdownMenuItem` that selects the dismissed items. */
8
+ children?: ReactNode;
9
+ /** The accessible name of the checkbox. */
10
+ label?: string;
11
+ /** The accessible name of the menu button. */
12
+ menuLabel?: string;
13
+ /** The text of the row that selects all items. */
14
+ allLabel?: string;
15
+ /** The text of the row that clears the selection. */
16
+ noneLabel?: string;
17
+ /** Extra classes for the root. */
18
+ className?: string;
19
+ }
20
+ /**
21
+ * The header checkbox of a selectable list, with a menu. The checkbox is checked when all items are selected and
22
+ * indeterminate when some are. A click selects all when none is selected, and clears the selection otherwise. The
23
+ * menu has "All", "None" and the rows the product passes in.
24
+ *
25
+ * @param props - The selection, the extra menu rows and the labels.
26
+ * @returns The checkbox and its menu button.
27
+ */
28
+ export declare function SelectAllCheckbox({ selection, children, label, menuLabel, allLabel, noneLabel, className }: SelectAllCheckboxProps): import("react").JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { type ComponentProps } from 'react';
2
+ import type { Selection } from './selection.hook';
3
+ /** Props of {@link SelectableList}. */
4
+ export interface SelectableListProps extends Omit<ComponentProps<'ul'>, 'onKeyDown'> {
5
+ /** The selection from {@link useSelection}, made with the ids of the rows in display order. */
6
+ selection: Selection;
7
+ }
8
+ /**
9
+ * A list of {@link SelectableRow} parts with Gmail-style multi-select. Each row has a checkbox, and one row is in the
10
+ * tab order. Up and Down move between rows. Space toggles the focused row, Shift+Up and Shift+Down extend the
11
+ * selection, Ctrl+A (or ⌘A) selects all, and Esc clears the selection.
12
+ *
13
+ * @param props - The selection, an accessible `aria-label`, and any `ul` props.
14
+ * @returns The list.
15
+ */
16
+ export declare function SelectableList({ selection, className, children, ...props }: SelectableListProps): import("react").JSX.Element;
17
+ /** Props of {@link SelectableRow}. */
18
+ export interface SelectableRowProps extends Omit<ComponentProps<'li'>, 'id'> {
19
+ /** The item id, one of the ids of the {@link Selection}. */
20
+ id: string;
21
+ /** The accessible name of the row checkbox, for example "Select Invoice 42". */
22
+ label: string;
23
+ }
24
+ /**
25
+ * One row of a {@link SelectableList}: a checkbox, then the content. Shift-click on the checkbox selects a range.
26
+ * While some rows are selected, a click on the row toggles it, and a link in the row does not open.
27
+ *
28
+ * @param props - The item id, the checkbox label, the content, and any `li` props.
29
+ * @returns The row.
30
+ * @throws {Error} When the row is not inside a {@link SelectableList}.
31
+ */
32
+ export declare function SelectableRow({ id, label, className, children, onClickCapture, onFocus, ...props }: SelectableRowProps): import("react").JSX.Element;
@@ -0,0 +1,44 @@
1
+ /** Options of {@link Selection.toggle}. */
2
+ export interface ToggleOptions {
3
+ /** Applies the new state to every item from the last toggled item to this one, as a shift-click does. */
4
+ range?: boolean;
5
+ }
6
+ /** The selection state and commands that {@link useSelection} returns. */
7
+ export interface Selection {
8
+ /** The ids of the list, in display order. */
9
+ ids: readonly string[];
10
+ /** The selected ids that are in the list now. */
11
+ selected: ReadonlySet<string>;
12
+ /** The number of selected ids in the list. */
13
+ count: number;
14
+ /** `true` when all items are selected, `false` when none is, and `indeterminate` for some. */
15
+ allState: boolean | 'indeterminate';
16
+ /** Tells if one item is selected. */
17
+ isSelected: (id: string) => boolean;
18
+ /** Selects or clears one item. With `range`, it sets each item from the last toggled item to the same state. */
19
+ toggle: (id: string, options?: ToggleOptions) => void;
20
+ /** Adds items to the selection. */
21
+ add: (ids: Iterable<string>) => void;
22
+ /** Replaces the selection with these items, for a filter such as "dismissed". */
23
+ set: (ids: Iterable<string>) => void;
24
+ /** Selects every item of the list. */
25
+ selectAll: () => void;
26
+ /** Clears the selection. */
27
+ clear: () => void;
28
+ }
29
+ /** Options of {@link useSelection}. */
30
+ export interface UseSelectionOptions {
31
+ /** The ids that are selected at first. */
32
+ defaultSelected?: Iterable<string>;
33
+ }
34
+ /**
35
+ * Keeps a multi-selection of list items by id, with Gmail-style toggle, shift-click range, all and none.
36
+ *
37
+ * The selection is stored by id, so it stays correct when the list sorts, filters or reloads. An id that leaves the
38
+ * list does not count and is not in `selected`. When it comes back, it is selected again.
39
+ *
40
+ * @param ids - The ids of the list, in display order.
41
+ * @param options - The first selection.
42
+ * @returns The selection state and its commands.
43
+ */
44
+ export declare function useSelection(ids: readonly string[], options?: UseSelectionOptions): Selection;