The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: TreeView primitive (#21960)
Jonathan Summers-Muir8f44716e72bf
diff --git a/apps/storybook/.storybook/main.js b/apps/storybook/.storybook/main.jsindex 32a1f1707a5..fb3b1849b2e 100644--- a/apps/storybook/.storybook/main.js+++ b/apps/storybook/.storybook/main.js@@ -15,6 +15,7 @@ const config = {'../../../packages/ui-patterns/**/*.stories.@(js|jsx|mjs|ts|tsx)',// primitives'../../../packages/ui/src/components/shadcn/**/*.stories.@(js|jsx|mjs|ts|tsx)',+ '../../../packages/ui/src/components/TreeView/**/*.stories.@(js|jsx|mjs|ts|tsx)','../../../packages/ui/src/components/Input/Input.stories.@(js|jsx|mjs|ts|tsx)','../../../packages/ui/src/components/Button/Button.stories.@(js|jsx|mjs|ts|tsx)',//diff --git a/package-lock.json b/package-lock.jsonindex b843147dc6d..7c1abe8e5e9 100644--- a/package-lock.json+++ b/package-lock.json@@ -38277,6 +38277,17 @@"node": ">=0.10.0"}},+ "node_modules/react-accessible-treeview": {+ "version": "2.8.3",+ "resolved": "https://registry.npmjs.org/react-accessible-treeview/-/react-accessible-treeview-2.8.3.tgz",+ "integrity": "sha512-taDTIYZ6p96/zIhJBUKvyGTXcInudatP/9fwKG0BW+VRf1PmU5hOT2FkDovDKzSwj2VSOj1PRx+E6ojhOA+2xA==",+ "peerDependencies": {+ "classnames": "^2.2.6",+ "prop-types": "^15.7.2",+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"+ }+ },"node_modules/react-beautiful-dnd": {"version": "13.1.1","license": "Apache-2.0",@@ -47716,6 +47727,7 @@"openai": "^4.17.0","postcss": "^8.4.31","prop-types": "^15.7.2",+ "react-accessible-treeview": "^2.8.3","react-copy-to-clipboard": "^5.1.0","react-countdown": "^2.3.5","react-day-picker": "^8.8.0",diff --git a/packages/ui/index.tsx b/packages/ui/index.tsxindex 81a86053c1b..5baa7c3317d 100644--- a/packages/ui/index.tsx+++ b/packages/ui/index.tsx@@ -32,7 +32,7 @@ export * from './src/components/NavMenu'export * from './src/components/Modal'export * from './src/components/SidePanel'-export * from './src/components/ContextMenu'+// export * from './src/components/ContextMenu'export * from './src/components/PromoToast'export * from './src/components/Popover'export * from './src/layout/PortalToast'@@ -82,6 +82,7 @@ export * from './src/components/shadcn/ui/toast'export * from './src/components/shadcn/ui/toaster'export * from './src/components/shadcn/ui/separator'+export * from './src/components/shadcn/ui/context-menu'export * from './src/components/shadcn/ui/sheet'export * from './src/components/shadcn/ui/badge'export * from './src/components/shadcn/ui/input-otp'diff --git a/packages/ui/package.json b/packages/ui/package.jsonindex d7c83cdaddf..c9b97d65013 100644--- a/packages/ui/package.json+++ b/packages/ui/package.json@@ -83,7 +83,8 @@"tailwindcss-animate": "^1.0.6","tailwindcss-radix": "^2.0.0","yup": "^1.4.0",- "zod": "^3.22.3"+ "zod": "^3.22.3",+ "react-accessible-treeview": "^2.8.3"},"devDependencies": {"@babel/plugin-syntax-flow": "^7.21.4",diff --git a/packages/ui/src/components/TreeView/TreeView.stories.tsx b/packages/ui/src/components/TreeView/TreeView.stories.tsxnew file mode 100644index 00000000000..bfd7ce2cebf--- /dev/null+++ b/packages/ui/src/components/TreeView/TreeView.stories.tsx@@ -0,0 +1,438 @@+import { StoryObj } from '@storybook/react'+import React, { useState } from 'react'+import { flattenTree } from 'react-accessible-treeview'+import {+ ContextMenu,+ ContextMenuContent,+ ContextMenuItem,+ ContextMenuSeparator,+ ContextMenuTrigger,+} from '../shadcn/ui/context-menu'+import { TreeView, TreeViewItem } from './TreeView'++// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export+export default {+ title: 'Primitives/TreeView',+ component: TreeView,+ subcomponents: { TreeViewItem },+ parameters: {+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout+ layout: 'centered',+ },+ decorators: [+ (Story: any) => {+ return (+ <div className="bg-studio border-l border-r">+ <Story />+ </div>+ )+ },+ ],+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs+ tags: ['autodocs'],+ // More on argTypes: https://storybook.js.org/docs/api/argtypes+ argTypes: {+ data: {},+ },+}++type Story = StoryObj<+ // Omit data so raw data can be passed to the story+ Omit<typeof TreeView, 'data'> & { data: any; className?: string }+>++export const DefaultFlatTree: Story = {+ args: {+ className: 'w-[420px] h-[520px]',+ data: {+ name: '',+ children: [+ {+ name: 'Current batch',+ },+ {+ name: 'Older queries',+ },+ {+ name: 'query all users',+ },+ {+ name: 'users in last day',+ },+ {+ name: 'new users over time',+ },+ ],+ },+ },+ /**+ * π To avoid linting issues, it is recommended to use a function with a capitalized name.+ * If you are not concerned with linting, you may use an arrow function.+ */+ render: function Render(args) {+ return (+ <TreeView+ {...args}+ data={flattenTree(args.data)}+ aria-label="directory tree"+ nodeRenderer={({ element, isBranch, isExpanded, getNodeProps, level, isSelected }) => (+ <TreeViewItem+ isExpanded={isExpanded}+ isBranch={isBranch}+ isSelected={isSelected}+ level={level}+ xPadding={16}+ name={element.name}+ {...getNodeProps()}+ />+ )}+ />+ )+ },+}++export const WithDirectories: Story = {+ args: {+ className: 'w-[420px] h-[520px]',+ data: {+ name: '',+ children: [+ {+ name: 'Current batch',+ children: [{ name: 'index.js' }, { name: 'styles.css' }],+ },+ {+ name: 'Older queries',+ children: [+ {+ name: 'all countries',+ },+ {+ name: 'add new countries',+ },+ {+ name: 'regions',+ },+ {+ name: 'regions by customer',+ },+ ],+ },+ {+ name: 'query all users',+ },+ {+ name: 'users in last day',+ },+ {+ name: 'new users over time',+ },+ ],+ },+ },+ /**+ * π To avoid linting issues, it is recommended to use a function with a capitalized name.+ * If you are not concerned with linting, you may use an arrow function.+ */+ render: function Render(args) {+ return (+ <TreeView+ {...args}+ data={flattenTree(args.data)}+ aria-label="directory tree"+ nodeRenderer={({ element, isBranch, isExpanded, getNodeProps, level, isSelected }) => (+ <TreeViewItem+ isExpanded={isExpanded}+ isBranch={isBranch}+ isSelected={isSelected}+ level={level}+ xPadding={16}+ name={element.name}+ {...getNodeProps()}+ />+ )}+ />+ )+ },+}+export const withEditEntity: Story = {+ args: {+ className: 'w-[420px] h-[520px]',+ data: {+ name: 'basic tree',+ children: [+ {+ id: 1,+ name: 'Current batch',+ children: [+ { id: 2, name: 'index.js' },+ { id: 3, name: 'styles.css' },+ ],+ },+ {+ id: 4,+ name: 'Older queries',+ children: [+ {+ id: 5,+ name: 'all countries',+ },+ {+ id: 6,+ name: 'add new countries',+ },+ {+ id: 7,+ name: 'regions',+ },+ {+ id: 8,+ name: 'regions by customer',+ },+ ],+ },+ {+ id: 9,+ name: 'query all users',+ },+ {+ id: 10,+ name: 'users in last day',+ },+ {+ id: 11,+ name: 'new users over time',+ },+ ],+ },+ },+ /**+ * π To avoid linting issues, it is recommended to use a function with a capitalized name.+ * If you are not concerned with linting, you may use an arrow function.+ */+ render: function Render(args) {+ const [treeData, setDataTreeState] = useState(args.data)++ function handleRenameSelect(id) {+ // find id in treeData and set it to edit mode+ let updatedTreeData = { ...treeData }+ const findNode = (node: any) => {+ if (node.id === id) {+ node.metadata = { isEditing: true }+ }+ if (node.children) {+ node.children.forEach(findNode)+ }+ }+ console.log(updatedTreeData)+ updatedTreeData.children.forEach(findNode)+ setDataTreeState(updatedTreeData)+ }++ return (+ <TreeView+ {...args}+ data={flattenTree(args.data)}+ aria-label="directory tree"+ nodeRenderer={({ element, isBranch, isExpanded, getNodeProps, level, isSelected }) => {+ return (+ <ContextMenu modal={false}>+ <ContextMenuTrigger asChild>+ <TreeViewItem+ isExpanded={isExpanded}+ isBranch={isBranch}+ isSelected={isSelected}+ level={level}+ xPadding={16}+ name={element.name}+ isEditing={element.metadata?.isEditing === true}+ onEditSubmit={(value) => {+ console.log('value', value)+ let updatedTreeData = { ...treeData }+ const findNode = (node: any) => {+ if (node.id === element.id) {+ node.name = value+ node.metadata = { isEditing: false }+ }+ if (node.children) {+ node.children.forEach(findNode)+ }+ }+ updatedTreeData.children.forEach(findNode)+ setDataTreeState(updatedTreeData)+ }}+ {...getNodeProps()}+ />+ </ContextMenuTrigger>+ <ContextMenuContent+ onCloseAutoFocus={(e) => {+ // stop focus propagation+ // so input in TreeViewItem gets focus+ e.stopPropagation()+ }}+ >+ <ContextMenuItem+ onSelect={(e) => {+ handleRenameSelect(element.id)+ }}+ onFocusCapture={(e) => {+ // stop focus propagation+ // so input in TreeViewItem gets focus+ e.stopPropagation()+ }}+ >+ Rename+ </ContextMenuItem>+ <ContextMenuItem disabled>Open in new tab</ContextMenuItem>+ <ContextMenuItem disabled>Share with team</ContextMenuItem>+ <ContextMenuSeparator />+ <ContextMenuItem disabled>Delete</ContextMenuItem>+ </ContextMenuContent>+ </ContextMenu>+ )+ }}+ />+ )+ },+}+export const withMultiSelect: Story = {+ args: {+ className: 'w-[420px] h-[520px]',+ multiselect: true,+ data: {+ name: 'basic tree',+ children: [+ {+ id: 1,+ name: 'Current batch',+ children: [+ { id: 2, name: 'index.js' },+ { id: 3, name: 'styles.css' },+ ],+ },+ {+ id: 4,+ name: 'Older queries',+ children: [+ {+ id: 5,+ name: 'all countries',+ },+ {+ id: 6,+ name: 'add new countries',+ },+ {+ id: 7,+ name: 'regions',+ },+ {+ id: 8,+ name: 'regions by customer',+ },+ ],+ },+ {+ id: 9,+ name: 'query all users',+ },+ {+ id: 10,+ name: 'users in last day',+ },+ {+ id: 11,+ name: 'new users over time',+ },+ ],+ },+ },+ /**+ * π To avoid linting issues, it is recommended to use a function with a capitalized name.+ * If you are not concerned with linting, you may use an arrow function.+ */+ render: function Render(args) {+ const [treeData, setDataTreeState] = useState(args.data)++ function handleRenameSelect(id) {+ // find id in treeData and set it to edit mode+ let updatedTreeData = { ...treeData }+ const findNode = (node: any) => {+ if (node.id === id) {+ node.metadata = { isEditing: true }+ }+ if (node.children) {+ node.children.forEach(findNode)+ }+ }+ console.log(updatedTreeData)+ updatedTreeData.children.forEach(findNode)+ setDataTreeState(updatedTreeData)+ }++ return (+ <TreeView+ {...args}+ data={flattenTree(args.data)}+ aria-label="directory tree"+ nodeRenderer={({ element, isBranch, isExpanded, getNodeProps, level, isSelected }) => {+ return (+ <ContextMenu modal={false}>+ <ContextMenuTrigger asChild>+ <TreeViewItem+ isExpanded={isExpanded}+ isBranch={isBranch}+ isSelected={isSelected}+ level={level}+ xPadding={16}+ name={element.name}+ isEditing={element.metadata?.isEditing === true}+ onEditSubmit={(value) => {+ console.log('value', value)+ let updatedTreeData = { ...treeData }+ const findNode = (node: any) => {+ if (node.id === element.id) {+ node.name = value+ node.metadata = { isEditing: false }+ }+ if (node.children) {+ node.children.forEach(findNode)+ }+ }+ updatedTreeData.children.forEach(findNode)+ setDataTreeState(updatedTreeData)+ }}+ {...getNodeProps()}+ />+ </ContextMenuTrigger>+ <ContextMenuContent+ onCloseAutoFocus={(e) => {+ // stop focus propagation+ // so input in TreeViewItem gets focus+ e.stopPropagation()+ }}+ >+ <ContextMenuItem+ onSelect={(e) => {+ handleRenameSelect(element.id)+ }}+ onFocusCapture={(e) => {+ // stop focus propagation+ // so input in TreeViewItem gets focus+ e.stopPropagation()+ }}+ >+ Rename+ </ContextMenuItem>+ <ContextMenuItem disabled>Open in new tab</ContextMenuItem>+ <ContextMenuItem disabled>Share with team</ContextMenuItem>+ <ContextMenuSeparator />+ <ContextMenuItem disabled>Delete</ContextMenuItem>+ </ContextMenuContent>+ </ContextMenu>+ )+ }}+ />+ )+ },+}diff --git a/packages/ui/src/components/TreeView/TreeView.tsx b/packages/ui/src/components/TreeView/TreeView.tsxnew file mode 100644index 00000000000..aa7ca7f186f--- /dev/null+++ b/packages/ui/src/components/TreeView/TreeView.tsx@@ -0,0 +1,219 @@+import { ChevronRight, FolderClosed, FolderOpen } from 'lucide-react'+import { ComponentPropsWithoutRef, forwardRef, useEffect, useRef, useState } from 'react'+import TreeViewPrimitive from 'react-accessible-treeview'+import { cn } from '../../lib/utils'+import { Input } from '../shadcn/ui/input'++const TreeView = TreeViewPrimitive++const TreeViewItem = forwardRef<+ HTMLDivElement,+ ComponentPropsWithoutRef<'div'> & {+ /** The level of the item in the tree */+ level: number+ /** Specifies if the item is expanded */+ isExpanded?: boolean+ /** Specifies if the item is a branch */+ isBranch?: boolean+ /** The padding for each level of the item */+ levelPadding?: number+ /** Specifies if the item is selected */+ isSelected?: boolean+ /** The horizontal padding of the item */+ xPadding: number+ /** name of entity */+ name: string+ /** Specifies if the item is being edited, shows an input */+ isEditing?: boolean+ /** Callback for when the item is edited */+ onEditSubmit?: (value: string) => void+ }+>(+ (+ {+ level = 1,+ isExpanded = false,+ isBranch = false,+ levelPadding = 56,+ isSelected = false,+ xPadding = 16,+ name = '',+ isEditing = false,+ onEditSubmit,+ ...props+ },+ ref+ ) => {+ const [localValueState, setLocalValueState] = useState(name)+ const inputRef = useRef<HTMLInputElement>(null)++ useEffect(() => {+ const handleClickOutside = (event: MouseEvent) => {+ console.log('handleClickOutside')+ if (inputRef.current && !inputRef.current.contains(event.target as Node)) {+ onEditSubmit?.(localValueState)+ }+ }++ document.addEventListener('mousedown', handleClickOutside)++ return () => {+ document.removeEventListener('mousedown', handleClickOutside)+ }+ }, [localValueState])++ useEffect(() => {+ if (isEditing) {+ inputRef.current?.focus()+ }+ }, [isEditing])++ const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {+ e.preventDefault()+ onEditSubmit?.(localValueState)+ }++ return (+ <div+ ref={ref}+ aria-selected={isSelected}+ aria-expanded={isExpanded}+ {...props}+ className={cn(+ 'relative',+ 'transition-colors',+ 'flex items-center gap-3',+ 'text-sm',+ 'cursor-pointer',+ 'select-none',+ 'text-foreground-light',+ 'aria-selected:text-foreground',+ 'aria-expanded:bg-control',+ 'aria-selected:!bg-selection',+ 'data-[state=open]:bg-control', // bg state for context menu open+ 'group',+ 'h-[28px]',+ 'hover:bg-control'+ )}+ style={{+ paddingLeft:+ level === 1 && !isBranch+ ? xPadding + levelPadding / 2 - 2+ : level+ ? levelPadding * (level - 1) + xPadding + (!isBranch ? 0 : 0)+ : levelPadding,+ ...props.style,+ }}+ data-treeview-is-branch={isBranch}+ data-treeview-level={level}+ >+ {level && level > 1 && (+ <div+ style={{+ left: (levelPadding / 2 + 4) * (level - 1) + xPadding,+ }}+ className={+ 'absolute h-full w-px group-data-[treeview-is-branch=false]:bg-border-strong'+ }+ ></div>+ )}+ <div className="absolute left-0 h-full w-0.5 group-aria-selected:bg-foreground"></div>+ {isBranch ? (+ <>+ <ChevronRight+ className={cn(+ 'text-foreground-muted',+ 'group-aria-selected:text-foreground-light',+ 'group-aria-expanded:text-foreground-light',+ 'transition-transform duration-200',+ 'group-aria-expanded:rotate-90'+ )}+ size={14}+ />+ <TreeViewFolderIcon+ className={cn(+ 'transition-colors',+ ' text-foreground-muted',+ 'group-aria-selected:text-foreground-light',+ 'group-aria-expanded:text-foreground-light'+ )}+ isOpen={isExpanded}+ size={16}+ strokeWidth={1.5}+ />+ </>+ ) : (+ <SQL_ICON+ className={cn(+ 'transition-colors',+ 'fill-foreground-muted',+ 'group-aria-selected:fill-foreground',+ 'w-5 h-5',+ '-ml-0.5'+ )}+ size={16}+ strokeWidth={1.5}+ />+ )}+ <span className={cn(isEditing && 'hidden')}>{name}</span>+ <form autoFocus onSubmit={handleSubmit} className={cn(!isEditing && 'hidden')}>+ <Input+ ref={inputRef}+ onChange={(e) => {+ setLocalValueState(e.target.value)+ }}+ onKeyDownCapture={(e) => {+ // stop keyboard down bubbling up to TreeView.root+ // on enter key, send onEditSubmit callback+ if (e.key === 'Enter') {+ onEditSubmit?.(localValueState)+ } else if (e.key === 'Escape') {+ setLocalValueState(name)+ onEditSubmit?.(name)+ } else {+ e.stopPropagation()+ }+ }}+ className="block w-full text-sm px-2 py-1 h-7 w"+ value={localValueState}+ />+ </form>+ </div>+ )+ }+)++const SQL_ICON = forwardRef<SVGSVGElement, LucideSVGProps>((props, ref) => (+ <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" {...props}>+ <g clipPath="url(#clip0_1018_49117)">+ <path d="M20.8457 14.4531V15.6348H17.8916V14.4531H20.8457ZM18.3311 8.52539V15.6348H16.9004V8.52539H18.3311Z" />+ <path d="M13.6865 14.5508L15.3857 16.084L14.4873 16.9092L12.8271 15.376L13.6865 14.5508ZM15.3564 11.5283V12.6318C15.3564 13.1429 15.2962 13.5938 15.1758 13.9844C15.0553 14.3717 14.8812 14.6956 14.6533 14.9561C14.4255 15.2132 14.1553 15.4069 13.8428 15.5371C13.5303 15.6673 13.1836 15.7324 12.8027 15.7324C12.4219 15.7324 12.0736 15.6673 11.7578 15.5371C11.4453 15.4069 11.1751 15.2132 10.9473 14.9561C10.7227 14.6956 10.5469 14.3717 10.4199 13.9844C10.2962 13.5938 10.2344 13.1429 10.2344 12.6318V11.5283C10.2344 11.0173 10.2962 10.568 10.4199 10.1807C10.5436 9.79329 10.7178 9.47103 10.9424 9.21387C11.1702 8.95345 11.4404 8.75814 11.7529 8.62793C12.0654 8.49447 12.4121 8.42773 12.793 8.42773C13.1771 8.42773 13.5254 8.49447 13.8379 8.62793C14.1504 8.75814 14.4206 8.95345 14.6484 9.21387C14.8796 9.47103 15.0553 9.79329 15.1758 10.1807C15.2962 10.568 15.3564 11.0173 15.3564 11.5283ZM13.9307 12.6318V11.5186C13.9307 11.1833 13.9062 10.8952 13.8574 10.6543C13.8086 10.4134 13.7354 10.2165 13.6377 10.0635C13.5433 9.91048 13.4245 9.79818 13.2812 9.72656C13.1413 9.65495 12.9785 9.61914 12.793 9.61914C12.6107 9.61914 12.4479 9.65495 12.3047 9.72656C12.1647 9.79818 12.0475 9.91048 11.9531 10.0635C11.8587 10.2165 11.7855 10.4134 11.7334 10.6543C11.6846 10.8952 11.6602 11.1833 11.6602 11.5186V12.6318C11.6602 12.9704 11.6846 13.2601 11.7334 13.501C11.7822 13.7419 11.8538 13.9404 11.9482 14.0967C12.0459 14.2497 12.1647 14.3636 12.3047 14.4385C12.4479 14.5101 12.6139 14.5459 12.8027 14.5459C12.985 14.5459 13.1462 14.5101 13.2861 14.4385C13.4294 14.3636 13.5482 14.2497 13.6426 14.0967C13.7402 13.9437 13.8118 13.7467 13.8574 13.5059C13.9062 13.2617 13.9307 12.9704 13.9307 12.6318Z" />+ <path d="M7.47266 13.7646C7.47266 13.6377 7.46126 13.5221 7.43848 13.418C7.41569 13.3138 7.36686 13.2178 7.29199 13.1299C7.22038 13.042 7.11458 12.9541 6.97461 12.8662C6.83789 12.7783 6.65885 12.6872 6.4375 12.5928C6.17383 12.4821 5.91829 12.3649 5.6709 12.2412C5.4235 12.1143 5.20052 11.9678 5.00195 11.8018C4.80339 11.6357 4.64551 11.4404 4.52832 11.2158C4.41439 10.988 4.35742 10.721 4.35742 10.415C4.35742 10.1156 4.41113 9.84375 4.51855 9.59961C4.62923 9.35547 4.78548 9.14714 4.9873 8.97461C5.18913 8.79883 5.42513 8.66374 5.69531 8.56934C5.96875 8.47493 6.27311 8.42773 6.6084 8.42773C7.06413 8.42773 7.45801 8.52214 7.79004 8.71094C8.12533 8.89974 8.38411 9.15853 8.56641 9.4873C8.75195 9.81608 8.84473 10.1937 8.84473 10.6201H7.41895C7.41895 10.4183 7.38965 10.2409 7.33105 10.0879C7.27572 9.93164 7.1862 9.80957 7.0625 9.72168C6.9388 9.63379 6.7793 9.58984 6.58398 9.58984C6.40169 9.58984 6.25033 9.62728 6.12988 9.70215C6.0127 9.77376 5.9248 9.87305 5.86621 10C5.81087 10.1237 5.7832 10.2637 5.7832 10.4199C5.7832 10.5371 5.81087 10.6429 5.86621 10.7373C5.9248 10.8285 6.00456 10.9115 6.10547 10.9863C6.20638 11.0579 6.3252 11.1279 6.46191 11.1963C6.60189 11.2646 6.75488 11.3314 6.9209 11.3965C7.24316 11.5234 7.52799 11.6634 7.77539 11.8164C8.02279 11.9661 8.22949 12.1354 8.39551 12.3242C8.56152 12.5098 8.68685 12.7197 8.77148 12.9541C8.85612 13.1885 8.89844 13.4554 8.89844 13.7549C8.89844 14.0511 8.84635 14.3213 8.74219 14.5654C8.64128 14.8063 8.49316 15.0146 8.29785 15.1904C8.10254 15.363 7.86654 15.4964 7.58984 15.5908C7.31641 15.6852 7.01042 15.7324 6.67188 15.7324C6.3431 15.7324 6.03223 15.6868 5.73926 15.5957C5.44629 15.5013 5.1875 15.3597 4.96289 15.1709C4.74154 14.9788 4.56738 14.7363 4.44043 14.4434C4.31348 14.1471 4.25 13.7972 4.25 13.3936H5.68066C5.68066 13.6084 5.70182 13.7923 5.74414 13.9453C5.78646 14.0951 5.85156 14.2155 5.93945 14.3066C6.02734 14.3945 6.13477 14.4613 6.26172 14.5068C6.39193 14.5492 6.54004 14.5703 6.70605 14.5703C6.89486 14.5703 7.0446 14.5345 7.15527 14.4629C7.26921 14.3913 7.35059 14.2952 7.39941 14.1748C7.44824 14.0544 7.47266 13.9176 7.47266 13.7646Z" />+ <path+ fillRule="evenodd"+ clipRule="evenodd"+ d="M20.5 5.73438H4.5C3.11929 5.73438 2 6.85366 2 8.23438V16.5039C2 17.8846 3.11929 19.0039 4.5 19.0039H20.5C21.8807 19.0039 23 17.8846 23 16.5039V8.23438C23 6.85366 21.8807 5.73438 20.5 5.73438ZM4.5 4.23438C2.29086 4.23438 0.5 6.02524 0.5 8.23438V16.5039C0.5 18.713 2.29086 20.5039 4.5 20.5039H20.5C22.7091 20.5039 24.5 18.713 24.5 16.5039V8.23438C24.5 6.02524 22.7091 4.23438 20.5 4.23438H4.5Z"+ />+ </g>+ <defs>+ <clipPath id="clip0_1018_49117">+ <rect width="24" height="24" transform="translate(0.5 0.269531)" />+ </clipPath>+ </defs>+ </svg>+))++// Define a custom type for SVG components including the size prop+interface LucideSVGProps extends Omit<React.SVGProps<SVGSVGElement>, 'ref'> {+ size?: number+}++const TreeViewFolderIcon = forwardRef<SVGSVGElement, LucideSVGProps & { isOpen?: boolean }>(+ ({ isOpen, ...props }, ref) => {+ const Icon = isOpen ? FolderOpen : FolderClosed++ return <Icon ref={ref} {...props} />+ }+)++export { TreeView, TreeViewFolderIcon, TreeViewItem }diff --git a/packages/ui/src/components/TreeView/TreeViewItem.stories.tsx b/packages/ui/src/components/TreeView/TreeViewItem.stories.tsxnew file mode 100644index 00000000000..7a8e3260517--- /dev/null+++ b/packages/ui/src/components/TreeView/TreeViewItem.stories.tsx@@ -0,0 +1,38 @@+import { StoryObj } from '@storybook/react'+import React from 'react'+import { TreeViewItem } from './TreeView'++// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export+export default {+ title: 'Primitives/TreeView',+ component: TreeViewItem,+ parameters: {+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout+ layout: 'centered',+ },+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs+ tags: ['autodocs'],+ // More on argTypes: https://storybook.js.org/docs/api/argtypes+ argTypes: {},+}++type Story = StoryObj<typeof TreeViewItem>++export const SingleItem: Story = {+ args: {+ isSelected: false,+ level: 1,+ xPadding: 16,+ isBranch: false,+ isExpanded: false,+ levelPadding: 16,+ name: 'Element name',+ },+ /**+ * π To avoid linting issues, it is recommended to use a function with a capitalized name.+ * If you are not concerned with linting, you may use an arrow function.+ */+ render: function Render(args) {+ return <TreeViewItem {...args}>Element name</TreeViewItem>+ },+}diff --git a/packages/ui/src/components/TreeView/index.tsx b/packages/ui/src/components/TreeView/index.tsxnew file mode 100644index 00000000000..e69de29bb2ddiff --git a/packages/ui/src/components/shadcn/ui/context-menu.tsx b/packages/ui/src/components/shadcn/ui/context-menu.tsxindex 1e472c73497..5b5608d2e9c 100644--- a/packages/ui/src/components/shadcn/ui/context-menu.tsx+++ b/packages/ui/src/components/shadcn/ui/context-menu.tsx@@ -1,8 +1,8 @@'use client'+import * as React from 'react'import * as ContextMenuPrimitive from '@radix-ui/react-context-menu'import { Check, ChevronRight, Circle } from 'lucide-react'-import * as React from 'react'import { cn } from '../../../lib/utils/cn'@@ -27,7 +27,7 @@ const ContextMenuSubTrigger = React.forwardRef<<ContextMenuPrimitive.SubTriggerref={ref}className={cn(- 'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground',+ 'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-selection focus:text-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground',inset && 'pl-8',className)}@@ -46,7 +46,7 @@ const ContextMenuSubContent = React.forwardRef<<ContextMenuPrimitive.SubContentref={ref}className={cn(- 'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-overlay p-1 text-popover-foreground shadow-md animate-in slide-in-from-left-1',+ 'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-foreground-light shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',className)}{...props}@@ -62,7 +62,7 @@ const ContextMenuContent = React.forwardRef<<ContextMenuPrimitive.Contentref={ref}className={cn(- 'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-overlay p-1 text-popover-foreground shadow-md animate-in fade-in-80',+ 'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-overlay p-1 text-foreground-light shadow-md animate-in fade-in-80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',className)}{...props}@@ -80,7 +80,7 @@ const ContextMenuItem = React.forwardRef<<ContextMenuPrimitive.Itemref={ref}className={cn(- 'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',+ 'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-xs outline-none focus:bg-selection focus:text-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',inset && 'pl-8',className)}@@ -96,7 +96,7 @@ const ContextMenuCheckboxItem = React.forwardRef<<ContextMenuPrimitive.CheckboxItemref={ref}className={cn(- 'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',+ 'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-selection focus:text-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',className)}checked={checked}@@ -119,7 +119,7 @@ const ContextMenuRadioItem = React.forwardRef<<ContextMenuPrimitive.RadioItemref={ref}className={cn(- 'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',+ 'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-selection focus:text-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',className)}{...props}@@ -163,7 +163,7 @@ ContextMenuSeparator.displayName = ContextMenuPrimitive.Separator.displayNameconst ContextMenuShortcut = ({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) => {return (<span- className={cn('ml-auto text-xs tracking-widest text-foreground-muted', className)}+ className={cn('ml-auto text-xs tracking-widest text-muted-foreground', className)}{...props}/>)@@ -172,18 +172,18 @@ ContextMenuShortcut.displayName = 'ContextMenuShortcut'export {ContextMenu,- ContextMenuCheckboxItem,+ ContextMenuTrigger,ContextMenuContent,- ContextMenuGroup,ContextMenuItem,- ContextMenuLabel,- ContextMenuPortal,- ContextMenuRadioGroup,+ ContextMenuCheckboxItem,ContextMenuRadioItem,+ ContextMenuLabel,ContextMenuSeparator,ContextMenuShortcut,+ ContextMenuGroup,+ ContextMenuPortal,ContextMenuSub,ContextMenuSubContent,ContextMenuSubTrigger,- ContextMenuTrigger,+ ContextMenuRadioGroup,}