Skip to content

Commit c8018ca

Browse files
authored
feat: treeview node context (#4058)
1 parent 4cc340b commit c8018ca

File tree

7 files changed

+49
-0
lines changed

7 files changed

+49
-0
lines changed

.changeset/loud-singers-march.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@skeletonlabs/skeleton-svelte": minor
3+
"@skeletonlabs/skeleton-react": minor
4+
---
5+
6+
Added the TreeView.NodeContext component
7+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { NodeContext as NodeContext_ } from '../modules/node-context.js';
2+
import type { NodeProps } from '@zag-js/tree-view';
3+
import { use } from 'react';
4+
import type { ReactNode } from 'react';
5+
6+
export interface TreeViewNodeContextProps {
7+
children: (treeView: NodeProps) => ReactNode;
8+
}
9+
10+
export default function NodeContext(props: TreeViewNodeContextProps) {
11+
const treeView = use(NodeContext_);
12+
13+
const { children } = props;
14+
15+
return children(treeView);
16+
}

packages/skeleton-react/src/components/tree-view/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ export type { TreeViewBranchTextProps } from './anatomy/branch-text.jsx';
1212
export type { TreeViewBranchIndicatorProps } from './anatomy/branch-indicator.jsx';
1313
export type { TreeViewBranchContentProps } from './anatomy/branch-content.jsx';
1414
export type { TreeViewBranchIndentGuideProps } from './anatomy/branch-indent-guide.jsx';
15+
export type { TreeViewNodeContextProps } from './anatomy/node-context.jsx';
1516
export type { TreeViewNodeProviderProps } from './anatomy/node-provider.jsx';
1617
export type { TreeViewLabelProps } from './anatomy/label.jsx';

packages/skeleton-react/src/components/tree-view/modules/anatomy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import BranchText from '../anatomy/branch-text.jsx';
66
import Branch from '../anatomy/branch.jsx';
77
import Item from '../anatomy/item.jsx';
88
import Label from '../anatomy/label.jsx';
9+
import NodeContext from '../anatomy/node-context.jsx';
910
import NodeProvider from '../anatomy/node-provider.jsx';
1011
import RootContext from '../anatomy/root-context.jsx';
1112
import RootProvider from '../anatomy/root-provider.jsx';
@@ -18,6 +19,7 @@ export const TreeView = Object.assign(Root, {
1819
Tree: Tree,
1920
Label: Label,
2021
NodeProvider: NodeProvider,
22+
NodeContext: NodeContext,
2123
Branch: Branch,
2224
BranchControl: BranchControl,
2325
BranchText: BranchText,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script lang="ts" module>
2+
import type { NodeProps } from '@zag-js/tree-view';
3+
import type { Snippet } from 'svelte';
4+
5+
export interface TreeViewNodeContextProps {
6+
children: Snippet<[() => NodeProps]>;
7+
}
8+
</script>
9+
10+
<script lang="ts">
11+
import { NodeContext } from '../modules/node-context.js';
12+
13+
const props: TreeViewNodeContextProps = $props();
14+
15+
const nodeProps = NodeContext.consume();
16+
17+
const { children } = $derived(props);
18+
</script>
19+
20+
{@render children(nodeProps)}

packages/skeleton-svelte/src/components/tree-view/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ export type { TreeViewBranchTextProps } from './anatomy/branch-text.svelte';
1212
export type { TreeViewBranchIndicatorProps } from './anatomy/branch-indicator.svelte';
1313
export type { TreeViewBranchContentProps } from './anatomy/branch-content.svelte';
1414
export type { TreeViewBranchIndentGuideProps } from './anatomy/branch-indent-guide.svelte';
15+
export type { TreeViewNodeContextProps } from './anatomy/node-context.svelte';
1516
export type { TreeViewNodeProviderProps } from './anatomy/node-provider.svelte';
1617
export type { TreeViewLabelProps } from './anatomy/label.svelte';

packages/skeleton-svelte/src/components/tree-view/modules/anatomy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import BranchText from '../anatomy/branch-text.svelte';
66
import Branch from '../anatomy/branch.svelte';
77
import Item from '../anatomy/item.svelte';
88
import Label from '../anatomy/label.svelte';
9+
import NodeContext from '../anatomy/node-context.svelte';
910
import NodeProvider from '../anatomy/node-provider.svelte';
1011
import RootContext from '../anatomy/root-context.svelte';
1112
import RootProvider from '../anatomy/root-provider.svelte';
@@ -31,6 +32,7 @@ export const TreeView: typeof Root & {
3132
Tree: Tree,
3233
Label: Label,
3334
NodeProvider: NodeProvider,
35+
NodeContext: NodeContext,
3436
Branch: Branch,
3537
BranchControl: BranchControl,
3638
BranchText: BranchText,

0 commit comments

Comments
 (0)