-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Resizable and Avatar components
- Loading branch information
1 parent
ee40b71
commit 9cc6d0b
Showing
19 changed files
with
399 additions
and
1 deletion.
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,77 @@ | ||
import { type VariantProps, cva } from "class-variance-authority"; | ||
|
||
import { cn } from "../utils"; | ||
|
||
const avatarVariants = cva( | ||
"rounded-full bg-neutral-200 dark:bg-neutral-800 overflow-hidden", | ||
{ | ||
variants: { | ||
size: { | ||
default: "h-8 w-8", | ||
sm: "h-6 w-6", | ||
lg: "h-10 w-10", | ||
xl: "h-12 w-12", | ||
}, | ||
}, | ||
defaultVariants: { | ||
size: "default", | ||
}, | ||
}, | ||
); | ||
|
||
export interface AvatarProps extends VariantProps<typeof avatarVariants> { | ||
alt?: string; | ||
className?: string; | ||
indicator?: "neutral" | "success" | "error"; | ||
src?: string; | ||
} | ||
|
||
function Avatar({ | ||
alt, | ||
className, | ||
indicator, | ||
size, | ||
src, | ||
...props | ||
}: AvatarProps) { | ||
let indicatorClassName = | ||
"absolute right-0 bottom-0 block h-2 w-2 rounded-full ring-2 ring-neutral-50 dark:ring-neutral-900"; | ||
|
||
if (indicator === "neutral") { | ||
indicatorClassName = `${indicatorClassName} bg-neutral-300 dark:bg-neutral-600`; | ||
} else if (indicator === "success") { | ||
indicatorClassName = `${indicatorClassName} bg-success-500`; | ||
} else if (indicator === "error") { | ||
indicatorClassName = `${indicatorClassName} bg-danger-500`; | ||
} | ||
|
||
return ( | ||
<span className="relative inline-block" title={alt} {...props}> | ||
<img | ||
className={cn(avatarVariants({ size, className }))} | ||
src={src} | ||
alt={alt} | ||
/> | ||
{indicator && <span className={indicatorClassName} />} | ||
</span> | ||
); | ||
} | ||
|
||
Avatar.displayName = "Avatar"; | ||
|
||
export interface AvatarGroupProps extends React.PropsWithChildren { | ||
className?: string; | ||
} | ||
|
||
Avatar.Group = function AvatarGroup({ children, className }: AvatarGroupProps) { | ||
return ( | ||
<div className={cn("flex -space-x-1 overflow-hidden", className)}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
// @ts-expect-error | ||
Avatar.Group.displayName = "Avatar.Group"; | ||
|
||
export { Avatar }; |
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
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
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
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
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,83 @@ | ||
import { | ||
Panel, | ||
PanelGroup, | ||
type PanelGroupProps, | ||
type PanelProps, | ||
PanelResizeHandle, | ||
type PanelResizeHandleProps, | ||
} from "react-resizable-panels"; | ||
|
||
import { cn } from "../utils"; | ||
|
||
export type ResizableProps = PanelGroupProps; | ||
|
||
function Resizable({ className, ...props }: ResizableProps) { | ||
return ( | ||
<PanelGroup | ||
className={cn( | ||
"flex h-full w-full data-[panel-group-direction=vertical]:flex-col", | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
Resizable.displayName = "Resizable"; | ||
|
||
export type ResizablePanelProps = PanelProps; | ||
|
||
Resizable.Panel = function ResizablePanel(props: ResizablePanelProps) { | ||
return <Panel {...props} />; | ||
}; | ||
|
||
// @ts-expect-error | ||
Resizable.Panel.displayName = "Resizable.Panel"; | ||
|
||
export interface ResizableHandleProps extends PanelResizeHandleProps { | ||
withHandle?: boolean; | ||
} | ||
|
||
Resizable.Handle = function ResizableHandle({ | ||
className, | ||
withHandle, | ||
...props | ||
}: ResizableHandleProps) { | ||
return ( | ||
<PanelResizeHandle | ||
className={cn( | ||
"relative flex w-px items-center justify-center bg-neutral-100 after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 hover:bg-brand-500 data-[resize-handle-active=pointer]:outline-none data-[resize-handle-active=pointer]:bg-brand-500 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90 dark:bg-neutral-900", | ||
className, | ||
)} | ||
{...props} | ||
> | ||
{withHandle && ( | ||
<div className="grid grid-cols-2 h-4 w-3 rounded-sm bg-neutral-200 border-2 border-neutral-100 z-10 dark:bg-neutral-800 dark:border-neutral-900"> | ||
<div className="flex justify-center items-center"> | ||
<span className="rounded-full h-[2px] w-[2px] bg-neutral-300 dark:bg-neutral-700" /> | ||
</div> | ||
<div className="flex justify-center items-center"> | ||
<span className="rounded-full h-[2px] w-[2px] bg-neutral-300 dark:bg-neutral-700" /> | ||
</div> | ||
<div className="flex justify-center items-center"> | ||
<span className="rounded-full h-[2px] w-[2px] bg-neutral-300 dark:bg-neutral-700" /> | ||
</div> | ||
<div className="flex justify-center items-center"> | ||
<span className="rounded-full h-[2px] w-[2px] bg-neutral-300 dark:bg-neutral-700" /> | ||
</div> | ||
<div className="flex justify-center items-center"> | ||
<span className="rounded-full h-[2px] w-[2px] bg-neutral-300 dark:bg-neutral-700" /> | ||
</div> | ||
<div className="flex justify-center items-center"> | ||
<span className="rounded-full h-[2px] w-[2px] bg-neutral-300 dark:bg-neutral-700" /> | ||
</div> | ||
</div> | ||
)} | ||
</PanelResizeHandle> | ||
); | ||
}; | ||
|
||
// @ts-expect-error | ||
Resizable.Handle.displayName = "Resizable.Handle"; | ||
|
||
export { Resizable }; |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.