- CSS Modules
- Adding a CSS File to Root Module
- Adding a CSS File to Child Module
- Using Reakit with One App
Since CSS is global, One App uses the CSS Modules pattern to avoid class name collisions. The main differences will be the strict use of camelCased class names and the way you import the class names.
/* good */
.myClass {
color: red;
}
/* not currently supported due to purge-css */
.my-class {
color: red;
}
import styles from './MyModule.scss';
const MyModule = () => (
<div className={styles.myClass}>
My Module
</div>
);
In order to provide global styles within your application, you can add a stylesheet to the
<head>
within your root module. You can achieve this by using react-helmet.
import React, { Fragment } from 'react';
import { Helmet } from 'react-helmet';
const MyRoot = ({ children }) => (
<Fragment>
<Helmet>
<link rel="stylesheet" href="https://www.example.com/styles.min.css" />
</Helmet>
{children}
</Fragment>
);
Note: Keep in mind that the domain in the stylesheet needs to be added to the csp.
This is done the same way as with the Root Module. However, keep in mind that if you add a stylesheet in the Root Module as well as a Child Module, this can cause collisions as well as multiple loads of the same styles.
If you are wanting to use Reakit, here is how to do so within One App.
npm install --save reakit
Add default their styling by installing reakit-system-bootstrap
. This is optional.
npm install --save reakit-system-bootstrap
import React, { Fragment } from 'react';
import { Provider } from 'reakit';
import * as system from 'reakit-system-bootstrap';
const MyRootModule = ({ children }) => (
<Fragment>
<Provider unstable_system={system}>
{ children }
</Provider>
</Fragment>
);
export default MyRootModule;
Wrapping your children with Reakit's Provider
will make the styles accessible by the children.
npm install --save reakit
Since reakit-system-bootstrap
was added in the root module, you do not need to npm install
it
in your child modules.
import React, { Fragment } from 'react';
import { Button } from 'reakit';
const MyModule = ({ children }) => (
<Button>Button</Button>
);
export default MyModule;
You can use one-app-bundler's
providedExternals
and requiredExternals
to avoid duplicating Reakit across all your modules.
Furthermore, due to Reakit using React's context API, in order for your child modules to leverage
this, you MUST add it to providedExternals
as well as requiredExternals
.
Add the following in your root module's package.json
.
"one-amex": {
"bundler": {
"providedExternals": [
"reakit"
]
}
},
"one-amex": {
"bundler": {
"requiredExternals": [
"reakit"
]
}
},
When using externals and how Webpack handles them, you will need to change your import from
import { Button } from 'Reakit/Button';
to
import { Button } from 'Reakit';