Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions src/components/Tree.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
width: 100%;
box-sizing: border-box;
outline: none;
border-radius: 6px;

/* Chevron */

Expand Down Expand Up @@ -108,6 +109,7 @@

&[data-focus-visible] {
outline: 2px solid var(--alinea-focus-ring-color);
background: var(--alinea-background-color);
outline-offset: -2px;
}

Expand Down Expand Up @@ -159,26 +161,9 @@
}
}

/* Action buttons */

button:not([slot]) {
margin-left: auto;
background: transparent;
border: none;
font-size: 1.05rem;
line-height: 1.2em;
padding: 4px 6px;
transition: background 200ms;

&[data-hovered] {
background: var(--alinea-highlight-hover);
}

&[data-pressed] {
background: var(--alinea-highlight-pressed);
box-shadow: none;
}
}
user-select: none;
-webkit-user-drag: element;
touch-action: none;
}

/* Drop indicator */
Expand Down Expand Up @@ -206,3 +191,43 @@
outline-offset: -1px;
background: var(--alinea-highlight-overlay);
}

.alinea-rac-TreeItem-controls {
position: relative;
width: 16px;
height: 16px;
& > * {
position: absolute !important;
top: 0 !important;
left: 0 !important;
}
}

.alinea-rac-TreeItem-dragHandle {
margin-left: auto;
background: transparent;
border: none;
font-size: 1.05rem;
line-height: 1.2em;
padding: 4px 6px;
transition: background 200ms;

&[data-hovered] {
background: var(--alinea-highlight-hover);
}

&[data-pressed] {
background: var(--alinea-highlight-pressed);
box-shadow: none;
}

&[data-invisible="true"] {
opacity: 0 !important;
&:focus-visible {
opacity: 1 !important;
+ .react-aria-Button[data-invisible="false"] {
opacity: 0 !important;
}
}
}
}
43 changes: 22 additions & 21 deletions src/components/Tree.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from 'clsx'
import {type ReactNode, memo, useMemo} from 'react'
import {type ReactNode, memo} from 'react'
import {
Tree as AriaTree,
TreeItem as AriaTreeItem,
Expand Down Expand Up @@ -42,36 +42,37 @@ export const TreeItemContent = memo(function TreeItemContent({
suffix,
children
}: TreeItemContentProps) {
const inner = useMemo(
() => (
<>
<Button slot="chevron">
<IcRoundKeyboardArrowRight />
</Button>
{icon && (
<span data-slot="icon">
<Icon icon={icon} />
</span>
)}
<span data-slot="label">{children}</span>
{suffix && <span data-slot="suffix">{suffix}</span>}
</>
),
[children, icon, suffix]
)
return (
<AriaTreeItemContent>
{({
selectionBehavior,
selectionMode,
allowsDragging
allowsDragging,
isDragging
}: TreeItemContentRenderProps) => (
<>
{allowsDragging && <Button slot="drag">≡</Button>}
{selectionBehavior === 'toggle' && selectionMode !== 'none' && (
<Checkbox slot="selection" />
)}
{inner}
<div className="alinea-rac-TreeItem-controls">
<Button
slot="drag"
data-invisible={!isDragging}
className="alinea-rac-TreeItem-dragHandle"
>
</Button>
<Button slot="chevron" data-invisible={isDragging}>
<IcRoundKeyboardArrowRight />
</Button>
</div>
{icon && (
<span data-slot="icon">
<Icon icon={icon} />
</span>
)}
<span data-slot="label">{children}</span>
{suffix && <span data-slot="suffix">{suffix}</span>}
</>
)}
</AriaTreeItemContent>
Expand Down
Loading