Skip to content

Commit ddabf67

Browse files
committed
initial commit
1 parent 9282bd8 commit ddabf67

38 files changed

+2724
-168
lines changed

.travis.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

README.md

Lines changed: 222 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# @frontarm/document
1+
@frontarm/document
2+
==================
23

3-
> A component for creating responsive documents with MDX
4+
> A set of components for creating rich, responsive documents built around MDX.
45
56
[![NPM](https://img.shields.io/npm/v/@frontarm/document.svg)](https://www.npmjs.com/package/@frontarm/document) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
67

@@ -10,22 +11,230 @@
1011
npm install --save @frontarm/document
1112
```
1213

13-
## Usage
1414

15-
```tsx
16-
import * as React from 'react'
15+
Main Components
16+
---------------
1717

18-
import MyComponent from '@frontarm/document'
18+
### `<Document>`
1919

20-
class Example extends React.Component {
21-
render () {
22-
return (
23-
<MyComponent />
24-
)
25-
}
20+
Expects an MDX component as its `Component` prop.
21+
22+
Like MDX components, the components that are used to render each type of Document component can be configured, either by passing in a `components` object to your `<Document>` component, or by using a `<DocumentProvider>` component.
23+
24+
#### `props
25+
26+
- `Component`
27+
28+
The MDX Document component to render.
29+
30+
- `documentProps?: DocumentProps`
31+
32+
Props that will be passed through to the rendered Document Component
33+
34+
- `demoboardHelpers?: { [name: string]: string }`
35+
36+
Helper files that will be available to all inline demoboards
37+
38+
- `canAccessRestrictedContent?: boolean`
39+
40+
If true, any editors/videos with the `isRestricted` attribute will be usable
41+
42+
- `isStatic?: boolean`
43+
44+
If true, any nested `<HideWhenStatic>` blocks will not be shown.
45+
46+
47+
### `<DocumentProvider components children>`
48+
49+
Merges in default values for the `components` object of any child `<Component>` elements.
50+
51+
52+
Content Components
53+
------------------
54+
55+
### `<Beware children title="Beware">`
56+
57+
Indicates content that helps the reader from hurting themselves or losing a large amount of time.
58+
59+
Assumes placement within the left column.
60+
61+
### `<Demoboard ...>`
62+
63+
Renders an inline demoboard.
64+
65+
#### `props`
66+
67+
- `persistenceKey`
68+
69+
If present, any changes will be saved for each user, and loaded when the user navigates back to the page. This key will not be visible to the user, and should be unique across the entire site. It should follow the format `path#keyWithinPage`. A warning will be logged if the path doesn't map to the current path, or if multiple keys are used on the same page.
70+
71+
- `restricted`
72+
73+
If true, readers won't be able to use the demoboard unless `canAccessRestrictedContent` is also passed to the parent `<Document>` element.
74+
75+
- `sources`
76+
77+
Accepts a list of sources, with magic sources prefixed by `magic:`, and solution sources prefixed by `solution:`.
78+
79+
*Future plan: create a loader that allows an entire directory to be smashed in here with a single `require()`...*
80+
81+
- `theme?: "dark" | "light"`
82+
83+
- `maximizeLeftPanel?: boolean`: *defaults to `true`*
84+
- `maximizeRightPanel?: boolean`: *defaults to `false`*
85+
- `leftPanel?: 'transformedSource' | 'solutionSource'`
86+
- `lineCount?: number`
87+
- `rightPanel?: 'console'`
88+
- `tab?: 'editor' | 'viewer'`
89+
90+
### `<Details children title=null>`
91+
92+
Can be placed in either the left or right columns.
93+
94+
### `<Spoiler children title="Spoiler">`
95+
96+
Assumes placement within the left column.
97+
98+
### `<Tangent children title=null>`
99+
100+
Assumes placement within the right column.
101+
102+
### `<Video ...>`
103+
104+
Can be placed anywhere; the left column, right column, both columns or full width are all allowable.
105+
106+
#### `props`
107+
108+
- `TODO`
109+
110+
- `restricted`
111+
112+
If true, readers won't be able to use the demoboard unless `canAccessRestrictedContent` is also passed to the parent `<Document>` element.
113+
114+
115+
Layout Components
116+
-----------------
117+
118+
Layout components are not configurable
119+
120+
### `<Document.AsideOrAfter aside children>`
121+
122+
Renders the `aside` element on the right of `children` if there's space, but when collpasing to a single column, renders the `aside` element underneath `children`.
123+
124+
### `<Document.LeftBlock children>`
125+
126+
Renders a block of content in the left column.
127+
128+
### `<Document.FloatRight children>`
129+
130+
Floats a block of content right of the following columns, similar to how floats in CSS work.
131+
132+
### `<Document.FullBlock children>`
133+
134+
Renders a block of content that takes the full width of the `<Document>` component, allowing you to choose your own margins.
135+
136+
### `<Document.DoubleBlock children>`
137+
138+
Renders a block of content that takes up the width of both columns, if they're available.
139+
140+
141+
Conditional Rendering Components
142+
--------------------------------
143+
144+
### `<Document.HideWhenStatic children>`
145+
146+
Hides its children when the document is being statically built -- useful for parts of the document that vary between guest and pro members.
147+
148+
### `<Document.Restricted restricted? children>`
149+
150+
Show the children only when the viewer has full access to the document. If the viewer doesn't have full access, show the `restricted` element instead.
151+
152+
153+
Code blocks
154+
-----------
155+
156+
When Markdown code blocks begin with the line `//---`, they'll be turned into `<Document.Demoboard>` elements. Otherwise, they'll be treated as code listings, which are rendered with the standard `codeBlock` component.
157+
158+
Demoboard code blocks will be split into sections denoted by `//---`. The first section contains configuration that will be passed as props to the `<Document.Demoboard>` component. The following sections will be treated differently depending on how they start:
159+
160+
- `--- filename`
161+
162+
Treats the following lines as a source file with the specified filename
163+
164+
- `-- solution:filename`
165+
166+
Treats the following lines as a solution for the specified filename
167+
168+
- `--- magic:filename`
169+
170+
Treats the following lines as a magic file with the specified filename
171+
172+
- `... <-- helperFilename`
173+
174+
Creates a file, solution or magic file from the helper with the given name.
175+
176+
### Example
177+
178+
```jsx
179+
//---
180+
// name: "Demoboard name"
181+
// description: "Some description about this demoboard"
182+
// isRestricted: true // if true, this will be hidden unless
183+
// defaultRightPanel: "console"
184+
// consoleIsMaximized: false
185+
// defaultViewerURL: ''
186+
//--- main.js
187+
const isDone = false
188+
//--- helper:main.js
189+
const isDone = true
190+
//--- magic:package.json
191+
{
192+
name: "magicFile",
193+
description: "built but not displayed in tabs"
194+
}
195+
//--- styles.css <-- styles-a.css
196+
.test {
197+
/**
198+
* Helpers allow files to be shared between demoboards
199+
*/
26200
}
27201
```
28202

203+
Note that while this inline syntax is great for small, quick examples, for bigger examples you might find it easier to manually add a `<Document.Demoboard>` element.
204+
205+
206+
`components` object
207+
-------------------
208+
209+
The `components` object can be passed to an individual `<Document>`, or can be passed to a `<DocumentProvider>` to set the default components for all child documents. It supports all MDX compnents, along with a number of document-specific components.
210+
211+
- `<wrapper>`
212+
213+
Like the MDX `wrapper` component, but also receives any `className`, `style` and `id` that were passed to the `<Document>` element itself.
214+
215+
- `<headingLink href>`
216+
217+
A link within heading elements that points to the heading itself.
218+
219+
220+
### Content components
221+
222+
- `Beware`
223+
- `Demoboard`: *also includes a `hasAccess` boolean*
224+
- `Details`
225+
- `Spoiler`
226+
- `Tangent`
227+
- `Video`: *also includes a `hasAccess` boolean*
228+
229+
### Layout components
230+
231+
- `AsideOrAfter`
232+
- `LeftBlock`
233+
- `FloatRight`
234+
- `FullBlock`
235+
- `DoubleBlock`
236+
237+
29238
## License
30239

31-
MIT © [jamesknelson](https://github.com/jamesknelson)
240+
MIT © [James K Nelson](https://frontarm.com)

TODO.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
More components:
2+
3+
- `<Tweet>`
4+
- `<Reset>` (removes layout styles on anything embedded within it, so that you can use `<p>`, etc. without applying layout styles)

example/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["react-app"]
3+
}

example/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
"license": "MIT",
66
"private": true,
77
"dependencies": {
8-
"prop-types": "^15.6.2",
9-
"react": "^16.4.1",
10-
"react-dom": "^16.4.1",
11-
"react-scripts": "^1.1.4",
12-
"@frontarm/document": "link:.."
8+
"@frontarm/document": "link:..",
9+
"react-scripts": "^1.1.4"
1310
},
1411
"scripts": {
1512
"start": "react-scripts start",

example/src/App.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
/* eslint-disable import/no-webpack-loader-syntax */
12
import React, { Component } from 'react'
2-
3-
import ExampleComponent from '@frontarm/document'
3+
import { NavProvider } from 'react-navi'
4+
import { Document } from '@frontarm/document'
45

56
export default class App extends Component {
6-
render () {
7+
render() {
78
return (
8-
<div>
9-
<ExampleComponent text='Modern React component module' />
10-
</div>
9+
<NavProvider navigation={this.props.navigation}>
10+
<Document
11+
Component={require('!babel-loader!mdx-loader!./document.md').default}
12+
/>
13+
</NavProvider>
1114
)
1215
}
1316
}

0 commit comments

Comments
 (0)