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

25 button component #32

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
16 changes: 8 additions & 8 deletions src/components/Button/Button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ type Story = StoryObj<typeof meta>;
export const Basic: Story = {
args: {
type: "button",
children: "Click",
children: "시작하기",
},
play: async ({ args: { onClick }, canvas, step }) => {
const button = canvas.getByRole("button");

await step("renders a button with text", async () => {
expect(button).toHaveTextContent("Click");
expect(button).toHaveTextContent("시작하기");
});

await step("calls onClick handler when clicked", async () => {
Expand All @@ -32,9 +32,9 @@ export const Basic: Story = {
},
};

export const Submit: Story = {
args: {
type: "submit",
children: "Submit",
},
};
// export const Submit: Story = {
// args: {
// type: "submit",
// children: "Submit",
// },
// };
158 changes: 130 additions & 28 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { css } from "../../../styled-system/css";
import React from "react";
import { css, cva } from "../../../styled-system/css";
import type { SystemStyleObject } from "@pandacss/types";
// import { colors } from "../../tokens/colors";

type ButtonVariant =
| "solid"
| "outline"
| "outline-gradient"
| "default"
| "accent"
| "danger"
| "warning";

export interface ButtonProps {
/** 버튼 텍스트 */
children: React.ReactNode;
type?: "button" | "submit";
onClick?: () => void;
variant?: ButtonVariant;
style?: SystemStyleObject; // Add style prop for custom inline styles
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

단일 속성으로 너무 다양한 종류의 버튼을 �표현하려고 하면 나중에 속성값의 개수가 폭발적으로 증가할 수 있으며 속성값의 이름을 짓는 것도 골치거리가 될 수 있습니다. 다음과 같이 두 개의 속성으로 분리하는 것을 제안드리고 싶습니다.

variant: "outline" | "solid" | "transparent";
tone?: "netural" | "accent" | "danger" | "warning" | "gradient";

}

/**
Expand All @@ -14,37 +28,17 @@ export const Button = ({
children,
type = "button",
onClick,
variant = "default",
style, // destructure the style prop
...rest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거는 자치샇면 일관성을 해칠 수 있는 독이 될 수도 있을 것 같은데, 우선은 제외하시는 게 어떠실까요?

}: ButtonProps) => {
return (
<button
className={css({
"--button-color": "#ffffff",
"--button-bg-color": "#0d6efd",
"--button-hover-bg-color": "#025ce2",
appearance: "none",
margin: "0",
padding: "0.5rem 1rem",
background: "var(--button-bg-color)",
color: "var(--button-color)",
fontSize: "1rem",
fontWeight: 400,
textAlign: "center",
textDecoration: "none",
display: "inline-block",
width: ["auto", "100%"],
border: "none",
borderRadius: "4px",
boxShadow:
"0 4px 6px -1px rgba(0, 0, 0, 0.1),\n 0 2px 4px -1px rgba(0, 0, 0, 0.06)",
cursor: "pointer",
transition: "0.5s",
"&:active, &:hover, &:focus": {
background: "var(--button-hover-bg-color)",
outline: "0",
},
"&:disabled": { opacity: 0.5 },
})}
className={css(
styles.raw({ variant }),
baseStyles,
...(Array.isArray(style) ? style : [style]) // Ensure style is an array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

옷, css.raw()로 안 감싸도 되나 보네요?

)}
type={type}
onClick={onClick}
{...rest}
Expand All @@ -53,3 +47,111 @@ export const Button = ({
</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: { base: "{colors.violet.10}", _dark: "{colors.violet.7}" },
outline: "3px solid",
outlineOffset: "2px",
},
"&:disabled": { opacity: 0.5 },
};

const styles = cva({
variants: {
variant: {
default: {
background: "bg",
color: "text",
"&:active, &:hover": {
background: "bg.hover",
},
},
accent: {
background: "bg.accent",
color: "text.accent",
"&:active, &:hover": {
background: "bg.hover.accent",
},
},
danger: {
background: "bg.danger",
color: "text.danger",
"&:active, &:hover": {
background: "bg.hover.danger",
},
},
warning: {
background: "bg.warning",
color: "text.warning",
"&:active, &:hover": {
background: "bg.hover.warning",
},
},
solid: {
background: { base: "{colors.violet.9}", _dark: "{colors.violet.9}" },
color: { base: "{colors.violet.1}", _dark: "{colors.violet.1}" },
"&:active, &:hover": {
background: {
base: "{colors.violet.8}",
_dark: "{colors.violetDark.10}",
},
},
},
outline: {
background: {
base: "{colors.violet.2}",
_dark: "{colors.violetDark.8}",
},
color: {
base: "{colors.violetDark.1}",
_dark: "{colors.violet.1}",
},
border: "4px solid",
borderColor: {
base: "{colors.violetDark.10}",
_dark: "{colors.violet.7}",
},
"&:active, &:hover": {
background: {
base: "{colors.violet.4}",
_dark: "{colors.violetDark.10}",
},
},
},
"outline-gradient": {
"--gradient-color":
"linear-gradient(90deg,{colors.teal.9},{colors.violet.10})",
background: "transparent",
color: {
base: "{colors.violetDark.1}",
_dark: "{colors.violet.1}",
},
border: "4px solid transparent",
borderRadius: "10px",
backgroundClip: "padding-box, border-box",
backgroundOrigin: "padding-box, border-box",
borderImage: "var(--gradient-color)",
borderImageSlice: "1",
borderImageOutset: "0",
"&:active, &:hover": {},
},
},
},
});
10 changes: 5 additions & 5 deletions src/tokens/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export const semanticColors: SemanticTokens["colors"] = {
bg: {
DEFAULT: {
DEFAULT: {
value: { base: "{colors.gray.3}", _dark: "{colors.grayDark.3}" },
value: { base: "{colors.grayDark.3}", _dark: "{colors.gray.3}" },
},
accent: {
value: { base: "{colors.teal.3}", _dark: "{colors.violetDark.3}" },
value: { base: "{colors.teal.5}", _dark: "{colors.tealDark.8}" },
},
danger: {
value: { base: "{colors.red.3}", _dark: "{colors.redDark.3}" },
Expand All @@ -23,7 +23,7 @@ export const semanticColors: SemanticTokens["colors"] = {
},
hover: {
DEFAULT: {
value: { base: "{colors.gray.4}", _dark: "{colors.grayDark.4}" },
value: { base: "{colors.grayDark.8}", _dark: "{colors.gray.6}" },
},
accent: {
value: { base: "{colors.teal.4}", _dark: "{colors.violetDark.4}" },
Expand Down Expand Up @@ -116,7 +116,7 @@ export const semanticColors: SemanticTokens["colors"] = {
value: { base: "{colors.gray.11}", _dark: "{colors.grayDark.11}" },
},
accent: {
value: { base: "{colors.teal.11}", _dark: "{colors.violetDark.11}" },
value: { base: "{colors.teal.11}", _dark: "{colors.tealDark.11}" },
},
danger: {
value: { base: "{colors.red.11}", _dark: "{colors.redDark.11}" },
Expand All @@ -127,7 +127,7 @@ export const semanticColors: SemanticTokens["colors"] = {
},
DEFAULT: {
DEFAULT: {
value: { base: "{colors.gray.12}", _dark: "{colors.grayDark.12}" },
value: { base: "{colors.grayDark.12}", _dark: "{colors.gray.12}" },
},
accent: {
value: { base: "{colors.teal.12}", _dark: "{colors.violetDark.12}" },
Expand Down
Loading