Skip to content
This repository was archived by the owner on Mar 16, 2026. It is now read-only.

Commit f9f6d2c

Browse files
committed
docs: update creating-your-themes
1 parent 04e7706 commit f9f6d2c

1 file changed

Lines changed: 54 additions & 35 deletions

File tree

src/docs/documentation/customizing/creating-your-themes.mdx

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ menu: Customizing
77

88
# Creating your themes
99

10-
One of the main features of Docz is that you can create your own theme from scratch and just use the data parsed from Docz.
10+
One of the main features of Docz is that it allows you to create your own theme from scratch and just use the data parsed from Docz.
1111
We provide a bunch of components that can help you create your own theme with little effort.
1212

13-
Let's use this project structure through the following examples:
13+
Let's assume we have the following project structure :
1414

1515
```
1616
pages/
@@ -25,12 +25,17 @@ package.json
2525
```
2626

2727

28-
The oldest way to acomplish that is by using the `theme` property inside the `doczrc.js` file. Now, if you want to create
29-
your own theme, just create a file located at `src/gatsby-theme-docz/index.js`
28+
The previous way of customizing docz in v0 and v1 was to use the `theme` property inside the `doczrc.js` file.
29+
30+
With v2, we leverage GatsbyJS theme shadowing to override any and all files of the theme.
31+
32+
For example, to create a new theme wrapper and override some styles, we create a file located at `src/gatsby-theme-docz/index.js` that shadows [gatsby-theme-docz/src/index.js](https://github.com/doczjs/docz/blob/master/core/gatsby-theme-docz/src/index.js)
33+
and provide a new theme container implementation as shown below.
34+
3035

3136
## Creating your theme component
3237

33-
Then just create your component passing the `children` inside it and export it as default using the [`theme()`](/docs/components-api) high order component as an enhancer.
38+
Create your theme component that takes in `children` as props and export it as default while using the [`theme()`](/docs/components-api) high order component as an enhancer.
3439

3540
```js
3641
// src/gatsby-theme-docz/index.js
@@ -42,16 +47,17 @@ const Theme = ({ children }) => <div>{children}</div>
4247
export default theme()(Theme)
4348
```
4449

45-
> It's required to pass the `children` property inside your theme in order to render Docz routes properly.
50+
> It's required to "pass down" the `children` property inside your theme component in order to render Docz routes properly.
4651
47-
In fact, if you just create something like above you won't have nothing too much useful to show.
48-
So, is important that you use the Docz [built-in components](/docs/components-api) to help you to create beautiful documents
49-
pages and use the parsed data from data for mount menus and other things.
52+
If you create something like the above example you won't have anything too useful to show.
53+
To customize your documentation make sure to check the [gatsby-docz-theme](https://github.com/doczjs/docz/tree/master/core/gatsby-theme-docz/src) source code
54+
to decide which modules you want to override.
5055

5156
## Default theme configuration
5257

53-
Each theme has your own default `themeConfig` object that define whatever you want to turn customizable.
54-
It's very useful to set something like custom fonts, colors, spaces, some styles properties and other project global variables.
58+
Each theme has its own default `themeConfig` object that allows you to override any part of the default theme found [here](https://github.com/doczjs/docz/blob/master/core/gatsby-theme-docz/src/theme/index.js).
59+
60+
The `themeConfig` allows you to customize fonts, colors, spaces, styles properties and other project global variables.
5561

5662
```js
5763
// src/gatsby-theme-docz/index.js
@@ -71,14 +77,15 @@ const themeConfig = {
7177
export default theme(themeConfig)(Theme)
7278
```
7379

74-
By default, Docz will use this object as default configuration and merge it with the `themeConfig` setting in the project configuration.
75-
Using together with `useConfig` hook you can do a lot of things, like use css-in-js theming or retrieve props from your `themeConfig` in a deep render component.
80+
By default, Docz will use [this object](https://github.com/doczjs/docz/blob/master/core/gatsby-theme-docz/src/theme/index.js) as the default configuration and merge it with the `themeConfig` setting in the project configuration.
81+
82+
You can then use the `useConfig` hook to do a lot of things, like use css-in-js theming or retrieve props from your `themeConfig` in a deep rendered component.
7683

7784
```js
7885
// src/gatsby-theme-docz/index.js
7986
import React from 'react'
8087
import { theme, useConfig } from 'docz'
81-
import { ThemeProvider } from 'emotion-theming'
88+
import { ThemeProvider } from 'theme-ui'
8289

8390
const Theme = () => {
8491
const config = useConfig()
@@ -102,15 +109,15 @@ export default theme(themeConfig)(Theme)
102109

103110
## Providing Components
104111

105-
How we explain in the components API section, the `<ComponentsProvider>` is the component responsible to
106-
provide for MDX and Docz each component that you want to render inside your documents. With these
107-
components passed to the provider, you can easily change how your mdx file will be rendered and change default behaviors and styles.
112+
As explained in the components API section, the `<ComponentsProvider>` is the component responsible for providing components to MDX and Docz to render your markdown files with.
113+
114+
With these components passed to the provider, you can change how your mdx file will be rendered and alter default behaviors and styles.
108115

109116
```js
110117
// src/gatsby-theme-docz/index.js
111118
import React from 'react'
112119
import { theme, useConfig, ComponentsProvider } from 'docz'
113-
import { ThemeProvider } from 'emotion-theming'
120+
import { ThemeProvider } from 'theme-ui'
114121

115122
import * as components from './ui'
116123

@@ -153,17 +160,21 @@ const themeConfig = {
153160
export default theme(themeConfig)(Theme)
154161
```
155162

156-
This is powerful because it forces you to write base components and create a default style for each one that will be used along the entire documents without the need to repeat any of them.
163+
This is powerful because it pushes you to think about your site as a set of base components
164+
and to create a default style for each one that will be used in all your documents while keeping your code DRY.
157165

158166
## Getting data from documents
159167

160-
So far you almost have an entire theme component. But just with the code above you will see just a document page without any link or
161-
information about all documents do you have. Create something like a menu with all documents is essential to create navigation.
168+
By now you should have a working site. But with the code above you will only see a single page without any link or information about the rest of your documents.
162169

163-
You can do this easily by using the `useMenus` and `<Link>` component.
170+
Having a way to navigate your documentation is essential in your documentation site.
164171

165-
The first one will give you information about all menus parsed from Docz and the second one ability to navigate to them.
166-
First of all, create something like a `<Menu />` component (we using a menu just to illustrate here):
172+
Let's create a `Menu` component by using the `useMenus` hook and the `<Link>` component.
173+
174+
The hook will give you information about all the menus' information parsed by Docz
175+
and the component will provide a way to navigate between them.
176+
177+
An example `Menu` component is shown below :
167178

168179
```js
169180
// src/Menu.js
@@ -184,7 +195,7 @@ export const Menu = () => {
184195
}
185196
```
186197

187-
Now you have a fully functional navigation to your documentation and you can simply use it your `<Menu />` component inside your theme:
198+
This will create a fully functional navigation menu to your documentation and you can then use the `<Menu />` component inside your theme:
188199

189200
```js
190201
// src/gatsby-theme-docz/index.js
@@ -234,27 +245,37 @@ const themeConfig = {
234245

235246
export default theme(themeConfig)(Theme)
236247
```
237-
238-
You can still use this component to create other things like a search component, some custom page or whatever came in your mind.
248+
You can also use this component to create other things like a search component, link to custom pages or whatever else you would like.
239249

240250
## Using documents settings
241251

242-
Another really interesting thing that you can do when you're creating your own theme is using the component's map `<Page>` to customize the document preview depending on each document settings. Since each document can have your own settings defined in the top of `.mdx` and the `Page` component receive a prop called `doc` that's the current rendered doc, you can use these settings to create page variations, like that:
252+
Another interesting thing that you can do when you're creating your own theme is to use the `componentMap`'s `<Page>` component to customize the document preview depending on each document's settings.
253+
254+
Each document can have its own settings defined in the header of the `.mdx` file.
243255

244-
Let's suppose that some pages of your documentation should have a hero image, but some don't. You can give a `hero` property for your document, and base on that prop you'll show or not the hero:
256+
The `Page` component receives a prop called `doc` that contains the settings data. You can use this data to build your own variations of the rendered pages.
257+
258+
For example, suppose that you'd like to add a hero image to some documents and leave others unchanged.
259+
260+
You could do that by providing a `hero` property to your document, and then if that property is defined you would render a hero, else you would show the document as is.
261+
262+
Your markdown would look something like this :
245263

246264
```markdown
265+
<!--
266+
hello-world.mdx
267+
-->
247268
---
248269
name: Hello world
249270
hero: /my/hero/img.png
250271
---
251272

252273
# Hello world
253274

254-
This is just a page!
275+
This is a page!
255276
```
256277

257-
After defining the hero page of your document, let's see how your `Page` component will look:
278+
And your `Page` component would look like the following :
258279

259280
```js
260281
// src/ui/Page.js
@@ -270,10 +291,8 @@ export const Page = ({ doc, children }) => (
270291
)
271292
```
272293

273-
Simple as that! Now you can create a lot of variations of your documents page.
274-
275-
How I told you, without pain and a lot of work your you can have a custom and very functional theme for your documentation. So, let's create your own theme and share with the community!
294+
Armed with this knowledge, you can create many variations of your documents based on the data provided in your MDX.
276295

277296
## Examples
278297

279-
If you'd like to see an example of a theme, you can check the [source code](https://github.com/doczjs/docz/tree/master/core/gatsby-theme-docz) of `gatsby-theme-docz`.
298+
To see an example of a theme, you can check the [source code](https://github.com/doczjs/docz/tree/master/core/gatsby-theme-docz/src) of `gatsby-theme-docz`.

0 commit comments

Comments
 (0)