Skip to content

feature request: shadow root stylesheets #50

@dakom

Description

@dakom

this was discussed on Discord and @Pauan suggested something like the following syntax:

static STYLE1: Lazy<Stylesheet> = Lazy::new(|| stylesheet!("div.bar", {
    .style(...)
}));

html!("div", {
    .shadow_root!(ShadowRootMode::Open, {
        .stylesheet(&*STYLE1)
        .children(&mut [ ... ])
    })
})

The Stylesheet here should somehow use Constructable Stylesheet Objects - such that if the above html! were called 100 times to add instances of this component to a page, they should all share the same static stylesheet.

Even though the stylesheet is static, its inner contents can be changed and so the above will support .style_signal()

It's likely that these stylesheets, scoped to a shadow root, will often define many rules at once - so it would be more efficient and convenient to have a wrapper that collects them all.

This wrapper could be called stylesheets!, or perhaps, stylesheet! becomes the wrapper and each rule uses a rule! macro. If going with the latter, the above could look like:

static STYLE1: Lazy<Stylesheet> = Lazy::new(|| stylesheet!(&[
    rule!("div.bar", {
      .style(...)
    }),
    rule!("ul > li + li", {
      .style_signal(...)
    })
]));

html!("div", {
    .shadow_root!(ShadowRootMode::Open, {
        .stylesheet(&*STYLE1)
        .children(&mut [ ... ])
    })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions