@tenphi/cookbook 0.25.4 → 0.27.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.
@@ -130,6 +130,73 @@ import { Preview } from "@tenphi/cookbook/components";
130
130
  css={"button { padding: 0.75rem; }"}
131
131
  />
132
132
 
133
+ To demonstrate your own library, build it into the site's public directory
134
+ (`public/` by default) and list the files in `scripts` by their public path,
135
+ without the Astro `base`. Cookbook inlines each file, in order, before
136
+ `javascript`, so the authored code can use what they define. Each file runs as
137
+ a classic script, so use a self-contained IIFE or UMD build without `import` or
138
+ `export`:
139
+
140
+ ```mdx
141
+ <Preview
142
+ title="Library button"
143
+ html={"<acme-button>Save</acme-button>"}
144
+ scripts={["/demo/button.js"]}
145
+ javascript={"document.querySelector('acme-button').loading = true;"}
146
+ />
147
+ ```
148
+
149
+ Inlining keeps the preview isolated and needs no request, so the demo works in
150
+ `astro dev`, `astro preview`, and offline as well as on the deployed site. A
151
+ `<script src>` in `html` is a cross-site request from the sandboxed frame:
152
+ `astro dev` rejects it, and Chrome blocks it from local servers. View source
153
+ shows each inlined file as a `<script src>` tag. Every preview embeds its own
154
+ copy, so keep demo bundles small. A missing file or a path outside the public
155
+ directory fails the build.
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.
162
+
163
+ ```mdx
164
+ <Preview
165
+ title="Library select"
166
+ height="18rem"
167
+ html={"<acme-select label='Fruit'></acme-select>"}
168
+ scripts={["/demo/select.js"]}
169
+ />
170
+ ```
171
+
172
+ Forms in a preview can be submitted. To show what a form sends, call
173
+ `event.preventDefault()` in a `submit` listener and read its `FormData`;
174
+ otherwise the submission navigates the frame away from the demo. The
175
+ documentation page itself is never navigated, and the frame keeps its separate
176
+ origin.
177
+
178
+ ```mdx
179
+ <Preview
180
+ title="Form data"
181
+ html={
182
+ '<form><label>Name <input name="name" value="Ada"></label> <button>Send</button></form><output></output>'
183
+ }
184
+ javascript={
185
+ "document.querySelector('form').addEventListener('submit', (event) => { event.preventDefault(); document.querySelector('output').value = JSON.stringify(Object.fromEntries(new FormData(event.target))); });"
186
+ }
187
+ />
188
+ ```
189
+
190
+ <Preview
191
+ title="Form data"
192
+ html={
193
+ '<form><label>Name <input name="name" value="Ada"></label> <button>Send</button></form><output></output>'
194
+ }
195
+ javascript={
196
+ "document.querySelector('form').addEventListener('submit', (event) => { event.preventDefault(); document.querySelector('output').value = JSON.stringify(Object.fromEntries(new FormData(event.target))); });"
197
+ }
198
+ />
199
+
133
200
  ## Cookbook logo
134
201
 
135
202
  `Logo` renders the Cookbook mark. Use `label` when it carries meaning or
@@ -149,12 +216,12 @@ markers remain visible independently of their theme-aware backgrounds:
149
216
 
150
217
  ## Component props
151
218
 
152
- | Component | Props and behavior |
153
- | --------- | --------------------------------------------------------------------------------------------------- |
154
- | `Card` | Optional `title` and `href`; renders an article or link with slot content |
155
- | `Steps` | Ordered list container; supply `li` elements |
156
- | `Logo` | Optional `label`, `decorative`, and root `class`; renders the Cookbook mark |
157
- | `Preview` | Required `title`; optional `html`, `css`, and `javascript`; isolates examples in a sandboxed iframe |
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 |
158
225
 
159
226
  The public package exports each component's props type, such as `TabProps`,
160
227
  `CalloutProps`, and `CodeGroupProps`. Styles and all named sub-elements are
@@ -474,7 +474,8 @@ 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
477
+ `theme.styles.Preview.Frame`, or one preview's minimum height with its `height`
478
+ prop. The documentation shell supports the CSP directive
478
479
  `style-src-attr 'none'`. A host's CSP may also restrict the preview document; when
479
480
  using that directive, authored previews must use style blocks rather than style
480
481
  attributes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenphi/cookbook",
3
- "version": "0.25.4",
3
+ "version": "0.27.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.25.4",
72
- "@tenphi/renderer": "0.25.4"
71
+ "@tenphi/docs": "0.27.0",
72
+ "@tenphi/renderer": "0.27.0"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "astro": "^7.3.2"