Skip to content

feat(ui-components): implement basic Button component - #45421

Merged
ahmaxed merged 3 commits into
freeCodeCamp:mainfrom
huyenltnguyen:feat/button-component
Mar 16, 2022
Merged

ahmaxed merged 3 commits into
freeCodeCamp:mainfrom
huyenltnguyen:feat/button-component

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.

Ref #45357

This PR:

Screenshot

Dark theme Light theme
Screen Shot 2022-03-12 at 14 45 25 Screen Shot 2022-03-12 at 14 45 16

@gitpod-io

gitpod-io Bot commented Mar 12, 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 Mar 12, 2022
@ghost

ghost commented Mar 12, 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

@huyenltnguyen
huyenltnguyen force-pushed the feat/button-component branch 2 times, most recently from f65bed4 to 3241bf6 Compare March 12, 2022 10:13
Comment on lines +33 to +43
switch (size) {
case 'large':
classNames.push('px-4 py-2.5 text-lg');
break;
case 'small':
classNames.push('px-2.5 py-1 text-sm');
break;
// default size is 'medium'
default:
classNames.push('px-3 py-1.5 text-md');
}

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.

px is horizontal padding, and py is vertical padding.

The values are from Tailwind padding doc:

  • {p}-1 is 4px
  • {p}-1.5 is 6px
  • {p}-2.5 is 10px
  • {p}-3 is 12px
  • {p}-4 is 16px

As for the text classes, refer to the changes I made to the tailwind.config.js file for their values.


Some values here are slightly different from those of the current button component. I have added the rationale to the issue description, under the "Spacing and typography" section, but I'm just copy-pasting it here:

The current values of font size, line height, and padding from Bootstrap seem a bit strange to me, as there are some odd numbers in there, which I think would add some challenges in scaling/positioning. Now that we switch to Tailwind, my proposal is to adopt its system and slightly adjust the styling of our component.

Size Current New
Small padding: 5px 10px
font-size: 16px
line-height: 1.5
padding: 4px 10px
font-size: 16px
line-height: 1.5
Medium padding: 6px 12px
font-size: 18px
line-height: 1.42857143
padding: 6px 12px
font-size: 18px
line-height: 1.42857143
Large padding: 10px 16px
font-size: 23px
line-height: 1.3333333
padding: 10px 16px
font-size: 24px
line-height: 1.3333333

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.

I completely agree.

@huyenltnguyen huyenltnguyen mentioned this pull request Mar 12, 2022
4 of 10 tasks
@huyenltnguyen
huyenltnguyen marked this pull request as ready for review March 12, 2022 11:02
@huyenltnguyen
huyenltnguyen requested a review from a team March 12, 2022 11:02
@ahmaxed
ahmaxed force-pushed the feat/button-component branch from 3241bf6 to 70bd3f1 Compare March 15, 2022 14:22
@ahmaxed

ahmaxed commented Mar 16, 2022

Copy link
Copy Markdown
Member

The controls need to be adjusted to show the available options for the buttons.
Screen Shot 2022-03-16 at 10 06 28 AM

[size, variant]
);

return (

@ahmaxed ahmaxed Mar 16, 2022 •

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.

Forwarding refs seem to be the best practice. React.forwardRef
Once added, we could write a test for it as well.

@ahmaxed
ahmaxed merged commit 3fc687a into freeCodeCamp:main Mar 16, 2022
@huyenltnguyen
huyenltnguyen deleted the feat/button-component branch March 20, 2022 02:49
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants