You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: changelog.md
+6-1Lines changed: 6 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,8 +15,12 @@
15
15
-[jss] Add scoped keyframes support ([#346](https://github.com/cssinjs/jss/pull/346))
16
16
-[jss] Function values and function rules support now fallbacks, media queries, nesting, global styles ([#682](https://github.com/cssinjs/jss/pull/682))
17
17
-[react-jss] Remove old lifecycle hooks ([#834](https://github.com/cssinjs/jss/pull/834))
18
+
-[react-jss] Move JssContext to new React Context, deprecate the `sheetOptions` prop on the JssProvider and support a `media` prop ([#924](https://github.com/cssinjs/jss/pull/924))
19
+
-[react-jss] Upgrade to theming version 3 ([#942](https://github.com/cssinjs/jss/pull/942))
20
+
-[react-jss] Add forwardRef support ([#943](https://github.com/cssinjs/jss/pull/943))
21
+
-[react-jss] Extend classes instead of overwriting theme ([#946](https://github.com/cssinjs/jss/pull/946))
-[jss] Migrate to a monorepo using yarn workspaces and lerna ([#729](https://github.com/cssinjs/jss/pull/729))
23
+
-[all] Migrate to a monorepo using yarn workspaces and lerna ([#729](https://github.com/cssinjs/jss/pull/729))
20
24
-[all] Add TypeScript definitions to all packages ([#889](https://github.com/cssinjs/jss/pull/889))
21
25
-[all] Use smaller version of the warning package ([#953](https://github.com/cssinjs/jss/pull/953))
22
26
@@ -27,6 +31,7 @@
27
31
-[jss] Rule @keyframes has now scoped name by default, which means that you can access it using `$ref` from the same sheet and generate global one as before using `@global` rule ([#346](https://github.com/cssinjs/jss/pull/346)).
28
32
-[jss][react-jss] Options `createGenerateClassName` and `generateClassName` are renamed to `createGenerateId` and `generateId` because the same function is now used to scope @keyframes rules.
29
33
-[react-jss] Drop support for older React versions, require v16.3 or higher ([#868](https://github.com/cssinjs/jss/pull/868), [#851](https://github.com/cssinjs/jss/pull/851))
Copy file name to clipboardExpand all lines: docs/react-jss.md
+90-61Lines changed: 90 additions & 61 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,8 @@ Benefits compared to the lower level core:
6
6
7
7
- Dynamic Theming - allows context based theme propagation and runtime updates.
8
8
- Critical CSS extraction - only CSS from rendered components gets extracted.
9
-
- Lazy evaluation - Style Sheets are only created when a component gets mounted.
10
-
-Static part of a Style Sheet is shared between all elements.
9
+
- Lazy evaluation - Style Sheets are created when a component mounts and removed when it's unmounted.
10
+
-The static part of a Style Sheet will be shared between all elements.
11
11
- Function values and rules are updated automatically with props as an argument.
12
12
13
13
### Table of Contents
@@ -36,7 +36,7 @@ yarn add react-jss
36
36
### Usage
37
37
38
38
React-JSS wraps your component with a [higher-order component](https://medium.com/@dan_abramov/mixins-are-dead-long-live-higher-order-components-94a0d2f9e750).
39
-
It injects a`classes` prop, which is a simple map of rule names and generated class names. It can act both as a simple wrapping function and as an [ES7 decorator](https://github.com/wycats/javascript-decorators).
39
+
It injects a`classes` prop, which is a simple map of rule names and generated class names.
40
40
41
41
Try it out in the [playground](https://codesandbox.io/s/j3l06yyqpw).
42
42
@@ -45,8 +45,7 @@ Try it out in the [playground](https://codesandbox.io/s/j3l06yyqpw).
45
45
```javascript
46
46
importReactfrom'react'
47
47
import {render} from'react-dom'
48
-
// Import React-JSS
49
-
importinjectSheetfrom'react-jss'
48
+
importwithStylesfrom'react-jss'
50
49
51
50
// Create your Styles. Remember, since React-JSS uses the default preset,
52
51
// most plugins are available without further configuration needed.
You can use [function values](jss-syntax.md#function-values), function rules and observables out of the box. Function values and function rules will receive a props object once the component receives new props or mounts for the first time.
119
+
You can use [function values](jss-syntax.md#function-values), Function rules and observables out of the box. Function values and function rules will receive a props object once the component receives new props or mounts for the first time.
121
120
122
121
Caveats:
123
122
124
123
Static properties being rendered first so that function values will have higher source order specificity.
- If it is `Object` and used in a nested `ThemeProvider`, then it gets merged with the theme from a parent `ThemeProvider` and passed down the react tree.
196
195
- If it is `Function` and used in a nested `ThemeProvider`, then it's being applied to the theme from a parent `ThemeProvider`. If the result is an `Object` it will be passed down the react tree, throws otherwise.
197
196
-`ThemeProvider` as every other component can render only a single child because it uses `React.Children.only` in render and throws otherwise.
198
-
-[Read more about `ThemeProvider` in `theming`'s documentation.](https://github.com/iamstarkov/theming#themeprovider)
197
+
-[Read more about `ThemeProvider` in `theming`'s documentation.](https://github.com/cssinjs/theming#themeprovider)
In case you need to access the theme but not render any CSS, you can also use `withTheme`. It is a Higher-order Component factory which takes a `React.Component` and maps the theme object from context to props. [Read more about `withTheme` in `theming`'s documentation.](https://github.com/iamstarkov/theming#withthemecomponent)
231
+
#### Accessing the theme inside the styled component
232
+
233
+
The theme will not be injecting into the wrapped component.
234
+
To inject the theme into the wrapped component, pass the `injectTheme` option to `withStyles`.
#### Accessing the theme without a styled component
263
+
264
+
In case you need to access the theme but not render any CSS, you can also use `withTheme`. It is a Higher-order Component factory which takes a `React.Component` and maps the theme object from context to props. [Read more about `withTheme` in `theming`'s documentation.](https://github.com/cssinjs/theming#withthemecomponent)
233
265
234
266
```javascript
235
267
importReactfrom'react'
236
-
importinjectSheet, {withTheme} from'react-jss'
268
+
import {withTheme} from'react-jss'
237
269
238
270
constButton=withTheme(({theme}) =><button>I can access {theme.colorPrimary}</button>)
239
271
```
240
272
273
+
#### Using custom Theming Context
274
+
241
275
Use _namespaced_ themes so that a set of UI components gets no conflicts with another set of UI components from a different library also using `react-jss`.
@@ -473,7 +521,7 @@ You will need [babel-plugin-transform-decorators-legacy](https://github.com/loga
473
521
474
522
```javascript
475
523
importReact, {Component} from'react'
476
-
importinjectSheetfrom'react-jss'
524
+
importwithStylesfrom'react-jss'
477
525
478
526
conststyles= {
479
527
button: {
@@ -484,7 +532,7 @@ const styles = {
484
532
}
485
533
}
486
534
487
-
@injectSheet(styles)
535
+
@withStyles(styles)
488
536
classButtonextendsComponent {
489
537
render() {
490
538
const {classes, children} =this.props
@@ -501,42 +549,23 @@ export default Button
501
549
502
550
### Injection order
503
551
504
-
Injection of style tags happens in the same order as the `injectSheet()` invocation.
505
-
Source order specificity is higher the lower style tag is in the tree. Therefore you should call `injectSheet` of components you want to override first.
552
+
Injection of style tags happens in the same order as the `withStyles()` invocation.
553
+
Source order specificity is higher the lower style tag is in the tree. Therefore you should call `withStyles` of components you want to override first.
By default "classes" and "theme" are going to be injected into the child component over props. Property `theme` is only passed when you use a function instead of styles object.
528
-
If you want to whitelist some of them, you can now use option `inject`. E.g., if you want to access the StyleSheet instance, you need to pass `{inject: ['sheet']}` and it will be available as `props.sheet`.
529
-
530
-
All user props passed to the HOC will still be forwarded as usual.
531
-
532
-
```js
533
-
importReactfrom'react'
534
-
importinjectSheetfrom'react-jss'
535
-
536
-
conststyles= {}
537
-
538
-
// Only `classes` prop will be passed by the ReactJSS HOC now. No `sheet` or `theme`.
0 commit comments