Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

The caller should specify the state, not consume it #8

Open
lijunle opened this issue May 6, 2020 · 0 comments
Open

The caller should specify the state, not consume it #8

lijunle opened this issue May 6, 2020 · 0 comments

Comments

@lijunle
Copy link

lijunle commented May 6, 2020

Hi, the :state pseudo class is a very interesting idea. I have another side for CSS hacking to provide the modularized ability to the CSS, which also need a "state" for a CSS component / custom component.

IMO, the state is the input for the component for the CSS side. So, the caller should use specify the state and let the component to decide what to display according to the state. It is a layer of abstraction and make the component's CSS work as black box.

Here is my proposal syntax:

<script>
class QuestionBox extends HTMLElement {
  constructor() {
    super();
    const shadowRoot = this.attachShadow({mode: 'closed'});
    shadowRoot.innerHTML =
      `:host { background-color: white }
       :host(:state(highlight)) { background-color: yellow }
       <div><slot>Question</slot></div>`;
  }
}
customElements.define('question-box', QuestionBox);
</script>

<style>
question-box:hover { state: highlight }
</style>
<question-box>Continue?</question-box>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant