Skip to content

Commit af1d148

Browse files
authored
Merge pull request #38 from i-am-the-slime/patch-3
Add usage example
2 parents fe0dff7 + 8057a72 commit af1d148

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,38 @@
99
</img>
1010
</a>
1111

12+
## Example usage:
13+
14+
```purescript
15+
import React.Basic.DOM as R
16+
import React.Basic.Hooks as React
17+
import React.Basic.Emotion as E
18+
19+
myUnstyledDiv :: JSX
20+
myUnstyledDiv = React.element R.div'
21+
{ children: [ R.text "I have no style :(" ]
22+
}
23+
24+
myStyledDiv :: JSX
25+
myStyledDiv = E.element R.div'
26+
{ className: "stylish-div"
27+
, css: E.css
28+
{ color: E.str "rebeccapurple"
29+
, padding: E.px 4
30+
}
31+
}
32+
```
33+
34+
Note that you need to use the apostrophised variants of react components from `React.Basic.DOM` since these represent the raw `ReactComponent`s that `Emotion` expects to work with.
35+
36+
## Going beyond what `style` can give you
37+
38+
Emotion allows you to define real CSS rules rather than only inline styles.
39+
Here's an example of something you can't do with inline styles:
40+
41+
```purescript
42+
myStyle :: Style
43+
myStyle = E.css
44+
{ "&:hover": E.nested (E.css { background: E.str "#fed" })
45+
}
46+
```

0 commit comments

Comments
 (0)