1
1
mirror of https://github.com/jxnblk/mdx-deck.git synced 2024-12-01 21:42:08 +03:00
mdx-deck/README.md

422 lines
9.2 KiB
Markdown
Raw Normal View History

2018-07-28 21:21:36 +03:00
# mdx-deck
2018-07-29 23:06:55 +03:00
![](https://s3.amazonaws.com/jxnblk/mdx-deck.gif)
2018-07-30 09:59:25 +03:00
[MDX][]-based presentation decks (**Beta**)
2018-07-29 19:11:24 +03:00
2018-07-30 02:08:19 +03:00
[![Build Status][badge]][travis]
2018-07-30 02:09:31 +03:00
[![Version][version-badge]][npm]
2018-07-31 02:16:39 +03:00
[![Downloads][downloads-badge]][npm]
2018-07-30 02:08:19 +03:00
[badge]: https://img.shields.io/travis/jxnblk/mdx-deck.svg?style=flat-square
[travis]: https://travis-ci.org/jxnblk/mdx-deck
2018-07-30 02:09:31 +03:00
[version-badge]: https://img.shields.io/npm/v/mdx-deck.svg?style=flat-square
2018-07-30 02:08:19 +03:00
[downloads-badge]: https://img.shields.io/npm/dw/mdx-deck.svg?style=flat-square
[npm]: https://npmjs.com/package/mdx-deck
2018-07-30 02:09:55 +03:00
```sh
npm i -D mdx-deck
```
2018-07-29 21:19:37 +03:00
- :memo: Write presentations in markdown
2018-07-29 21:17:53 +03:00
- :atom_symbol: Import and use React components
2018-08-04 00:31:35 +03:00
- :nail_care: Customizable [themes](#theming) and [components](#custom-components)
2018-07-29 21:17:53 +03:00
- :zero: Zero-config CLI
2018-08-03 22:55:34 +03:00
- :tipping_hand_woman: [Presenter mode](#presenter-mode)
- :notebook: [Speaker notes](#speaker-notes)
2018-07-29 21:17:53 +03:00
2018-07-29 23:38:32 +03:00
[View demo](https://jxnblk.com/mdx-deck)
2018-07-30 02:08:19 +03:00
2018-07-29 19:37:09 +03:00
## Getting Started
2018-07-29 19:21:37 +03:00
Create an [MDX][] file and separate each slide with `---`.
2018-07-29 02:28:36 +03:00
````mdx
2018-07-28 21:21:36 +03:00
# This is the title of my deck
---
# About Me
---
```jsx
<CodeSnippet />
```
---
2018-07-29 01:49:02 +03:00
import Demo from './components/Demo'
2018-07-28 21:21:36 +03:00
<Demo />
---
# The end
````
2018-07-29 21:38:37 +03:00
Add a run script to your `package.json` with the mdx-deck CLI
pointing to the `.mdx` file to start the dev server:
```json
"scripts": {
"start": "mdx-deck deck.mdx"
}
```
Start the dev server:
2018-07-29 19:21:37 +03:00
2018-07-28 21:21:36 +03:00
```sh
2018-07-29 21:38:37 +03:00
npm start
2018-07-28 21:21:36 +03:00
```
### Video Tutorial
2018-07-31 01:31:55 +03:00
For a video introduction, see this [egghead tutorial][egghead] by [@andrewdelprete](https://github.com/andrewdelprete).
[egghead]: https://egghead.io/lessons/react-build-a-slide-deck-with-mdx-deck-using-markdown-react
2018-07-29 02:28:36 +03:00
## Usage
MDX can use Markdown syntax and render React components with JSX.
### Imports
To import components, use ES import syntax separated with empty lines from any markdown or JSX syntax.
```mdx
import { Box } from 'grid-styled'
<Box color='tomato'>
Hello
</Box>
```
### Theming
2018-07-29 19:37:09 +03:00
mdx-deck uses [styled-components][] for styling.
### Built-in Themes
2018-07-29 20:18:00 +03:00
mdx-deck includes several built-in themes to change the look and feel of the presentation.
2018-07-31 02:00:45 +03:00
Export `theme` from your MDX file to enable a theme.
2018-07-29 20:18:00 +03:00
```mdx
export { dark as theme } from 'mdx-deck/themes'
2018-07-29 20:18:00 +03:00
# Dark Theme
```
2018-07-31 02:00:45 +03:00
The following themes are available from `mdx-deck/themes`:
2018-07-29 20:18:00 +03:00
- `theme`: default theme with white background
- `dark`: black background dark theme
- `future`: dark theme with Avenir Next
2018-07-29 20:19:11 +03:00
- `condensed`: dark theme with Roboto Condensed
2018-07-29 19:37:09 +03:00
### Custom Themes
2018-07-29 02:28:36 +03:00
A custom theme can be provided by exporting `theme` from the MDX file.
```mdx
export { default as theme } from './theme'
# Hello
```
The theme should be an object based on [styled-system][]'s theme schema.
```js
// example theme.js
export default {
2018-07-29 19:37:09 +03:00
font: 'Georgia',
monospace: 'Menlo, monospace',
2018-07-29 02:28:36 +03:00
fontSizes: [
2018-07-31 01:54:18 +03:00
'0.75em', '1em', '1.5em', '2em', '3em'
2018-07-29 02:28:36 +03:00
],
colors: {
2018-07-29 19:37:09 +03:00
text: '#000',
background: 'transparent',
link: '#07c',
heading: '#000',
quote: '#000',
pre: '#f0f',
preBackground: '#333',
code: '#f0f',
codeBackground: 'transparent',
2018-07-29 02:28:36 +03:00
},
css: {
// apply any styles to the root element
2018-07-29 19:37:09 +03:00
},
// custom CSS can be provided to any of the default components:
heading: {
fontWeight: 400
},
link: {
textDecoration: 'none',
'&:hover': {
textDecoration: 'underline',
}
2018-07-29 02:28:36 +03:00
}
}
```
2018-07-31 01:54:18 +03:00
The following keys are available for theming:
- `font`: base font family
- `monospace`: font family for `<pre>` and `<code>`
- `fontSizes`: array of font sizes from smallest to largest
- `colors`: object of colors used for MDX components
- `text`: root foreground color
- `background`: root background color
- `link`
- `heading`
- `blockquote`
- `pre`
- `preBackground`
- `code`
- `codeBackground`
- `css`: root CSS object
- `heading`: CSS for all headings
- `h1`: CSS for `<h1>`
- `h2`: CSS for `<h2>`
- `h3`: CSS for `<h3>`
- `paragraph`: CSS for `<p>`
- `link`: CSS for `<a>`
- `ul`: CSS for `<ul>`
- `ol`: CSS for `<ol>`
- `li`: CSS for `<li>`
- `img`: CSS for `<img>`
2018-07-29 02:28:36 +03:00
### Custom Components
2018-07-29 20:18:00 +03:00
mdx-deck includes default components for MDX, but to provide custom components to the [MDXProvider][], export a `components` object.
2018-07-29 02:28:36 +03:00
```mdx
export { default as components } from './components'
# Custom Components
```
2018-08-01 02:27:52 +03:00
### Components
mdx-deck includes some built-in components to help with creating presentations.
#### Image
Use the `<Image />` component to render a fullscreen image (using the CSS `background-image` property).
```mdx
import { Image } from 'mdx-deck'
<Image src='kitten.png' />
```
2018-08-04 00:30:39 +03:00
#### Appear
Use the `<Appear />` component to make its children appear one at a time within a single slide.
Use the up and down arrow keys to step through each element.
```mdx
import { Appear } from 'mdx-deck'
<ul>
<Appear>
<li>One</li>
<li>Two</li>
<li>Three</li>
</Appear>
</ul>
```
2018-07-29 02:28:36 +03:00
### Layouts
Each slide can include a custom layout around its content.
2018-07-31 01:54:18 +03:00
This can be used as a substitute for slide templates found in other presentation apps and libraries.
```js
// example Layout.js
import React from 'react'
export default ({ children }) =>
<div
style={{
width: '100vw',
height: '100vw',
backgroundColor: 'tomato'
}}>
{children}
</div>
```
2018-07-29 02:28:36 +03:00
```mdx
import Layout from './Layout'
# No Layout
---
export default Layout
# Custom Layout
```
2018-07-31 01:54:18 +03:00
The layout component will wrap the MDX elements within that slide,
which means you can use a nested ThemeProvider or target elements with CSS-in-JS.
2018-07-29 19:37:09 +03:00
### Custom Provider
A custom Provider component can be exported to wrap the entire application.
2018-07-31 01:54:18 +03:00
This is useful for adding custom context providers in React.
2018-07-29 19:37:09 +03:00
```mdx
export { default as Provider } from './Provider'
# Hello
```
2018-08-04 00:36:51 +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
- `index`: (number) the current slide index
- `length`: (number) the length of the slides array
2018-08-04 00:37:59 +03:00
- `mode`: (string) the current mode (one of `'NORMAL'` or `'PRESENTER'`)
2018-08-04 00:36:51 +03:00
- `notes`: (object) custom [speaker notes](#speaker-notes) for all slides
2018-08-03 03:32:56 +03:00
## Presenter Mode
mdx-deck includes a built-in presenter mode, with a preview of the next slide and a timer.
To use presenter mode:
2018-08-03 03:34:11 +03:00
- Open two windows in the same browser, with the same URL on two different screens. (this should work in both development and exported presentations)
2018-08-03 03:32:56 +03:00
- In your window press the `p` key to enter presenter mode.
- Display the other window on the screen for the audience to see.
- Control the presentation from your window by using the left and right arrow keys; the other window should stay in sync
2018-08-03 05:15:33 +03:00
### Speaker Notes
Notes that only show in presenter mode can be added to any slide.
Speaker notes can be added in one of the following two ways:
**Markdown:** Use the `notes` language attribute in a fenced code block to add speaker notes.
````mdx
# Slide Content
```notes
These are only visible in presenter mode
```
````
**Notes Component:** Use the `Notes` component to create more complex speaker notes.
````mdx
import { Notes } from 'mdx-deck'
# Slide Content
<Notes>
Only visible in presenter mode
</Notes>
````
2018-07-29 02:28:36 +03:00
## Exporting
2018-07-31 01:54:18 +03:00
Add a `build` script to your `package.json` to export a presentation as HTML with a JS bundle.
2018-07-29 19:37:09 +03:00
2018-07-31 01:54:18 +03:00
```json
"scripts": {
"build": "mdx-deck build deck.mdx"
}
2018-07-29 19:37:09 +03:00
```
2018-08-01 02:12:55 +03:00
### PDF Export
Presentations can be exported as PDF using the CLI.
2018-08-01 02:15:35 +03:00
This works well as a backup option for any unforeseen technical difficulties.
2018-08-01 02:12:55 +03:00
```json
"script": {
"pdf": "mdx-deck pdf deck.mdx"
}
```
2018-07-31 01:54:18 +03:00
2018-07-30 03:31:30 +03:00
## CLI Options
```
-p --port Dev server port
--no-open Prevent from opening in default browser
-d --out-dir Output directory for exporting
--title Title for the HTML document
```
2018-07-29 19:37:09 +03:00
## React API
2018-07-29 20:18:00 +03:00
mdx-deck components can also be used in any React application, such as [create-react-app][] or [next.js][].
2018-07-29 19:37:09 +03:00
### Webpack Loader
mdx-deck uses a custom webpack loader to split MDX files into an array of slides. Use this loader to import mdx files in a webpack application.
```js
// example webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.mdx$/,
ignore: /node_modules/,
use: [
'babel-loader',
'mdx-deck/loader'
]
}
]
}
}
```
### SlideDeck Component
```js
import React from 'react'
import { SlideDeck } from 'mdx-deck'
import slides from './deck.mdx'
import theme from './theme'
import components from './components'
export default () =>
<SlideDeck
slides={slides}
theme={theme}
components={components}
width='100vw'
height='100vh'
/>
```
View the source for other components available for use.
2018-07-29 02:28:36 +03:00
2018-07-29 01:49:02 +03:00
---
2018-07-29 20:20:57 +03:00
### Related
- [MDX][]
2018-07-29 23:26:54 +03:00
- [ok-mdx][]
- [ok-cli][]
- [Compositor x0][]
2018-07-29 20:20:57 +03:00
- [styled-components][]
- [styled-system][]
- [Spectacle][]
2018-07-29 20:21:24 +03:00
[MIT License](LICENSE.md)
2018-07-29 01:49:02 +03:00
2018-07-28 21:21:36 +03:00
[MDX]: https://github.com/mdx-js/mdx
2018-07-29 02:28:36 +03:00
[MDXProvider]: https://github.com/mdx-js/mdx#mdxprovider
2018-07-29 23:26:54 +03:00
[ok-mdx]: https://github.com/jxnblk/ok-mdx
[ok-cli]: https://github.com/jxnblk/ok-mdx/tree/master/packages/ok-cli
[Compositor x0]: https://github.com/c8r/x0
2018-07-29 02:28:36 +03:00
[styled-system]: https://github.com/jxnblk/styled-system
2018-07-29 19:11:24 +03:00
[styled-components]: https://github.com/styled-components/styled-components
2018-07-29 19:37:09 +03:00
[create-react-app]: https://github.com/facebook/create-react-app
[next.js]: https://github.com/zeit/next.js/
2018-07-29 20:20:57 +03:00
[Spectacle]: https://github.com/FormidableLabs/spectacle