@oaiz/app-kit 0.1.4250 → 0.1.4256

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oaiz/app-kit",
3
- "version": "0.1.4250",
3
+ "version": "0.1.4256",
4
4
  "description": "Source components, hooks and theme for apps built on OAIZ, to copy and change",
5
5
  "keywords": [
6
6
  "oaiz",
@@ -115,7 +115,7 @@ const ToastDescription = React.forwardRef<
115
115
  asChild
116
116
  size="sm"
117
117
  className={cn(
118
- 'opacity-90 group-[.destructive]:text-destructive-foreground group-[.destructive]:opacity-100',
118
+ 'whitespace-pre-line opacity-90 group-[.destructive]:text-destructive-foreground group-[.destructive]:opacity-100',
119
119
  className,
120
120
  )}
121
121
  >
@@ -94,21 +94,18 @@ export function Toaster({ labels }: { labels?: ToasterLabels } = {}) {
94
94
  aria-keyshortcuts={keyshortcuts}
95
95
  {...props}
96
96
  >
97
- <div className="flex min-w-0 flex-col gap-2">
97
+ <div className="flex min-w-0 flex-1 flex-col gap-stack">
98
98
  <ToastText title={title} description={description} />
99
99
  {action ? (
100
100
  <div
101
- className="flex flex-wrap items-center gap-inline"
101
+ className="flex flex-wrap items-center justify-end gap-inline"
102
102
  data-testid="toast-actions"
103
103
  >
104
104
  {action}
105
105
  </div>
106
106
  ) : null}
107
107
  </div>
108
- <ToastClose
109
- className="top-1/2 -translate-y-1/2"
110
- aria-label={closeLabel}
111
- />
108
+ <ToastClose aria-label={closeLabel} />
112
109
  </Toast>
113
110
  );
114
111
  }
@@ -24,6 +24,11 @@ export interface TreeViewProps {
24
24
  onSelect?: (node: TreeNode) => void;
25
25
  /** The ids of nodes open at first. */
26
26
  defaultExpanded?: string[];
27
+ /** The ids of open nodes, when the caller owns them, such as to reveal a node. */
28
+ expanded?: string[];
29
+ onExpandedChange?: (expanded: string[]) => void;
30
+ /** Nodes with children open and close instead of being chosen, as in a file tree. */
31
+ selectLeavesOnly?: boolean;
27
32
  className?: string;
28
33
  }
29
34
 
@@ -63,11 +68,17 @@ function TreeView({
63
68
  selected = null,
64
69
  onSelect,
65
70
  defaultExpanded = [],
71
+ expanded: controlledExpanded,
72
+ onExpandedChange,
73
+ selectLeavesOnly = false,
66
74
  className,
67
75
  }: TreeViewProps) {
68
- const [expanded, setExpanded] = React.useState(
76
+ const [ownExpanded, setOwnExpanded] = React.useState(
69
77
  () => new Set(defaultExpanded),
70
78
  );
79
+ const expanded = controlledExpanded
80
+ ? new Set(controlledExpanded)
81
+ : ownExpanded;
71
82
  const [focused, setFocused] = React.useState<string | null>(null);
72
83
  const refs = React.useRef(new Map<string, HTMLDivElement>());
73
84
  const rows = visibleRows(nodes, expanded);
@@ -78,13 +89,20 @@ function TreeView({
78
89
  setFocused(id);
79
90
  refs.current.get(id)?.focus();
80
91
  };
81
- const toggle = (id: string, open: boolean) =>
82
- setExpanded((now) => {
83
- const next = new Set(now);
84
- if (open) next.add(id);
85
- else next.delete(id);
86
- return next;
87
- });
92
+ const toggle = (id: string, open: boolean) => {
93
+ const next = new Set(expanded);
94
+ if (open) next.add(id);
95
+ else next.delete(id);
96
+ if (!controlledExpanded) setOwnExpanded(next);
97
+ onExpandedChange?.([...next]);
98
+ };
99
+
100
+ const choosable = (node: TreeNode) =>
101
+ onSelect !== undefined && !(selectLeavesOnly && node.children?.length);
102
+ const activate = (row: Row) => {
103
+ if (choosable(row.node)) onSelect?.(row.node);
104
+ else if (row.node.children?.length) toggle(row.node.id, !row.open);
105
+ };
88
106
 
89
107
  function onKeyDown(event: React.KeyboardEvent, row: Row, index: number) {
90
108
  const hasChildren = Boolean(row.node.children?.length);
@@ -111,8 +129,7 @@ function TreeView({
111
129
  break;
112
130
  case 'Enter':
113
131
  case ' ':
114
- onSelect?.(row.node);
115
- if (hasChildren && !onSelect) toggle(row.node.id, !row.open);
132
+ activate(row);
116
133
  break;
117
134
  default:
118
135
  if (event.key.length === 1 && /\S/.test(event.key)) {
@@ -149,15 +166,14 @@ function TreeView({
149
166
  role="treeitem"
150
167
  aria-level={row.level}
151
168
  aria-expanded={hasChildren ? row.open : undefined}
152
- aria-selected={onSelect ? isSelected : undefined}
169
+ aria-selected={choosable(row.node) ? isSelected : undefined}
153
170
  aria-label={textOf(row.node)}
154
171
  tabIndex={row.node.id === current ? 0 : -1}
155
172
  onFocus={() => setFocused(row.node.id)}
156
173
  onKeyDown={(event) => onKeyDown(event, row, index)}
157
174
  onClick={() => {
158
175
  setFocused(row.node.id);
159
- if (onSelect) onSelect(row.node);
160
- else if (hasChildren) toggle(row.node.id, !row.open);
176
+ activate(row);
161
177
  }}
162
178
  // Each level indents by one stack step from the inline gutter.
163
179
  style={{
@@ -12,8 +12,8 @@ type ToasterToast = ToastProps & {
12
12
  description?: React.ReactNode;
13
13
  action?: ToastActionElement;
14
14
  /**
15
- * `stacked` puts the actions in a row under the title, for toasts with more
16
- * than one action.
15
+ * `stacked` puts the actions in a right-aligned row under the text, for
16
+ * toasts with more than one action or a long description.
17
17
  */
18
18
  layout?: 'inline' | 'stacked';
19
19
  /** Runs when the person presses Cmd+Z or Ctrl+Z while the toast is open. */