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
Consolidate CSS stylesheets #61
Comments
@ahmaxed Not sure if it's your birthday, but this one is a surprise for you 😉 I'm tagging you for a review and inputs, but I can handle the implementation. I know it's a big wall of text, so please take your time, I'm not blocked by this issue. |
It does not have to be my birthday. I always celebrate when I see well-thought out issues like this.
Finally, this is a great blueprint for the stylesheet consolidation. At the same time, it might be helpful to evaluate how it would impact the migration. If we decide to do this before or after the migration, I am on board either way. It is a task that we need to take care of at some point. |
Thank you for going through my wall of text 😄
I had the same impression until I had to dig deeper and compare From what I gathered:
Just to clarify, by "presets", do you mean custom CSS rules and the rules would override the base Tailwind styles? I won't object that, if that's what you mean 🙂 I think there are a couple of rules that we need to set to the component library, for branding and accessibility. Off the top of my head:
Anyway, we can discuss what global styles the library should have separately. For now, I only need to confirm if I understand the idea correctly. So I'll go ahead and experiment the proposed approach. The steps would roughly be:
|
I meant normalizers by presets, and look forward to hear about your progress with the experimentation. |
(Please ignore. I'm using this comment as my notepad.) Rules to be removed from
|
*, | |
::before, | |
::after { | |
/* Override the browser default border width in order to style individual border sides | |
* Ref: https://stackoverflow.com/a/76961084 | |
*/ | |
border-width: 0; | |
} |
Lines 20 to 24 in 9698a82
/* Override Tailwind's default `-webkit-tap-highlight-color` rule. */ /* https://github.com/tailwindlabs/tailwindcss/discussions/2984 */ button { -webkit-tap-highlight-color: transparent; } - Tailwind preflight was updated and now has this rule covered: https://github.com/tailwindlabs/tailwindcss/blob/f1f419a9ecfcd00a2001ee96ab252739fca47564/src/css/preflight.css#L39
Rules to be added to base.css
- Link underline:
Lines 43 to 44 in 9698a82
/* This is required in order to improve text readability in Arabic */ text-underline-position: under;
- Focus outline:
Other notes
- We only need to define
font-family
intailwind.config.js
. Tailwind automatically specifies which element should have which fontLines 90 to 93 in 9698a82
fontFamily: { sans: ["Lato", "sans-serif"], mono: ["Hack-ZeroSlash", "monospace"], }, html
getssans
: https://github.com/tailwindlabs/tailwindcss/blob/f1f419a9ecfcd00a2001ee96ab252739fca47564/src/css/preflight.css#L36code
,kbd
,samp
, andpre
getmono
: https://github.com/tailwindlabs/tailwindcss/blob/f1f419a9ecfcd00a2001ee96ab252739fca47564/src/css/preflight.css#L115
- Heading elements should not have font size specified in
base.css
, as each component may have its heading in different size (Modal
is an example).- For now, we should just set the font size on the component level.
- In the future, we might want to have text components (
Title
,Subtitle
,Caption
, etc.), each has a fixed font size and accepts anas
prop that allows changing the heading level.// Pseudo code <Caption as="h1" />
- The custom
.sr-only
styles can be removed as Tailwind already supports this class
This ticket is semi-related to freeCodeCamp/freeCodeCamp#52030.
In order to replace Bootstrap in /learn, we need to export a stylesheet from the component library to be used as the
bootstrap.min.css
replacement. However, the stylesheet situation in the component library itself needs to be sorted out, and this ticket is to track this work.Current problem
The library currently has multiple stylesheets. Their purposes aren't clear, they have many similar CSS rules and some of the CSS rules don't match, which could cause styling issue if the import order changes.
The stylesheets are:
ui/src/global-element-styles.css
Lines 1 to 3 in 3886b61
Observation:
colors.css
, the stylesheets overlap each other:ui/src/base.css
Lines 16 to 18 in 3886b61
ui/src/global-element-styles.css
Lines 397 to 400 in 3886b61
ui/src/normalize.css
Lines 40 to 42 in 3886b61
ui/src/normalize.css
Lines 61 to 64 in 3886b61
ui/src/global-element-styles.css
Lines 150 to 155 in 3886b61
normalize.css
is supposed to match the original https://necolas.github.io/normalize.css/3.0.3/normalize.css, but I found some discrepancies: POC: try restoring normalize.css to the original huyenltnguyen/freeCodeCamp-ui#1normalize.css
. However, we turned this option off in favor of our custom stylesheets (global-element-styles.css
andnormalize.css
)ui/tailwind.config.js
Line 6 in 1e3252f
global-element-styles.css
andnormalize.css
in because we wanted to mimic the /learn environment in Storybook, in order to develop components for /learnui/.storybook/preview.js
Lines 1 to 5 in 3886b61
global-element-styles.css
andnormalize.css
,global-element-styles.css
will take precedence.colors.css
andbase.css
are bundledui/src/base.css
Line 1 in 3886b61
ui/package.json
Line 32 in 4dfc72e
What we want to achieve
For the component library itself, we want:
For the library consumers, we want:
Approaches
I think we should start developing the component library as a standalone package, rather than having /learn influence it.
So I'd propose:
global-element-styles.css
since this comes from Bootstrap, and includes a lot of CSS customization, not just resetpreflight
flag totrue
)normalize.css
and Tailwind preflight stylesheets: huyenltnguyen/freeCodeCamp-ui@f81770d
(#2)normalize.css
is the library is not actively maintained, while Tailwind is an active project and its preflight stylesheet is written upon modern-normalize, which is... more modern.normalize.css
, if we choose to use Tailwind preflightAs for the styling strategy in the component library, I think:
base.css
. As the file name suggests, the file should house very basic CSS styles, and we want to be mindful when adding changes as they will require overrides on the component level, which would bring inconsistencies.Implications for the Bootstrap removal in /learn
Given that we tried replacing the Bootstrap stylesheet with
normalize.css
and the result was positive (ref), I don't think the Tailwind preflight would cause a catastrophe./learn has a huge global.css file that has all sort of CSS rules to override Bootstrap. I think those rules would help keep the UI intact (or mostly intact) when we swap the stylesheets. (The
global.css
file also needs a round of review and cleanup as part of the Bootstrap removal, but that's a separate topic.)The text was updated successfully, but these errors were encountered: