diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-09-22 18:28:37 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-09-22 18:28:37 +0200 |
commit | fa7cf3a65f7a19b2870e6d92c2e110e2356189ae (patch) | |
tree | 4ef3f8e4f713091ba24947cd97d470dd9ec5bd70 /docs | |
parent | d0885491b764718cb77dd86b179a9e959dfa32e1 (diff) | |
download | gitbook-fa7cf3a65f7a19b2870e6d92c2e110e2356189ae.zip gitbook-fa7cf3a65f7a19b2870e6d92c2e110e2356189ae.tar.gz gitbook-fa7cf3a65f7a19b2870e6d92c2e110e2356189ae.tar.bz2 |
Start documenting components
Diffstat (limited to 'docs')
-rw-r--r-- | docs/api/components.md | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/docs/api/components.md b/docs/api/components.md index 77f1bb1..64185a2 100644 --- a/docs/api/components.md +++ b/docs/api/components.md @@ -1,7 +1,21 @@ +# Components +## Injection -### Roles +Plugins can inject components by registering react components to some roles. + +#### Register a components + +During the initialization phase of your plugin, dispatch the `GitBook.registerComponent` action: + +```js +dispatch(GitBook.registerComponent(MyCustomButton, { role: 'toolbar:buttons:left' })); +``` + +#### Roles + +Custom roles can be use for interopability with other plugins, but GitBook and the default theme set a convention for common roles: | Role | Description | Props | | ---- | ----------- | ----- | @@ -10,3 +24,51 @@ | `summary:part` | DIV for a specific part | `{ part: SummaryPart }` | | `summary:articles` | UL container for a part's articles | `{ articles: List<SummaryArticle> }` | | `summary:article` | LI for a specific article | `{ article: SummaryArticle }` | + +## Default Components + +#### `GitBook.Head` + +Extends the meta tags of the page. This is an alias for [react-helmet](https://github.com/nfl/react-helmet). + +```js +<GitBook.Head + title="My page" + /> +``` + +#### `GitBook.ImportCSS` + +Import a CSS file by resolving the path correctly according to the current page: + +```js +<GitBook.ImportCSS href="myfile.css" /> +``` + +#### `GitBook.ImportJS` + +Import a JS file by resolving the path correctly according to the current page: + +```js +<GitBook.ImportJS src="mylib.js" /> +``` + +#### `GitBook.InjectedComponent` + +Inject a component matching a specific role: + +```js +<GitBook.InjectedComponent matching={{ role: 'mycustomrole' }} props={{ someProp: 1 }}> + <b>Inner content</b> +</GitBook.InjectedComponent> +``` + +#### `GitBook.InjectedComponentSet` + +Same API as `InjectedComponentSet` but render the matching components in chain instead of composed: + +```js +<GitBook.InjectedComponentSet matching={{ role: 'mytoolbar' }} /> +``` + +**Warning:** Children are discarded. |