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

304 lines
7.0 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-08-05 18:33:04 +03:00
[MDX][]-based presentation decks
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-08-05 21:09:16 +03:00
- :atom_symbol: Import and use [React components](#imports)
- :nail_care: Customizable [themes](#theming) and 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-08-05 18:33:04 +03:00
mdx-deck uses [styled-components][] for styling, making practically any part of the presentation themeable.
2018-07-29 19:37:09 +03:00
### Built-in Themes
2018-08-05 18:38:21 +03:00
<div>
<img src='docs/images/future.png' width='256' />
<img src='docs/images/comic.png' width='256' />
<img src='docs/images/yellow.png' width='256' />
</div>
2018-08-05 18:37:43 +03:00
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-08-05 20:11:25 +03:00
MDX uses [exports](https://github.com/mdx-js/mdx#exports) as a way for files to communicate with their parent components.
2018-08-05 17:14:46 +03:00
For a list of available themes see the [Themes Docs](docs/themes.md).
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
```
2018-08-05 18:27:17 +03:00
The theme should be an object with fields for fonts, colors, and CSS for individual components.
It's recommended that all custom themes extend the default theme as a base.
2018-07-29 02:28:36 +03:00
```js
2018-08-05 20:11:25 +03:00
// example theme.js
2018-08-05 18:27:17 +03:00
import { theme } from 'mdx-deck/themes'
2018-08-05 00:29:38 +03:00
export default {
2018-08-05 18:27:17 +03:00
// extends the default theme
...theme,
// add a custom font
font: 'Roboto, sans-serif',
// custom colors
colors: {
text: '#f0f',
background: 'black',
link: '#0ff',
2018-08-05 00:29:38 +03:00
}
}
```
2018-08-05 18:27:17 +03:00
Read more about theming in the [Theming docs](docs/theming.md)
2018-07-29 02:28:36 +03:00
2018-08-01 02:27:52 +03:00
### Components
2018-08-05 18:27:17 +03:00
mdx-deck includes built-in components to help with creating presentations, including a full screen Image component, the Appear component that allows stepping through parts of a single slide, and the Notes component for adding speaker notes.
2018-08-04 00:30:39 +03:00
2018-08-05 20:11:25 +03:00
Read more in the [components docs](docs/components.md).
2018-08-04 00:30:39 +03:00
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-08-05 20:11:25 +03:00
### Built-in Layouts
2018-08-04 23:45:55 +03:00
2018-08-05 20:11:25 +03:00
mdx-deck includes some built-in layouts for inverting theme colors and changing the layout of a slide. Read more about [built-in layouts](docs/components.md#layouts).
2018-08-04 00:36:51 +03:00
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.
2018-08-05 18:39:34 +03:00
![presenter mode screenshot](docs/images/presenter-mode.png)
2018-08-04 00:43:01 +03:00
2018-08-03 03:32:56 +03:00
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-04 18:14:36 +03:00
- In your window press the `Option + P` (`Alt + P`) key to enter presenter mode.
2018-08-03 03:32:56 +03:00
- 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-08-04 18:14:36 +03:00
### Keyboard Shortcuts
Key | Description
---|---
Left Arrow | Go to previous slide
Right Arrow | Go to next slide
Space | Go to next slide
Option + P | Toggle [Presenter Mode](#presenter-mode)
Up Arrow | Hide current step in [Appear](#appear) component
Down Arrow | Show next step in [Appear](#appear) component
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-08-05 18:27:17 +03:00
## Docs
2018-07-29 19:37:09 +03:00
2018-08-05 18:27:17 +03:00
- [Theming](docs/theming.md)
2018-08-05 19:49:27 +03:00
- [Built-in Themes](docs/themes.md)
2018-08-05 20:11:25 +03:00
- [Layouts](docs/layouts.md)
2018-08-05 18:27:17 +03:00
- [Components](docs/components.md)
2018-08-05 20:03:25 +03:00
- [Advanced Usage](docs/advanced.md)
2018-08-05 18:27:17 +03:00
- [React API](docs/react.md)
2018-07-29 19:37:09 +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 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 20:20:57 +03:00
[Spectacle]: https://github.com/FormidableLabs/spectacle