@setsquare/ui 0.4.0 → 0.5.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/CHANGELOG.md +71 -0
- package/README.md +4 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lint/index.d.ts +5 -0
- package/dist/lint/index.d.ts.map +1 -1
- package/dist/lint/index.js +80 -3
- package/dist/lint/index.js.map +1 -1
- package/dist/styles/theme.css +2 -0
- package/dist/styles/tokens.css +9 -0
- package/dist/testing/index.d.ts +54 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +246 -9
- package/dist/testing/index.js.map +1 -1
- package/dist/tokens.json +25 -0
- package/dist/ui/breadcrumbs.d.ts +9 -1
- package/dist/ui/breadcrumbs.d.ts.map +1 -1
- package/dist/ui/breadcrumbs.js +3 -3
- package/dist/ui/breadcrumbs.js.map +1 -1
- package/dist/ui/button-styles.d.ts.map +1 -1
- package/dist/ui/button-styles.js +16 -6
- package/dist/ui/button-styles.js.map +1 -1
- package/dist/ui/combo-box.d.ts +6 -1
- package/dist/ui/combo-box.d.ts.map +1 -1
- package/dist/ui/combo-box.js +2 -2
- package/dist/ui/combo-box.js.map +1 -1
- package/dist/ui/drop-indicator.d.ts +21 -0
- package/dist/ui/drop-indicator.d.ts.map +1 -0
- package/dist/ui/drop-indicator.js +20 -0
- package/dist/ui/drop-indicator.js.map +1 -0
- package/dist/ui/grid-list.d.ts +10 -3
- package/dist/ui/grid-list.d.ts.map +1 -1
- package/dist/ui/grid-list.js +18 -7
- package/dist/ui/grid-list.js.map +1 -1
- package/dist/ui/switch.d.ts +2 -1
- package/dist/ui/switch.d.ts.map +1 -1
- package/dist/ui/switch.js +5 -2
- package/dist/ui/switch.js.map +1 -1
- package/dist/ui/toolbar.d.ts +22 -0
- package/dist/ui/toolbar.d.ts.map +1 -0
- package/dist/ui/toolbar.js +22 -0
- package/dist/ui/toolbar.js.map +1 -0
- package/dist/ui/tree.d.ts +57 -12
- package/dist/ui/tree.d.ts.map +1 -1
- package/dist/ui/tree.js +54 -15
- package/dist/ui/tree.js.map +1 -1
- package/package.json +3 -3
package/dist/ui/tree.js
CHANGED
|
@@ -1,29 +1,68 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { ChevronRight } from 'lucide-react';
|
|
3
|
+
import { ChevronRight, GripVertical } from 'lucide-react';
|
|
4
4
|
import { Button as RACButton, Tree as RACTree, TreeHeader as RACTreeHeader, TreeItem as RACTreeItem, TreeItemContent, TreeSection as RACTreeSection, } from 'react-aria-components';
|
|
5
5
|
import { cn } from '../lib/cn.js';
|
|
6
6
|
import { SelectionCheckbox } from './checkbox.js';
|
|
7
|
+
import { renderIcon } from './icon.js';
|
|
7
8
|
/**
|
|
8
|
-
* Nested things people open, close and act on: the steps of a workflow and their outcomes,
|
|
9
|
-
* resource. React Aria's Tree, a `treegrid` and one tab stop. ↑ ↓ move between rows, → opens a
|
|
10
|
-
* it, Home and End go to the ends, and typing jumps to the next row whose name starts with what you
|
|
11
|
-
* open row, → moves to the row's own buttons.
|
|
12
|
-
*
|
|
9
|
+
* Nested things people open, close and act on: the blocks of a page, the steps of a workflow and their outcomes,
|
|
10
|
+
* operations grouped by resource. React Aria's Tree, a `treegrid` and one tab stop. ↑ ↓ move between rows, → opens a
|
|
11
|
+
* row and ← closes it, Home and End go to the ends, and typing jumps to the next row whose name starts with what you
|
|
12
|
+
* typed. On an open row, → moves to the row's own buttons.
|
|
13
|
+
*
|
|
14
|
+
* It draws no box of its own: rows sit on whatever surface holds the tree (a panel, a card), `--nav-item-gap`
|
|
15
|
+
* apart, like a nav list. The tree is `relative` because it scrolls, and because React Aria positions its drop
|
|
16
|
+
* indicators absolutely.
|
|
17
|
+
*
|
|
18
|
+
* Drag and drop: pass `dragAndDropHooks` from React Aria's `useDragAndDrop`, with
|
|
19
|
+
* `renderDropIndicator: (target) => <DropIndicator target={target} />`. Every draggable row then shows a drag
|
|
20
|
+
* button, which is how a keyboard or screen reader drag starts: Enter on it, ↑ ↓ to a drop place, Enter to drop,
|
|
21
|
+
* Esc to cancel.
|
|
13
22
|
*/
|
|
14
23
|
export function Tree({ className, ...props }) {
|
|
15
|
-
return (_jsx(RACTree, { ...props, className: cn('relative flex max-h-[inherit] flex-col
|
|
24
|
+
return (_jsx(RACTree, { ...props, className: cn('relative flex max-h-[inherit] flex-col gap-(--nav-item-gap) overflow-auto text-sm outline-none data-focus-visible:focus-ring',
|
|
25
|
+
// Dropping onto the tree itself (an empty tree, or the end of it).
|
|
26
|
+
'data-drop-target:bg-brand-subtle data-drop-target:outline-2 data-drop-target:outline-solid data-drop-target:outline-brand data-drop-target:-outline-offset-2', className) }));
|
|
16
27
|
}
|
|
28
|
+
/** The column the chevron, or the space for one, takes: one target wide, so every title lines up. */
|
|
29
|
+
const lead = 'w-[max(var(--target-min),var(--control-height-sm))] shrink-0';
|
|
17
30
|
/**
|
|
18
|
-
* One row and the rows inside it
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* GridList; with multiple selection, a ticked box too.
|
|
31
|
+
* One row and the rows inside it, on one line while it fits: chevron, icon, title, description, status, then its
|
|
32
|
+
* buttons. Each level indents by `--tree-indent` (16px). A row is at least `--nav-item-height` tall and `--target-min` at AAA,
|
|
33
|
+
* rounded, with the `accent` ground on hover. Selected: `brand-subtle`, the 3px `sidebar-primary` marker, a bold
|
|
34
|
+
* title and a `brand` icon, as in a GridList and the sidebar; with multiple selection, a ticked box too.
|
|
35
|
+
*
|
|
36
|
+
* A row that only holds other rows, such as a column in a page layout, can be focused and opened but never
|
|
37
|
+
* selected: put its id in the Tree's `disabledKeys` and set `disabledBehavior="selection"`. React Aria then
|
|
38
|
+
* leaves it focusable and doesn't mark it disabled, so it isn't dimmed.
|
|
39
|
+
*
|
|
40
|
+
* While a drag is over the row, as a place to drop into, it gets the `brand-subtle` ground and a 2px `brand`
|
|
41
|
+
* outline inside its edge. The row being dragged fades to 50%.
|
|
22
42
|
*/
|
|
23
|
-
export function TreeItem({ title, textValue, description, actions, children, className, ...props }) {
|
|
24
|
-
|
|
43
|
+
export function TreeItem({ title, textValue, icon, description, status, statusLabel, actions, alwaysShowActions, children, dragLabel, allowsDragging: rowDrags = true, className, ...props }) {
|
|
44
|
+
const text = textValue ?? (typeof title === 'string' ? title : '');
|
|
45
|
+
const named = [
|
|
46
|
+
props['aria-label'] ?? text,
|
|
47
|
+
typeof description === 'string' ? description : '',
|
|
48
|
+
statusLabel ?? '',
|
|
49
|
+
]
|
|
50
|
+
.filter(Boolean)
|
|
51
|
+
.join(', ');
|
|
52
|
+
return (_jsxs(RACTreeItem, { ...props, textValue: text, "aria-label": named || undefined, style: ({ level }) => ({ '--tree-level': level }), className: cn(
|
|
25
53
|
// React Aria sets data-hovered only on a row that can be selected or has an action: the pointer then.
|
|
26
|
-
'group/tree-item relative flex min-h-[
|
|
54
|
+
'group/tree-item relative flex min-h-[max(var(--target-min),var(--nav-item-height))] cursor-default items-center gap-0.5 rounded-md py-1 ps-[calc((var(--tree-level)-1)*var(--tree-indent))] pe-1 outline-none', 'data-hovered:cursor-pointer data-disabled:cursor-not-allowed data-hovered:bg-accent data-selected:bg-brand-subtle data-selected:shadow-[inset_3px_0_0_var(--sidebar-primary)] data-focus-visible:focus-ring-inset data-disabled:opacity-60', 'data-dragging:opacity-50 data-drop-target:bg-brand-subtle data-drop-target:outline-2 data-drop-target:outline-solid data-drop-target:outline-brand data-drop-target:-outline-offset-2',
|
|
55
|
+
// Forced colours drop the selected ground and the inset marker: draw the marker in Highlight instead.
|
|
56
|
+
"forced-colors:data-selected:before:absolute forced-colors:data-selected:before:inset-y-1 forced-colors:data-selected:before:start-0 forced-colors:data-selected:before:w-[3px] forced-colors:data-selected:before:bg-[Highlight] forced-colors:data-selected:before:forced-color-adjust-none forced-colors:data-selected:before:content-['']", className), children: [_jsx(TreeItemContent, { children: ({ hasChildItems, selectionMode, selectionBehavior, allowsDragging: treeDrags }) => {
|
|
57
|
+
const allowsDragging = treeDrags && rowDrags;
|
|
58
|
+
return (_jsxs(_Fragment, { children: [hasChildItems ? (_jsx(RACButton, { slot: "chevron", className: cn('group/tree-chevron relative flex min-h-target cursor-pointer items-center justify-center outline-none', lead), children: _jsx("span", { className: "flex size-control-sm items-center justify-center rounded-md text-muted-foreground group-data-hovered/tree-chevron:bg-muted group-data-hovered/tree-chevron:text-foreground", children: _jsx(ChevronRight, { "aria-hidden": "true", className: "size-4 group-data-expanded/tree-item:rotate-90" }) }) })) : (_jsx("span", { "aria-hidden": "true", className: lead })), selectionMode === 'multiple' && selectionBehavior === 'toggle' && (_jsx(SelectionCheckbox, {})), _jsxs("span", { className: "flex min-w-0 flex-1 flex-wrap items-center gap-x-2 px-2", children: [icon &&
|
|
59
|
+
renderIcon(icon, 'size-4 shrink-0 text-muted-foreground group-data-selected/tree-item:text-brand'), _jsx("span", { className: "min-w-0 leading-5 font-semibold [overflow-wrap:anywhere] text-foreground group-data-selected/tree-item:font-bold", children: title }), description && (_jsx("span", { className: "min-w-0 leading-5 [overflow-wrap:anywhere] text-muted-foreground", children: description })), status && (_jsx("span", { className: "flex flex-wrap items-center gap-1", children: status }))] }), (actions || allowsDragging) && (_jsxs("span", { className: cn('flex shrink-0 items-center gap-0.5', !alwaysShowActions &&
|
|
60
|
+
// Faded out, not hidden: they stay focusable, so focus can land on them (and shows
|
|
61
|
+
// them) and React Aria can hand focus back to the drag button when a drag ends. No
|
|
62
|
+
// pointer events until they show: group-hover needs a device that hovers, so on touch
|
|
63
|
+
// a tap selects the row first.
|
|
64
|
+
'pointer-events-none opacity-0', 'group-hover/tree-item:pointer-events-auto group-hover/tree-item:opacity-100', 'group-focus-within/tree-item:pointer-events-auto group-focus-within/tree-item:opacity-100', 'group-data-selected/tree-item:pointer-events-auto group-data-selected/tree-item:opacity-100', 'group-data-dragging/tree-item:opacity-100'), children: [allowsDragging && (_jsx(RACButton, { slot: "drag", "aria-label": dragLabel, className: "group/tree-drag relative flex min-h-target min-w-target shrink-0 cursor-grab items-center justify-center outline-none", children: _jsx("span", { className: "flex size-control-sm items-center justify-center rounded-md text-muted-foreground group-data-focus-visible/tree-drag:focus-ring group-data-hovered/tree-drag:bg-muted group-data-hovered/tree-drag:text-foreground", children: _jsx(GripVertical, { "aria-hidden": "true", className: "size-4" }) }) })), actions] }))] }));
|
|
65
|
+
} }), children] }));
|
|
27
66
|
}
|
|
28
67
|
/** A group of top-level rows under a `TreeHeader`: operations by resource, steps by phase. */
|
|
29
68
|
export function TreeSection({ className, ...props }) {
|
|
@@ -31,6 +70,6 @@ export function TreeSection({ className, ...props }) {
|
|
|
31
70
|
}
|
|
32
71
|
/** The name of a `TreeSection`, read before its rows. Not a target: arrow keys pass over it. */
|
|
33
72
|
export function TreeHeader({ children, className }) {
|
|
34
|
-
return (_jsx(RACTreeHeader, { className: cn('
|
|
73
|
+
return (_jsx(RACTreeHeader, { className: cn('px-3 pt-3 pb-1 text-caption-strong text-muted-foreground first:pt-1', className), children: children }));
|
|
35
74
|
}
|
|
36
75
|
//# sourceMappingURL=tree.js.map
|
package/dist/ui/tree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/ui/tree.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/ui/tree.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EACL,MAAM,IAAI,SAAS,EACnB,IAAI,IAAI,OAAO,EACf,UAAU,IAAI,aAAa,EAC3B,QAAQ,IAAI,WAA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AAsF;oCACtF,+BAA+B;oCAC/B,+BAA+B,EACjC,6EAA6E,EAC7E,2FAA2F,EAC3F,6FAA6F,EAC7F,2CAA2C,CAC5C,aAEA,cAAc,IAAI,CACjB,KAAC,SAAS,IACR,IAAI,EAAC,MAAM,gBACC,SAAS,EACrB,SAAS,EAAC,uHAAuH,YAEjI,eAAM,SAAS,EAAC,oNAAoN,YAClO,KAAC,YAAY,mBAAa,MAAM,EAAC,SAAS,EAAC,QAAQ,GAAG,GACjD,GACG,CACb,EACA,OAAO,IACH,CACR,IACA,CACJ,CAAC;gBACJ,CAAC,GACe,EACjB,QAAQ,IACG,CACf,CAAC;AACJ,CAAC;AAYD,8FAA8F;AAC9F,MAAM,UAAU,WAAW,CAAmB,EAAE,SAAS,EAAE,GAAG,KAAK,EAAuB;IACxF,OAAO,KAAC,cAAc,OAAK,KAAK,EAAE,SAAS,EAAE,SAAS,GAAI,CAAC;AAC7D,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,SAAS,EAA+C;IAC7F,OAAO,CACL,KAAC,aAAa,IACZ,SAAS,EAAE,EAAE,CACX,qEAAqE,EACrE,SAAS,CACV,YAEA,QAAQ,GACK,CACjB,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@setsquare/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "React Aria components, design tokens, a dashboard shell and a site shell, with a switch between WCAG 2.2 AA and AAA sizing, spacing and contrast.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/Worktree-Amigos/setsquare-ui#readme",
|
|
@@ -101,8 +101,8 @@
|
|
|
101
101
|
"access": "public"
|
|
102
102
|
},
|
|
103
103
|
"scripts": {
|
|
104
|
-
"build": "node scripts/build-css.mjs && tsc -p tsconfig.json && pnpm --filter @setsquare/ui-flows build",
|
|
105
|
-
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json && pnpm --filter @setsquare/ui-flows typecheck",
|
|
104
|
+
"build": "node scripts/build-css.mjs && tsc -p tsconfig.json && pnpm --filter @setsquare/ui-flows build && pnpm --filter @setsquare/ui-blocks build",
|
|
105
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json && pnpm --filter @setsquare/ui-flows typecheck && pnpm --filter @setsquare/ui-blocks typecheck",
|
|
106
106
|
"lint": "oxlint && node scripts/check-contrast.mjs",
|
|
107
107
|
"format": "oxfmt",
|
|
108
108
|
"format:check": "oxfmt --check",
|