-
Notifications
You must be signed in to change notification settings - Fork 37
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
chore: Responsive Card Section button on cards (WEB-15) #27
Conversation
Thoughts on turning these into a reusable button component? This approach would offer several benefits:
|
Does this code change include the arrow next to the button itself? |
buttonText: string; | ||
} | ||
|
||
export default function CtaButton({ href, buttonText }: CtaButtonProps) { |
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.
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. :)
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.
This is great feedback, i'll implement this!
Should we create a test file for the new button component and include some basic tests? |
…thin labelmap. removed boolean logic and used external link within Link, switched from using white to the hex value (WEB-15)
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} /> |
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.
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; |
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.
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.
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.
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; |
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.
If we're justing using left padding here, consider removing the shorthand and using padding-left: 5px
.
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.
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'); |
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.
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.
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.
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?
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.
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!
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.
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)
Having trouble getting the tests to mock / pick up the import styles in the test file. used a snapshot test for the primary button |
37c3d1d
into
dallassoftwaredevelopers:main
No description provided.