Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/react-jss.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,66 @@ const App = () => <Button fontStyle="italic">Submit</Button>

The above code will compile to

```html
<div id="root">
<button class="myButton-1-25">
<span class="myLabel-1-26">
Submit
</span>
</button>
</div>
```

and

```css
.myButton-1-25 {
padding: 10px;
}
.myLabel-1-26 {
display: block;
color: red;
font-weight: bold;
font-style: italic;
}
```
## Adding Component Prefix Option
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I would probably write them lower case
  2. headlines need to be added to the TOC above manually

```javascript
import React from 'react'
import {createUseStyles} from 'react-jss'

const useStyles = createUseStyles({
myButton: {
padding: props => props.spacing
},
myLabel: props => ({
display: 'block',
color: props.labelColor,
fontWeight: props.fontWeight,
fontStyle: props.fontStyle
})
}, {name: 'Button'})

const Button = ({children, ...props}) => {
const classes = useStyles(props)
return (
<button className={classes.myButton}>
<span className={classes.myLabel}>{children}</span>
</button>
)
}

Button.defaultProps = {
spacing: 10,
fontWeight: 'bold',
labelColor: 'red'
}

const App = () => <Button fontStyle="italic">Submit</Button>
```

The above code will compile to

```html
<div id="root">
<button class="Button-myButton-1-25">
Expand Down