You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 16, 2026. It is now read-only.
Copy file name to clipboardExpand all lines: src/docs/documentation/customizing/creating-your-themes.mdx
+54-35Lines changed: 54 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,10 @@ menu: Customizing
7
7
8
8
# Creating your themes
9
9
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.
11
11
We provide a bunch of components that can help you create your own theme with little effort.
12
12
13
-
Let's use this project structure through the following examples:
13
+
Let's assume we have the following project structure :
14
14
15
15
```
16
16
pages/
@@ -25,12 +25,17 @@ package.json
25
25
```
26
26
27
27
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
+
30
35
31
36
## Creating your theme component
32
37
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.
> 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.
46
51
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.
50
55
51
56
## Default theme configuration
52
57
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.
55
61
56
62
```js
57
63
// src/gatsby-theme-docz/index.js
@@ -71,14 +77,15 @@ const themeConfig = {
71
77
exportdefaulttheme(themeConfig)(Theme)
72
78
```
73
79
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.
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.
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.
157
165
158
166
## Getting data from documents
159
167
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.
162
169
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.
164
171
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 :
167
178
168
179
```js
169
180
// src/Menu.js
@@ -184,7 +195,7 @@ export const Menu = () => {
184
195
}
185
196
```
186
197
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:
188
199
189
200
```js
190
201
// src/gatsby-theme-docz/index.js
@@ -234,27 +245,37 @@ const themeConfig = {
234
245
235
246
exportdefaulttheme(themeConfig)(Theme)
236
247
```
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.
239
249
240
250
## Using documents settings
241
251
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.
243
255
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 :
245
263
246
264
```markdown
265
+
<!--
266
+
hello-world.mdx
267
+
-->
247
268
---
248
269
name: Hello world
249
270
hero: /my/hero/img.png
250
271
---
251
272
252
273
# Hello world
253
274
254
-
This is just a page!
275
+
This is a page!
255
276
```
256
277
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 :
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.
276
295
277
296
## Examples
278
297
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