Skip to content

Commit

Permalink
feat(*): integrate latest ark ui
Browse files Browse the repository at this point in the history
  • Loading branch information
cschroeter committed Nov 18, 2024
1 parent 24d1912 commit 38f1494
Show file tree
Hide file tree
Showing 27 changed files with 496 additions and 499 deletions.
Binary file modified bun.lockb
Binary file not shown.
24 changes: 12 additions & 12 deletions components/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
"private": true,
"scripts": {
"prepare": "panda codegen --silent",
"dev": "storybook dev -p 6006",
"dev": "bun run storybook",
"lint": "biome lint ./src",
"storybook": "storybook dev -p 6006",
"typecheck": "tsc"
},
"dependencies": {
"@ark-ui/react": "4.2.0",
"@pandacss/dev": "0.47.0",
"@ark-ui/react": "4.4.4",
"@pandacss/dev": "0.48.0",
"@park-ui/panda-preset": "workspace:*",
"@storybook/addon-a11y": "8.4.1",
"@storybook/addon-essentials": "8.4.1",
"@storybook/addon-themes": "8.4.1",
"@storybook/react-vite": "8.4.1",
"@storybook/react": "8.4.1",
"@storybook/addon-a11y": "8.4.4",
"@storybook/addon-essentials": "8.4.4",
"@storybook/addon-themes": "8.4.4",
"@storybook/react-vite": "8.4.4",
"@storybook/react": "8.4.4",
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"@vitejs/plugin-react": "4.3.3",
"lucide-react": "0.454.0",
"lucide-react": "0.460.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"storybook": "8.4.1",
"storybook": "8.4.4",
"typescript": "5.6.3",
"vite": "5.4.10",
"vite-tsconfig-paths": "5.0.1"
"vite": "5.4.11",
"vite-tsconfig-paths": "5.1.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Basic = () => (
<Button variant="outline">Toggle</Button>
</Collapsible.Trigger>
<Collapsible.Content>
<Box width="sm" bg="accent.default" color="accent.fg" p="4" borderRadius="l3">
<Box width="sm" bg="colorPalette.default" color="colorPalette.fg" p="4" borderRadius="l3">
Content
</Box>
</Collapsible.Content>
Expand Down
96 changes: 47 additions & 49 deletions components/react/src/components/stories/tree-view.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,58 @@
import { createTreeCollection } from '@ark-ui/react/tree-view'
import type { Meta } from '@storybook/react'
import { TreeView, type TreeViewData } from '~/components/ui/tree-view'
import { TreeView } from '~/components/ui/tree-view'

const meta: Meta = {
title: 'Components/Tree View',
}

export default meta

export const Base = () => {
return <TreeView data={data} maxW="2xs" />
interface Node {
id: string
name: string
children?: Node[]
}

const data: TreeViewData = {
label: 'Root',
children: [
{
value: '1',
name: 'Item 1',
children: [
{
value: '1.1',
name: 'Item 1.1',
},
{
value: '1.2',
name: 'Item 1.2',
children: [
{
value: '1.2.1',
name: 'Item 1.2.1',
},
{
value: '1.2.2',
name: 'Item 1.2.2',
},
],
},
],
},
{
value: '2',
name: 'Item 2',
children: [
{
value: '2.1',
name: 'Item 2.1',
},
{
value: '2.2',
name: 'Item 2.2',
},
],
},
{
value: '3',
name: 'Item 3',
},
],
const collection = createTreeCollection<Node>({
nodeToValue: (node) => node.id,
nodeToString: (node) => node.name,
rootNode: {
id: 'ROOT',
name: '',
children: [
{
id: 'node_modules',
name: 'node_modules',
children: [
{ id: 'node_modules/zag-js', name: 'zag-js' },
{ id: 'node_modules/pandacss', name: 'panda' },
{
id: 'node_modules/@types',
name: '@types',
children: [
{ id: 'node_modules/@types/react', name: 'react' },
{ id: 'node_modules/@types/react-dom', name: 'react-dom' },
],
},
],
},
{
id: 'src',
name: 'src',
children: [
{ id: 'src/app.tsx', name: 'app.tsx' },
{ id: 'src/index.ts', name: 'index.ts' },
],
},
{ id: 'panda.config', name: 'panda.config.ts' },
{ id: 'package.json', name: 'package.json' },
{ id: 'renovate.json', name: 'renovate.json' },
{ id: 'readme.md', name: 'README.md' },
],
},
})

export const Base = () => {
return <TreeView collection={collection} maxW="2xs" />
}
33 changes: 22 additions & 11 deletions components/react/src/components/ui/styled/tree-view.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'
import type { Assign } from '@ark-ui/react'
import { TreeView } from '@ark-ui/react/tree-view'
import { type TreeNode, TreeView } from '@ark-ui/react/tree-view'
import { type TreeViewVariantProps, treeView } from 'styled-system/recipes'
import type { ComponentProps, HTMLStyledProps } from 'styled-system/types'
import { createStyleContext } from './utils/create-style-context'
Expand All @@ -10,18 +10,21 @@ const { withProvider, withContext } = createStyleContext(treeView)
export type RootProviderProps = ComponentProps<typeof RootProvider>
export const RootProvider = withProvider<
HTMLDivElement,
Assign<Assign<HTMLStyledProps<'div'>, TreeView.RootProviderBaseProps>, TreeViewVariantProps>
Assign<
Assign<HTMLStyledProps<'div'>, TreeView.RootProviderBaseProps<TreeNode>>,
TreeViewVariantProps
>
>(TreeView.RootProvider, 'root')

export type RootProps = ComponentProps<typeof Root>
export const Root = withProvider<
HTMLDivElement,
Assign<Assign<HTMLStyledProps<'div'>, TreeView.RootBaseProps>, TreeViewVariantProps>
Assign<Assign<HTMLStyledProps<'div'>, TreeView.RootBaseProps<TreeNode>>, TreeViewVariantProps>
>(TreeView.Root, 'root')

export const BranchContent = withContext<
HTMLUListElement,
Assign<HTMLStyledProps<'ul'>, TreeView.BranchContentBaseProps>
HTMLDivElement,
Assign<HTMLStyledProps<'div'>, TreeView.BranchContentBaseProps>
>(TreeView.BranchContent, 'branchContent')

export const BranchControl = withContext<
Expand All @@ -35,15 +38,20 @@ export const BranchIndicator = withContext<
>(TreeView.BranchIndicator, 'branchIndicator')

export const Branch = withContext<
HTMLLIElement,
Assign<HTMLStyledProps<'li'>, TreeView.BranchBaseProps>
HTMLDivElement,
Assign<HTMLStyledProps<'div'>, TreeView.BranchBaseProps>
>(TreeView.Branch, 'branch')

export const BranchText = withContext<
HTMLSpanElement,
Assign<HTMLStyledProps<'span'>, TreeView.BranchTextBaseProps>
>(TreeView.BranchText, 'branchText')

export const BranchIndentGuide = withContext<
HTMLDivElement,
Assign<HTMLStyledProps<'div'>, TreeView.BranchIndentGuideBaseProps>
>(TreeView.BranchIndentGuide, 'branchIndentGuide')

export const BranchTrigger = withContext<
HTMLDivElement,
Assign<HTMLStyledProps<'div'>, TreeView.BranchTriggerBaseProps>
Expand All @@ -55,8 +63,8 @@ export const ItemIndicator = withContext<
>(TreeView.ItemIndicator, 'itemIndicator')

export const Item = withContext<
HTMLLIElement,
Assign<HTMLStyledProps<'li'>, TreeView.ItemBaseProps>
HTMLDivElement,
Assign<HTMLStyledProps<'div'>, TreeView.ItemBaseProps>
>(TreeView.Item, 'item')

export const ItemText = withContext<
Expand All @@ -70,8 +78,11 @@ export const Label = withContext<
>(TreeView.Label, 'label')

export const Tree = withContext<
HTMLUListElement,
Assign<HTMLStyledProps<'ul'>, TreeView.TreeBaseProps>
HTMLDivElement,
Assign<HTMLStyledProps<'div'>, TreeView.TreeBaseProps>
>(TreeView.Tree, 'tree')

export type NodeProviderProps = TreeView.NodeProviderProps<TreeNode>
export const NodeProvider = TreeView.NodeProvider

export { TreeViewContext as Context } from '@ark-ui/react/tree-view'
100 changes: 45 additions & 55 deletions components/react/src/components/ui/tree-view.tsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,56 @@
'use client'
import { CheckSquareIcon, ChevronRightIcon, FileIcon, FolderIcon } from 'lucide-react'
import { forwardRef } from 'react'
import * as StyledTreeView from './styled/tree-view'

interface Child {
value: string
name: string
children?: Child[]
}

export interface TreeViewData {
label: string
children: Child[]
}

export interface TreeViewProps extends StyledTreeView.RootProps {
data: TreeViewData
}

export const TreeView = forwardRef<HTMLDivElement, TreeViewProps>((props, ref) => {
const { data, ...rootProps } = props

const renderChild = (child: Child) => (
<StyledTreeView.Branch key={child.value} value={child.value}>
<StyledTreeView.BranchControl>
<StyledTreeView.BranchIndicator>
<ChevronRightIcon />
</StyledTreeView.BranchIndicator>
<StyledTreeView.BranchText>{child.name}</StyledTreeView.BranchText>
</StyledTreeView.BranchControl>
<StyledTreeView.BranchContent>
{child.children?.map((child) =>
child.children ? (
renderChild(child)
) : (
<StyledTreeView.Item key={child.value} value={child.value}>
<StyledTreeView.ItemText>{child.name}</StyledTreeView.ItemText>
</StyledTreeView.Item>
),
)}
</StyledTreeView.BranchContent>
</StyledTreeView.Branch>
)

export const TreeView = forwardRef<HTMLDivElement, StyledTreeView.RootProps>((props, ref) => {
return (
<StyledTreeView.Root ref={ref} aria-label={data.label} {...rootProps}>
<StyledTreeView.Tree>{data.children.map(renderChild)}</StyledTreeView.Tree>
<StyledTreeView.Root ref={ref} {...props}>
<StyledTreeView.Tree>
{/* @ts-expect-error */}
{props.collection.rootNode.children.map((node, index) => (
<TreeNode key={node.id} node={node} indexPath={[index]} />
))}
</StyledTreeView.Tree>
</StyledTreeView.Root>
)
})

TreeView.displayName = 'TreeView'

const ChevronRightIcon = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<title>Chevron Right Icon</title>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="m9 18l6-6l-6-6"
/>
</svg>
)
const TreeNode = (props: StyledTreeView.NodeProviderProps) => {
const { node, indexPath } = props
return (
<StyledTreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
{node.children ? (
<StyledTreeView.Branch>
<StyledTreeView.BranchControl>
<StyledTreeView.BranchText>
<FolderIcon /> {node.name}
</StyledTreeView.BranchText>
<StyledTreeView.BranchIndicator>
<ChevronRightIcon />
</StyledTreeView.BranchIndicator>
</StyledTreeView.BranchControl>
<StyledTreeView.BranchContent>
<StyledTreeView.BranchIndentGuide />
{/* @ts-expect-error */}
{node.children.map((child, index) => (
<TreeNode key={child.id} node={child} indexPath={[...indexPath, index]} />
))}
</StyledTreeView.BranchContent>
</StyledTreeView.Branch>
) : (
<StyledTreeView.Item>
<StyledTreeView.ItemIndicator>
<CheckSquareIcon />
</StyledTreeView.ItemIndicator>
<StyledTreeView.ItemText>
<FileIcon />
{node.name}
</StyledTreeView.ItemText>
</StyledTreeView.Item>
)}
</StyledTreeView.NodeProvider>
)
}
2 changes: 1 addition & 1 deletion components/react/src/demos/collapsible.demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const Demo = (props: Collapsible.RootProps) => {
<Button variant="outline">Toggle</Button>
</Collapsible.Trigger>
<Collapsible.Content>
<Box bg="accent.default" color="accent.fg" p="4" borderRadius="l3" mt="3">
<Box bg="colorPalette.default" color="colorPalette.fg" p="4" borderRadius="l3" mt="3">
Content
</Box>
</Collapsible.Content>
Expand Down
Loading

0 comments on commit 38f1494

Please sign in to comment.