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

[MAIN][FEATURE] Button Component #108

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions modules/shared/components/buttons/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { MouseEventHandler } from "react";
import { background, Button as CharkraButton, useMultiStyleConfig } from "@chakra-ui/react";

interface ButtonProps {
size: string;
light?: boolean;
outline?: boolean;
disabled?: boolean;
onClick?: MouseEventHandler;
children: React.ReactNode;
}

export default function Button({
size = "md",
light,
outline,
disabled,
onClick,
children,
}: ButtonProps) {
let variant = light ? "light" : "primary";
let styles = useMultiStyleConfig("Button", { size, variant });

if (outline) {
variant = "outlined";
const outlinedStyles = useMultiStyleConfig("Button", { size, variant });
styles = {
...styles,
...outlinedStyles,
};
}

return (
<CharkraButton onClick={onClick} disabled={disabled} __css={styles}>
{children}
</CharkraButton>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,3 @@ function StudySessionCard({
}

export default StudySessionCard;

39 changes: 38 additions & 1 deletion modules/shared/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,23 @@ const colors: CustomColors = {
const components: Theme["components"] = {
Button: {
baseStyle: {
height: "auto",
width: "auto",
},
sizes: {
sm: {
padding: "6px 12px",
gap: "8px",
height: "40px",
},
md: {
padding: "8px 16px",
gap: "8px",
height: "44px",
},
lg: {
padding: "10px 24px",
gap: "8px",
height: "48px",
},
},
variants: {
Expand All @@ -65,6 +70,38 @@ const components: Theme["components"] = {
backgroundColor: "disabled.primary !important",
},
},
outlined: {
border: "1px solid #E2E8F0",
boxShadow: "0px 1px 3px rgba(0, 0, 0, 0.1), 0px 1px 2px rgba(0, 0, 0, 0.06)",
_hover: {
background: "#EDF2F7",
border: "1px solid #CFD3DC",
},
_focus: {
background: "#E2E8F0",
border: "1px solid #CFD3DC",
},
_disabled: {
opacity: 0.5,
border: "1px solid #CFD3DC",
},
},
light: {
backgroundColor: "#FFFFFF",
color: "primary.300",
fontWeight: 600,
borderRadius: "6px",
boxSizing: "border-box",
_hover: {
background: "#EDF2F7",
},
_focus: {
background: "#E2E8F0",
},
_disabled: {
opacity: 0.5,
},
},
},
defaultProps: {
variant: "primary",
Expand Down
95 changes: 95 additions & 0 deletions pages/demo/buttons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import type { NextPage } from "next";

import Button from "@/modules/shared/components/buttons/button";
import { Container, Stack } from "@chakra-ui/react";

const ButtonsDemo: NextPage = () => {
const clickHandler = () => {
Comment on lines +1 to +7
Copy link
Collaborator

Choose a reason for hiding this comment

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

Buena idea esta pagina!

alert("Click");
};

return (
<Container maxW="6xl" style={{ marginTop: 40 }}>
<Stack gap={10}>
<h1 style={{ fontWeight: 600, fontSize: 20, textAlign: "center" }}>Buttons Demo</h1>

<Stack gap={2}>
<p style={{ borderBottom: "1px solid #eee" }}>Primary</p>
<Stack gap={2} direction="row">
<Button onClick={clickHandler} size="sm">
Button
</Button>
<Button onClick={clickHandler} size="md">
Button
</Button>
<Button onClick={clickHandler} size="lg">
Button
</Button>
</Stack>
</Stack>

<Stack gap={2}>
<p style={{ borderBottom: "1px solid #eee" }}>Light</p>
<Stack gap={2} direction="row">
<Button onClick={clickHandler} light size="sm">
Button
</Button>
<Button onClick={clickHandler} light size="md">
Button
</Button>
<Button onClick={clickHandler} light size="lg">
Button
</Button>
</Stack>
</Stack>

<Stack gap={2}>
<p style={{ borderBottom: "1px solid #eee" }}>Light Outlined</p>
<Stack gap={2} direction="row">
<Button onClick={clickHandler} light outline size="sm">
Button
</Button>
<Button onClick={clickHandler} light outline size="md">
Button
</Button>
<Button onClick={clickHandler} light outline size="lg">
Button
</Button>
</Stack>
</Stack>

<Stack gap={2}>
<p style={{ borderBottom: "1px solid #eee" }}>Light Disabled</p>
<Stack gap={2} direction="row">
<Button onClick={clickHandler} light disabled size="sm">
Button
</Button>
<Button onClick={clickHandler} light disabled size="md">
Button
</Button>
<Button onClick={clickHandler} light disabled size="lg">
Button
</Button>
</Stack>
</Stack>

<Stack gap={2}>
<p style={{ borderBottom: "1px solid #eee" }}>Light Outlined Disabled</p>
<Stack gap={2} direction="row">
<Button onClick={clickHandler} light disabled outline size="sm">
Button
</Button>
<Button onClick={clickHandler} light disabled outline size="md">
Button
</Button>
<Button onClick={clickHandler} light disabled outline size="lg">
Button
</Button>
</Stack>
</Stack>
</Stack>
</Container>
);
};

export default ButtonsDemo;