|
| 1 | +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import { html } from 'lit'; |
| 5 | +import '@nvidia-elements/code/iframe/define.js'; |
| 6 | + |
| 7 | +export default { |
| 8 | + title: 'Code/Iframe', |
| 9 | + component: 'nve-iframe' |
| 10 | +}; |
| 11 | + |
| 12 | +/** |
| 13 | + * @summary Supplies the iframe with Elements themes, utilities, fonts, and component registrations through its head template. Use this structure because iframe documents do not inherit resources from the parent document. |
| 14 | + */ |
| 15 | +export const Default = { |
| 16 | + render: () => html` |
| 17 | +<nve-iframe> |
| 18 | + <template slot="head"> |
| 19 | + <title>Elements iframe example</title> |
| 20 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/themes/dist/bundles/index.css" /> |
| 21 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/themes/dist/fonts/inter.css" /> |
| 22 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/styles/dist/bundles/index.css" /> |
| 23 | + <script type="module" src="https://cdn.jsdelivr.net/npm/@nvidia-elements/core/dist/bundles/index.min.js"></script> |
| 24 | + </template> |
| 25 | + <template> |
| 26 | + <nve-alert status="success">isolated iframe content</nve-alert> |
| 27 | + </template> |
| 28 | +</nve-iframe> |
| 29 | + ` |
| 30 | +}; |
| 31 | + |
| 32 | +/** |
| 33 | + * @summary Synchronizes the iframe height with expandable content so the host layout avoids empty space or internal scrollbars. Use for previews whose intrinsic height changes after interaction. |
| 34 | + * @tags test-case |
| 35 | + */ |
| 36 | +export const DynamicHeight = { |
| 37 | + render: () => html` |
| 38 | +<nve-iframe style="--border: 1px solid red"> |
| 39 | + <template slot="head"> |
| 40 | + <title>Dynamic iframe height</title> |
| 41 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/themes/dist/bundles/index.css" /> |
| 42 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/themes/dist/fonts/inter.css" /> |
| 43 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/styles/dist/bundles/index.css" /> |
| 44 | + <script type="module" src="https://cdn.jsdelivr.net/npm/@nvidia-elements/core/dist/bundles/index.min.js"></script> |
| 45 | + </template> |
| 46 | + <template> |
| 47 | + <nve-accordion behavior-expand> |
| 48 | + <nve-accordion-header> |
| 49 | + <h2 nve-text="heading xs medium" slot="prefix">Dynamic height in iframe</h2> |
| 50 | + </nve-accordion-header> |
| 51 | + <nve-accordion-content> |
| 52 | + The iframe expands when this content opens and contracts when it closes. |
| 53 | + </nve-accordion-content> |
| 54 | + </nve-accordion> |
| 55 | + </template> |
| 56 | +</nve-iframe> |
| 57 | + ` |
| 58 | +}; |
| 59 | + |
| 60 | +/** |
| 61 | + * @summary Overrides intrinsic iframe dimensions with `--width` and `--height` to create a stable preview viewport. Use when you need to inspect embedded content at a fixed size regardless of its rendered bounds. |
| 62 | + * @tags test-case |
| 63 | + */ |
| 64 | +export const FixedSize = { |
| 65 | + render: () => html` |
| 66 | +<nve-iframe style="--height: 256px; --width: 256px; --border: 1px solid red"> |
| 67 | + <template><p style="height: 128px; width: 128px; margin: 1px; outline: 1px solid yellow;">override iframe size</p></template> |
| 68 | +</nve-iframe> |
| 69 | + ` |
| 70 | +}; |
| 71 | + |
| 72 | +/** |
| 73 | + * @summary The iframe browsing-context boundary clips popovers at its viewport and prevents them from escaping. Keep overlays inside the frame, or render them outside the iframe when they must overlap surrounding content. |
| 74 | + * @tags test-case |
| 75 | + */ |
| 76 | +export const OverflowClip = { |
| 77 | + render: () => html` |
| 78 | +<nve-iframe style="--height: 150px; --border: 1px solid red"> |
| 79 | + <template slot="head"> |
| 80 | + <title>Clipped iframe popover</title> |
| 81 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/themes/dist/bundles/index.css" /> |
| 82 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/themes/dist/fonts/inter.css" /> |
| 83 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/styles/dist/bundles/index.css" /> |
| 84 | + <script type="module" src="https://cdn.jsdelivr.net/npm/@nvidia-elements/core/dist/bundles/index.min.js"></script> |
| 85 | + </template> |
| 86 | + <template> |
| 87 | + <div nve-layout="pad:md"> |
| 88 | + <nve-dropdown id="dropdown">Popovers <strong>are clipped</strong> by the iframe.</nve-dropdown> |
| 89 | + <nve-button popovertarget="dropdown">Open popover</nve-button> |
| 90 | + </div> |
| 91 | + </template> |
| 92 | +</nve-iframe> |
| 93 | + ` |
| 94 | +}; |
| 95 | + |
| 96 | +/** |
| 97 | + * @summary Regenerates the iframe document when its source template changes. Use for live previews or generated output that must stay synchronized with edits made in the parent document. |
| 98 | + * @tags test-case |
| 99 | + */ |
| 100 | +export const DynamicallyUpdatedContent = { |
| 101 | + render: () => html` |
| 102 | +<nve-iframe id="property-example"> |
| 103 | + <template> |
| 104 | + <p nve-text="body">Initial iframe content.</p> |
| 105 | + </template> |
| 106 | +</nve-iframe> |
| 107 | +<script type="module"> |
| 108 | + document.querySelector('#property-example template').innerHTML = |
| 109 | + '<p nve-text="body">This template was dynamically updated.</p>'; |
| 110 | +</script> |
| 111 | + ` |
| 112 | +}; |
0 commit comments