- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 0
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
25 button component #32
Merged
+437
−87
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d9a58b0
Started button component and storybook
nhistory b5110cf
Merge branch '29-heading' into 25-button-component
nhistory 934a153
Made Button stories and update semantic colors for improved accessibi…
nhistory 87e77f6
Merge branch 'main' into 25-button-component
nhistory 5aca818
Refactor Button component styles for improved color semantics and acc…
nhistory b7b77c0
Merge branch 'main' into 25-button-component
nhistory 2a5b378
feat: enhance Button component with tone and variant options
nhistory 37cd145
feat: update Button component to remove primary tone and enhance colo…
nhistory ea04e01
Fixed Button component with size and disabled properties, and update …
nhistory 66f81d9
Updated Button component in App to use 'solid' variant
nhistory 5324976
deps: update bun
DaleSeo 416cdff
deps: update vite, vitest, react, panda, storybook
DaleSeo 7ab7c7b
deps: install lucide-react vite-plugin-svgr
DaleSeo fa0c5fb
feat: add icon tokens
DaleSeo 8c98494
feat: implement icon component
DaleSeo 5b6da92
Merge branch 'main' into 25-button-component
nhistory a84896b
Update Button component to use shorthand size props and remove unnece…
nhistory File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Made Button stories and update semantic colors for improved accessibi…
…lity and consistency
commit 934a15328a9d8a10bdfe70652f0aaac42ad93a82
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,40 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { expect, fn, userEvent } from "@storybook/test"; | ||
import { Button } from "./Button"; | ||
|
||
const meta: Meta<typeof Button> = { | ||
title: "Components/Button", | ||
const meta = { | ||
component: Button, | ||
tags: ["autodocs"], | ||
argTypes: { | ||
variant: { | ||
control: "select", | ||
options: [ | ||
"default", | ||
"solid", | ||
"outline", | ||
"outlineGradient", | ||
"accent", | ||
"danger", | ||
"warning", | ||
], | ||
}, | ||
size: { control: "select", options: ["small", "medium", "large"] }, | ||
disabled: { control: "boolean" }, | ||
loading: { control: "boolean" }, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
}; | ||
args: { onClick: fn() }, | ||
} satisfies Meta<typeof Button>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Button>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
children: "Default Button", | ||
}, | ||
}; | ||
|
||
export const Solid: Story = { | ||
args: { | ||
variant: "solid", | ||
children: "Solid Button", | ||
}, | ||
}; | ||
|
||
export const Outline: Story = { | ||
args: { | ||
variant: "outline", | ||
children: "Outline Button", | ||
}, | ||
}; | ||
|
||
export const OutlineGradient: Story = { | ||
args: { | ||
variant: "outlineGradient", | ||
children: "Outline Gradient Button", | ||
}, | ||
}; | ||
|
||
export const Accent: Story = { | ||
args: { | ||
variant: "accent", | ||
children: "Accent Button", | ||
}, | ||
}; | ||
|
||
export const Danger: Story = { | ||
args: { | ||
variant: "danger", | ||
children: "Danger Button", | ||
}, | ||
}; | ||
|
||
export const Warning: Story = { | ||
args: { | ||
variant: "warning", | ||
children: "Warning Button", | ||
}, | ||
}; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Small: Story = { | ||
export const Basic: Story = { | ||
args: { | ||
size: "small", | ||
children: "Small Button", | ||
type: "button", | ||
children: "시작하기", | ||
}, | ||
}; | ||
play: async ({ args: { onClick }, canvas, step }) => { | ||
const button = canvas.getByRole("button"); | ||
|
||
export const Medium: Story = { | ||
args: { | ||
size: "medium", | ||
children: "Medium Button", | ||
}, | ||
}; | ||
await step("renders a button with text", async () => { | ||
expect(button).toHaveTextContent("시작하기"); | ||
}); | ||
|
||
export const Large: Story = { | ||
args: { | ||
size: "large", | ||
children: "Large Button", | ||
await step("calls onClick handler when clicked", async () => { | ||
await userEvent.click(button); | ||
expect(onClick).toHaveBeenCalledTimes(1); | ||
}); | ||
}, | ||
}; | ||
|
||
// export const WithIcon: Story = { | ||
// args: { | ||
// children: "Button with Icon", | ||
// icon: <ArrowRightIcon />, | ||
// }, | ||
// export const Submit: Story = { | ||
// args: { | ||
// type: "submit", | ||
// children: "Submit", | ||
// }, | ||
// }; | ||
|
||
export const Disabled: Story = { | ||
args: { | ||
children: "Disabled Button", | ||
disabled: true, | ||
}, | ||
}; | ||
|
||
export const Loading: Story = { | ||
args: { | ||
children: "Loading Button", | ||
loading: true, | ||
}, | ||
}; | ||
|
||
export const CustomStyled: Story = { | ||
args: { | ||
children: "Custom Styled Button", | ||
customStyle: { backgroundColor: "red", color: "white", padding: "1rem" }, | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,260 +1,145 @@ | ||
import React, { ReactNode, HTMLAttributes, forwardRef } from "react"; | ||
import React from "react"; | ||
import { css, cva } from "../../../styled-system/css"; | ||
import ClipLoader from "react-spinners/ClipLoader"; | ||
import { SystemStyleObject } from "@pandacss/types"; | ||
import type { SystemStyleObject } from "@pandacss/types"; | ||
// import { colors } from "../../tokens/colors"; | ||
|
||
type ButtonVariant = | ||
| "solid" | ||
| "outline" | ||
| "outlineGradient" | ||
| "outline-gradient" | ||
| "default" | ||
| "accent" | ||
| "danger" | ||
| "warning"; | ||
|
||
type ButtonSize = "small" | "medium" | "large"; | ||
|
||
export interface ButtonProps | ||
extends Omit<HTMLAttributes<HTMLButtonElement>, "style"> { | ||
children: ReactNode; | ||
export interface ButtonProps { | ||
/** 버튼 텍스트 */ | ||
children: React.ReactNode; | ||
type?: "button" | "submit"; | ||
onClick?: () => void; | ||
variant?: ButtonVariant; | ||
size?: ButtonSize; | ||
disabled?: boolean; | ||
icon?: ReactNode; | ||
loading?: boolean; | ||
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void; | ||
onFocus?: (event: React.FocusEvent<HTMLButtonElement>) => void; | ||
onBlur?: (event: React.FocusEvent<HTMLButtonElement>) => void; | ||
customStyle?: SystemStyleObject; | ||
style?: SystemStyleObject; // Add style prop for custom inline styles | ||
} | ||
|
||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>( | ||
( | ||
{ | ||
children, | ||
variant = "default", | ||
size = "medium", | ||
disabled = false, | ||
icon, | ||
loading = false, | ||
onClick, | ||
onFocus, | ||
onBlur, | ||
...rest | ||
}, | ||
ref | ||
) => { | ||
return ( | ||
<button | ||
ref={ref} | ||
className={css( | ||
{ | ||
cursor: "pointer", | ||
borderRadius: "md", | ||
fontWeight: "semibold", | ||
whiteSpace: "nowrap", | ||
transition: | ||
"background-color 0.2s ease-in-out, border-color 0.2s ease-in-out, color 0.2s ease-in-out", | ||
fontFamily: "body", | ||
}, | ||
styles.raw({ variant, size }), // Apply styles here | ||
css.raw({ | ||
display: "inline-flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
gap: "0.5rem", | ||
}) | ||
)} | ||
disabled={disabled || loading} | ||
onClick={onClick} | ||
onFocus={onFocus} | ||
onBlur={onBlur} | ||
{...rest} | ||
> | ||
{loading ? <ClipLoader size="sm" /> : null} | ||
{icon && !loading ? icon : null} | ||
{children} | ||
</button> | ||
); | ||
} | ||
); | ||
/** | ||
* 버튼 컴포넌트입니다. | ||
*/ | ||
export const Button = ({ | ||
children, | ||
type = "button", | ||
onClick, | ||
variant = "default", | ||
style, // destructure the style prop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요거는 자치샇면 일관성을 해칠 수 있는 독이 될 수도 있을 것 같은데, 우선은 제외하시는 게 어떠실까요? |
||
...rest | ||
}: ButtonProps) => { | ||
return ( | ||
<button | ||
className={css( | ||
styles.raw({ variant }), | ||
baseStyles, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 옷, |
||
...(Array.isArray(style) ? style : [style]) // Ensure style is an array | ||
)} | ||
type={type} | ||
onClick={onClick} | ||
{...rest} | ||
> | ||
{children} | ||
</button> | ||
); | ||
}; | ||
|
||
Button.displayName = "Button"; | ||
const baseStyles = { | ||
appearance: "none", | ||
margin: "0", | ||
padding: "0.7rem 3rem", | ||
fontSize: "1.5rem", | ||
fontWeight: 500, | ||
textAlign: "center", | ||
textDecoration: "none", | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
width: ["auto", "100%"], | ||
borderRadius: "10px", | ||
cursor: "pointer", | ||
transition: "0.2s", | ||
lineHeight: "1", | ||
outline: "0", | ||
"&:focus": { | ||
outlineColor: "focus", | ||
outline: "3px solid", | ||
outlineOffset: "2px", | ||
borderRadius: "10px", | ||
}, | ||
"&:disabled": { opacity: 0.5 }, | ||
}; | ||
|
||
const styles = cva({ | ||
variants: { | ||
variant: { | ||
default: { | ||
backgroundColor: "bg.DEFAULT", | ||
color: "text.DEFAULT", | ||
"&:hover": { | ||
backgroundColor: "bg.hover", | ||
}, | ||
"&:focus": { | ||
outline: "2px solid", | ||
outlineColor: "focus", | ||
outlineOffset: "2px", | ||
}, | ||
"&:active": { | ||
backgroundColor: "bg.active", | ||
}, | ||
"&:disabled": { | ||
backgroundColor: "bg.disabled", | ||
color: "text.disabled", | ||
cursor: "not-allowed", | ||
}, | ||
}, | ||
solid: { | ||
backgroundColor: "solid.DEFAULT", | ||
color: "text.contrast", | ||
"&:hover": { | ||
backgroundColor: "solid.hover", | ||
}, | ||
"&:focus": { | ||
outline: "2px solid", | ||
outlineColor: "focus", | ||
outlineOffset: "2px", | ||
}, | ||
"&:active": { | ||
backgroundColor: "solid.DEFAULT", | ||
}, | ||
"&:disabled": { | ||
backgroundColor: "bg.disabled", | ||
color: "text.disabled", | ||
cursor: "not-allowed", | ||
}, | ||
}, | ||
outline: { | ||
backgroundColor: "transparent", | ||
border: "2px solid", | ||
borderColor: "border.DEFAULT", | ||
color: "text.DEFAULT", | ||
"&:hover": { | ||
backgroundColor: "bg.hover", | ||
}, | ||
"&:focus": { | ||
outline: "2px solid", | ||
outlineColor: "focus", | ||
outlineOffset: "2px", | ||
}, | ||
"&:active": { | ||
backgroundColor: "bg.active", | ||
}, | ||
"&:disabled": { | ||
borderColor: "border.disabled", | ||
color: "text.disabled", | ||
cursor: "not-allowed", | ||
}, | ||
}, | ||
outlineGradient: { | ||
backgroundColor: "transparent", | ||
border: "2px solid", | ||
borderColor: "teal.7", // Using the teal color for now because no specific gradient color defined in tokens for border yet. | ||
color: "teal.7", | ||
background: "linear-gradient(to right, teal.7, teal.9)", | ||
backgroundClip: "text", | ||
"-webkit-background-clip": "text", | ||
"-webkit-text-fill-color": "transparent", | ||
"&:hover": { | ||
borderColor: "teal.9", | ||
color: "teal.9", | ||
background: "linear-gradient(to right, teal.9, teal.7)", | ||
backgroundClip: "text", | ||
"-webkit-background-clip": "text", | ||
"-webkit-text-fill-color": "transparent", | ||
}, | ||
"&:focus": { | ||
outline: "2px solid", | ||
outlineColor: "focus", | ||
outlineOffset: "2px", | ||
}, | ||
"&:active": { | ||
background: "linear-gradient(to right, teal.7, teal.9)", | ||
backgroundClip: "text", | ||
"-webkit-background-clip": "text", | ||
"-webkit-text-fill-color": "transparent", | ||
}, | ||
"&:disabled": { | ||
borderColor: "border.disabled", | ||
color: "text.disabled", | ||
cursor: "not-allowed", | ||
background: "none", | ||
"-webkit-text-fill-color": "text.disabled", | ||
background: "bg", | ||
color: "text", | ||
"&:active, &:hover": { | ||
background: "bg.hover", | ||
outline: "0", | ||
}, | ||
}, | ||
accent: { | ||
backgroundColor: "bg.accent", | ||
color: "text.contrast", | ||
"&:hover": { | ||
backgroundColor: "bg.hover.accent", | ||
}, | ||
"&:focus": { | ||
outline: "2px solid", | ||
outlineColor: "focus", | ||
outlineOffset: "2px", | ||
}, | ||
"&:active": { | ||
backgroundColor: "bg.active.accent", | ||
}, | ||
"&:disabled": { | ||
backgroundColor: "bg.disabled", | ||
color: "text.disabled", | ||
cursor: "not-allowed", | ||
background: "bg.accent", | ||
color: "text.accent", | ||
"&:active, &:hover": { | ||
background: "bg.hover.accent", | ||
outline: "0", | ||
}, | ||
}, | ||
danger: { | ||
backgroundColor: "bg.danger", | ||
color: "text.contrast", | ||
"&:hover": { | ||
backgroundColor: "bg.hover.danger", | ||
}, | ||
"&:focus": { | ||
outline: "2px solid", | ||
outlineColor: "focus", | ||
outlineOffset: "2px", | ||
}, | ||
"&:active": { | ||
backgroundColor: "bg.active.danger", | ||
}, | ||
"&:disabled": { | ||
backgroundColor: "bg.disabled", | ||
color: "text.disabled", | ||
cursor: "not-allowed", | ||
background: "bg.danger", | ||
color: "text.danger", | ||
"&:active, &:hover": { | ||
background: "bg.hover.danger", | ||
outline: "0", | ||
}, | ||
}, | ||
warning: { | ||
backgroundColor: "bg.warning", | ||
color: "text.contrast", | ||
"&:hover": { | ||
backgroundColor: "bg.hover.warning", | ||
}, | ||
"&:focus": { | ||
outline: "2px solid", | ||
outlineColor: "focus", | ||
outlineOffset: "2px", | ||
}, | ||
"&:active": { | ||
backgroundColor: "bg.active.warning", | ||
}, | ||
"&:disabled": { | ||
backgroundColor: "bg.disabled", | ||
color: "text.disabled", | ||
cursor: "not-allowed", | ||
background: "bg.warning", | ||
color: "text.warning", | ||
"&:active, &:hover": { | ||
background: "bg.hover.warning", | ||
outline: "0", | ||
}, | ||
}, | ||
}, | ||
size: { | ||
small: { | ||
fontSize: "sm", | ||
padding: "0.5rem 1rem", | ||
solid: { | ||
background: "bg.solid", | ||
color: "text.solid", | ||
"&:active, &:hover": { | ||
background: "bg.hover.solid", | ||
outline: "0", | ||
}, | ||
}, | ||
medium: { | ||
fontSize: "md", | ||
padding: "0.75rem 1.5rem", | ||
outline: { | ||
background: "bg.outline", | ||
color: "text.outline", | ||
border: "4px solid", | ||
borderColor: "border.outline", | ||
"&:active, &:hover": { | ||
background: "bg.hover.outline", | ||
outline: "0", | ||
}, | ||
}, | ||
large: { | ||
fontSize: "lg", | ||
padding: "1rem 2rem", | ||
"outline-gradient": { | ||
"--gradient-color": "linear-gradient(135deg, #24eaca, #846de9)", | ||
background: "transparent", | ||
color: "text.outline", | ||
border: "4px solid transparent", | ||
backgroundClip: "padding-box, border-box", | ||
backgroundOrigin: "padding-box, border-box", | ||
borderImage: "var(--gradient-color)", | ||
borderImageSlice: "1", | ||
borderImageOutset: "0", | ||
"&:active, &:hover": { | ||
outline: "0", | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
단일 속성으로 너무 다양한 종류의 버튼을 �표현하려고 하면 나중에 속성값의 개수가 폭발적으로 증가할 수 있으며 속성값의 이름을 짓는 것도 골치거리가 될 수 있습니다. 다음과 같이 두 개의 속성으로 분리하는 것을 제안드리고 싶습니다.