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

Commit c130aa2

Browse files
author
Jesper Orb
authored
chore: update v2 documentation on multiple points (#80)
chore: update v2 documentation on multiple points
2 parents 8c75345 + 4cdddd2 commit c130aa2

10 files changed

Lines changed: 172 additions & 43 deletions

src/docs/documentation/customizing/add-favicon-and-metadata.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@ parent: Documentation
55
menu: Customizing
66
---
77

8-
To add a favicon and metadata to your generated gatsby site, follow this quick guide
8+
# Add favicon and metadata
99

10-
Add [`react-helmet`](https://github.com/nfl/react-helmet) along with [`gatsby-plugin-react-helmet`](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-react-helmet)
10+
Adding metadata to your site is done by configuring Gatsby in combination with [`react-helmet`](https://github.com/nfl/react-helmet) [**source @ gatsby**](https://www.gatsbyjs.org/docs/add-page-metadata/).
1111

12-
[How do I add react-helmet to my docz app ?](https://www.gatsbyjs.org/docs/add-page-metadata/)
1312

14-
Once you've added react-helmet you can shadow the `src/wrapper.js` theme component to add metadata
13+
### Shadowing the Wrapper-component
1514

16-
so you would create a file : `src/gatsby-theme-docz/wrapper.js` (path is important) and inside it :
15+
The metadata is set up in a file called `wrapper.js` which lives in docz theme package: `gatsby-theme-docz`. To override it we need to [Shadow the component](https://www.gatsbyjs.org/blog/2019-04-29-component-shadowing/), which means that we need to create a copy of the file with the "same" file path and name in our own `src`-directory.
1716

17+
1. Create a file called `wrapper.js` in `src/gatsby-theme-docz`. Then path is important.
18+
2. Paste the following content and edit it to your liking
1819
```js
1920
import * as React from 'react'
2021
import { Helmet } from 'react-helmet'
2122

2223
const Wrapper = ({ children }) => <React.Fragment>
2324
<Helmet>
2425
<meta charSet="utf-8" />
25-
<title>My Title</title>
26-
<link rel="icon"
27-
type="image/png"
28-
href="http://example.com/myicon.png"
29-
>
26+
<title>My Shadow!</title>
27+
<link rel="icon"
28+
type="image/png"
29+
href="http://example.com/myicon.png"
30+
/>
3031
</Helmet>
3132
{children}
3233
</React.Fragment>
3334
export default Wrapper
34-
3535
```
3636

37-
And that should do it 👍.
37+
If you rebuild your site now it should use this component as a wrapper instead of the themes component.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: Component Shadowing
3+
route: /docs/component-shadowing
4+
parent: Documentation
5+
menu: Customizing
6+
---
7+
8+
# Component Shadowing
9+
10+
All components that comes with the standard theme `gatsby-theme-docz` can be [**shadowed**](https://www.gatsbyjs.org/blog/2019-04-29-component-shadowing/). This means that you can supply your own component that will shadow/override the themes component. This is done by placing a component with the same name as the themes component in the "same filepath" as the original component.
11+
12+
For example if you want to shadow the `Logo`-component you would have to have the following structure in your folder:
13+
14+
```
15+
your-site
16+
└── src
17+
└── gatsby-theme-docz
18+
└── components
19+
└── Logo
20+
└──index.js
21+
```
22+
23+
If it has the matching folder structure and name the theme component will be shadowed and you can freely edit.

src/docs/documentation/customizing/powered-by-gatsby.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ and properties you can use with Docz.
3030

3131
> Check [all Gatsby API references](https://www.gatsbyjs.org/docs/api-reference/) here
3232
33-
So, if you want to use any of those Gatsby configurations file inside your Docz project, just create it in the root and we'll lead with them for you.
33+
So, if you want to use any of those Gatsby configurations file inside your Docz project, create it in the root and we'll handle them for you.
3434

35-
Like, if you want to make some change in the webpack configuration, you can use
35+
If you want to make some change in the webpack configuration, you can use
3636
the `onCreateWebpackConfig` hook inside the `gatsby-node.js` file:
3737

3838
```js

src/docs/documentation/general/built-in-components.mdx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { Button } from './Button'
3535
![](https://cdn-std.dprcdn.net/files/acc_649651/hrRpoR)
3636

3737
As you see, `<Playground>` rendered your component in a blank state, and right below, displayed the code used to.
38-
This can be very useful to test and develop your components in a good environment while you document it.
38+
This can be very useful to test and develop your components in a good environment while you document it. The code below the component is also editable and the changes you make to that code will reflect live in the component above!
3939

4040
## Component Props
4141

@@ -67,8 +67,44 @@ import { Button } from './'
6767
</Playground>
6868
```
6969

70-
And now you have a list of properties:
70+
The button that will display the props must have some annotation on the props. For non flow or typescript users this can be achieved with [`prop-types`](https://www.npmjs.com/package/prop-types)
71+
72+
```jsx
73+
import React from 'react'
74+
import t from 'prop-types'
75+
76+
const Button = ({ children, kind }) => {
77+
// Do something nice with the kind prop, like add a class with it
78+
return <button>{children}</button>
79+
}
80+
81+
Button.propTypes = {
82+
/**
83+
* This is a pretty good description for this prop.
84+
*/
85+
kind: t.oneOf(['primary', 'secondary', 'cancel', 'dark', 'gray']),
86+
}
87+
Button.defaultProps = {
88+
kind: 'primary',
89+
}
90+
export Button
91+
```
92+
93+
If you have used `prop-types` you should now have a list of properties in a nicely formatted table:
7194

7295
![](https://cdn-std.dprcdn.net/files/acc_649651/KEm5mH)
7396

74-
You can see more about our built-in components on [Components API](/docs/components-api).
97+
The same can be achieved in typescript by adding comments to the props interface of your component:
98+
99+
```jsx
100+
import React from 'react'
101+
102+
interface ButtonProps {
103+
/**
104+
* This is a pretty good description for this prop.
105+
*/
106+
kind: 'primary' | 'secondary' | 'cancel' | 'dark' | 'gray'
107+
}
108+
```
109+
110+
You can read more in depth about our built-in components on [**Components API**](/docs/components-api). If you are more interested in learning more about the MDX-pages you could head on to [**Document Settings**](/docs/document-settings)

src/docs/documentation/general/deploying-your-docs.mdx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Now that you know about writing your docs, let's talk about how you can build an
1111
The first thing that you need to do is run the build script created in your `package.json`:
1212

1313
```bash
14-
$ yarn build
14+
$ yarn docz:build
1515
```
1616

1717
If everything goes well, this command will generate all static files for you in the `.docz/dist` folder and you will see something like this in your terminal:
@@ -31,6 +31,17 @@ export default {
3131
}
3232
```
3333

34+
## Changing base folder
35+
36+
If you are using something like [GitHub Pages](https://pages.github.com/) chances are that you are not deploying your site directly under the root of your user. For example if you have a `docz`-repository on your GitHub the URL for deploying that repository will be `https://your-username.github.io/docz`. You can specify in which subdirectory your files will be deployed with the `base`-property of `doczrc.js`.
37+
38+
```js
39+
// doczrc.js
40+
export default {
41+
base: '/docz',
42+
}
43+
```
44+
3445
## Using Netlify
3546

3647
If you understand nothing about deploys, we highly recommend that you use the service we're using to host this website that you're seeing, called [Netlify](http://netlify.com/). Netlify is a really fantastic and easy tool that allows you to deploy your application in an automatic way by running the deploy on every push from a branch in seconds.

src/docs/documentation/general/document-settings.mdx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ menu: General
1010
Document settings can be something simple, but powerful. They should be defined in the top of the `.mdx`
1111
using yaml and can be used to change whatever you want by passing this config to your theme.
1212

13-
By default the document has just three properties that can't be overrided:
13+
By default the document has **three** properties that can't be overriden:
1414

1515
```markdown
1616
---
@@ -20,9 +20,7 @@ menu: Documents
2020
---
2121
```
2222

23-
These properties are self-explanatory, but here is their definition:
24-
25-
- `name` Define the name of your component.
23+
- `name` Define the name of your component, the title of the page
2624
- `route *(optional)*` Define the route of your component.
2725

2826
>If you don't pass any here, we'll create a slug getting the filepath of your file as route.
@@ -31,18 +29,14 @@ These properties are self-explanatory, but here is their definition:
3129

3230
## Custom properties
3331

34-
With just this properties perhaps you couldn't do many customizations.
35-
But, all documents can have arbitrary properties and you can use them to built your theme.
36-
37-
Example: you can define a property called `fullpage` to define whether your document is a page with `100%` width or not:
32+
The built in properties are for docz but docz is exstensible and you can create your own themes where you could have different needs and need different properties. Custom properties can be set in the document settings and they will automatically be parsed.
3833

34+
For example you can define a property called `fullpage` to define whether your document is a page with `100%` width or not:
3935
```
4036
---
4137
name: My Document
4238
fullpage: true
4339
---
4440
```
4541

46-
Now when you're creating your theme you can use this property to define inside your page component if shows a container of not.
47-
48-
This is very powerful and gives you flexibility when developing your own themes.
42+
When you later on are creating a theme these settings are passed to your theme components which you can read more about under [**Creating your themes: Using documents settings**](/docz/creating-your-themes#using-documents-settings)

src/docs/documentation/general/getting-started.mdx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ menu: General
1111
1212
## Migration Guide
1313

14-
This documentation it's about v2. If you need to migrate your Docz project, please read our [Migration Guide](/docs/migration-guide)
14+
This documentation it's about **v2**. If you need to migrate your Docz project, please read our [**Migration Guide**](/docs/migration-guide).
15+
If you are looking for documentation for v1 it's [**here**](https://docz-v1.surge.sh/)
1516

1617
## Installation
1718

1819
Getting started with **Docz** is something really easy and quick.
19-
First of all, you will need to install **Docz** using your favorite package manager (we'll assume yarn for this example):
20+
First of all, you will need to install **Docz** using your favorite package manager:
2021

2122
```bash
22-
$ yarn add docz@next react react-dom --dev
23+
$ yarn add docz@next react react-dom
24+
```
25+
or
26+
```bash
27+
$ npm add docz@next react react-dom
2328
```
2429

2530
> ### Warnings and tips
@@ -29,26 +34,32 @@ $ yarn add docz@next react react-dom --dev
2934
3035
```json
3136
{
32-
"name": "mycoolproject",
37+
"name": "next-gen-documentation",
3338
"scripts": {
3439
"docz:dev": "docz dev",
3540
"docz:build": "docz build"
3641
},
37-
"devDependencies": {
38-
"docz": "latest"
42+
"dependencies": {
43+
"docz": "latest",
44+
"react": "16.8.0",
45+
"react-dom": "16.8.0"
3946
}
4047
}
4148
```
4249

43-
Now you can spin up your dev server just by running:
50+
Now you can spin up your dev server by running:
4451

45-
```
52+
```bash
4653
$ yarn docz:dev
4754
```
55+
or
56+
```bash
57+
$ npm run docz:dev
58+
```
4859

4960
## Using
5061

51-
With your dev server up, you can start writing your documentation. Docz uses [MDX](https://mdxjs.com/) as a standard
62+
With your dev server up, you can start writing your documentation. Docz uses [**MDX**](https://mdxjs.com/) as a standard
5263
format because of the flexibility of writing JSX inside markdown files.
5364

5465
> Note that you **don't need to follow any strict file architecture**. You can just create your `.mdx` files **anywhere in your project**.
@@ -69,3 +80,5 @@ Hello, I'm a mdx file!
6980
With your first `.mdx` created, you can open your browser and visit `localhost:3000` and you should see something like this:
7081

7182
![](https://cdn-std.dprcdn.net/files/acc_649651/Y825GV)
83+
84+
_MDX_ is markdown with extra everything. We cover more on what you can do with _MDX_ under [**Writing MDX**](/docs/writing-mdx)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: Usage with CSS Preprocessors
3+
route: /docs/usage-with-css-preprocessors
4+
parent: Documentation
5+
menu: General
6+
---
7+
8+
# Using docz with CSS Preprocessors
9+
10+
Most configuration is from version 2 handled by Gatsby, and CSS preprocessing is no exception. Gatsby uses a range of [**Plugins**](https://www.gatsbyjs.org/plugins/) to handle things like `sass`, `less` and `postcss`. Gatsby supports CSS Modules out of the box.
11+
12+
These plugins are added by adding a `gatsby-config.js` in your project root or modifying an existing one. For example if you want to add support for `sass` you would do the following:
13+
14+
1. Install [`node-sass`](https://github.com/sass/node-sass) and [`gatsby-plugin-sass`](https://www.gatsbyjs.org/packages/gatsby-plugin-sass/)
15+
```bash
16+
# npm
17+
npm install --save node-sass gatsby-plugin-sass
18+
19+
# yarn
20+
yarn add node-sass gatsby-plugin-sass
21+
```
22+
23+
2. Add the plugin to your `gatsby-config.js`
24+
```js
25+
//gatsby-config.js
26+
module.exports = {
27+
plugins: ['gatsby-plugin-sass']
28+
}
29+
```
30+
You should now be able to use `sass` in your components!

src/docs/documentation/general/usage-with-typescript.mdx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ menu: General
77

88
# Using docz with Typescript
99

10-
To use docz with TypeScript codebase you need to add `typescript: true` to your doczrc.js
10+
To use docz with TypeScript codebase you need to add `typescript: true` to your `doczrc.js`, the rest will be setup by _docz_.
1111

1212
```js
1313
export default {
@@ -17,11 +17,20 @@ export default {
1717

1818
# Documenting Props in TypeScript
1919

20-
`docz` exports a Props component that takes in a component and generates a table of its props types, descriptions and default values.
20+
As mentioned in [**Built-in components**](/docs/built-in-components) the `<Props/>`-component is used to automatically document your components props assuming you have the correct comments on your components like below.
2121

22-
Make sure to reference the full path to the module you're documenting in your MDX file
22+
```js
23+
interface ButtonProps {
24+
/**
25+
* A description of the prop that you seem fit :)
26+
*/
27+
kind: 'primary' | 'secondary' | 'cancel' | 'dark' | 'gray'
28+
}
29+
```
2330

24-
```mdx
31+
The typescript parser can be a bit fussy sometimes (and we are working on it) so if your typescript-files are not being found you may have to write out the full path with the file ending. If this doesn't do the trick you can try checking if using `default` exports or `named` exports are the problem.
32+
33+
```js
2534
import { Props } from 'docz'
2635
import Button from './Button.tsx'
2736

@@ -30,3 +39,14 @@ import Button from './Button.tsx'
3039

3140
```
3241

42+
# Advanced configuration
43+
44+
If you have particular needs or need to control exactly which files are being picked up or if you want to tap into the parser that creates the documentation there are two properties on the `doczrc.js` that you can use: `filterComponents` and `docgenConfig` (some use cases explained [here](https://github.com/doczjs/docz/issues/827))
45+
46+
```js
47+
export default {
48+
filterComponents: (files) =>
49+
//This overrides the default filtering of components
50+
files.filter(filepath => /[w-]*.(js|jsx|ts|tsx)$/.test(filepath)),
51+
}
52+
```

src/docs/documentation/general/writing-mdx.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ More details about MDX in the [Official website.](https://mdxjs.com/)
1515
## Working with components
1616

1717
For now, you only need to know that with MDX you can use your components inside markdown.
18-
But how? Let's take a look at how we can improve our `.mdx` created before by importing and using a component inside it:
18+
But how? Let's take a look at how we can improve our `.mdx` created before by importing and using a component inside it. The example below assumes we have a exported component named `Button` in a file named `Button.jsx`/`Button.tsx` located in the same folder as the `.mdx`-file we are editing.
1919

2020
```markdown
2121
---
@@ -35,6 +35,8 @@ And, if you really have a `Button` component to import, you'll see something lik
3535

3636
![](https://cdn-std.dprcdn.net/files/acc_649651/Fgbg4F)
3737

38+
With MDX you can mix _React Components_ or _html-elements_ with regular markdown allowing you to either document your own components _or_ creating helper components that makes documentation easier. **Docz** comes with some prebuilt helper components which will help you document components faster, these are covered in [**Built-in components**](/docs/built-ins-components).
39+
3840
> ### Note
3941
>
4042
> So far Docz only works with React components. But stay calm, we are working to bring Preact, Vue and some others libraries to Docz!

0 commit comments

Comments
 (0)