generated from ziyadedher/webdev-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8934de
commit c50f74c
Showing
6 changed files
with
134 additions
and
11 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import classNames from "classnames"; | ||
import React from "react"; | ||
|
||
enum ButtonStyle { | ||
PRIMARY = "bg-green-500 hover:bg-green-700 text-white border-green-500 hover:border-green-700 border-2", | ||
SECONDARY = "bg-transparent hover:bg-green-500 text-green-500 hover:text-white border-green-500 border-2", | ||
} | ||
|
||
interface ButtonProps { | ||
readonly buttonStyle: ButtonStyle; | ||
readonly onClick: () => void; | ||
readonly children: React.ReactNode; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- React.ReactNode | ||
const Button: React.FunctionComponent<ButtonProps> = ({ | ||
buttonStyle, | ||
onClick: handleClick, | ||
children, | ||
}) => ( | ||
<button | ||
type="button" | ||
onClick={handleClick} | ||
className={classNames( | ||
"font-normal py-2 px-4 rounded transition-all", | ||
buttonStyle | ||
)} | ||
> | ||
{children} | ||
</button> | ||
); | ||
|
||
export default Button; | ||
export { ButtonStyle }; |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import Button, { ButtonStyle } from "../../../src/components/buttons/button"; | ||
|
||
import type { Meta, Story } from "@storybook/react"; | ||
|
||
const META: Meta = { | ||
title: "Components/Buttons/Button", | ||
component: Button, | ||
}; | ||
|
||
interface ButtonTemplateProps { | ||
readonly text: string; | ||
readonly buttonStyle: ButtonStyle; | ||
readonly onClick: () => void; | ||
} | ||
|
||
const ButtonTemplate: Story<ButtonTemplateProps> = ({ | ||
text, | ||
buttonStyle, | ||
onClick: handleClick, | ||
}: ButtonTemplateProps) => ( | ||
<Button buttonStyle={buttonStyle} onClick={handleClick}> | ||
{text} | ||
</Button> | ||
); | ||
|
||
const ButtonStory = ButtonTemplate.bind({}); | ||
ButtonStory.storyName = "Button"; | ||
ButtonStory.args = { | ||
text: "Submit!", | ||
buttonStyle: ButtonStyle.PRIMARY, | ||
}; | ||
ButtonStory.argTypes = { | ||
buttonStyle: { | ||
options: Object.values(ButtonStyle), | ||
control: { type: "select" }, | ||
}, | ||
onClick: { action: "clicked" }, | ||
}; | ||
|
||
export { ButtonStory }; | ||
export default META; |