-
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
Added Button Components #33
Merged
+239
−0
Merged
Changes from 1 commit
Commits
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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Poppins } from "next/font/google"; | ||
import React from "react"; | ||
|
||
import styles from "../styles/Button.module.css"; | ||
|
||
const poppins = Poppins({ weight: "400", style: "normal", subsets: [] }); | ||
|
||
export type ButtonProps = { | ||
label: string; | ||
kind?: "primary" | "secondary" | "destructive" | "destructive-secondary"; | ||
size?: "default" | "small"; | ||
disabled?: boolean; | ||
} & React.ComponentProps<"button">; | ||
|
||
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Button( | ||
{ label, kind = "primary", size = "default", disabled = false, className, ...props }: ButtonProps, | ||
ref, | ||
) { | ||
let buttonClass = styles.button; | ||
Check failure on line 19 in frontend/src/components/Button.tsx GitHub Actions / Frontend lint and style check
|
||
|
||
// All disabled buttons have same style, so we can ignore kind | ||
if (disabled) { | ||
buttonClass += ` ${styles.disabled}`; | ||
} | ||
|
||
// If not disabled, assign style based on kind | ||
else { | ||
switch (kind) { | ||
case "secondary": | ||
buttonClass += ` ${styles.secondary}`; | ||
break; | ||
case "destructive": | ||
buttonClass += ` ${styles.destructive}`; | ||
break; | ||
case "destructive-secondary": | ||
buttonClass += ` ${styles.destructiveSecondary}`; | ||
break; | ||
default: | ||
buttonClass += ` ${styles.primary}`; | ||
} | ||
} | ||
|
||
// button size styling depends on size | ||
switch (size) { | ||
case "small": | ||
buttonClass += ` ${styles.small}`; | ||
break; | ||
default: | ||
buttonClass += ` ${styles.default}`; | ||
break; | ||
} | ||
|
||
// Lets developers apply their own styling | ||
if (className) { | ||
buttonClass += ` ${className}`; | ||
} | ||
|
||
// Set font to poppins | ||
buttonClass += ` ${poppins.className}`; | ||
|
||
return ( | ||
<button ref={ref} className={buttonClass} {...props}> | ||
{label} | ||
</button> | ||
); | ||
}); |
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,39 @@ | ||
import { Poppins } from "next/font/google"; | ||
import React from "react"; | ||
|
||
import styles from "../styles/TagButton.module.css"; | ||
|
||
const poppins = Poppins({ weight: "400", style: "normal", subsets: [] }); | ||
|
||
export type TagButtonProps = { | ||
label: string; | ||
disabled?: boolean; | ||
} & React.ComponentProps<"button">; | ||
|
||
export const TagButton = React.forwardRef<HTMLButtonElement, TagButtonProps>(function TagButton( | ||
{ label, disabled = false, className, ...props }: TagButtonProps, | ||
ref, | ||
) { | ||
let buttonClass = styles.button; | ||
|
||
// disabled buttons have different styling | ||
if (disabled) { | ||
buttonClass += ` ${styles.disabled}`; | ||
} else { | ||
buttonClass += ` ${styles.tagButton}`; | ||
} | ||
|
||
// Lets developers apply their own styling | ||
if (className) { | ||
buttonClass += ` ${className}`; | ||
} | ||
|
||
// Set font to Poppins | ||
buttonClass += ` ${poppins.className}`; | ||
|
||
return ( | ||
<button ref={ref} disabled={disabled} className={buttonClass} {...props}> | ||
{label} | ||
</button> | ||
); | ||
}); |
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,7 @@ | ||
import "../styles/globals.css"; | ||
|
||
import { AppProps } from "next/app"; | ||
|
||
export default function MyApp({ Component, pageProps }: AppProps<object>) { | ||
return <Component {...pageProps} />; | ||
} |
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,75 @@ | ||
.button { | ||
width: auto; | ||
border-radius: 0.25rem; | ||
cursor: pointer; | ||
letter-spacing: 2%; | ||
line-height: 150%; | ||
font-size: 16px; | ||
} | ||
|
||
/* styling for default size */ | ||
.default { | ||
height: 3rem; | ||
padding-left: 1.5rem; | ||
padding-right: 1.5rem; | ||
} | ||
|
||
.small { | ||
height: 2.5rem; | ||
padding-left: 1rem; | ||
padding-right: 1rem; | ||
} | ||
|
||
.disabled { | ||
background-color: rgb(var(--gray-2)); | ||
color: rgb(--var(white)); | ||
border: none; | ||
} | ||
|
||
.primary { | ||
background-color: rgb(var(--primary-dark-green)); | ||
color: rgb(var(--white)); | ||
border: none; | ||
} | ||
.primary:hover { | ||
background-color: rgba(var(--primary-dark-green), 80%); | ||
} | ||
.primary:active { | ||
background-color: rgba(var(--primary-dark-green), 88%); | ||
} | ||
|
||
.secondary { | ||
background-color: rgb(var(--white)); | ||
color: rgb(var(--primary-dark-green)); | ||
border: 0.0625rem solid rgb(var(--primary-dark-green)); | ||
} | ||
.secondary:hover { | ||
background-color: rgba(var(--primary-dark-green), 22%); | ||
} | ||
.secondary:active { | ||
background-color: rgba(var(--primary-dark-green), 20%); | ||
} | ||
|
||
.destructive { | ||
background-color: rgb(var(--error-red)); | ||
color: rgb(var(--white)); | ||
border: none; | ||
} | ||
.destructive:hover { | ||
background-color: rgba(var(--error-red), 88%); | ||
} | ||
.destructive:active { | ||
background-color: rgba(var(--error-red), 92%); | ||
} | ||
|
||
.destructiveSecondary { | ||
background-color: rgb(var(--white)); | ||
color: rgb(var(--error-red)); | ||
border: 0.0625rem solid rgb(var(--error-red)); | ||
} | ||
.destructiveSecondary:hover { | ||
background-color: rgba(var(--error-red), 22%); | ||
} | ||
.destructiveSecondary:active { | ||
background-color: rgba(var(--error-red), 20%); | ||
} |
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,28 @@ | ||
.button { | ||
width: auto; | ||
height: 2.5rem; | ||
padding-left: 1rem; | ||
padding-right: 1rem; | ||
border-radius: 4rem; | ||
cursor: pointer; | ||
letter-spacing: 2%; | ||
line-height: 150%; | ||
font-size: 16px; | ||
} | ||
|
||
.tagButton { | ||
border: 1px solid rgb(var(--black)); | ||
background-color: rgb(var(--white)); | ||
} | ||
.tagButton:hover { | ||
background-color: rgba(var(--white), 22%); | ||
} | ||
.tagButton:active { | ||
background-color: rgba(var(--white), 20%); | ||
} | ||
|
||
.disabled { | ||
background-color: rgb(var(--gray-2)); | ||
color: rgb(var(--white)); | ||
border: none; | ||
} |
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,9 @@ | ||
:root { | ||
--primary-light-green: 238, 247, 247; | ||
--primary-dark-green: 0, 104, 103; | ||
--primary-text: 32, 33, 36; | ||
--white: 255, 255, 255; | ||
--error-red: 185, 59, 69; | ||
--gray-2: 216, 216, 216; | ||
--black: 0, 0, 0; | ||
} |
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.
We're getting this error because styles is some any type by default. Here is a hacky solution that you could try
. Basically we just need to create a ButtonStyles type and then import the styles as that type (see const buttonStyles). I tested it and it shouldn't break the functionality of the button component. Go ahead and give this a try and see if the github action check passes.