chore(ui,icons,ui-preset,toolbox): Move design system packages to monorepo (#5470)

This commit is contained in:
Kasper Fabricius Kristensen
2023-11-07 22:17:44 +01:00
committed by GitHub
parent 71853eafdd
commit e4ce2f4e07
722 changed files with 30300 additions and 186 deletions
@@ -0,0 +1,52 @@
import type { Meta, StoryObj } from "@storybook/react"
import { Avatar } from "./avatar"
const meta: Meta<typeof Avatar> = {
title: "Components/Avatar",
component: Avatar,
argTypes: {
src: {
control: {
type: "text",
},
},
fallback: {
control: {
type: "text",
},
},
variant: {
control: {
type: "select",
options: ["rounded", "squared"],
},
},
size: {
control: {
type: "select",
options: ["default", "large"],
},
},
},
parameters: {
layout: "centered",
},
}
export default meta
type Story = StoryObj<typeof Avatar>
export const WithImage: Story = {
args: {
src: "https://avatars.githubusercontent.com/u/10656202?v=4",
fallback: "J",
},
}
export const WithFallback: Story = {
args: {
fallback: "J",
},
}
@@ -0,0 +1,90 @@
"use client"
import * as Primitives from "@radix-ui/react-avatar"
import { cva, type VariantProps } from "class-variance-authority"
import * as React from "react"
import { clx } from "@/utils/clx"
const avatarVariants = cva(
"border-ui-border-strong flex shrink-0 items-center justify-center overflow-hidden border",
{
variants: {
variant: {
squared: "rounded-lg",
rounded: "rounded-full",
},
size: {
base: "h-8 w-8",
large: "h-10 w-10",
},
},
defaultVariants: {
variant: "rounded",
size: "base",
},
}
)
const innerVariants = cva("aspect-square object-cover object-center", {
variants: {
variant: {
squared: "rounded-lg",
rounded: "rounded-full",
},
size: {
base: "txt-compact-small-plus h-6 w-6",
large: "txt-compact-medium-plus h-8 w-8",
},
},
defaultVariants: {
variant: "rounded",
size: "base",
},
})
interface AvatarProps
extends Omit<
React.ComponentPropsWithoutRef<typeof Primitives.Root>,
"asChild" | "children" | "size"
>,
VariantProps<typeof avatarVariants> {
src?: string
fallback: string
}
const Avatar = React.forwardRef<
React.ElementRef<typeof Primitives.Root>,
AvatarProps
>(
(
{ src, fallback, variant = "rounded", size = "base", className, ...props },
ref
) => {
return (
<Primitives.Root
ref={ref}
{...props}
className={clx(avatarVariants({ variant, size }), className)}
>
{src && (
<Primitives.Image
src={src}
className={innerVariants({ variant, size })}
/>
)}
<Primitives.Fallback
className={clx(
innerVariants({ variant, size }),
"bg-ui-bg-component text-ui-fg-subtle pointer-events-none flex select-none items-center justify-center"
)}
>
{fallback}
</Primitives.Fallback>
</Primitives.Root>
)
}
)
Avatar.displayName = "Avatar"
export { Avatar }
@@ -0,0 +1 @@
export * from "./avatar"