Skip to content

style(components): fix styles when only a single component is imported#14015

Merged
kodiakhq[bot] merged 13 commits into
carbon-design-system:mainfrom
tw15egan:single-component-import-fixes
Jul 6, 2023
Merged

style(components): fix styles when only a single component is imported#14015
kodiakhq[bot] merged 13 commits into
carbon-design-system:mainfrom
tw15egan:single-component-import-fixes

Conversation

@tw15egan

@tw15egan tw15egan commented Jun 15, 2023

Copy link
Copy Markdown
Contributor

Closes #14008

This ensures all component styles have the necessary imports to render correctly if only that single component is imported.

Changelog

Changed

  • Added necessary imports so the component rendered correctly in isolation (layer)
  • Ensured component-reset.reset was being applied properly so there were no padding issues when the global reset was not present
  • Reordered some style @use declarations

Testing / Reviewing

Question: Should font declarations be included in each component import? Right now it does not set IBM Plex Sans anywhere. If so, we just need to add @include font-family('sans'); right after the component-reset for each component

Test out a bunch of components by pulling this down locally, going to packages/react/.storybook/styles.scss and commenting everything out. Then, test individual components like so @use '@carbon/styles/scss/components/button'; and ensure it renders as expected. Also, there should be no visual differences when importing all styles

@netlify

netlify Bot commented Jun 15, 2023

Copy link
Copy Markdown

Deploy Preview for carbon-components-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 69279ac
🔍 Latest deploy log https://app.netlify.com/sites/carbon-components-react/deploys/64a6fe41ef896b0008c0b982
😎 Deploy Preview https://deploy-preview-14015--carbon-components-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify

netlify Bot commented Jun 15, 2023

Copy link
Copy Markdown

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 69279ac
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/64a6fe4151ad2b0008e17b25
😎 Deploy Preview https://deploy-preview-14015--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tw15egan tw15egan force-pushed the single-component-import-fixes branch from 133364f to 9991e8d Compare June 21, 2023 13:48
@tw15egan tw15egan marked this pull request as ready for review June 21, 2023 13:56
@tw15egan tw15egan requested a review from a team as a code owner June 21, 2023 13:56
@tw15egan tw15egan changed the title [WIP] style(components): fix styles when only a single component is imported style(components): fix styles when only a single component is imported Jun 21, 2023
@tw15egan tw15egan requested a review from tay1orjones June 21, 2023 14:01

@francinelucca francinelucca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested the following components:

  • Copy Button ✅
  • Button ✅
  • Datepicker ✅
  • Dropdown ✅
  • Loading ✅
  • MenuButton ✅
  • Search ✅
  • Select ✅
  • Tabs ✅
  • Breadcrumb
    I see a mismatch on the padding of the ol:
image image
  • Popover
    I see some extra spacing:
image image
  • TimePicker
    Invalid icon color is off:
image image

Also noticed the difference in font, I do feel those should carry over, or is that supposed to be set somewhere at the lop level of the application? 🤔

@tw15egan tw15egan force-pushed the single-component-import-fixes branch from 5c408aa to 3adadc5 Compare June 21, 2023 16:16
@tw15egan

Copy link
Copy Markdown
Contributor Author

@francine pushed up some fixes, namely adding the font-family declaration to the type-style declaration blocks in the type package

@tw15egan tw15egan force-pushed the single-component-import-fixes branch from 3adadc5 to fc3237c Compare June 21, 2023 16:17

@tay1orjones tay1orjones left a comment

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.

Looks good to me, I couldn't find any defects perusing the storybook for a while. Snapshots do need updated though, looks like the changes from adding the font-family and such are the root of the snapshot changes.

@tw15egan tw15egan force-pushed the single-component-import-fixes branch 2 times, most recently from df87da9 to e1b7dc9 Compare June 22, 2023 16:10

@francinelucca francinelucca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested the following:

  • Accordion ✅
  • Breadcrumb ✅
  • Multiselect ✅
  • Popover ✅
  • Slider ✅
  • StructuredList ✅
  • ContentSwitcher ✅
  • Treeview ✅
  • Modal
    I see a difference in spacing:
image image
  • TimePicker
    Warn icon is read instead of yellow
image image

Overall:
I see a difference in the text color:

Screen.Recording.2023-06-22.at.2.02.21.PM.mov

@tw15egan

Copy link
Copy Markdown
Contributor Author

@francinelucca The text change is coming from the -webkit-font-smoothing: antialiased that is applied to the body, and is inherited by all components. I'll see where it makes most sense to try and emit this to body somewhere

@tw15egan

tw15egan commented Jun 22, 2023

Copy link
Copy Markdown
Contributor Author

@francinelucca I've fixed the other issues. As far as the type issue, I've added it to our config.scss that is pulled in by each component, since it handles all of our environment tokens. This is the simplest solution, however, we could do it a few other ways but would involve either touching every single component stylesheet and importing a new utility, or adding it to the type-token definition and bloating it a bit.

It seems like adding it to config is causing other issues. I'm almost wondering if we should just expect users to do something like this:

@use '@carbon/styles/scss/type';
@use '@carbon/styles/scss/components/accordion';

@include type.reset();

and this would pull in all of the font families as well and would reduce a lot of the changes here. What do you think?

@tw15egan tw15egan force-pushed the single-component-import-fixes branch from 72abd60 to 6fa5668 Compare June 23, 2023 15:21
@tw15egan tw15egan requested a review from francinelucca June 23, 2023 15:24
@tw15egan

tw15egan commented Jun 23, 2023

Copy link
Copy Markdown
Contributor Author

Reverted all type package changes, if a user is expecting to use Carbon type/fonts they would need to also pull in @carbon/styles/scss/type

@tay1orjones

Copy link
Copy Markdown
Member

if a user is expecting to use Carbon type/fonts they would need to also pull in @carbon/styles/scss/type

@tw15egan That's probably going to be the default expectation by and large from everyone, right? I think we need to heavily document this in the repo (@carbon/react readme, @carbon/styles readme, v11.md changelog, etc) and the website.

Is this isolated to only use-cases where component styles are brought in individually? Consumers won't need to do this if they just @use @carbon/styles?

@tw15egan

Copy link
Copy Markdown
Contributor Author

@tay1orjones correct, if you pull in @carbon/styles, you get it all. This is only if you pull in individual component styles, you'd also need to make sure you are pulling in our type package.

@tay1orjones

Copy link
Copy Markdown
Member

@tw15egan That makes sense 👍

If they @include type.reset(); across multiple files, it'll still result in duplication in the final stylesheet, right? Do we need to create a new module that automatically emits the type reset via an @include so the sass module system would prevent that duplication and only emit it once?

@tw15egan

Copy link
Copy Markdown
Contributor Author

I hadn't thought about that, I would assume the type.reset() would only be used once on the main scss file, as it just sets global styles that are inherited down

@francinelucca francinelucca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Confirmed previously reported issues have been fixed
Confirmed can correctly pull in types using @use '@carbon/styles/scss/type' as type; and @include type.reset();

Approving pending Taylor's docs comments

@tay1orjones tay1orjones mentioned this pull request Jul 6, 2023
2 tasks
@kodiakhq kodiakhq Bot merged commit 183dba3 into carbon-design-system:main Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure all component styles using layer or field tokens @use the layer module

3 participants