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(ui): add ui-components package #7223

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

RedYetiDev
Copy link
Member

@RedYetiDev RedYetiDev commented Nov 13, 2024

This PR moves the first few components into the ui-components package.

For now, only the Icons/ folder has been moved, as it's quite simple to move (unlike some other components), and it gives a good basis of what this package will look like.

Over coming PRs, I'll slowly move more pieces into this package.

Copy link

vercel bot commented Nov 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nodejs-org ✅ Ready (Inspect) Visit Preview Nov 23, 2024 1:40am

@RedYetiDev
Copy link
Member Author

Any idea why Vercel is failing?

@AugustinMauroy
Copy link
Member

Maybe create a package stories ?

@AugustinMauroy
Copy link
Member

Any idea why Vercel is failing?

cc @ovflowd and @bmuenzenmeyer

@RedYetiDev RedYetiDev marked this pull request as draft November 14, 2024 23:33
@RedYetiDev
Copy link
Member Author

RedYetiDev commented Nov 14, 2024

FYI I'm drafting until the Next.js update is done.

Feel free to review, this just can't land until that does (given that it modifies the package-lock.json files along with other configuration/storybook files, which is also being done by that more important upgrade).

@RedYetiDev
Copy link
Member Author

Hey, can someone let me know why Vercel is failing?

import {
STORYBOOK_MODES,
STORYBOOK_SIZES,
} from '../../../.storybook/constants';
Copy link
Member

@ovflowd ovflowd Nov 17, 2024

Choose a reason for hiding this comment

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

FYI Storybook should exist only within the UI components package :) -- not within the root of the repository.

Copy link
Member Author

Choose a reason for hiding this comment

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

Storybook is in use in both the UI components, and the app/site. To prevent duplicate code, I moved it to the repo root (like Tailwind), what do you have in mind?

Copy link
Member

Choose a reason for hiding this comment

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

Which components are on app/site that use Storybook? IMO, Storybook should ONLY exist for the UI components package.

Because semantically, that's what it is supposed to be used for. For describing components. I think we use it on apps/site only for visual regression, for whose I don't think they should be storybooks but just snapshots. We should probably make that change before we make this package then.

Copy link
Member

Choose a reason for hiding this comment

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

We can still use Chromatic for that: https://www.chromatic.com/features/visual-test.

IMO you can do that on this PR, decoupling stories from website-only components (which actually are combination of the base components) and simply use Cypress or Node.js or whatever for the visual regression tests with Chromatic.

Copy link
Member Author

@RedYetiDev RedYetiDev Nov 18, 2024

Choose a reason for hiding this comment

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

I agree with this overall, I just don't think that this should be done now. Currently, while only a subset of features are available in the UI package, I think it's okay to share a storybook config, as both the UI package and the apps/site package ned it. Later on, once more stuff is moved into the package, the storybook should only exist there, just not yet. Not while only the icons have been transferred.

But, in the future, this is probably the best direction to go in.

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 current Storybook configuration in /apps/site differs from the one in packages/ui-components because the ui-components package doesn't rely on Next.js internally. If we were to move the Storybook setup into ui-components now, we'd have to introduce Next.js dependencies, as the configuration in apps/site depends on Next.js internals. The goal of this package is to not have Next.js dependencies.

A more effective approach IMO would be to gradually migrate components to the packages/ui-components package while removing Next.js-related elements from their Storybook configurations. Once all configurations are free of Next.js and consolidated in packages/ui-components, transferring the entire Storybook setup to this package will be much smoother.

By "Next.js-free," I mean the removal of dependencies like next-intl, Link, and similar Next.js-specific elements.

Copy link
Member

Choose a reason for hiding this comment

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

The current Storybook configuration in /apps/site differs from the one in packages/ui-components because the ui-components package doesn't rely on Next.js internally.

That doesn't make sense. The current Storybook configuration is Next.js-agnostic.

Copy link
Member

Choose a reason for hiding this comment

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

If we were to move the Storybook setup into ui-components now, we'd have to introduce Next.js dependencies, as the configuration in apps/site depends on Next.js internals. The goal of this package is to not have Next.js dependencies.

Could you elaborate where you saw that? I'm pretty sure it is not.

Copy link
Member

Choose a reason for hiding this comment

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

By "Next.js-free," I mean the removal of dependencies like next-intl, Link, and similar Next.js-specific elements.

You do know these lines are to "mock" components that use such dependencies, and that the ui-components library does not use these said dependencies, since the Link component for example, will now use Dependency Injection... Also, the Storybook should only exist for UI components, meaning there is nothing Next.js specific; I'm not sure where the confusion is here.

Sorry, but I'm adamant that Storybook should only be for ui-components, I won't approve this PR without that :/

Copy link
Member

Choose a reason for hiding this comment

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

A more effective approach IMO would be to gradually migrate components to the packages/ui-components package while removing Next.js-related elements from their Storybook configurations. Once all configurations are free of Next.js and consolidated in packages/ui-components, transferring the entire Storybook setup to this package will be much smoother.

I don't think we need a gradative migration on the main branch; as mentioned before, nothing stops you from making a feature branch and gradatively migrating the components; there's no rush to getting this done, and I doubt that conflicts will arise over time...

I'll defer to the rest of the @nodejs/nodejs-website if they are fine with merging this, as it will complicate things further with two different Storybooks.

