This repository has been archived by the owner on Oct 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add docs about migrating to react-jss from jss-theme-reactor
read more: * Migrating from jss-theme-reactor to react-jss https://git.io/v7d6e * v1.7.0 migrations https://git.io/v7d6I
- Loading branch information
1 parent
cf63ce2
commit 482013c
Showing
5 changed files
with
133 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Documentation | ||
|
||
* [In App usage](./in-app-usage.md) | ||
* [Writing a component](./writing-component.md) | ||
* [Styling a component](./styling-component.md) | ||
* [Testing a component](./testing-component.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# In App usage | ||
|
||
You need `ThemeProvider` from `react-jss` and `theme` from `nordnet-ui-kit` in your App. | ||
|
||
```js | ||
// src/root.js | ||
import { ThemeProvider } from 'react-jss'; | ||
import { theme } from 'nordnet-ui-kit'; | ||
import App from './App' | ||
|
||
const Root = ( | ||
<ThemeProvider theme={theme}> | ||
<App /> | ||
</ThemeProvider> | ||
); | ||
|
||
ReactDOM.render(Root, document.getElementById('app')); | ||
``` | ||
|
||
```js | ||
// src/App.js | ||
import { Button } from 'nordnet-ui-kit'; | ||
|
||
const App = props => ( | ||
<div> | ||
<Button variant="primary" modifier="success"> | ||
Success | ||
</Button> | ||
</div> | ||
); | ||
|
||
export default App; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# migration from jss-theme-reactor to react-jss | ||
|
||
## ThemeProviders duplication in the meantime | ||
|
||
If you use any components which are not yet refactored into `react-jss`, then you need to use two `ThemeProviders`: | ||
So jss-theme-reactor based components will not be broken, because of lack of context. | ||
|
||
```js | ||
// src/root.js | ||
import { ThemeProvider } from 'react-jss'; | ||
import { theme, ThemeProvider as UiThemeProvider } from 'nordnet-ui-kit'; | ||
import App from './App' | ||
|
||
const Root = ( | ||
<ThemeProvider theme={theme}> | ||
<UiThemeProvider> | ||
<App /> | ||
</UiThemeProvider> | ||
</ThemeProvider> | ||
); | ||
|
||
ReactDOM.render(Root, document.getElementById('app')); | ||
``` | ||
|
||
## Components refactoring | ||
|
||
TL:DR: | ||
|
||
* you dont care about context anymore. | ||
* you will get classes as prop from now on. | ||
|
||
```diff | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import cn from 'classnames'; | ||
-import { createStyleSheet } from '@iamstarkov/jss-theme-reactor'; | ||
-// or | ||
-import { createStyleSheet } from 'jss-theme-reactor'; | ||
+import injectSheet from 'react-jss'; | ||
|
||
- export const styleSheet = createStyleSheet('Badge', theme => { | ||
+ const styles = theme => { | ||
const { palette, typography, mixins } = theme; | ||
|
||
return { | ||
/* … */ | ||
}; | ||
}); | ||
|
||
-function Badge({ modifier, children }, { styleManager }) { | ||
- const classes = styleManager.render(styleSheet); | ||
+ function Badge({ classes, modifier, children }) | ||
|
||
/* … */ | ||
|
||
Badge.propTypes = { | ||
+ /** @ignore */ | ||
+ classes: PropTypes.object.isRequired, | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
modifier: PropTypes.oneOf(['success', 'warning', 'danger']), | ||
}; | ||
|
||
-Badge.contextTypes = { | ||
- styleManager: PropTypes.object.isRequired, | ||
-}; | ||
|
||
-export default Badge; | ||
+export { Badge as Component, styles }; | ||
+export default injectSheet(styles)(Badge); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# v1.7.0 migrations | ||
|
||
in v1.7.0 test utils are deprecated: | ||
|
||
* `ThemeProvider`— use `import { ThemeProvider } from 'react-jss';` instead, read more [in app usage documentation](../in-app-usage.md) | ||
* `createShallow` and `createMount`—use `mockClasses` helper, read more in [testing documentation](../testing-component.md) | ||
* `Animate` component doesn't require `animationName` anymore. | ||
|
||
in `2.0` aforementioned helpers will be removed. |