Skip to content

feat(ui-components): add support for link to Button component - #45671

Merged
ahmaxed merged 8 commits into
freeCodeCamp:mainfrom
huyenltnguyen:feat/link-button
Apr 25, 2022
Merged

ahmaxed merged 8 commits into
freeCodeCamp:mainfrom
huyenltnguyen:feat/link-button

Conversation

@huyenltnguyen

Copy link
Copy Markdown
Member

Checklist:

  • I have read freeCodeCamp's contribution guidelines.
  • My pull request has a descriptive title (not a vague title like Update index.md)
  • My pull request targets the main branch of freeCodeCamp.
  • I have tested these changes either locally on my machine, or GitPod.

Closes #45357.

This PR:

Note: I mentioned the ButtonGroup component in the issue for completeness, but since there isn't a use case for it yet, I think we can ignore it for now.

Screenshots

link-button

@gitpod-io

gitpod-io Bot commented Apr 11, 2022

Copy link
Copy Markdown

@github-actions github-actions Bot added the scope: tools/scripts Scripts for supporting dev work, generating config and build artifacts, etc. label Apr 11, 2022
@ghost

ghost commented Apr 11, 2022 •

Copy link
Copy Markdown

👀 Review this PR in a CodeSee Review Map

Preview the Review Map

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

Comment on lines +169 to +173
if (to) {
return renderLink();
} else {
return renderButton();
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The rendering logic here is a bit complicated in order to make our component semantically correct:

  • If the to prop is defined, we render an a element
  • If both to and disabled are defined, we render a button element because a link cannot be disabled
  • If the to prop is not defined, we render a button element

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As a matter of curiosity, when would there be both a to and disabled?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hopefully, never :), just in case we pass both by mistake the element would just return a button element.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yup. This is me being paranoid. There should never be a case where both to and disabled are passed in.

I believe we can enforce this rule with TypeScript using union types, but the typing ended up a bit crazy in my initial attempt, so I decided to just keep the interface as-is and silently handle invalid use case for now.

@huyenltnguyen huyenltnguyen added the status: blocked In a transient & temporary hold. label Apr 11, 2022
@huyenltnguyen huyenltnguyen mentioned this pull request Apr 11, 2022
4 of 10 tasks
@ahmaxed

ahmaxed commented Apr 18, 2022

Copy link
Copy Markdown
Member

So this should be a button that looks like a link. I know it does not follow the best practices, so I will prioritize a/b testing an alternative as soon as we ship our component library.

Finally, we would need to add onClick as an action in argTypes in a separate pr perhaps. That insures all props are documented.
https://storybook.js.org/docs/react/essentials/actions

@huyenltnguyen

Copy link
Copy Markdown
Member Author

So this should be a button that looks like a link.

This one is a link that looks like a button actually 😅 It will be used for the Download your data "button" on the Settings page.

The rendering approach I'm following is to make our Button behave similar to the Bootstrap one, in that it can be a real <button> but also can accept an URL and behave like a link. The rendering logic here is a bit complicated because we need to check for the to prop to render the appropriate HTML element.

What alternative do you have in mind?

@huyenltnguyen
huyenltnguyen marked this pull request as ready for review April 18, 2022 16:01
@huyenltnguyen
huyenltnguyen requested a review from a team April 18, 2022 16:01
@huyenltnguyen huyenltnguyen removed the status: blocked In a transient & temporary hold. label Apr 18, 2022
@raisedadead raisedadead added the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Apr 19, 2022
@ahmaxed ahmaxed self-assigned this Apr 22, 2022
@ahmaxed

ahmaxed commented Apr 22, 2022 •

Copy link
Copy Markdown
Member

@huyenltnguyen, my bad. I thought you were working on the Link variation described in #45357.

The logic makes sense. It seems more intuitive to me to ignore the disable prop and return a link when href prop is provided, but feel free to ignore this suggestion if the current logic makes more sense to you.

The only nitpick is that the text does not center for the button styled link when the block prop is passed.

Finally, we would need to get the link styled button before closing this issue.
We would probably need to name these two variations in a way so that they are distinguishable.

@ahmaxed ahmaxed added status: waiting update Is awaiting update, after feedback or request for changes and removed status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. labels Apr 22, 2022
@huyenltnguyen

Copy link
Copy Markdown
Member Author

Oh @ahmadabdolsaheb, guess what, I thought I posted this in the issue thread, but I realized that I have not.

Regarding the link styled thing, I was wondering if it would be more appropriate as a Link component with the block prop instead. I reckon that it would be less confusing that way, since the component is technically a link, and its styling is a bit different from a block button.

@ahmaxed
ahmaxed merged commit 86935fa into freeCodeCamp:main Apr 25, 2022
@huyenltnguyen
huyenltnguyen deleted the feat/link-button branch April 25, 2022 15:18
@huyenltnguyen huyenltnguyen mentioned this pull request Apr 25, 2022
37 of 49 tasks
@qasim-you

Copy link
Copy Markdown

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: tools/scripts Scripts for supporting dev work, generating config and build artifacts, etc. status: waiting update Is awaiting update, after feedback or request for changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Button component

5 participants