-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for descendant selectors. #61
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,6 +173,45 @@ const styles = StyleSheet.create({ | |
|
||
Aphrodite will ensure that the global `@font-face` rule for this font is only inserted once, no matter how many times it's referenced. | ||
|
||
# Descendant selectors | ||
|
||
Descendant rules (i.e. a rule like `.parent:hover .child { ... }` in CSS) are created by adding values to your styles indicating the styles to apply to the child. To distinguish the styles from normal CSS keys, the keys start with a `>>`, like `'>>child'`. | ||
|
||
```js | ||
const styles = StyleSheet.create({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great that we could accomplish this without having to have a special API for child selectors 👍 |
||
someContainer: { | ||
":hover": { | ||
">>myChild": { | ||
// Styles to apply to the child when the parent is | ||
// hovered over. | ||
color: "red", | ||
fontWeight: "bold" | ||
} | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add the example css output of this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
Then, apply the `someContainer` style using `css(styles.someContainer)`, and add the child's style to a descendant of the parent using `css(styles.someContainer.myChild)`, where `myChild` is the name of the key you used, without the `>>`. | ||
|
||
For example, using React's jsx syntax: | ||
|
||
```jsx | ||
<div className={css(styles.someContainer, ...)}> | ||
<div className={css(styles.someContainer.myChild, ...)}> | ||
This turns red and bold when the parent is hovered over | ||
</div> | ||
</div> | ||
``` | ||
|
||
This will generate CSS that looks like: | ||
```css | ||
.someContainer_xxx:hover .myChild_xxx { | ||
color: red; | ||
font-weight: bold; | ||
} | ||
``` | ||
|
||
# Caveats | ||
|
||
## Assigning a string to a content property for a pseudo-element | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On initial read of this, I assumed that
child
would be a literal class name and it took me a couple read throughs to figure out thatchild
would be a classname generated by Aphrodite.It might be worth explaining here that this is really only for cases that can't be expressed directly through others mean (which, I believe, is only styling children of pseudo-selector-modified parents).