@tensor_1/react 2.61.0 → 2.62.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/README.md +19 -0
- package/component-inventory.json +4 -0
- package/dist/components/ListSummary.d.ts +32 -0
- package/dist/components/ListSummary.js +49 -0
- package/dist/index.cjs +2551 -2503
- package/dist/index.d.cts +29 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -831,6 +831,25 @@ Both are a `role="grid"` table with one tab stop. Arrow keys move between cells,
|
|
|
831
831
|
- `count: 0` shows a zero. `hideCount` shows the band alone, for a zero you would rather not print. A row and column left out of `cells` is drawn empty (dashed, `labels.empty`), and can still be opened: `onOpenCell` gets only its `rowId` and `columnId`.
|
|
832
832
|
- Tones are `neutral`, `info`, `success`, `warning`, `attention` and `danger`, always beside their words.
|
|
833
833
|
|
|
834
|
+
### ListSummary: long lists of names
|
|
835
|
+
|
|
836
|
+
A cell that lists sixteen roles makes every row of its table tall. `ListSummary` shows a count, the first `max` names (default 3) and the words for the rest, with one button that shows the whole list in place and hides it again (`aria-expanded`, `aria-controls`). A list only one name longer than `max` is shown whole, because hiding a single name saves no space. Every word is a prop; the defaults are English.
|
|
837
|
+
|
|
838
|
+
```tsx
|
|
839
|
+
import { ListSummary } from '@tensor_1/react';
|
|
840
|
+
|
|
841
|
+
<ListSummary
|
|
842
|
+
items={roles.map((r) => r.name)}
|
|
843
|
+
count={(n) => `${n} Rollen`}
|
|
844
|
+
more={(n) => `und ${n} weitere`}
|
|
845
|
+
expandLabel="Alle anzeigen"
|
|
846
|
+
collapseLabel="Weniger anzeigen"
|
|
847
|
+
empty="Keine Rolle"
|
|
848
|
+
/>
|
|
849
|
+
```
|
|
850
|
+
|
|
851
|
+
The toggle sits in the line of names: underlined, so colour is not its only cue, with a 24 px hit area that leaves the line height alone (`.uix-list-summary__toggle`).
|
|
852
|
+
|
|
834
853
|
### FilterEditor (typed column filters)
|
|
835
854
|
|
|
836
855
|
`FilterEditor` is the content of one column-filter popover with a typed value (HAR-1365; TENSOR's
|
package/component-inventory.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { HTMLAttributes, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface ListSummaryProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
5
|
+
/** The names, in the order to show them. */
|
|
6
|
+
items: ReadonlyArray<string>;
|
|
7
|
+
/** How many names show while the list is collapsed. Default 3. */
|
|
8
|
+
max?: number;
|
|
9
|
+
/** An optional first line that counts the whole list, e.g. `(n) => \`${n} roles\``. */
|
|
10
|
+
count?: (total: number) => ReactNode;
|
|
11
|
+
/** The words for the names not shown, e.g. `(n) => \`und ${n} weitere\``. Default `and N more`. */
|
|
12
|
+
more?: (hidden: number) => string;
|
|
13
|
+
/** The toggle while collapsed. Translatable; default `Show all`. */
|
|
14
|
+
expandLabel?: string;
|
|
15
|
+
/** The toggle while expanded. Translatable; default `Show less`. */
|
|
16
|
+
collapseLabel?: string;
|
|
17
|
+
/** Shown instead of the list when `items` is empty. */
|
|
18
|
+
empty?: ReactNode;
|
|
19
|
+
/** Joins the names. Default `, `. */
|
|
20
|
+
separator?: string;
|
|
21
|
+
/** Start with the whole list shown. */
|
|
22
|
+
defaultExpanded?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A long list of names (roles, teams, recipients) read as a count, the first few names and the
|
|
26
|
+
* words for the rest, with a button that shows the whole list in place and hides it again
|
|
27
|
+
* (HAR-3069). A list only one name longer than `max` is shown whole: hiding a single name saves
|
|
28
|
+
* no space. Every word is a prop; the defaults are English.
|
|
29
|
+
*/
|
|
30
|
+
declare function ListSummary({ items, max, count, more, expandLabel, collapseLabel, empty, separator, defaultExpanded, className, ...props }: ListSummaryProps): react.JSX.Element;
|
|
31
|
+
|
|
32
|
+
export { ListSummary, type ListSummaryProps };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useState } from "react";
|
|
4
|
+
import { cx } from "../cx.js";
|
|
5
|
+
function ListSummary({
|
|
6
|
+
items,
|
|
7
|
+
max = 3,
|
|
8
|
+
count,
|
|
9
|
+
more = (hidden) => `and ${hidden} more`,
|
|
10
|
+
expandLabel = "Show all",
|
|
11
|
+
collapseLabel = "Show less",
|
|
12
|
+
empty,
|
|
13
|
+
separator = ", ",
|
|
14
|
+
defaultExpanded = false,
|
|
15
|
+
className,
|
|
16
|
+
...props
|
|
17
|
+
}) {
|
|
18
|
+
const [expanded, setExpanded] = useState(defaultExpanded);
|
|
19
|
+
const listId = useId();
|
|
20
|
+
const limit = Math.max(1, Math.floor(max));
|
|
21
|
+
const collapsible = items.length > limit + 1;
|
|
22
|
+
const shown = collapsible && !expanded ? items.slice(0, limit) : items;
|
|
23
|
+
return /* @__PURE__ */ jsx("div", { className: cx("uix-list-summary", className), ...props, children: items.length === 0 ? /* @__PURE__ */ jsx("p", { className: "uix-list-summary__items", children: empty }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
24
|
+
count ? /* @__PURE__ */ jsx("p", { className: "uix-list-summary__count", children: count(items.length) }) : null,
|
|
25
|
+
/* @__PURE__ */ jsxs("p", { className: "uix-list-summary__items", children: [
|
|
26
|
+
/* @__PURE__ */ jsxs("span", { id: listId, children: [
|
|
27
|
+
shown.join(separator),
|
|
28
|
+
collapsible && !expanded ? ` ${more(items.length - limit)}` : null
|
|
29
|
+
] }),
|
|
30
|
+
collapsible ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
31
|
+
" ",
|
|
32
|
+
/* @__PURE__ */ jsx(
|
|
33
|
+
"button",
|
|
34
|
+
{
|
|
35
|
+
type: "button",
|
|
36
|
+
className: "uix-list-summary__toggle",
|
|
37
|
+
"aria-expanded": expanded,
|
|
38
|
+
"aria-controls": listId,
|
|
39
|
+
onClick: () => setExpanded((open) => !open),
|
|
40
|
+
children: expanded ? collapseLabel : expandLabel
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
] }) : null
|
|
44
|
+
] })
|
|
45
|
+
] }) });
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
ListSummary
|
|
49
|
+
};
|