@tenphi/cookbook 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -154,6 +154,95 @@ shows each inlined file as a `<script src>` tag. Every preview embeds its own
154
154
  copy, so keep demo bundles small. A missing file or a path outside the public
155
155
  directory fails the build.
156
156
 
157
+ A preview that runs scripts, with `javascript` or `scripts`, fits its frame to
158
+ its content. The frame grows and shrinks as the content changes, the page
159
+ width changes, or fonts load. It is at least `10rem` tall and at most as tall
160
+ as the browser window; taller content scrolls inside the frame. A preview
161
+ without scripts keeps a `10rem` frame, and content beyond it scrolls.
162
+
163
+ ```mdx
164
+ <Preview
165
+ title="Growing list"
166
+ html={'<button type="button">Add item</button><ol></ol>'}
167
+ javascript={
168
+ "document.querySelector('button').addEventListener('click', () => document.querySelector('ol').append(document.createElement('li')));"
169
+ }
170
+ />
171
+ ```
172
+
173
+ <Preview
174
+ title="Growing list"
175
+ html={'<button type="button">Add item</button><ol></ol>'}
176
+ javascript={
177
+ "document.querySelector('button').addEventListener('click', () => document.querySelector('ol').append(document.createElement('li')));"
178
+ }
179
+ />
180
+
181
+ The frame fits the content in the document's flow. An overlay, such as a
182
+ listbox, a popover, a modal dialog, or an absolutely positioned menu, doesn't
183
+ make it taller when it opens, so reserve room for it:
184
+
185
+ - `buffer` adds room below the content for a picker's list, such as a select's
186
+ or a combobox's. The room follows the content as the page width changes it.
187
+ It defaults to `0`. A preview without scripts can't measure its content, so
188
+ `buffer` has no effect there.
189
+ - `height` sets the frame's minimum height in place of `10rem`, for an overlay
190
+ that uses the whole frame, such as a modal dialog. It also applies to
191
+ previews without scripts.
192
+
193
+ The frame is as tall as the content plus `buffer`, up to the window's height,
194
+ and never shorter than `height`. Both take a CSS length, such as `12rem` or `320px`; any other value, including
195
+ a percentage or `calc()`, fails the build. To change every preview, style
196
+ `theme.styles.Preview.Frame` instead.
197
+
198
+ ```mdx
199
+ <Preview
200
+ title="Library select"
201
+ buffer="15rem"
202
+ html={"<acme-select label='Fruit'></acme-select>"}
203
+ scripts={["/demo/select.js"]}
204
+ />
205
+
206
+ <Preview
207
+ title="Library dialog"
208
+ height="24rem"
209
+ html={"<acme-dialog open>Saved</acme-dialog>"}
210
+ scripts={["/demo/dialog.js"]}
211
+ />
212
+ ```
213
+
214
+ Don't size the content by the frame, for example with `100vh` or
215
+ `height: 100%` on the root element: the frame can't fit such content, and it
216
+ can grow to the window's height.
217
+
218
+ Forms in a preview can be submitted. To show what a form sends, call
219
+ `event.preventDefault()` in a `submit` listener and read its `FormData`;
220
+ otherwise the submission navigates the frame away from the demo. The
221
+ documentation page itself is never navigated, and the frame keeps its separate
222
+ origin.
223
+
224
+ ```mdx
225
+ <Preview
226
+ title="Form data"
227
+ html={
228
+ '<form><label>Name <input name="name" value="Ada"></label> <button>Send</button></form><output></output>'
229
+ }
230
+ javascript={
231
+ "document.querySelector('form').addEventListener('submit', (event) => { event.preventDefault(); document.querySelector('output').value = JSON.stringify(Object.fromEntries(new FormData(event.target))); });"
232
+ }
233
+ />
234
+ ```
235
+
236
+ <Preview
237
+ title="Form data"
238
+ html={
239
+ '<form><label>Name <input name="name" value="Ada"></label> <button>Send</button></form><output></output>'
240
+ }
241
+ javascript={
242
+ "document.querySelector('form').addEventListener('submit', (event) => { event.preventDefault(); document.querySelector('output').value = JSON.stringify(Object.fromEntries(new FormData(event.target))); });"
243
+ }
244
+ />
245
+
157
246
  ## Cookbook logo
158
247
 
159
248
  `Logo` renders the Cookbook mark. Use `label` when it carries meaning or
@@ -173,12 +262,12 @@ markers remain visible independently of their theme-aware backgrounds:
173
262
 
174
263
  ## Component props
175
264
 
176
- | Component | Props and behavior |
177
- | --------- | -------------------------------------------------------------------------------------------------------------------------- |
178
- | `Card` | Optional `title` and `href`; renders an article or link with slot content |
179
- | `Steps` | Ordered list container; supply `li` elements |
180
- | `Logo` | Optional `label`, `decorative`, and root `class`; renders the Cookbook mark |
181
- | `Preview` | Required `title`; optional `html`, `css`, `javascript`, and public-file `scripts`; isolates examples in a sandboxed iframe |
265
+ | Component | Props and behavior |
266
+ | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
267
+ | `Card` | Optional `title` and `href`; renders an article or link with slot content |
268
+ | `Steps` | Ordered list container; supply `li` elements |
269
+ | `Logo` | Optional `label`, `decorative`, and root `class`; renders the Cookbook mark |
270
+ | `Preview` | Required `title`; optional `html`, `css`, `javascript`, public-file `scripts`, minimum frame `height`, and overlay `buffer`; isolates examples in a sandboxed iframe that fits scripted content |
182
271
 
183
272
  The public package exports each component's props type, such as `TabProps`,
184
273
  `CalloutProps`, and `CodeGroupProps`. Styles and all named sub-elements are
@@ -474,10 +474,14 @@ shadow-root templates), and non-Tasty stylesheets throughout documentation HTML.
474
474
  It parses actual markup, so escaped examples and strings in scripts are allowed.
475
475
  The explicit exception is the separate document in a sandboxed `Preview` iframe;
476
476
  it cannot access its parent's origin. Configure its size with
477
- `theme.styles.Preview.Frame`. The documentation shell supports the CSP directive
478
- `style-src-attr 'none'`. A host's CSP may also restrict the preview document; when
479
- using that directive, authored previews must use style blocks rather than style
480
- attributes.
477
+ `theme.styles.Preview.Frame`, or one preview's minimum height with its `height`
478
+ prop. For a preview that runs scripts, a client script sets the frame's
479
+ `height` to its content plus its `buffer` prop, within the frame's `min-height`
480
+ and `max-height` (by default `10rem` and the window's height). The
481
+ documentation shell supports the CSP directive `style-src-attr 'none'`, which
482
+ allows that script's style changes. A host's CSP may also restrict the preview
483
+ document; when using that directive, authored previews must use style blocks
484
+ rather than style attributes.
481
485
 
482
486
  Search uses an owned, keyboard-accessible dialog and server-rendered input so
483
487
  the first opening can focus the field immediately on mobile. Pagefind's indexing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenphi/cookbook",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
4
4
  "description": "Repository-native static documentation for Astro",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -68,8 +68,8 @@
68
68
  "author": "Andrey Yamanov",
69
69
  "license": "MIT",
70
70
  "dependencies": {
71
- "@tenphi/docs": "0.26.0",
72
- "@tenphi/renderer": "0.26.0"
71
+ "@tenphi/docs": "0.28.0",
72
+ "@tenphi/renderer": "0.28.0"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "astro": "^7.3.2"