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(global-styles): Create mechanism for global resets & primitives to be shared between components #11182

Draft
wants to merge 463 commits into
base: main
Choose a base branch
from

Conversation

jkaeser
Copy link
Member

@jkaeser jkaeser commented Dec 1, 2023

Related Ticket(s)

Closes #10794

Description

Re-roll of #10800

This PR creates two new lower-level concepts, which when combined allow components to adopt one or more "global" stylesheets.

Consider the wide variety of components that contain button styles. Instead of re-defining those button styles in each component's own internal stylesheets, we can define those styles in one place and have all components adopt that single stylesheet.

This should reduce the filesize (and therefore bandwidth used/blocking time) of every single component by stripping out large chunks of the CSS. Additionally, since each component class defines it's own stylesheet, moving those duplicated styles to a single stylesheet that can be adopted many times frees up large chunks of system memory.

To prove the efficacy of this approach, I've also implemented this setup into the button-group and button-group-item components. To further reduce each component's definition size I've split the suite of styles (button-group.scss) into individual stylesheets for each component. (button-group.scss and button-group-item.scss).

CarbonBase class

The CarbonBase class is intended to exist between the LitElement framework and all carbon components. As of this PR, its only job is to handle the global style adoption, but it could also take on the role of the StableSelector mixin or act as another entry point to all components.

CarbonStyles class

The CarbonStyles class acts as a global storage point for all the CSS primitives. Each stylesheet can be requested by name using the getStyleSheets() method, which will return an array of CSSStyleSheet objects.

How it all ties together

  1. Styles package generates Sass primitives.
  2. Utilities package imports primitives in CarbonStyles class, which converts the imported CSS strings into CSSStyleSheet objects, and stores them on the class instance keyed by name (e.g. "reset").
  3. Carbon Web Components package defines CarbonBase class that extends LitElement. It provides mechanisms for extending elements to attach the CSSStyleSheet objects to the shadow root's adoptedStylesheets.
    1. _requestCarbonStyles() method defines which primitives should be adopted, by default requesting reset and type primitives. This method can be overridden by extending classes in the event they need to request additional primitives (e.g. button styles) or they don't need one or more of the default primitives.
    2. The requested primitives are adopted in the connectedCallback() lifecycle method.

Changelog

New

  • Add CarbonBase and CarbonStyles classes

Changed

  • split button-group.scss files into individual component stylesheets

annawen1 and others added 30 commits July 27, 2023 09:02
…panel (carbon-design-system#10739)

* fix(ui-shell): adjust header action button

* fix(header-global-action): set the panel expanded state

* fix(ui-shell): add tooltip-text for initial
* chore(workflows): allow on feat/*

* fix(percy): ensure percy runs

* chore(react): remove package

* chore(e2e): remove react in workflows

* fix(react): adding pictogram and removing react e2e

* fix(test): installed enzyme

* fix(tests): tests succeed

* chore(jest): update snapshots

* fix(yarn): update lockfile

* fix(yarn): updated lockfile

* fix(storybook): react wrapper now compiles

---------

Co-authored-by: kennylam <909118+kennylam@users.noreply.github.com>
* fix(cwc-v2): fix styles and theme examples

* fix(docs): add style info

* fix(styles): remove layer tokens from styles

* fix(styling): temp layout mixin

* fix(ui-shell): missing style and format code

* fix(popover): button style extend

* fix(overflow): missing class and fix prefixes

* fix(code): format everything

* fix(combo-box): placeholder padding

* fix(data-table): batch actions size

* fix(examples): with update theme token info

* fix(tile): add emit layout token for all variants

* fix(ui-shell): storybook padding

* fix(styling-story): test

* fix(styling): docs set specific tag

---------

Co-authored-by: Anna Wen <54281166+annawen1@users.noreply.github.com>
* fix(styling): missing tokens

* fix(search): hover

* fix(search): format and remove pointer events

* fix(data-table): hover

* fix(search): expandable size
Co-authored-by: Anna Wen <54281166+annawen1@users.noreply.github.com>
Co-authored-by: Ariella Gilmore <ariellalgilmore@gmail.com>
…design-system#10767)

* chore(upgrade-cwc-v2): upgrade to latest carbon styles/icons

* fix(header-global-action): bring back header action button

---------

Co-authored-by: Ariella Gilmore <ariellalgilmore@gmail.com>
Co-authored-by: Anna Wen <54281166+annawen1@users.noreply.github.com>
Co-authored-by: kennylam <909118+kennylam@users.noreply.github.com>
kennylam and others added 24 commits November 9, 2023 15:22
Closes carbon-design-system#11117

This upgrades Typescript to v5

**New**

- {{new thing}}

**Changed**

- `@carbon/web-components` and `@carbon/ibmdotcom-web-components` upgraded to Typescript 5

**Removed**

- {{removed thing}}

<!-- React and Web Component deploy previews are enabled by default. -->
<!-- To enable additional available deploy previews, apply the following -->
<!-- labels for the corresponding package: -->
<!-- *** "test: e2e": Codesandbox examples and e2e integration tests -->
<!-- *** "package: services": Services -->
<!-- *** "package: utilities": Utilities -->
<!-- *** "RTL": React / Web Components (RTL) -->
<!-- *** "feature flag": React / Web Components (experimental) -->
…at/footer-v2-updates

feat(footer): v2 layout updates
…m#11043)

* feat(styles): update card-group and video-player styles

---------

Co-authored-by: kennylam <909118+kennylam@users.noreply.github.com>
Co-authored-by: kennylam <909118+kennylam@users.noreply.github.com>
…x/video-player-v2-alignment

fix(video-player): v2 alignment
…x/v2-carbon-dependencies

fix(dependencies): core carbon updates
@jkaeser jkaeser added package: utilities Work necessary for the Carbon for IBM.com utilities package package: styles Work necessary for the Carbon for IBM.com styles package package: web components Work necessary for the IBM.com Library web components package package: carbon web components owner: Innovation Team used when the engineering work will be done by Hybrid Cloud with DDS engineers as consultants prototype Proof of concept work that should not be merged down labels Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
owner: Innovation Team used when the engineering work will be done by Hybrid Cloud with DDS engineers as consultants package: carbon web components package: styles Work necessary for the Carbon for IBM.com styles package package: utilities Work necessary for the Carbon for IBM.com utilities package package: web components Work necessary for the IBM.com Library web components package prototype Proof of concept work that should not be merged down
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a mechanism/utility for components to request & adopt global/primitive styles