summaryrefslogtreecommitdiffstats
path: root/docs/api/components.md
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-12-22 10:18:38 +0100
committerGitHub <noreply@github.com>2016-12-22 10:18:38 +0100
commit194ebc3da9641ff96f083f9d8ab43c2d27944f9a (patch)
treec50988f32ccf18df93ae7ab40be78e9459642818 /docs/api/components.md
parent64ccb6b00b4b63fa0e516d4e35351275b34f8c07 (diff)
parent16af264360e48e8a833e9efa9ab8d194574dbc70 (diff)
downloadgitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.zip
gitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.tar.gz
gitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.tar.bz2
Merge pull request #1543 from GitbookIO/dream
React for rendering website with plugins
Diffstat (limited to 'docs/api/components.md')
-rw-r--r--docs/api/components.md86
1 files changed, 86 insertions, 0 deletions
diff --git a/docs/api/components.md b/docs/api/components.md
new file mode 100644
index 0000000..e323abc
--- /dev/null
+++ b/docs/api/components.md
@@ -0,0 +1,86 @@
+# Components
+
+
+## Injection
+
+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 |
+| ---- | ----------- | ----- |
+| `page:container` | DIV container for the page's content | `{ page: Page }` |
+| `summary:container` | DIV container for the whole summary | `{ summary: Summary }` |
+| `summary:parts` | DIV container for summary's parts | `{ parts: List<SummaryPart> }` |
+| `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.
+
+#### `GitBook.FlexLayout` and `GitBook.FlexBox`
+
+A simple wrapper that provides a Flexbox layout with the given direction and style. Any additional props you set on the Flexbox are rendered.
+
+```js
+<GitBook.FlexLayout column>
+ <GitBook.FlexBox>First column</GitBook.FlexBox>
+ <GitBook.FlexBox>Second column</GitBook.FlexBox>
+</GitBook.FlexLayout>
+```