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 3 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
82 changes: 82 additions & 0 deletions modules/shared/components/buttons/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { MouseEventHandler } from "react";
import { background, Button as CharkraButton } 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 props = {};

if (light) {
props = {
...props,
backgroundColor: "#FFFFFF",
color: "primary.300",
fontWeight: 600,
borderRadius: "6px",
boxSizing: "border-box",
_hover: {
background: "#EDF2F7",
},
_focus: {
background: "#E2E8F0",
mariodev9 marked this conversation as resolved.
Show resolved Hide resolved
},
_disabled: {
opacity: 0.5,
},
};
}

if (outline) {
props = {
...props,
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",
},
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Esto tambien podrias moverlo afuera del componente

  if (outline) {
    props = {
      ...props,
      ...outlineStyles
    }
  }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

listo!

}

if (disabled) {
props = {
...props,
_hover: {},
_focus: {},
};
}

const sizeProps = {
sm: { padding: "10px 12px", gap: "8px", height: "40px" },
md: { padding: "10px 16px", gap: "8px", height: "44px" },
lg: { padding: "10px 24px", gap: "8px", height: "48px" },
}[size];
Copy link
Collaborator

Choose a reason for hiding this comment

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

este objeto podrias moverlo afuera del componente

y tendrias algo asi como:

const sizeProps = buttonSizes[size] ?? buttonSizes.md // <- esto es para tener un size por default si el size que le pasas no es correcto

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moví los estilos de size y demas css al theme


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

export default StudySessionCard;

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" }}>Normal</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;