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

chore: Responsive Card Section button on cards (WEB-15) #27

Merged
merged 12 commits into from
Mar 16, 2024

Conversation

joshuaow91
Copy link
Contributor

No description provided.

@braydoncoyer
Copy link
Contributor

@joshuaow91

Thoughts on turning these into a reusable button component? This approach would offer several benefits:

  1. Enables creating specific tests for the button.
  2. Keeps styles confined to the button rather than the card component.

@braydoncoyer
Copy link
Contributor

Does this code change include the arrow next to the button itself?

buttonText: string;
}

export default function CtaButton({ href, buttonText }: CtaButtonProps) {
Copy link
Contributor

@braydoncoyer braydoncoyer Mar 9, 2024

Choose a reason for hiding this comment

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

nit: We could potentially give this component a more generic name so that it can be used for various functions in the future. As is, the Figma file only shows primary buttons, but I assume that we may have different variants in the future (non-CTA) and scoping buttons to scenarios may be overkill.

Additionally, to make it more reusable, consider simply presenting the buttonText and optional (maybe, ask Danny) icon and allowing the consumer of this component to handle what happens on click (notice the onClick callback prop below).

Perhaps something like this?

export type ButtonVariant = "primary"; // To be extended later on when design calls for additional variants

export interface ButtonProps {
  buttonText: string;
  variant?: ButtonVariant;
  onClick: () => void;
  showIcon?: boolean;
}

export default function Button({
  buttonText,
  onClick,
  variant = "primary",
  showIcon,
}: ButtonProps) {
  const buttonClass = variant === "primary" ? styles["button--primary"] : "";

  return (
    <button className={`${styles.button} ${buttonClass}`} onClick={onClick}>
      {buttonText}
      {showIcon ? <span className={styles.button__icon}> ARROW ICON GOES HERE ></span> : null}
    </button>
  );
}

Leaving this feedback as a nit because I can see the argument of creating another ticket to refactor this to a more generic button component. :)

Copy link
Contributor Author

@joshuaow91 joshuaow91 Mar 9, 2024

Choose a reason for hiding this comment

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

This is great feedback, i'll implement this!

@braydoncoyer
Copy link
Contributor

Should we create a test file for the new button component and include some basic tests?

@joshuaow91
Copy link
Contributor Author

button extracted into reusable component, test file also there

@@ -35,6 +58,9 @@ export default function CardsSection({ label }: CardsSectionProps) {
<Card key={card.id}>
<header className={styles.cardHeader}>{card.title}</header>
<p className={styles.cardContent}>{card.content}</p>
<Link href={card.href} passHref>
<Button buttonText={card.buttonText} showIcon={true} />
Copy link
Contributor

Choose a reason for hiding this comment

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

nit and non-blocking: Instead of explicitly setting showIcon={true}, we can simply use showIcon as a prop, and it will be considered true by default.

@@ -0,0 +1,21 @@
.button--primary {
background-color: #3c3db9;
width: 200px;
Copy link
Contributor

Choose a reason for hiding this comment

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

If a max-width isn't needed, consider letting the button adjust its size based on the text from the component prop. This can be done by setting appropriate padding, rather than an explicit width here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is my usual approach but with tailwind, i was following the guidelines in the original issue. I agree though, i'll make this change!

}

.button__icon {
padding: 0 0 0 5px;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're justing using left padding here, consider removing the shorthand and using padding-left: 5px.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no problem, thank you

test('has a class when variant is primary', () => {
render(<Button buttonText='Primary Button' variant='primary' />);
const buttonElement = screen.getByText(/primary button/i);
expect(buttonElement).toHaveAttribute('class');
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this test is actually doing what you think it may be doing. Whether the primary variable is applied or not, this button element will also have a class applied to it, correct? This test may be giving you a false-positive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure if this was even the correct approach. Also wasn't sure how to make this more flexible and dynamic if at even possible, otherwise wouldn't it require a separate test for each variant?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would need a new test for each variant - generally, though, that's not a bad thing. I think it provides value to know if a specific variant suddenly fails or breaks. Buttons typically have 2-3 variants. Adding a couple of extra tests to our testing suite is manageable imho!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this appropriate? it's telling me it can't find the class

test('has the correct class when variant is primary', () => { render(<Button buttonText='Primary Button' variant='primary' />); const buttonElement = screen.getByText(/primary button/i); expect(buttonElement).toHaveClass(styles['button--primary']); });

…ns for padding, replaced shorthand for padding (WEB-15)
@joshuaow91
Copy link
Contributor Author

Having trouble getting the tests to mock / pick up the import styles in the test file. used a snapshot test for the primary button

@TheDThompsonDev TheDThompsonDev merged commit 37c3d1d into dallassoftwaredevelopers:main Mar 16, 2024
4 checks passed
@joshuaow91 joshuaow91 deleted the WEB-15 branch March 16, 2024 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants