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

feat: add Spacer component #248

Merged
merged 2 commits into from
Jul 24, 2024

Conversation

huyenltnguyen
Copy link
Member

Checklist:

This PR adds a new Spacer component to the library.

This component will be a replacement for https://github.com/freeCodeCamp/freeCodeCamp/blob/main/client/src/components/helpers/spacer.tsx.

Screenshot

Screenshot 2024-07-24 at 03 17 52

Comment on lines +6 to +15
/**
* Sizes:
* - xxs: 5px
* - xs: 10px
* - s: 20px
* - m: 30px
* - l: 60px
* - xl: 90px
* - xxl: 180px
*/
Copy link
Member Author

Choose a reason for hiding this comment

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

I thought the annotation would save devs a trip to the component docs / implementation to look up the value.

Screenshot 2024-07-24 at 03 16 40

// NOTE: Do not construct class names dynamically
// https://tailwindcss.com/docs/content-configuration#classes-arent-generated
if (size === "xxs") {
cls = "h-[5px]";
Copy link
Member Author

Choose a reason for hiding this comment

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

The Spacer in /learn is a div with top and bottom paddings, and the padding values are just the padding on one side.

If we have:

<Spacer size="medium" />

It will be a div with 15px of padding on the top and bottom, so the total height will be 30px.


This is too much math for me, so with the new component, I changed the height value instead. I also went ahead and used t-shirt sizes for size.

Name/value mapping:

/learn Spacer fcc/ui Spacer
xxSmall - 2.5px xxs - 5px
small - 5px xs - 10px
xSmall - 10px s - 20px
medium - 15px m - 30px
large - 30px l - 60px
exLarge - 45px xl - 90px
doubleXL - 90px xxl - 180px

@huyenltnguyen huyenltnguyen marked this pull request as ready for review July 23, 2024 20:44
@huyenltnguyen huyenltnguyen requested a review from a team as a code owner July 23, 2024 20:44

type Size = "xxs" | "xs" | "s" | "m" | "l" | "xl" | "xxl";

interface SpacerProps {
Copy link
Member Author

Choose a reason for hiding this comment

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

The /learn Spacer accepts children, which was needed to account for a section on the profile page (freeCodeCamp/freeCodeCamp#49828). The rendering logic of the page has changed and I'm not seeing this kind of usage anywhere in /learn, so I'm not including this feature in the new version.

IMHO, I don't think Spacer should accept any children. As the name implies, it should just be a simple block or gap. Anything fancier should be handled by a layout component (#13).

Copy link
Contributor

@ojeytonwilliams ojeytonwilliams left a comment

Choose a reason for hiding this comment

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

LGTM as is, but I think the code reads a bit better if we refactor the if-else chain:

src/spacer/spacer.tsx Outdated Show resolved Hide resolved
src/spacer/spacer.tsx Outdated Show resolved Hide resolved
src/spacer/spacer.tsx Outdated Show resolved Hide resolved
Co-authored-by: Oliver Eyton-Williams <[email protected]>
@huyenltnguyen huyenltnguyen merged commit a79b03e into freeCodeCamp:main Jul 24, 2024
7 checks passed
@huyenltnguyen huyenltnguyen deleted the feat/spacer branch July 24, 2024 18:01
@huyenltnguyen huyenltnguyen mentioned this pull request Aug 8, 2024
2 tasks
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.

2 participants