@tenphi/cookbook 0.27.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,21 +154,67 @@ 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
- The frame is at least `10rem` tall, and content outside it is clipped. Give a
158
- demo with an overlay, such as a listbox, a popover, or a modal dialog, more
159
- room with `height`, the frame's minimum height as a CSS length such as `18rem`
160
- or `320px`. Any other value, including a percentage or `calc()`, fails the
161
- build. To change every preview, style `theme.styles.Preview.Frame` instead.
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.
162
197
 
163
198
  ```mdx
164
199
  <Preview
165
200
  title="Library select"
166
- height="18rem"
201
+ buffer="15rem"
167
202
  html={"<acme-select label='Fruit'></acme-select>"}
168
203
  scripts={["/demo/select.js"]}
169
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
+ />
170
212
  ```
171
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
+
172
218
  Forms in a preview can be submitted. To show what a form sends, call
173
219
  `event.preventDefault()` in a `submit` listener and read its `FormData`;
174
220
  otherwise the submission navigates the frame away from the demo. The
@@ -216,12 +262,12 @@ markers remain visible independently of their theme-aware backgrounds:
216
262
 
217
263
  ## Component props
218
264
 
219
- | Component | Props and behavior |
220
- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
221
- | `Card` | Optional `title` and `href`; renders an article or link with slot content |
222
- | `Steps` | Ordered list container; supply `li` elements |
223
- | `Logo` | Optional `label`, `decorative`, and root `class`; renders the Cookbook mark |
224
- | `Preview` | Required `title`; optional `html`, `css`, `javascript`, public-file `scripts`, and frame `height`; 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 |
225
271
 
226
272
  The public package exports each component's props type, such as `TabProps`,
227
273
  `CalloutProps`, and `CodeGroupProps`. Styles and all named sub-elements are
@@ -475,10 +475,13 @@ 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
477
  `theme.styles.Preview.Frame`, or one preview's minimum height with its `height`
478
- prop. The documentation shell supports the CSP directive
479
- `style-src-attr 'none'`. A host's CSP may also restrict the preview document; when
480
- using that directive, authored previews must use style blocks rather than style
481
- attributes.
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.
482
485
 
483
486
  Search uses an owned, keyboard-accessible dialog and server-rendered input so
484
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.27.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.27.0",
72
- "@tenphi/renderer": "0.27.0"
71
+ "@tenphi/docs": "0.28.0",
72
+ "@tenphi/renderer": "0.28.0"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "astro": "^7.3.2"