Skip to content

Commit 8635cc7

Browse files
committed
refactor: update tree components for improved styling and functionality
1 parent e30f7b9 commit 8635cc7

File tree

8 files changed

+38
-26
lines changed

8 files changed

+38
-26
lines changed

docs/src/routes/components/tree/examples/hero.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default component$(() => {
4646
];
4747

4848
return (
49-
<Tree.Root class="tree-root">
49+
<Tree.Root class="ml-4 p-4 min-w-60 border border-[#0f1317]">
5050
{treeData.map((item) => renderTreeItem(item))}
5151
</Tree.Root>
5252
);
@@ -56,11 +56,11 @@ function renderTreeItem(item: TreeItemType) {
5656
if (item.children && item.children.length > 0) {
5757
return (
5858
<Tree.Item key={item.id}>
59-
<Tree.ItemTrigger class="tree-item-trigger">
59+
<Tree.ItemTrigger class="flex gap-2 items-center cursor-pointer w-full">
6060
<Tree.ItemLabel>{item.label}</Tree.ItemLabel>
61-
<LuChevronRight />
61+
<LuChevronRight class="not-ui-open:rotate-none ui-open:rotate-90 transition-transform duration-200" />
6262
</Tree.ItemTrigger>
63-
<Tree.ItemContent class="tree-item-content">
63+
<Tree.ItemContent class="pl-4">
6464
{item.children.map((child) => renderTreeItem(child))}
6565
</Tree.ItemContent>
6666
</Tree.Item>

libs/components/src/switch/switch-root.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export const SwitchRoot = component$<PublicRootProps>((props) => {
9292
aria-describedby={descriptionId}
9393
aria-errormessage={hasErrorMessageSig.value ? errorId : undefined}
9494
data-qds-switch-root
95+
data-qds-scope
9596
// Indicates whether the switch is currently checked
9697
data-checked={checkedSig.value}
9798
// Indicates whether the switch is currently disabled

libs/components/src/tree/tree-item-content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type PropsOf, Slot, component$ } from "@qwik.dev/core";
1+
import { component$, type PropsOf, Slot } from "@qwik.dev/core";
22
import { CollapsibleContent } from "../collapsible/collapsible-content";
33

44
export const TreeItemContent = component$((props: PropsOf<typeof CollapsibleContent>) => {

libs/components/src/tree/tree-item-indicator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type PropsOf, Slot, component$ } from "@qwik.dev/core";
1+
import { component$, type PropsOf, Slot } from "@qwik.dev/core";
22
import { Render } from "../render/render";
33

44
export const TreeItemIndicator = component$((props: PropsOf<"span">) => {

libs/components/src/tree/tree-item-label.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type PropsOf, Slot, component$ } from "@qwik.dev/core";
1+
import { component$, type PropsOf, Slot } from "@qwik.dev/core";
22
import { Render } from "../render/render";
33

44
export const TreeItemLabel = component$((props: PropsOf<"span">) => {

libs/components/src/tree/tree-item-trigger.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
type Component,
3+
component$,
34
type PropsOf,
45
Slot,
5-
component$,
66
useContext
77
} from "@qwik.dev/core";
88
import { CollapsibleTrigger } from "../collapsible/collapsible-trigger";

libs/components/src/tree/tree-item.tsx

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { useBoundSignal } from "@qds.dev/utils";
1+
import { type BindableProps, useBindings } from "@qds.dev/utils";
22
import {
33
$,
4-
type PropsOf,
5-
type Signal,
6-
Slot,
74
component$,
85
createContextId,
96
isServer,
7+
type PropsOf,
8+
type Signal,
9+
Slot,
1010
sync$,
1111
useContext,
1212
useContextProvider,
@@ -18,34 +18,44 @@ import { CollapsibleRoot } from "../collapsible/collapsible-root";
1818
import { TreeRootContextId } from "./tree-root";
1919
import { useTree } from "./use-tree";
2020

21-
type TreeItemContext = {
21+
export const itemContextId = createContextId<TreeItemContext>("tree-item");
22+
23+
export interface TreeItemContext {
2224
id: string;
2325
level: number;
24-
isOpenSig: Signal<boolean>;
25-
};
26-
27-
export const itemContextId = createContextId<TreeItemContext>("tree-item");
26+
isOpen: Signal<boolean>;
27+
isDisabled: Signal<boolean>;
28+
}
2829

29-
interface TreeItemProps extends PropsOf<typeof CollapsibleRoot> {
30+
export type TreeItemProps = Omit<PropsOf<typeof CollapsibleRoot>, "open" | "disabled"> & {
3031
_index?: number;
3132
groupTrigger?: boolean;
3233
groupId?: string;
33-
}
34+
} & BindableProps<TreeItemBinds>;
35+
36+
type TreeItemBinds = {
37+
open: boolean;
38+
disabled: boolean;
39+
};
3440

3541
export const TreeItem = component$((props: TreeItemProps) => {
3642
const context = useContext(TreeRootContextId);
3743
const parentContext = useContext(itemContextId, null);
3844
const id = useId();
3945
const itemRef = useSignal<HTMLElement>();
40-
const isOpenSig = useBoundSignal(props["bind:open"], false);
46+
const { openSig: isOpen, disabledSig: isDisabled } = useBindings<TreeItemBinds>(props, {
47+
open: false,
48+
disabled: false
49+
});
4150
const { getCurrentLevel } = useTree();
4251
const isHighlightedSig = useSignal(false);
4352
const level = getCurrentLevel(parentContext?.level);
4453

4554
const itemContext: TreeItemContext = {
4655
id,
4756
level,
48-
isOpenSig
57+
isOpen,
58+
isDisabled
4959
};
5060

5161
useContextProvider(itemContextId, itemContext);
@@ -92,14 +102,14 @@ export const TreeItem = component$((props: TreeItemProps) => {
92102
case "ArrowRight": {
93103
const isCollapsed = currentItem.hasAttribute("data-closed");
94104
if (isCollapsed) {
95-
isOpenSig.value = true;
105+
isOpen.value = true;
96106
}
97107
return;
98108
}
99109
case "ArrowLeft": {
100110
const isExpanded = !currentItem.hasAttribute("data-closed");
101111
if (isExpanded) {
102-
isOpenSig.value = false;
112+
isOpen.value = false;
103113
}
104114
return;
105115
}
@@ -136,7 +146,8 @@ export const TreeItem = component$((props: TreeItemProps) => {
136146
id={id}
137147
ref={itemRef}
138148
role="row"
139-
bind:open={isOpenSig}
149+
open={isOpen.value}
150+
disabled={isDisabled.value}
140151
tabIndex={
141152
context.currentFocusEl.value === itemRef.value ||
142153
context.currentFocusEl.value === null

libs/components/src/tree/tree-root.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// no-bound-signal
22

33
import {
4+
component$,
5+
createContextId,
46
type PropsOf,
57
type Signal,
68
Slot,
7-
component$,
8-
createContextId,
99
useContextProvider,
1010
useSignal
1111
} from "@qwik.dev/core";

0 commit comments

Comments
 (0)