1
1
mirror of https://github.com/jxnblk/mdx-deck.git synced 2024-11-30 00:44:20 +03:00
mdx-deck/docs/advanced.md

122 lines
3.2 KiB
Markdown
Raw Normal View History

2018-08-05 20:00:52 +03:00
# Advanced Usage
## Custom MDX components
2019-03-10 03:31:30 +03:00
MDX Deck includes default components for MDX, but to provide custom components to the [MDXProvider][], add a `components` object to the `theme`.
2018-08-05 20:00:52 +03:00
```js
// example theme
import Heading from './Heading'
2018-08-05 20:00:52 +03:00
export default {
components: {
2019-03-10 03:31:30 +03:00
h1: Heading,
},
2018-08-05 20:00:52 +03:00
}
```
See the [MDX][] docs for more or take a look
2019-03-10 03:31:30 +03:00
at the [default set of components](../packages/components/src/mdx-components.js) as a reference.
2018-08-05 20:00:52 +03:00
## Custom Provider component
A custom Provider component can be added to the theme to wrap the entire application.
2019-03-10 03:31:30 +03:00
This is useful for adding custom context providers in React or adding persistent UI elements to the entire deck.
2018-08-05 20:00:52 +03:00
```js
// example theme.js
import Provider from './Provider'
2018-08-05 20:00:52 +03:00
export default {
font: 'Georgia, serif',
2019-03-10 03:31:30 +03:00
Provider,
}
2018-08-05 20:00:52 +03:00
```
A custom Provider component will receive the application's state as props,
which can be used to show custom page numbers or add other elements to the UI.
#### Props
2019-03-10 03:31:30 +03:00
- `slides`: (array) the components for each slide
2018-08-05 20:00:52 +03:00
- `index`: (number) the current slide index
2019-03-10 03:31:30 +03:00
- `mode`: (string) the current mode (one of `'normal'`, `'presenter'`, or `'overview'`)
- `step`: (number) the current visible step in an Appear or Step component
- Each slide includes a `meta` object with a `notes` field when the Notes component is used within a slide
2018-08-05 20:00:52 +03:00
## Combining multiple mdx files
2018-08-05 20:03:49 +03:00
Unlike the official `@mdx-js/loader`,
2019-03-10 03:31:30 +03:00
the `@mdx-deck/loader` exports an additional `slides` array of components instead of just the entire document.
2018-08-05 20:00:52 +03:00
Multiple MDX files can be combined into a single presentation if the filesize is getting difficult to manage.
2019-03-10 03:31:30 +03:00
First create a couple `.mdx` files like any other MDX Deck file, with `---` to separate the different slides.
2018-08-05 20:00:52 +03:00
```mdx
# one.mdx
---
This is the first file
```
```mdx
# two.mdx
---
This is the second file
```
Next, create a `.js` file to import and combine the two `.mdx` files.
```js
// deck.js
2019-03-10 03:31:30 +03:00
import { slides as one } from './one.mdx'
import { slides as two } from './two.mdx'
2018-08-05 20:00:52 +03:00
2019-03-10 05:30:43 +03:00
export const slides = [...one, ...two]
2018-08-05 20:00:52 +03:00
```
2019-03-10 03:31:30 +03:00
Then, point the MDX Deck CLI comment in your `package.json` to the `deck.js` file.
2018-08-05 20:00:52 +03:00
```json
"scripts": {
"start": "mdx-deck deck.js"
}
```
2018-08-27 01:12:29 +03:00
## Custom webpack config
2019-03-10 03:31:30 +03:00
Webpack configuration files named `webpack.config.js` will automatically be merged with the built-in configuration,
using [webpack-merge](https://github.com/survivejs/webpack-merge).
To use a custom filename, pass the file path to the `--webpack` flag.
2018-08-27 01:12:29 +03:00
```js
// webpack.config.js example
module.exports = {
module: {
rules: [
2019-03-10 03:31:30 +03:00
{
test: /\.svg$/,
use: [{ loader: 'babel-loader' }, { loader: 'react-svg-loader' }],
},
],
},
2018-08-27 01:12:29 +03:00
}
```
2019-03-10 03:31:30 +03:00
**Careful**: When overwriting the loader for `mdx` files, make sure to include the default loader from `@mdx-deck/loader`.
2018-08-27 04:44:34 +03:00
2018-08-05 20:00:52 +03:00
## Custom build setups
2019-03-10 03:31:30 +03:00
The core MDX Deck components can also be used in any React application,
2018-08-05 20:00:52 +03:00
such as [create-react-app][] or [next.js][].
2019-03-10 03:31:30 +03:00
See the [`@mdx-deck/components`](../packages/components) package for more.
2018-08-05 20:00:52 +03:00
2019-03-10 03:31:30 +03:00
[mdx]: https://mdxjs.com
2019-03-10 20:29:02 +03:00
[mdxprovider]: https://github.com/mdx-js/mdx/blob/master/docs/getting-started/index.md#mdxprovider
2018-08-05 20:00:52 +03:00
[create-react-app]: https://github.com/facebook/create-react-app
[next.js]: https://github.com/zeit/next.js/