1
1
mirror of https://github.com/jxnblk/mdx-deck.git synced 2024-11-29 13:58:02 +03:00
mdx-deck/docs/theming.md

186 lines
4.4 KiB
Markdown
Raw Normal View History

2018-08-05 18:27:17 +03:00
# Theming
mdx-deck uses [styled-components][] for styling, making practically any part of the presentation themeable.
## Built-in Themes
mdx-deck includes several built-in themes to change the look and feel of the presentation.
Export `theme` from your MDX file to enable a theme.
```mdx
export { dark as theme } from 'mdx-deck/themes'
# Dark Theme
```
2018-08-05 19:41:47 +03:00
View the [List of Themes](themes.md).
2018-08-05 18:27:17 +03:00
## Custom Themes
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 with fields for fonts, colors, and CSS for individual components.
It's recommended that all custom themes extend the default theme as a base.
```js
2018-08-05 20:11:25 +03:00
// Example theme.js
import theme from 'mdx-deck/themes'
2018-08-05 18:27:17 +03:00
export default {
// extends the default theme
...theme,
// add a custom font
font: 'Roboto, sans-serif',
// custom colors
colors: {
text: '#f0f',
background: 'black',
},
2018-08-05 18:27:17 +03:00
}
```
### Google Fonts
TK
<!--
2018-08-05 18:27:17 +03:00
To use webfonts, mdx-deck will attempt to add `<link>` tags for any font from Google Fonts.
2018-08-05 21:09:16 +03:00
To load webfonts from other sources, use a custom [Provider component](advanced.md#custom-provider-component) to add custom `<link>` tags.
-->
2018-08-05 18:27:17 +03:00
### Syntax Highlighting
TK
<!--
2018-08-05 18:27:17 +03:00
By default fenced code blocks do not include any syntax highlighting.
Syntax highlighting in fenced code blocks can be enabled by providing a `prism` style object in a theme.
The syntax highlighting is built with [react-syntax-highlighter][] and [PrismJS][].
Create a `theme.js` file and export it via the `MDX` file.
```js
export { default as theme } from './theme'
//...
```
```js
// example theme.js
import { future } from 'mdx-deck/themes'
import okaidia from 'react-syntax-highlighter/styles/prism/okaidia'
export default {
...future,
prism: {
style: okaidia
}
}
```
By default, only JavaScript and JSX are enabled for syntax highlighting to keep bundle sizes to a minimum.
To enable other languages, add a `languages` object to the `prism` object in the theme.
```js
// example theme.js
import { future } from 'mdx-deck/themes'
import okaidia from 'react-syntax-highlighter/styles/prism/okaidia'
import prismRuby from 'react-syntax-highlighter/languages/prism/ruby'
export default {
...future,
prism: {
style: okaidia,
languages: {
ruby: prismRuby
}
}
}
```
2018-08-05 19:41:47 +03:00
For lists of available syntax styles and languages, see:
2018-08-05 18:27:17 +03:00
- [Prism languages](https://github.com/conorhastings/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_PRISM.MD)
- [Prism styles](https://github.com/conorhastings/react-syntax-highlighter/blob/master/AVAILABLE_STYLES_PRISM.MD)
[PrismJS]: https://github.com/PrismJS/prism
[react-syntax-highlighter]: https://github.com/conorhastings/react-syntax-highlighter
-->
2018-08-05 18:27:17 +03:00
<!--
2018-08-25 18:25:42 +03:00
### Slide Transitions
The slide transition timing function and duration can be customized with a custom theme.
```js
// example theme
import theme from 'mdx-deck/themes'
export default {
...theme,
transitionTimingFunction: 'linear',
transitionDuration: '.1s'
}
```
-->
2018-08-05 18:27:17 +03:00
### Styling Elements
Each element can be styled with a theme. Add a style object (or string) to the theme to target specific elements.
```js
// example theme
import theme from 'mdx-deck/themes'
2018-08-05 18:27:17 +03:00
export default {
...theme,
h1: {
textTransform: 'uppercase',
letterSpacing: '0.1em',
2018-08-05 18:27:17 +03:00
},
blockquote: {
fontStyle: 'italic',
},
2018-08-05 18:27:17 +03:00
}
```
See the [reference](#reference) below for a full list of element keys.
2018-08-05 19:41:47 +03:00
## Reference
2018-08-05 18:27:17 +03:00
The following keys are available for theming:
- `font`: base font family
- `monospace`: font family for `<pre>` and `<code>`
- `colors`: object of colors used for MDX components
- `text`: root foreground color
- `background`: root background color
- `css`: root CSS object
- `h1`: CSS for `<h1>`
- `h2`: CSS for `<h2>`
- `h3`: CSS for `<h3>`
2018-08-05 21:09:16 +03:00
- `h4`: CSS for `<h4>`
- `h5`: CSS for `<h5>`
- `h6`: CSS for `<h6>`
2018-08-05 18:27:17 +03:00
- `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-08-05 21:09:16 +03:00
- `blockquote`: CSS for `<blockquote>`
2018-08-05 18:27:17 +03:00
- `table`: CSS for `<table>`
- `components`: object of MDX components to render markdown
- `Provider`: component for wrapping the entire app
2018-08-05 20:00:52 +03:00
## Advanced Usage
For more advanced customizations see the [Advanced Usage](advanced.md) docs.
2018-08-05 18:33:04 +03:00
2018-08-05 18:27:17 +03:00
[styled-components]: https://github.com/styled-components/styled-components
[mdx]: https://github.com/mdx-js/mdx