I only want that we have a dedicated Storybook for UI components and that's it; No other Storybook, not mess needed. I won't block this PR, but I'm expressing my discontent.

require('@tailwindcss/container-queries'),
],
} satisfies Config;
export { default } from '../../tailwind.config';
Copy link
Member

Choose a reason for hiding this comment

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

IMO tailwind config should be part of the UI components package as a base tailwind config and we should be able to import it on the Website package.

Copy link
Member

Choose a reason for hiding this comment

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

This also means that font loading should be done within the UI components package instead on Next.js-side.

Meaning, we should stop using next-fonts and use something that is pure react-ish and that can integrate natively with Tailwind.

Copy link
Member

Choose a reason for hiding this comment

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

Meaning this package (ui-components) should also export a base CSS file that is something like:

/* global.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

/* update this to use the two fonts we use */
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500&display=swap");

Copy link
Member

Choose a reason for hiding this comment

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

Wow, I'm not a fan of what you're proposing. Why does next-font exist, it's to prevent the user of the page from depending on google. but if we do what you suggest that's what's going to happen. Our user will have to go through google. We would therefore need to add a file download system to the building time. To note that googleapis is blocked by not badly of proxy http in company or other thus this user would not have the font.

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 agree with @AugustinMauroy. It's not ideal for the users to need to fetch the font from an external source. If we really wanted to get rid of next-font, we could store the font file as an asset, but even if that was the direction we were going to do in, it should be it's own discussion, and not part of this PR (IMO).

Copy link
Member

Choose a reason for hiding this comment

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

It is important to mention that all that next-fonts does is download the font during build-time and bundle it within our assets. It still imports the font the same way with a @import url

Copy link
Member

Choose a reason for hiding this comment

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

There are a couple of issues with next-fonts and why it doesn't work for us:

  • We cannot use net-fonts in the UI components package. That package is agnostic and should only require TailwindCSS and React.
    • The fonts are essential for the UI components; without the right font families, our Storybooks and Visual Regression tests will have no meaning.
  • We shouldn't rely on Next.js to have custom fonts within our Application. next-fonts is just an easy one-liner abstraction that is nice for most simple projects, but not here.

Our user will have to go through google.

Our servers will anyway need to go through Google, and Google Fonts is also used everywhere across the internet. The chances that these fonts will already be cached by the time they need to request them from our website (at least Open Sans) reduce already the extra request they need to make to our infrastructure to load the font.

Why does next-font exist, it's to prevent the user of the page from

Just because something exists doesn't mean we need to use it.

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 misunderstood what you were initially asking. I thought you meant to get rid of next-fonts for the entire site. Now I understand that you mean only for this package. Yes, you are right, I'll update the CSS file.

Copy link
Member

Choose a reason for hiding this comment

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

I actually did mean for everything. There's no point of having next-fonts if the ui-components package already loads the fonts 🤷

Copy link
Member

Choose a reason for hiding this comment

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

Otherwise we are double loading fonts.

tailwind.config.ts Outdated Show resolved Hide resolved
Copy link
Member

@ovflowd ovflowd left a comment

Choose a reason for hiding this comment

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

I left an initial round of comments 🙏

@RedYetiDev
Copy link
Member Author

Hey @ovflowd. I've responded to some of your concerns, but I still have my reservations about the storybook / tailwind concerns, PTAL when you get a chance, thanks!

@ovflowd
Copy link
Member

ovflowd commented Nov 20, 2024

Thanks @RedYetiDev I've replied to your points ;)

@RedYetiDev
Copy link
Member Author

The deployment was successful!!

@RedYetiDev RedYetiDev marked this pull request as ready for review November 20, 2024 23:42
@ovflowd ovflowd added the github_actions:pull-request Trigger Pull Request Checks label Nov 23, 2024
@ovflowd
Copy link
Member

ovflowd commented Nov 23, 2024

@RedYetiDev maybe you're unfamiliar with the website workflows, but we add a github_actions:pull-request label to trigger our CI xD

Copy link

github-actions bot commented Nov 23, 2024

Lighthouse Results

URL Performance Accessibility Best Practices SEO Report
/en 🟠 75 🟢 100 🟢 100 🟢 91 🔗
/en/about 🟢 100 🟢 100 🟢 100 🟢 91 🔗
/en/about/previous-releases 🟢 99 🟢 100 🟢 100 🟢 92 🔗
/en/download 🟢 100 🟢 100 🟢 100 🟢 91 🔗
/en/blog 🟢 100 🟢 100 🟢 96 🟢 92 🔗

Copy link

Unit Test Coverage Report

Lines Statements Branches Functions
Coverage: 92%
90.73% (627/691) 72.44% (184/254) 94.53% (121/128)

Unit Test Report

Tests Skipped Failures Errors Time
143 0 💤 0 ❌ 0 🔥 5.616s ⏱️

@@ -0,0 +1,7 @@
@import 'https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap';
Copy link
Member

Choose a reason for hiding this comment

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

FYI don't forget to add a preconnect on the Next.js base layout.

@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
@import '../../../apps/site/styles/base.css';
Copy link
Member

Choose a reason for hiding this comment

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

It feels weired that the ui components package depends on another package's styles (the website) -- that should definitely not be the case. These styles should live here if nothing else.

Copy link
Member

Choose a reason for hiding this comment

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

(But I see this is only for storybook, so 🤷)

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