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

Use CSS Logical Properties and Values for Styling #13619

Closed
6 tasks
Tracked by #14477
tay1orjones opened this issue Apr 18, 2023 · 0 comments · Fixed by #14531 or #14580
Closed
6 tasks
Tracked by #14477

Use CSS Logical Properties and Values for Styling #13619

tay1orjones opened this issue Apr 18, 2023 · 0 comments · Fixed by #14531 or #14580
Assignees
Labels
adopter: strategic-product Work-stream that directly effects the Product-led Growth initiative. proposal: accepted This request has gone through triaging and we are accepting PR's against it. role: dev 🤖 type: bidi ↔️ type: enhancement 💡
Milestone

Comments

@tay1orjones
Copy link
Member

tay1orjones commented Apr 18, 2023

The problem

Component styling currently uses typical properties for positioning and sizing, things like margin-top, padding-left, border-right, etc.

These properties are static and are not impacted by the writing mode. When a page is rendered in rtl, padding-left does not automatically become padding-right. It is static on the left.

Due to this, we currently recommend that applications using Carbon with a requirement to support rtl mode use a postprocessor like RTLCSS. RTLCSS converts these static properties into their logical inverse property for rtl mode( padding-left becomes padding-right). The output stylesheet can then be loaded when the document is in rtl mode and override the default styles provided by Carbon.

We do not have RTLCSS as part of the pipeline within the monorepo. This means that if we were to alter the writing mode in the storybook canvas, the components would not have appropriate styling to be rendered correctly.

The solution

We should instead use Logical Properties and Values to specify styling that will be impacted by the writing mode.

From the MDN docs:

CSS Logical Properties and Values is a module of CSS introducing logical properties and values that provide the ability to control layout through logical, rather than physical, direction and dimension mappings.
...
Logical properties and values use the abstract terms block and inline to describe the direction in which they flow. The physical meaning of these terms depends on the writing mode.

In effect, this means that we can specify things like padding, margin, text-alignment, etc. to be dependent on the writing mode rather than static right/left/top/bottom values.

Examples

Here's an example from this excellent article on the topic. It does a much better job of explaining all the facets of this than I can do here, please read.

/* Without logical properties and values */
.my-element {
  padding-top: 2em;
  padding-bottom: 2em;
  margin-left: 2em;
  position: relative;
  top: 0.2em;
}

/* With logical properties and values */
.my-element {
  padding-block-start: 2em;
  padding-block-end: 2em;
  margin-inline-start: 2em;
  position: relative;
  inset-block-start: 0.2em;
}

Tasks

With this mapping I think we could get most (all?) of the way there in a single sprint https://github.com/csstools/stylelint-use-logical#property-and-value-mapping

@tay1orjones tay1orjones added the proposal: accepted This request has gone through triaging and we are accepting PR's against it. label Apr 18, 2023
@tay1orjones tay1orjones added this to the 2023 Q3 milestone Jun 7, 2023
@tay1orjones tay1orjones added planning: umbrella Umbrella issues, surfaced in Projects views role: dev 🤖 and removed planning: umbrella Umbrella issues, surfaced in Projects views labels Jun 7, 2023
@sstrubberg sstrubberg added the adopter: strategic-product Work-stream that directly effects the Product-led Growth initiative. label Aug 22, 2023
@tay1orjones tay1orjones assigned tw15egan and alisonjoseph and unassigned tw15egan Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adopter: strategic-product Work-stream that directly effects the Product-led Growth initiative. proposal: accepted This request has gone through triaging and we are accepting PR's against it. role: dev 🤖 type: bidi ↔️ type: enhancement 💡
Projects
Archived in project
Archived in project
4 participants