Skip to content

Commit 6719248

Browse files
authored
Update README.md
Rework example to show sass-extract-loader usage.
1 parent 37c2db5 commit 6719248

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

README.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ I work on a team that uses Sass. We've got a shared variables file that gets ref
1111

1212
## Cool! How do I get it?
1313

14-
You'll need to install [sass-extract][sass-extract], [node-sass][node-sass], and this plugin.
14+
You'll need to install [sass-extract][sass-extract], [sass-extract-loader][sass-extract-loader], [node-sass][node-sass], and this plugin.
1515

1616
```sh
1717
$ yarn add sass-extract node-sass sass-extract-js
@@ -21,23 +21,15 @@ $ yarn add sass-extract node-sass sass-extract-js
2121

2222
## Nice! How do I use it?
2323

24-
Wrap your App in a ThemeProvider component like this:
24+
Assuming you're using webpack, you'll need to use sass-extract-loader to require/transform your sass variables file. Then you can pass the styles as a theme via a ThemeProvider component like this:
2525

2626
```jsx
27-
// Import `sass-extract` library
28-
import sassExtract from 'sass-extract';
29-
30-
// Call the `renderSync` function with the path to your Sass file
31-
// and specify the `sass-extract-js` plugin
32-
const rendered = sassExtract.renderSync({
33-
file: './path/to/vars.scss'
34-
}, {
35-
plugins: ['sass-extract-js']
36-
});
27+
// Require your sass variables using sass-extract-loader and specify the plugin
28+
const theme = require('sass-extract-loader?{"plugins":["sass-extract-js"]}!./path/to/vars.scss');
3729

3830
// Pass the vars into your ThemeProvider component
3931
render(
40-
<ThemeProvider theme={rendered.vars}>
32+
<ThemeProvider theme={theme}>
4133
<App />
4234
</ThemeProvider>
4335
);
@@ -49,7 +41,7 @@ Then use themes in your styled components:
4941
import styled from 'styled-components';
5042

5143
const Button = styled.button`
52-
background-color: ${props => props.theme.primary}
44+
background-color: ${p => p.theme.primary}
5345
`;
5446

5547
```
@@ -136,7 +128,7 @@ If, for some reason, you don't want to use this package as a sass-extract plugin
136128
import transformVars from 'sass-extract-js/lib/transformVars';
137129

138130
// Call the function, passing in your options
139-
const trasformed = transformVars(objectWithExtractedStyles, { camelCase: false });
131+
const transformed = transformVars(objectWithExtractedStyles, { camelCase: false });
140132
```
141133

142134

@@ -158,4 +150,5 @@ MIT
158150
[theming]: https://www.styled-components.com/docs/advanced#theming
159151
[node-sass]: https://github.com/sass/node-sass#options
160152
[sass-extract]: https://github.com/jgranstrom/sass-extract
161-
[glamorous]: https://github.com/paypal/glamorous
153+
[sass-extract-loader]: https://github.com/jgranstrom/sass-extract-loader
154+
[glamorous]: https://github.com/paypal/glamorous

0 commit comments

Comments
 (0)