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

Added Button Components #33

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
66 changes: 66 additions & 0 deletions frontend/src/components/Button.tsx
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

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe assignment of an `any` value

Check failure on line 19 in frontend/src/components/Button.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe member access .button on an `any` value
Copy link
Member

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
Screenshot 2024-01-20 at 7 55 45 PM. 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.


// All disabled buttons have same style, so we can ignore kind
if (disabled) {
buttonClass += ` ${styles.disabled}`;

Check failure on line 23 in frontend/src/components/Button.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe member access .disabled on an `any` value
}

// If not disabled, assign style based on kind
else {
switch (kind) {
case "secondary":
buttonClass += ` ${styles.secondary}`;

Check failure on line 30 in frontend/src/components/Button.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe member access .secondary on an `any` value
break;
case "destructive":
buttonClass += ` ${styles.destructive}`;

Check failure on line 33 in frontend/src/components/Button.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe member access .destructive on an `any` value
break;
case "destructive-secondary":
buttonClass += ` ${styles.destructiveSecondary}`;

Check failure on line 36 in frontend/src/components/Button.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe member access .destructiveSecondary on an `any` value
break;
default:
buttonClass += ` ${styles.primary}`;

Check failure on line 39 in frontend/src/components/Button.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe member access .primary on an `any` value
}
}

// button size styling depends on size
switch (size) {
case "small":
buttonClass += ` ${styles.small}`;

Check failure on line 46 in frontend/src/components/Button.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe member access .small on an `any` value
break;
default:
buttonClass += ` ${styles.default}`;

Check failure on line 49 in frontend/src/components/Button.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe member access .default on an `any` value
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}>

Check failure on line 62 in frontend/src/components/Button.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe assignment of an `any` value
{label}
</button>
);
});
39 changes: 39 additions & 0 deletions frontend/src/components/TagButton.tsx
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>
);
});
7 changes: 7 additions & 0 deletions frontend/src/pages/_app.tsx
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} />;
}
75 changes: 75 additions & 0 deletions frontend/src/styles/Button.module.css
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%);
}
28 changes: 28 additions & 0 deletions frontend/src/styles/TagButton.module.css
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;
}
9 changes: 9 additions & 0 deletions frontend/src/styles/globals.css
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;
}