Skip to content

Commit

Permalink
UI: Create Files component
Browse files Browse the repository at this point in the history
  • Loading branch information
fuma-nama committed Aug 16, 2023
1 parent f756fc5 commit 689c75d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/five-cameras-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'next-docs-ui': patch
---

Create Files component
53 changes: 53 additions & 0 deletions packages/next-docs-ui/src/components/files.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use client'

import * as Collapsible from '@radix-ui/react-collapsible'
import clsx from 'clsx'
import { ChevronDown, FileIcon, FolderIcon, FolderOpenIcon } from 'lucide-react'
import type { ReactNode } from 'react'

export function Files({ children }: { children: ReactNode }) {
return (
<div className="nd-flex nd-flex-col nd-not-prose nd-border nd-rounded-md nd-p-2">
{children}
</div>
)
}

export function File({
title,
defaultOpen,
children
}: {
title: string
defaultOpen?: boolean
children?: ReactNode
}) {
if (children == null) {
return (
<p className="nd-flex nd-flex-row nd-items-center nd-text-sm nd-rounded-md nd-px-2 nd-py-1.5 nd-transition-colors hover:nd-bg-accent hover:nd-text-accent-foreground">
<FileIcon className="nd-w-4 nd-h-4 nd-mr-2" />
{title}
</p>
)
}

return (
<Collapsible.Root defaultOpen={defaultOpen}>
<Collapsible.Trigger className="nd-group nd-flex nd-w-full nd-flex-row nd-items-center nd-text-sm nd-px-2 nd-py-1.5 nd-transition-colors nd-rounded-md hover:nd-bg-accent hover:nd-text-accent-foreground">
<FolderIcon className="nd-w-4 nd-h-4 nd-mr-2 group-data-[state=open]:nd-hidden" />
<FolderOpenIcon className="nd-w-4 nd-h-4 nd-mr-2 group-data-[state=closed]:nd-hidden" />
{title}
<ChevronDown
className={clsx(
'nd-w-4 nd-h-4 nd-transition-transform nd-ml-auto group-data-[state=open]:nd-rotate-180'
)}
/>
</Collapsible.Trigger>
<Collapsible.Content className="nd-overflow-hidden data-[state=closed]:nd-animate-collapsible-up data-[state=open]:nd-animate-collapsible-down">
<div className="nd-flex nd-flex-col nd-ml-4 nd-pl-2 nd-border-l nd-py-2">
{children}
</div>
</Collapsible.Content>
</Collapsible.Root>
)
}
2 changes: 1 addition & 1 deletion packages/next-docs-ui/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import tsconfig from './tsconfig.json'

export default defineConfig({
entry: [
'./src/components/{type-table,roll-button,tabs,steps,index}.{ts,tsx}',
'./src/components/{type-table,roll-button,files,tabs,steps,index}.{ts,tsx}',
'./src/components/dialog/search.tsx',
'./src/*.{ts,tsx}'
],
Expand Down

0 comments on commit 689c75d

Please sign in to comment.