@datalayer/primer-addons 1.0.50 → 1.0.51
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
CHANGED
|
@@ -40,6 +40,38 @@ visual values. For example, toolbar icon buttons and dropdown triggers read
|
|
|
40
40
|
`--theme-radius-control`: they retain the regular Primer corner in the default
|
|
41
41
|
themes and become fully rounded controls in `loop`.
|
|
42
42
|
|
|
43
|
+
### Toolbar overflow
|
|
44
|
+
|
|
45
|
+
`Toolbar` keeps to one line: what does not fit moves into a menu behind a
|
|
46
|
+
"…" button at the end of the line, measured with a `ResizeObserver` on the
|
|
47
|
+
toolbar, its parent and every item (an item that draws nothing takes no room).
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
<Toolbar
|
|
51
|
+
variant="inline" // no ground, border or padding: inside a header row of yours
|
|
52
|
+
gap={4}
|
|
53
|
+
items={[
|
|
54
|
+
{ key: 'lead', type: 'spacer' }, // push the actions to the trailing edge
|
|
55
|
+
{ key: 'chip', type: 'custom', priority: -1, render: () => <Label>Connected</Label>,
|
|
56
|
+
overflow: { label: 'Connected', onSelect: openAccounts } }, // a row in the menu
|
|
57
|
+
{ key: 'new', type: 'button', icon: PlusIcon, ariaLabel: 'New chat', onClick: newChat },
|
|
58
|
+
{ key: 'close', type: 'button', icon: XIcon, ariaLabel: 'Close', pinned: true, onClick: close },
|
|
59
|
+
]}
|
|
60
|
+
/>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- `pinned: true` never leaves the line; `priority` orders who leaves first
|
|
64
|
+
(lowest first, then the last on the line); the menu lists them in line order.
|
|
65
|
+
- In the menu a button shows its icon and name and closes the menu once
|
|
66
|
+
chosen; a custom item becomes its `overflow` — `{ label, icon, onSelect }`
|
|
67
|
+
(a row), `{ render }` (a node of its own) — or itself when it has none.
|
|
68
|
+
- Arrow keys, Home and End move the focus between the controls
|
|
69
|
+
(`keyboardNavigation={false}` to opt out); `overflowAriaLabel` names the
|
|
70
|
+
"…" button; `overflow={false}` lays every item on the line.
|
|
71
|
+
- In a row with other things, wrap the toolbar in a box of its own
|
|
72
|
+
(`flex: 1 1 0; min-width: 0`): that box's width is the room it measures.
|
|
73
|
+
- The gallery's *Toolbar* page shows an editor strip and a header row narrowing.
|
|
74
|
+
|
|
43
75
|
## Reactor Plugins
|
|
44
76
|
|
|
45
77
|
Three plugins for hosts built on [`@datalayer/reactor`](https://github.com/datalayer/reactor), imported by path so a page without a reactor never pulls it in:
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
import type { ToolbarProps } from "./types";
|
|
2
|
-
|
|
1
|
+
import type { ToolbarProps, ToolbarItem } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* The keys to take off the line so the rest fits in `available`.
|
|
4
|
+
*
|
|
5
|
+
* Exported for tests. Pinned items, spacers and items that take no room
|
|
6
|
+
* never leave; the others leave lowest `priority` first, the last on the
|
|
7
|
+
* line first among equals — with every priority equal, the tail of the
|
|
8
|
+
* line, as a reader expects.
|
|
9
|
+
*/
|
|
10
|
+
export declare function overflowKeys(ordered: ToolbarItem[], widthOf: (key: string) => number, available: number, gap?: number, triggerWidth?: number): Set<string>;
|
|
11
|
+
export declare function Toolbar({ items, extraItems, className, disabled, ariaLabel, overflow, variant, gap, overflowAriaLabel, keyboardNavigation, }: ToolbarProps): import("react").JSX.Element;
|
|
3
12
|
export default Toolbar;
|
|
Binary file
|
|
@@ -20,6 +20,36 @@ export interface ToolbarItemBase {
|
|
|
20
20
|
disabled?: boolean;
|
|
21
21
|
/** Whether to hide the item */
|
|
22
22
|
hidden?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Never moved into the overflow menu, however narrow the line: the
|
|
25
|
+
* controls a reader must always find where they left them (a close
|
|
26
|
+
* button, a session menu). Pinned items count against the room first.
|
|
27
|
+
*/
|
|
28
|
+
pinned?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Which items leave the line first when the room runs out: the lowest
|
|
31
|
+
* priority goes first, and among equals the last item on the line.
|
|
32
|
+
* Default: 0. The menu lists what left in the line's own order.
|
|
33
|
+
*/
|
|
34
|
+
priority?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* What a custom item becomes in the overflow menu.
|
|
38
|
+
*
|
|
39
|
+
* - `onSelect`: a labelled menu row (`label`, `icon`) that runs it and
|
|
40
|
+
* closes the menu — for a control whose node only makes sense on the line.
|
|
41
|
+
* - `render`: a node of its own for the menu.
|
|
42
|
+
* - neither: the item's own `render()` is drawn in the menu as on the line.
|
|
43
|
+
*/
|
|
44
|
+
export interface ToolbarOverflowRepresentation {
|
|
45
|
+
/** The menu row's name (required with `onSelect`). */
|
|
46
|
+
label?: string;
|
|
47
|
+
/** The menu row's icon. */
|
|
48
|
+
icon?: React.ComponentType<IconProps> | ReactNode;
|
|
49
|
+
/** Run when the menu row is chosen; the menu closes after. */
|
|
50
|
+
onSelect?: () => void;
|
|
51
|
+
/** A node of its own for the menu instead of a row. */
|
|
52
|
+
render?: () => ReactNode;
|
|
23
53
|
}
|
|
24
54
|
/**
|
|
25
55
|
* Toolbar button item definition.
|
|
@@ -104,6 +134,8 @@ export interface ToolbarCustomItem extends ToolbarItemBase {
|
|
|
104
134
|
type: "custom";
|
|
105
135
|
/** Custom render function */
|
|
106
136
|
render: () => ReactNode;
|
|
137
|
+
/** What it becomes in the overflow menu — see `ToolbarOverflowRepresentation`. */
|
|
138
|
+
overflow?: ToolbarOverflowRepresentation;
|
|
107
139
|
}
|
|
108
140
|
/**
|
|
109
141
|
* Union of all toolbar item types.
|
|
@@ -130,6 +162,25 @@ export interface ToolbarProps {
|
|
|
130
162
|
* up to the host to leave room for them.
|
|
131
163
|
*/
|
|
132
164
|
overflow?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* `bar` (the default): an editor's strip — its own ground, a hairline
|
|
167
|
+
* under it, sticky at the top. `inline`: the items alone, no ground, no
|
|
168
|
+
* border, no padding — for a toolbar inside a header row of the host's.
|
|
169
|
+
*/
|
|
170
|
+
variant?: "bar" | "inline";
|
|
171
|
+
/** Space between two items, in px. Default: 2. */
|
|
172
|
+
gap?: number;
|
|
173
|
+
/**
|
|
174
|
+
* The name of the button opening the overflow menu. Default:
|
|
175
|
+
* "N more toolbar items".
|
|
176
|
+
*/
|
|
177
|
+
overflowAriaLabel?: string;
|
|
178
|
+
/**
|
|
179
|
+
* Arrow keys, Home and End move the focus between the toolbar's controls
|
|
180
|
+
* (Tab still leaves it); keys typed into a field are left alone. On by
|
|
181
|
+
* default.
|
|
182
|
+
*/
|
|
183
|
+
keyboardNavigation?: boolean;
|
|
133
184
|
}
|
|
134
185
|
/**
|
|
135
186
|
* Props for the extensible FloatingToolbar component.
|