-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
214 lines (170 loc) · 6.14 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Docoff</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<link type="text/css" rel="stylesheet" href="/main.css" />
<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15/prop-types.min.js"></script>
<script src="/generated/bundle.js"></script>
<style>
h2 {
padding-top: 2em;
}
h3, h4 {
padding-top: 1em;
}
th, td {
border: 1px solid black;
padding: 8px;
}
thead th {
width: 25%;
}
</style>
</head>
<body class="py-5">
<div class="container">
<h1>Docoff Demo</h1>
<p>Styles used in this demo:</p>
<ul>
<li><code>/shadow.css</code> Sets all text inside preview to be red and monospaced.</li>
<li><code>/main.css</code> Sets CSS custom properties including location of the <code>/shadow.css</code></li>
</ul>
<p>Feel free to inspect them in dev tools!</p>
<h2><code>docoff-react-base</code></h2>
<p><code><docoff-react-base></code> allows to define code that is common for all <code>docoff-react-preview</code> elements on the
given page. This is handy for defining code fragments susch as constants or placeholder React components that
can be used further on.</p>
<h3>Usage</h3>
<h4>Pure HTML</h4>
<pre><code>
<textarea is="docoff-react-base">
// Your JS code here
</textarea>
</code></pre>
<h4>Markdown</h4>
<pre><code>
```docoff-react-base
// Your JS code here
```
</code></pre>
<h3>Example</h3>
<textarea is="docoff-react-base">
const MyHello = ({name}) => (
<strong>Hello, {name}</strong>
);
</textarea>
<h2><code>docoff-react-preview</code></h2>
<p><code><docoff-react-preview></code> renders a live preview of JSX code.</p>
<h3>Usage</h3>
<h4>Pure HTML</h4>
<pre><code>
<textarea is="docoff-react-preview" css="/shadow.css">
<YourCustomJSX />
</textarea>
</code></pre>
<h4>Markdown</h4>
<pre><code>
```docoff-react-base
// Your JS code here
```
</code></pre>
<h3>Example</h3>
<h4>Single Component</h4>
<textarea is="docoff-react-preview">
<MyHello name="Igor" />
</textarea>
<h4>Multiple Components</h4>
<textarea is="docoff-react-preview">
<>
<MyHello name="Igor" />
<br />
<MyHello name="Mia" />
</>
</textarea>
<h4>With Hooks</h4>
<textarea is="docoff-react-preview">
React.createElement(() => {
const [name, setName] = React.useState('Igor');
const MyButton = ({
label,
onClick,
}) => (
<button onClick={onClick}>{label}</button>
);
return (
<>
<MyHello name={name} />
<br />
<MyButton
label={'Swap name'}
onClick={() => setName(name === 'Igor' ? 'Mia' : 'Igor')}
/>
</>
);
});
</textarea>
<h2><code>docoff-react-props</code></h2>
<p><code><docoff-react-props></code> renders the component prop definition table.</p>
<p>The props can be loaded from multiple files. This allows for writing more DRY code when several components share same props.</p>
<p>There are simple rules for loading props from multiple files:</p>
<ul>
<li>Files get processed sequentially
<li>The result of merging all previous files is used as base when merging in the current file</li>
<li>When a prop is not defined in the current file, it will not be present in the merge result</li>
<li>When a prop is defined in the current file, with docblock description of the prop type definition, the definition from current file will be used</li>
<li>When a prop default value is defined in the current file, with no docblock description of the prop type definition, the definition from base will be used, but with the default value from the current file</li>
<li>When a prop is defined in the current file, with no docblock description of the prop type definition, the definition from base will be used including default value</li>
</ul>
<h3>Examples</h3>
<p>Using <code>docoff-react-preview</code> :)</p>
<h4>Relative URL with Overloading</h4>
<textarea is="docoff-react-preview">
<docoff-react-props src="
/exampleJS/common.props.js
|/exampleJS/Greeting.jsx
"></docoff-react-props>
</textarea>
<h4>Absolute URL</h4>
<textarea is="docoff-react-preview">
<docoff-react-props
src="https://raw.githubusercontent.com/react-ui-org/react-ui/master/src/components/Alert/Alert.jsx"
></docoff-react-props>
</textarea>
<h2><code>docoff-placeholder</code></h2>
<code><docoff-placeholder></code> renders a placeholder that can be used in code examples.
<textarea is="docoff-react-preview">
<docoff-placeholder bordered></docoff-placeholder>
</textarea>
<h3>Children</h3>
<p>Children can be inserted</p>
<textarea is="docoff-react-preview">
<docoff-placeholder bordered>Hello</docoff-placeholder>
</textarea>
<h3>Color</h3>
<p>It can be rendered dark</p>
<textarea is="docoff-react-preview">
<docoff-placeholder dark></docoff-placeholder>
</textarea>
<h3>Size</h3>
<p>Size can be set using any valid css units</p>
<textarea is="docoff-react-preview">
<docoff-placeholder width="50px" height="50px" bordered></docoff-placeholder>
</textarea>
<h3>Layout</h3>
<p>It can be rendered inline</p>
<textarea is="docoff-react-preview">
Inline <docoff-placeholder inline bordered></docoff-placeholder>
</textarea>
</div>
</body>
</html>