-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(www): add folder icons component
- Loading branch information
1 parent
f21e3ee
commit 3364fb2
Showing
7 changed files
with
565 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { type IconProps, Icons } from "@kanpeki/ui/icons"; | ||
import { cn } from "@kanpeki/utils/cn"; | ||
|
||
const folderNameMap = new Map([ | ||
["src", [Icons.SrcFolder, Icons.SrcFolderOpen]], | ||
["app", [Icons.AppFolder, Icons.AppFolderOpen]], | ||
["components", [Icons.ComponentsFolder, Icons.ComponentsFolderOpen]], | ||
["config", [Icons.ConfigFolder, Icons.ConfigFolderOpen]], | ||
["hooks", [Icons.HookFolder, Icons.HookFolderOpen]], | ||
["styles", [Icons.CssFolder, Icons.CssFolderOpen]], | ||
["utils", [Icons.UtilsFolder, Icons.UtilsFolderOpen]], | ||
["ui", [Icons.ThemeFolder, Icons.ThemeFolderOpen]], | ||
]); | ||
|
||
interface FolderIconProps extends IconProps { | ||
title: string; | ||
isOpen: boolean; | ||
} | ||
|
||
export function FolderIcon({ | ||
title, | ||
isOpen, | ||
className, | ||
...props | ||
}: FolderIconProps) { | ||
const Icon = folderNameMap.get(title); | ||
|
||
if (!Icon) { | ||
return isOpen ? ( | ||
<Icons.FolderOpen className={cn("size-4", className)} {...props} /> | ||
) : ( | ||
<Icons.Folder className={cn("size-4", className)} {...props} /> | ||
); | ||
} | ||
|
||
const [FolderIcon, FolderIconOpen] = Icon; | ||
|
||
return isOpen ? ( | ||
<FolderIconOpen className={cn("size-4", className)} {...props} /> | ||
) : ( | ||
<FolderIcon className={cn("size-4", className)} {...props} /> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use client"; | ||
|
||
import { Collapsible } from "@kanpeki/ui/collapsible"; | ||
import { useState } from "react"; | ||
import { FileStyles } from "./files"; | ||
import { FolderIcon } from "./folder-icon"; | ||
|
||
interface FolderProps extends React.ComponentProps<"div"> { | ||
name: string; | ||
defaultOpen?: boolean; | ||
} | ||
|
||
export function Folder({ | ||
children, | ||
name, | ||
defaultOpen = false, | ||
className, | ||
...rest | ||
}: FolderProps) { | ||
const [isOpen, setIsOpen] = useState(defaultOpen); | ||
|
||
return ( | ||
<Collapsible.Root open={isOpen} onOpenChange={setIsOpen} {...rest}> | ||
<Collapsible.Trigger className={FileStyles({ className })}> | ||
<FolderIcon title={name} isOpen={isOpen} /> | ||
{name} | ||
</Collapsible.Trigger> | ||
<Collapsible.Content> | ||
<div className="ml-2 flex flex-col border-l pl-2">{children}</div> | ||
</Collapsible.Content> | ||
</Collapsible.Root> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.