Reference helpers help with nested styles and referncing other styles:
1linkimport { style, when } from 'themed-jss'
2link
3linkconst styleA = style((theme, $) => ({
4link // ...
5link
6link [when(':hover')]: {
7link color: 'red'
8link }
9link}))
☝️ Color of elements styled with styleA
is red when they are hovered.
1linkimport { style, parentIs } from 'themed-jss'
2link
3linkconst styleA = style((theme, $) => ({
4link // ...
5link
6link [parentIs($(styleB))]: {
7link marginLeft: 32
8link }
9link}))
☝️ elements styled with styleA
will have margin when their parent element is styled with styleB
.
1linkimport { style, descendant, not, when } from 'themed-jss'
2link
3linkconst styleA = style((theme, $) => ({
4link // ...
5link
6link [when(not(':hover'))]: {
7link [descendant('input', $(styleB), ':disabled')]: {
8link background: 'gray'
9link }
10link }
11link}))
☝️ When element is not hovered, descendants that are inputs, styled with styleB
and are disabled will
have a gray background.
You can also use JSS's nested rule for self-referencing to reference the parent rule. For example, the last example can be written as follows, without use of reference helpers:
1linkconst styleA = style((theme, $) => ({2link // ...3link4link [`&:not(:hover) input${styleB}:disabled`]: {5link background: 'gray'6link }7link}))
The following helpers match self (the element having the style) when other elements have specified styles / rules.
when()
👉 Matches self when also has specified styles / rules:
1link[when($(styleX), not($(styleY)), ':hover')]: { ... }
1link/* sass equivalent */
2link&.class-of-styleX:not(.class-of-styleY):hover { ... }
ancestorIs()
👉 Matches self when there is an ancestor with given styles / rules
1link[ancestorIs($(styleA))]: { ... }
1link/* sass equivalent */
2link.class-of-styleA & { ... }
parentIs()
👉 Matches self when parent (immediate ancestor) has given styles / rules
1link[parentIs('div', $(styleA))]: { ... }
1link/* sass equivalent */
2link.class-of-styleA>& { ... }
precedingIs()
👉 Matches self when the some preceding element has given styles / rules
1link[precedingIs($(styleA), ':focus')]: { ... }
1link/* sass equivalent */
2link.class-of-styleA~& { ... }
previousIs()
👉 Matches self when the (immediately) previous element has given styles / rules
1link[previousIs('input', $(styleA), not('[type="text"]'))]: { ... }
1link/* sass equivalent */
2link.class-of-styleA+& { ... }
The following helpers match other elements in relation self.
descendant()
👉 Matches a descendant with given styles / rules
1link[descendant($(styleA))]: { ... }
1link/* sass equivalent */
2link& .class-of-styleA { ... }
child()
👉 Matches a child (immediate descendant) with given styles / rules
1link[child($(styleA), ':last-child')]: { ... }
1link/* sass equivalent */
2link&>.class-of-styleA { ... }
succeeding()
👉 Matches an element that comes after self with given styles / rules
1link[succeeding($(styleA), not(':hover'))]: { ... }
1link/* sass equivalent */
2link&~.class-of-styleA { ... }
next()
👉 Matches the element coming immediately after self with given styles / rules
1link[next($(styleA), not(':disabled'))]: { ... }
1link/* sass equivalent */
2link&+.class-of-styleA { ... }
combined()
👉 Matches elements with all of given styles / rules:
1link[combined($(styleA), $(styleB), not(':disabled'), ':hover')]: { ... }
1link/* sass equivalent */
2link.class-of-styleA.class-of-styleB:not(:disabled):hover { ... }
either()
👉 Matches elements with any one of given styles / rules:
1link[either(
2link $(styleA),
3link combined($(styleB), not(':disabled'))
4link)]: { ... }
1link/* sass equivalent */
2link.class-of-styleA,
3link.class-of-styleB:not(:disabled) { ... }
Home Usage Dark Mode Reference Helpers