Skip to content

Consider implementing toString() for CSSResult #487

@tlouisse

Description

@tlouisse

Description

Currently, CSSResult seems to be designed for LitElements having shadow dom. CSSResult modules tend to be quite closely coupled to the get static styles array as well.

Imagine however the following situation: I have an implementation of a Design System consisting of css modules (meaning equivalents of BEM/SMACCS etc. type of components) that should be reusable in many 'technology contexts' (meaning with and without shadow DOM and in multiple frameworks (React, Angular, Vue, vanilla, whatever).

This example illustrates how one would be able to reuse a 'technology agnostic' implementation of a Design System across different technologies:

For me, it would increase the Developer Experience when I can think about those CSS Modules as being technology agnostic strings.
So then instead of {myModule.cssText}, I could do {myModule}.

Seems like a small thing, but for me it would just be a better experience and it would feel like my styles would be less tightly coupled to CSSResult (and thus LitElement and shadow dom).

Also, It will help decrease verbosity in situations like this:

.grid-container {
  margin: auto;
  max-width: ${unsafeCss(Number(small.cssText.slice(0,-2)) -(Number(containerPadding.cssText.slice(0,-2) * 2)))}px;
}

https://stackblitz.com/edit/css-variables-for-computations?file=style%2Fmodules%2Fgrid-css-module_numbersNotAllowed.js

Would it be possible to add a toString() method that returns the cssText?

Live Demo

See links above.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions