-
Notifications
You must be signed in to change notification settings - Fork 9
feat(code): iframe component #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
coryrylan
wants to merge
1
commit into
main
Choose a base branch
from
topic-iframe
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { define } from '@nvidia-elements/core/internal'; | ||
| import { Iframe } from './iframe.js'; | ||
|
|
||
| define(Iframe); | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'nve-iframe': Iframe; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ | ||
| /* SPDX-License-Identifier: Apache-2.0 */ | ||
|
|
||
| :host { | ||
| --width: var(--_width, fit-content); | ||
| --height: var(--_height, fit-content); | ||
| --border: none; | ||
| display: block; | ||
| width: fit-content; | ||
| height: fit-content; | ||
| border: var(--border); | ||
| } | ||
|
|
||
| iframe { | ||
| width: var(--width); | ||
| height: var(--height); | ||
| border: 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { html } from 'lit'; | ||
| import '@nvidia-elements/code/iframe/define.js'; | ||
|
|
||
| export default { | ||
| title: 'Code/Iframe', | ||
| component: 'nve-iframe' | ||
| }; | ||
|
|
||
| /** | ||
| * @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. | ||
| */ | ||
| export const Default = { | ||
| render: () => html` | ||
| <nve-iframe aria-label="Elements iframe example"> | ||
| <template slot="head"> | ||
| <title>Elements iframe example</title> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/themes/dist/bundles/index.css" /> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/themes/dist/fonts/inter.css" /> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/styles/dist/bundles/index.css" /> | ||
| <script type="module" src="https://cdn.jsdelivr.net/npm/@nvidia-elements/core/dist/bundles/index.min.js"></script> | ||
| </template> | ||
| <template> | ||
| <nve-alert status="success">isolated iframe content</nve-alert> | ||
| </template> | ||
| </nve-iframe> | ||
| ` | ||
| }; | ||
|
|
||
| /** | ||
| * @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. | ||
| * @tags test-case | ||
| */ | ||
| export const DynamicHeight = { | ||
| render: () => html` | ||
| <nve-iframe aria-label="Dynamic height iframe example" style="--border: 1px solid red"> | ||
| <template slot="head"> | ||
| <title>Dynamic iframe height</title> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/themes/dist/bundles/index.css" /> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/themes/dist/fonts/inter.css" /> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/styles/dist/bundles/index.css" /> | ||
| <script type="module" src="https://cdn.jsdelivr.net/npm/@nvidia-elements/core/dist/bundles/index.min.js"></script> | ||
| </template> | ||
| <template> | ||
| <nve-accordion behavior-expand> | ||
| <nve-accordion-header> | ||
| <h2 nve-text="heading xs medium" slot="prefix">Dynamic height in iframe</h2> | ||
| </nve-accordion-header> | ||
| <nve-accordion-content> | ||
| The iframe expands when this content opens and contracts when it closes. | ||
| </nve-accordion-content> | ||
| </nve-accordion> | ||
| </template> | ||
| </nve-iframe> | ||
| ` | ||
| }; | ||
|
|
||
| /** | ||
| * @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. | ||
| * @tags test-case | ||
| */ | ||
| export const FixedSize = { | ||
| render: () => html` | ||
| <nve-iframe aria-label="Fixed-size iframe example" style="--height: 256px; --width: 256px; --border: 1px solid red"> | ||
| <template><p style="height: 128px; width: 128px; margin: 1px; outline: 1px solid yellow;">override iframe size</p></template> | ||
| </nve-iframe> | ||
| ` | ||
| }; | ||
|
|
||
| /** | ||
| * @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. | ||
| * @tags test-case | ||
| */ | ||
| export const OverflowClip = { | ||
| render: () => html` | ||
| <nve-iframe aria-label="Overflow clipping iframe example" style="--height: 150px; --border: 1px solid red"> | ||
| <template slot="head"> | ||
| <title>Clipped iframe popover</title> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/themes/dist/bundles/index.css" /> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/themes/dist/fonts/inter.css" /> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@nvidia-elements/styles/dist/bundles/index.css" /> | ||
| <script type="module" src="https://cdn.jsdelivr.net/npm/@nvidia-elements/core/dist/bundles/index.min.js"></script> | ||
| </template> | ||
| <template> | ||
| <div nve-layout="pad:md"> | ||
| <nve-dropdown id="dropdown">Popovers <strong>are clipped</strong> by the iframe.</nve-dropdown> | ||
| <nve-button popovertarget="dropdown">Open popover</nve-button> | ||
| </div> | ||
| </template> | ||
| </nve-iframe> | ||
| ` | ||
| }; | ||
|
|
||
| /** | ||
| * @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. | ||
| * @tags test-case | ||
| */ | ||
| export const DynamicallyUpdatedContent = { | ||
| render: () => html` | ||
| <nve-iframe id="property-example" aria-label="Dynamically updated iframe example"> | ||
| <template> | ||
| <p nve-text="body">Initial iframe content.</p> | ||
| </template> | ||
| </nve-iframe> | ||
| <script type="module"> | ||
| document.querySelector('#property-example template').innerHTML = | ||
| '<p nve-text="body">This template was dynamically updated.</p>'; | ||
| </script> | ||
| ` | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { html } from 'lit'; | ||
| import { describe, expect, it, beforeEach, afterEach } from 'vitest'; | ||
| import { createFixture, elementIsStable, removeFixture } from '@internals/testing'; | ||
| import { runAxe } from '@internals/testing/axe'; | ||
| import { Iframe } from '@nvidia-elements/code/iframe'; | ||
| import '@nvidia-elements/code/iframe/define.js'; | ||
|
|
||
| describe(Iframe.metadata.tag, () => { | ||
| let fixture: HTMLElement; | ||
| let element: Iframe; | ||
|
|
||
| beforeEach(async () => { | ||
| fixture = await createFixture(html`<nve-iframe aria-label="iframe test"></nve-iframe>`); | ||
| element = fixture.querySelector<Iframe>(Iframe.metadata.tag)!; | ||
| await elementIsStable(element); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| afterEach(() => { | ||
| removeFixture(fixture); | ||
| }); | ||
|
|
||
| it('should pass axe check', async () => { | ||
| const results = await runAxe([Iframe.metadata.tag]); | ||
| expect(results.violations.length).toBe(0); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { expect, test, describe } from 'vitest'; | ||
| import { lighthouseRunner } from '@internals/vite'; | ||
|
|
||
| describe('iframe lighthouse report', () => { | ||
| test('iframe should meet lighthouse benchmarks', async () => { | ||
| const report = await lighthouseRunner.getReport('nve-iframe', /* html */` | ||
| <nve-iframe aria-label="iframe test"></nve-iframe> | ||
| <script type="module"> | ||
| import '@nvidia-elements/code/iframe/define.js'; | ||
| </script> | ||
| `); | ||
|
|
||
| expect(report.scores.performance).toBe(100); | ||
| expect(report.scores.accessibility).toBe(100); | ||
| expect(report.scores.bestPractices).toBe(100); | ||
| expect(report.payload.javascript.kb).toBeLessThan(10); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { html } from 'lit'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { ssrRunner } from '@internals/vite'; | ||
| import { Iframe } from '@nvidia-elements/code/iframe'; | ||
| import '@nvidia-elements/code/iframe/define.js'; | ||
|
|
||
| describe(Iframe.metadata.tag, () => { | ||
| it('should pass baseline ssr check', async () => { | ||
| const result = await ssrRunner.render(html` | ||
| <nve-iframe> | ||
| <template slot="head"><title>Iframe SSR test</title></template> | ||
| <template><p nve-text="body">Iframe SSR content</p></template> | ||
| </nve-iframe> | ||
| `); | ||
|
|
||
| expect(result.includes('shadowroot="open"')).toBe(true); | ||
| expect(result.includes('nve-iframe')).toBe(true); | ||
| expect(result.includes('sandbox="allow-scripts"')).toBe(true); | ||
| expect(result.includes('allow-same-origin')).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.