Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: IconButton component & stories #1493

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions src/v2/components/ui/IconButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { CircleDashed } from "@phosphor-icons/react/dist/ssr"
import { Meta, StoryObj } from "@storybook/react"
import { IconButton, IconButtonProps } from "./IconButton"

type IconButtonExampleProps = Omit<IconButtonProps, "aria-label" | "icon">

const IconButtonExample = (props: IconButtonExampleProps) => (
<IconButton
{...props}
aria-label="IconButton example"
icon={<CircleDashed weight="bold" />}
/>
)

const meta: Meta<typeof IconButtonExample> = {
title: "Design system/IconButton",
component: IconButtonExample,
}

export default meta

type Story = StoryObj<typeof IconButton>

export const Solid: Story = {
args: {
size: "md",
variant: "solid",
colorScheme: "primary",
isLoading: false,
disabled: false,
},
argTypes: {
size: {
type: "string",
control: "select",
options: ["sm", "md", "lg"] satisfies IconButtonProps["size"][],
},
colorScheme: {
type: "string",
control: "select",
options: [
"primary",
"secondary",
"info",
"destructive",
"success",
] satisfies IconButtonProps["colorScheme"][],
},
variant: {
control: {
disable: true,
},
},
disabled: {
type: "boolean",
control: "boolean",
},
},
}

export const Outline: Story = {
args: {
...Solid.args,
variant: "outline",
},
argTypes: {
...Solid.argTypes,
},
}

export const Ghost: Story = {
args: {
...Solid.args,
variant: "ghost",
},
argTypes: {
...Solid.argTypes,
},
}

export const Subtle: Story = {
args: {
...Solid.args,
variant: "subtle",
},
argTypes: {
...Solid.argTypes,
},
}
48 changes: 48 additions & 0 deletions src/v2/components/ui/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { cn } from "@/lib/utils"
import { VariantProps, cva } from "class-variance-authority"
import { ReactNode, forwardRef } from "react"
import { Button, ButtonProps } from "./Button"

const iconButtonVariants = cva("p-0", {
variants: {
size: {
sm: "size-8",
md: "size-10",
lg: "size-12",
},
},
defaultVariants: {
size: "md",
},
})

export interface IconButtonProps
extends Omit<
ButtonProps,
| "size"
| "loadingText"
| "leftIcon"
| "rightIcon"
| "asChild"
| "children"
| "aria-label"
>,
VariantProps<typeof iconButtonVariants> {
"aria-label": string
// icon: ButtonProps["leftIcon"] // TODO: uncomment this in the Button refactor PR
icon: ReactNode
}

const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(
({ size, icon, className, ...props }, ref) => (
<Button
ref={ref}
{...props}
className={cn(iconButtonVariants({ size, className }))}
>
{icon}
</Button>
)
)

export { IconButton }
Loading