Open
Description
- [X ] I searched for an existing RRFC which might be relevant to my RRFC
Motivation
There are many longstanding requests to improve Lit's styling API to better support things like (1) dynamic style changes, (2) theming, (3) application of document styles, (4) slightly relaxing the restrictions of Shadow DOM's style scoping.
Related
- [RRFC] Add ability to set dynamic styles programatically after render #13
- [RRFC] LitElement theming API #10
This is a complex topic and a lot of customization is possible using css custom properties
, shadow parts
, and shared constructible CSSStyleSheets
. However, it would be nice if Lit provided some convenient helpers and guidance/best practices for these needs. This would probably make sense as a lit-labs package that could be iterated on via extensive feedback.
How
Here is a prototype of new capability to support these needs. It includes:
- a new
sheet
TTL to use instead ofcss
which mainly is less restrictive around accepting values and has customizable caching behavior via including an inlinestoreAs({key, scope})
value. This makes stylesheets shareable by key, without having to explicitly pass around the sheet itself. - sheet mutation API:
hasSheet
,addSheets
,removeSheets
,toggleSheets
. These helpers just make it more convenient to work withadoptedStyleSheets
. getDocumentStyles
: retrieves and tracks document styles/links and auto-convert them to adoptable sheets and Lit renderable link template results. This makes it possible easily to include document styles in elements. Caveats: only styles available when the element is defined are available and tracked.themeSheet({...part: "css"})
: intended for theming this let's users provide styles for parts and custom properties that are not necessarily restricted by the DOM tree or export parts.fromSelectors({...class: "css"})
: this provides type-safe access to a set of css classes defined by name, returning{sheet, selectors}
wheresheet
is intended to be included in the element's styles andclass=${selectors.name}
is included in the template. The advantage is that TS will ensure only defined class selectors can be included.
Metadata
Metadata
Assignees
Labels
No labels