Skip to content

How to use styling based on parent state #97

Answered by danpacho
Superpat asked this question in Q&A
Discussion options

You must be logged in to vote

You can use tw.style method's 'group' property to write type-safe group style classnames.

For instance

const groups = tw.style({
    // basic styles here
    group: {
        ":hover": {
            backgroundColor: "group-hover:bg-red-100",
            borderColor: "group-hover:border-red-300",
        },
        ":active": {
            backgroundColor: "group-active:bg-green-300",
            borderColor: "group-active:border-green-100",
        },
    },
})

And then apply it group's children elements.

🔮 You should write "group" property at parent element by manually.

const MyGroups = () => 
  <details open={expanded.value} class="group">
    <summary class={groups.class}>
      Exa…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by danpacho
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants