@alexgorbatchev/shadcn 0.0.109 → 0.0.111
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.
|
@@ -19,8 +19,24 @@ type TreeItemProps<T> = useRender.ComponentProps<"div", TreeItemState> & IDensit
|
|
|
19
19
|
expandOn?: "click" | "doubleClick" | "disclosure";
|
|
20
20
|
isEditing?: boolean;
|
|
21
21
|
isDropTarget?: boolean;
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Fades a settled row, such as completed work, to 70% opacity; hover and keyboard focus restore full opacity. The
|
|
24
|
+
* `marker` stays at full opacity, so new activity on a settled row stands out without un-fading it.
|
|
25
|
+
*/
|
|
23
26
|
isDimmed?: boolean;
|
|
27
|
+
/** Marks a row with activity its reader has not seen yet: the label turns bold. Pair it with a `marker`. */
|
|
28
|
+
isUnread?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The row's start slot, before its icon and label and outside its link: a status control (a `TreeItemAction`
|
|
31
|
+
* holding a `TreeItemStatusIcon`) or a plain status icon. `null` keeps the slot empty so rows stay aligned. It
|
|
32
|
+
* fades with the row.
|
|
33
|
+
*/
|
|
34
|
+
leading?: ReactNode;
|
|
35
|
+
/**
|
|
36
|
+
* A visual marker at the row's end, such as a `TreeItemDot` for new activity, never faded by `isDimmed`. It is
|
|
37
|
+
* hidden from assistive technology; state what it means in `descriptionLabel`.
|
|
38
|
+
*/
|
|
39
|
+
marker?: ReactNode;
|
|
24
40
|
/** The registered native link owns row focus; disclosure and actions remain siblings. */
|
|
25
41
|
linkProps?: useRender.ComponentProps<"a", TreeItemState>;
|
|
26
42
|
/** Domain-controlled drag feedback; omitted rows have no tooltip wrapper. */
|
|
@@ -49,9 +65,34 @@ type TreeItemActionProps = ComponentProps<typeof Button>;
|
|
|
49
65
|
* menu trigger renders it, so the tree keeps one Tab stop.
|
|
50
66
|
*/
|
|
51
67
|
export declare function TreeItemAction({ variant, size, ...props }: TreeItemActionProps): ReactElement;
|
|
68
|
+
/**
|
|
69
|
+
* A row's hand-back state, drawn by `TreeItemStatusIcon`: two waiting states, waiting with unsent answers, failed,
|
|
70
|
+
* held for an Undo window, handed back, and handed back with unsent changes.
|
|
71
|
+
*/
|
|
72
|
+
export type TreeItemStatus = "needs-answers" | "needs-review" | "unsent" | "failed" | "held" | "handed-back" | "handed-back-unsent";
|
|
73
|
+
interface ITreeItemStatusIconProps {
|
|
74
|
+
status: TreeItemStatus;
|
|
75
|
+
className?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The status icon set for a row's `leading` slot. Each state has its own shape, so forced colors keep them apart; the
|
|
79
|
+
* unsent states add a filled marker at the top end. It is decorative: the row's `descriptionLabel` names the state.
|
|
80
|
+
*/
|
|
81
|
+
export declare function TreeItemStatusIcon({ status, className }: ITreeItemStatusIconProps): ReactElement;
|
|
82
|
+
interface ITreeItemDotProps {
|
|
83
|
+
/** The number shown beside the dot, such as the new pages inside a collapsed folder; omitted for a single item. */
|
|
84
|
+
count?: number;
|
|
85
|
+
className?: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The new-activity dot for a `TreeItem`'s `marker`, with an optional count for a collapsed container that rolls up its
|
|
89
|
+
* rows. Drawn as an SVG fill in `currentColor`, so forced colors keep it visible. It is decorative: the row's
|
|
90
|
+
* `descriptionLabel` names it ("New round", "1 new page").
|
|
91
|
+
*/
|
|
92
|
+
export declare function TreeItemDot({ count, className }: ITreeItemDotProps): ReactElement;
|
|
52
93
|
/**
|
|
53
94
|
* Registered tree row; compose menus with render, put counts in `description` and pointer shortcuts in `actions`.
|
|
54
95
|
* `endEnhancer` holds controls that must stay keyboard reachable on their own.
|
|
55
96
|
*/
|
|
56
|
-
export declare function TreeItem<T>({ analytics, item, children, startEnhancer, endEnhancer, description, descriptionLabel, actions, expandOn, isEditing, isDropTarget, isDimmed, linkProps, dropHint, density, render, ref, ...props }: TreeItemProps<T>): ReactElement;
|
|
97
|
+
export declare function TreeItem<T>({ analytics, item, children, startEnhancer, endEnhancer, description, descriptionLabel, actions, expandOn, isEditing, isDropTarget, isDimmed, isUnread, leading, marker, linkProps, dropHint, density, render, ref, ...props }: TreeItemProps<T>): ReactElement;
|
|
57
98
|
export type { TreeItemProps };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Tree } from "./Tree.js";
|
|
2
|
-
export { TreeItem, TreeItemAction } from "./TreeItem.js";
|
|
2
|
+
export { TreeItem, TreeItemAction, TreeItemDot, TreeItemStatusIcon } from "./TreeItem.js";
|
|
3
3
|
export type { TreeProps } from "./Tree.js";
|
|
4
|
-
export type { TreeItemProps } from "./TreeItem.js";
|
|
4
|
+
export type { TreeItemProps, TreeItemStatus } from "./TreeItem.js";
|
|
5
5
|
export { useTree, AssistiveTreeDescription } from "@headless-tree/react";
|
|
6
6
|
export { syncDataLoaderFeature, asyncDataLoaderFeature, hotkeysCoreFeature, selectionFeature, checkboxesFeature, searchFeature, renamingFeature, expandAllFeature, dragAndDropFeature, keyboardDragAndDropFeature, isOrderedDragTarget, } from "@headless-tree/core";
|
|
7
7
|
export type { TreeInstance, ItemInstance, TreeConfig, DragTarget } from "@headless-tree/core";
|
|
@@ -21,7 +21,17 @@ import {
|
|
|
21
21
|
// src/components/tree/TreeItem.tsx
|
|
22
22
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
23
23
|
import { useRender } from "@base-ui/react/use-render";
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
ChevronRightIcon,
|
|
26
|
+
CircleAlertIcon,
|
|
27
|
+
CircleCheckIcon,
|
|
28
|
+
CircleDotIcon,
|
|
29
|
+
CircleIcon,
|
|
30
|
+
FileIcon,
|
|
31
|
+
FolderIcon,
|
|
32
|
+
FolderOpenIcon,
|
|
33
|
+
HourglassIcon
|
|
34
|
+
} from "lucide-react";
|
|
25
35
|
import { use, useId } from "react";
|
|
26
36
|
|
|
27
37
|
// src/components/tree/TreeTabStopContext.ts
|
|
@@ -38,6 +48,63 @@ function TreeItemAction({ variant = "ghost", size = "icon-xs", ...props }) {
|
|
|
38
48
|
tabIndex: -1
|
|
39
49
|
});
|
|
40
50
|
}
|
|
51
|
+
var STATUS_ICONS = {
|
|
52
|
+
"needs-answers": CircleDotIcon,
|
|
53
|
+
"needs-review": CircleIcon,
|
|
54
|
+
unsent: CircleIcon,
|
|
55
|
+
failed: CircleAlertIcon,
|
|
56
|
+
held: HourglassIcon,
|
|
57
|
+
"handed-back": CircleCheckIcon,
|
|
58
|
+
"handed-back-unsent": CircleCheckIcon
|
|
59
|
+
};
|
|
60
|
+
function TreeItemStatusIcon({ status, className }) {
|
|
61
|
+
const Icon = STATUS_ICONS[status];
|
|
62
|
+
const hasMarker = status === "unsent" || status === "handed-back-unsent";
|
|
63
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
64
|
+
"aria-hidden": "true",
|
|
65
|
+
"data-slot": "tree-item-status",
|
|
66
|
+
"data-status": status,
|
|
67
|
+
className: cn2("relative inline-flex size-4 shrink-0 items-center justify-center [&>svg]:size-3.5", className),
|
|
68
|
+
children: [
|
|
69
|
+
/* @__PURE__ */ jsx(Icon, {}),
|
|
70
|
+
hasMarker && /* @__PURE__ */ jsx("svg", {
|
|
71
|
+
viewBox: "0 0 6 6",
|
|
72
|
+
className: "absolute -top-0.5 -right-0.5 size-1.5",
|
|
73
|
+
focusable: "false",
|
|
74
|
+
children: /* @__PURE__ */ jsx("circle", {
|
|
75
|
+
cx: "3",
|
|
76
|
+
cy: "3",
|
|
77
|
+
r: "3",
|
|
78
|
+
fill: "currentColor"
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
]
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function TreeItemDot({ count, className }) {
|
|
85
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
86
|
+
"aria-hidden": "true",
|
|
87
|
+
"data-slot": "tree-item-dot",
|
|
88
|
+
className: cn2("inline-flex items-center gap-1 text-xs font-medium text-primary tabular-nums", className),
|
|
89
|
+
children: [
|
|
90
|
+
/* @__PURE__ */ jsx("svg", {
|
|
91
|
+
viewBox: "0 0 8 8",
|
|
92
|
+
className: "size-2 shrink-0",
|
|
93
|
+
focusable: "false",
|
|
94
|
+
children: /* @__PURE__ */ jsx("circle", {
|
|
95
|
+
cx: "4",
|
|
96
|
+
cy: "4",
|
|
97
|
+
r: "4",
|
|
98
|
+
fill: "currentColor"
|
|
99
|
+
})
|
|
100
|
+
}),
|
|
101
|
+
count !== undefined && /* @__PURE__ */ jsx("span", {
|
|
102
|
+
"data-slot": "tree-item-dot-count",
|
|
103
|
+
children: count
|
|
104
|
+
})
|
|
105
|
+
]
|
|
106
|
+
});
|
|
107
|
+
}
|
|
41
108
|
function isRowControl(event) {
|
|
42
109
|
return event.target !== event.currentTarget && event.target instanceof Element && Boolean(event.target.closest("a,button,input,textarea,select,form"));
|
|
43
110
|
}
|
|
@@ -54,6 +121,9 @@ function TreeItem({
|
|
|
54
121
|
isEditing = false,
|
|
55
122
|
isDropTarget = false,
|
|
56
123
|
isDimmed = false,
|
|
124
|
+
isUnread = false,
|
|
125
|
+
leading,
|
|
126
|
+
marker,
|
|
57
127
|
linkProps,
|
|
58
128
|
dropHint,
|
|
59
129
|
density,
|
|
@@ -104,6 +174,7 @@ function TreeItem({
|
|
|
104
174
|
item.getTree().getDataRef().current.selectUpToAnchorId = item.getId();
|
|
105
175
|
item.primaryAction();
|
|
106
176
|
};
|
|
177
|
+
const faded = isDimmed && "opacity-70 group-hover/tree-item:opacity-100 group-focus-within/tree-item:opacity-100";
|
|
107
178
|
const label = /* @__PURE__ */ jsxs(Fragment, {
|
|
108
179
|
children: [
|
|
109
180
|
/* @__PURE__ */ jsx("span", {
|
|
@@ -112,7 +183,7 @@ function TreeItem({
|
|
|
112
183
|
children: startEnhancer ?? (item.isFolder() ? isExpanded ? /* @__PURE__ */ jsx(FolderOpenIcon, {}) : /* @__PURE__ */ jsx(FolderIcon, {}) : /* @__PURE__ */ jsx(FileIcon, {}))
|
|
113
184
|
}),
|
|
114
185
|
/* @__PURE__ */ jsx("div", {
|
|
115
|
-
className: "min-w-0 flex-1 truncate",
|
|
186
|
+
className: cn2("min-w-0 flex-1 truncate", isUnread && "font-semibold"),
|
|
116
187
|
children: children ?? item.getItemName()
|
|
117
188
|
})
|
|
118
189
|
]
|
|
@@ -124,7 +195,7 @@ function TreeItem({
|
|
|
124
195
|
props: mergeProps({
|
|
125
196
|
...nativeProps,
|
|
126
197
|
ref: undefined,
|
|
127
|
-
className: "flex min-w-0 flex-1 items-center gap-2 outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
198
|
+
className: cn2("flex min-w-0 flex-1 items-center gap-2 outline-none focus-visible:ring-2 focus-visible:ring-ring", faded),
|
|
128
199
|
children: label,
|
|
129
200
|
onFocus: () => item.setFocused(),
|
|
130
201
|
onClick: (event) => {
|
|
@@ -178,12 +249,13 @@ function TreeItem({
|
|
|
178
249
|
onDragStart: undefined
|
|
179
250
|
} : {},
|
|
180
251
|
style: { paddingInlineStart: `${item.getItemMeta().level * (item.getTree().getConfig().indent ?? 20) + 8}px` },
|
|
181
|
-
className: cn2("relative flex min-h-control min-w-0 cursor-default items-center gap-2 rounded-sm py-1 pr-2 text-sm outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring", (isSelected || isDropTarget || isInsideTarget) && "bg-accent text-accent-foreground", isDimmed && "
|
|
252
|
+
className: cn2("relative flex min-h-control min-w-0 cursor-default items-center gap-2 rounded-sm py-1 pr-2 text-sm outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring", (isSelected || isDropTarget || isInsideTarget) && "bg-accent text-accent-foreground", isDimmed && "group/tree-item"),
|
|
182
253
|
children: /* @__PURE__ */ jsxs(Fragment, {
|
|
183
254
|
children: [
|
|
184
255
|
item.isFolder() && expandOn === "disclosure" ? /* @__PURE__ */ jsx(Button2, {
|
|
185
256
|
variant: "plain",
|
|
186
257
|
size: "icon-xs",
|
|
258
|
+
className: cn2(faded),
|
|
187
259
|
tabIndex: -1,
|
|
188
260
|
"aria-hidden": "true",
|
|
189
261
|
"aria-label": `${isExpanded ? "Collapse" : "Expand"} ${item.getItemName()}`,
|
|
@@ -199,20 +271,37 @@ function TreeItem({
|
|
|
199
271
|
})
|
|
200
272
|
}) : item.isFolder() ? /* @__PURE__ */ jsx(ChevronRightIcon, {
|
|
201
273
|
"aria-hidden": "true",
|
|
202
|
-
className: cn2("size-3.5 shrink-0", isExpanded && "rotate-90")
|
|
274
|
+
className: cn2("size-3.5 shrink-0", isExpanded && "rotate-90", faded)
|
|
203
275
|
}) : /* @__PURE__ */ jsx("span", {
|
|
204
276
|
className: cn2("shrink-0", expandOn === "disclosure" ? "size-control-xs" : "size-3.5")
|
|
205
277
|
}),
|
|
206
|
-
|
|
278
|
+
leading !== undefined && /* @__PURE__ */ jsx("div", {
|
|
279
|
+
"data-slot": "tree-item-leading",
|
|
280
|
+
className: cn2("flex size-control-xs shrink-0 items-center justify-center", faded),
|
|
281
|
+
onClick: (event) => event.stopPropagation(),
|
|
282
|
+
onDoubleClick: (event) => event.stopPropagation(),
|
|
283
|
+
onKeyDown: (event) => event.stopPropagation(),
|
|
284
|
+
children: leading
|
|
285
|
+
}),
|
|
286
|
+
linkProps && !isEditing ? link : isDimmed ? /* @__PURE__ */ jsx("div", {
|
|
287
|
+
className: cn2("flex min-w-0 flex-1 items-center gap-2", faded),
|
|
288
|
+
children: label
|
|
289
|
+
}) : label,
|
|
207
290
|
endEnhancer && /* @__PURE__ */ jsx("div", {
|
|
208
|
-
className: "flex shrink-0 items-center gap-1 text-xs tabular-nums",
|
|
291
|
+
className: cn2("flex shrink-0 items-center gap-1 text-xs tabular-nums", faded),
|
|
209
292
|
onClick: (event) => event.stopPropagation(),
|
|
210
293
|
onDoubleClick: (event) => event.stopPropagation(),
|
|
211
294
|
onKeyDown: (event) => event.stopPropagation(),
|
|
212
295
|
children: endEnhancer
|
|
213
296
|
}),
|
|
297
|
+
marker !== undefined && marker !== null && marker !== false && /* @__PURE__ */ jsx("div", {
|
|
298
|
+
"aria-hidden": "true",
|
|
299
|
+
"data-slot": "tree-item-marker",
|
|
300
|
+
className: "flex shrink-0 items-center",
|
|
301
|
+
children: marker
|
|
302
|
+
}),
|
|
214
303
|
(hasDescription || actions) && /* @__PURE__ */ jsxs("div", {
|
|
215
|
-
className: "flex shrink-0 items-center gap-1 text-xs tabular-nums",
|
|
304
|
+
className: cn2("flex shrink-0 items-center gap-1 text-xs tabular-nums", faded),
|
|
216
305
|
children: [
|
|
217
306
|
description !== undefined && description !== null && /* @__PURE__ */ jsx("span", {
|
|
218
307
|
"aria-hidden": "true",
|
|
@@ -2545,6 +2634,8 @@ export {
|
|
|
2545
2634
|
Tree,
|
|
2546
2635
|
TreeItem,
|
|
2547
2636
|
TreeItemAction,
|
|
2637
|
+
TreeItemDot,
|
|
2638
|
+
TreeItemStatusIcon,
|
|
2548
2639
|
asyncDataLoaderFeature,
|
|
2549
2640
|
checkboxesFeature,
|
|
2550
2641
|
dragAndDropFeature,
|
package/dist/prototype.js
CHANGED
|
@@ -2051,7 +2051,7 @@ var program = new Command;
|
|
|
2051
2051
|
// package.json
|
|
2052
2052
|
var package_default = {
|
|
2053
2053
|
name: "@alexgorbatchev/shadcn",
|
|
2054
|
-
version: "0.0.
|
|
2054
|
+
version: "0.0.111",
|
|
2055
2055
|
description: "Sharp, monospace React components with compact and comfortable densities.",
|
|
2056
2056
|
license: "MIT",
|
|
2057
2057
|
repository: {
|
|
@@ -8,7 +8,7 @@ Source: src/components/stories/navigation/Tree.stories.tsx
|
|
|
8
8
|
## Public imports
|
|
9
9
|
|
|
10
10
|
```tsx
|
|
11
|
-
import { Tree, TreeItem, TreeItemAction, useTree, syncDataLoaderFeature, hotkeysCoreFeature, selectionFeature } from "@alexgorbatchev/shadcn/tree";
|
|
11
|
+
import { Tree, TreeItem, TreeItemAction, TreeItemDot, TreeItemStatusIcon, useTree, syncDataLoaderFeature, hotkeysCoreFeature, selectionFeature, type TreeItemStatus } from "@alexgorbatchev/shadcn/tree";
|
|
12
12
|
import { Button, ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuGroup, ContextMenuItem, InlineEdit } from "@alexgorbatchev/shadcn";
|
|
13
13
|
```
|
|
14
14
|
|
|
@@ -84,3 +84,19 @@ Storybook CSF excerpts. Default args and render apply unless overridden. Local h
|
|
|
84
84
|
render: () => <DimmedExample />
|
|
85
85
|
}
|
|
86
86
|
```
|
|
87
|
+
|
|
88
|
+
### NewActivity
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
{
|
|
92
|
+
render: () => <NewActivityExample />
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### StatusRows
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
{
|
|
100
|
+
render: () => <StatusRowsExample />
|
|
101
|
+
}
|
|
102
|
+
```
|