Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 12
feat(core): add format-truncate#216
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
mainChoose a base branch
from
topic-format-truncate
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.
Uh oh!
There was an error while loading. Please reload this page.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 { FormatTruncate } from '@nvidia-elements/core/format-truncate'; | ||
| define(FormatTruncate); | ||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'nve-format-truncate': FormatTruncate; | ||
| } | ||
| } |
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 */ | ||
| :host { | ||
| display: contents; | ||
| } | ||
| span { | ||
| text-wrap: nowrap; | ||
| } | ||
| slot { | ||
| display: initial; | ||
| position: absolute; | ||
| width: 1px; | ||
| height: 1px; | ||
| padding: 0; | ||
| overflow: hidden; | ||
| clip-path: inset(50%); | ||
| white-space: nowrap; | ||
| } |
64 changes: 64 additions & 0 deletions
64 projects/core/src/format-truncate/format-truncate.examples.ts
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,64 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import { html } from 'lit'; | ||
| import '@nvidia-elements/core/format-truncate/define.js'; | ||
| export default { | ||
| title: 'Elements/FormatTruncate', | ||
| component: 'nve-format-truncate' | ||
| }; | ||
| /** | ||
| * @summary Start, center, and end positions keep the most useful part of constrained text. Choose the position that matches how users distinguish each value. | ||
| */ | ||
| export const Default = { | ||
| render: () => html` | ||
| <div nve-layout="column gap:sm" style="max-width: 16rem"> | ||
| <nve-format-truncate position="start">training-pipeline-2026-08-05-production</nve-format-truncate> | ||
| <nve-format-truncate position="center">training-pipeline-2026-08-05-production</nve-format-truncate> | ||
| <nve-format-truncate position="end">training-pipeline-2026-08-05-production</nve-format-truncate> | ||
| </div> | ||
| ` | ||
| }; | ||
| /** | ||
| * @summary Inherited heading, body, and code styles keep truncated text aligned with surrounding typography. Place the component inside semantic text elements to preserve their visual hierarchy. | ||
| * @tags test-case | ||
| */ | ||
| export const Typography = { | ||
| render: () => html` | ||
| <div nve-layout="column gap:lg align:stretch" style="max-width: 16rem"> | ||
| <h2 nve-text="heading lg"><nve-format-truncate position="center">training-pipeline-2026-08-05-production</nve-format-truncate></h2> | ||
| <p nve-text="body"><nve-format-truncate position="center">training-pipeline-2026-08-05-production</nve-format-truncate></p> | ||
| <code nve-text="code sm muted"><nve-format-truncate position="center">training-pipeline-2026-08-05-production</nve-format-truncate></code> | ||
| </div> | ||
| ` | ||
| }; | ||
| /** | ||
| * @summary Center truncation bias keeps units from either the start or end. Use end bias for shared suffixes and start bias for identifiers with meaningful endings. | ||
| * @tags test-case | ||
| */ | ||
| export const Bias = { | ||
| render: () => html` | ||
| <div nve-layout="column gap:sm" style="max-width: 16rem"> | ||
| <nve-format-truncate position="center" bias="start" preserve="10">sha256:1234567890abcdef1234567890abcdef</nve-format-truncate> | ||
| <nve-format-truncate position="center" bias="end" preserve="10">sha256:1234567890abcdef1234567890abcdef</nve-format-truncate> | ||
| </div> | ||
| ` | ||
| }; | ||
| /** | ||
| * @summary Character, word, and path strategies preserve complete graphemes or meaningful text units. Match the strategy to identifiers, labels, or file paths. | ||
| * @tags test-case | ||
| */ | ||
| export const Strategy = { | ||
| render: () => html` | ||
| <div nve-layout="column gap:sm" style="max-width: 16rem"> | ||
| <nve-format-truncate position="center" strategy="character" preserve="8">experiment-👩🏽💻-0123456789abcdef</nve-format-truncate> | ||
| <nve-format-truncate position="center" strategy="word" preserve="3">NVIDIA autonomous vehicle training pipeline production run</nve-format-truncate> | ||
| <nve-format-truncate position="center" strategy="path" preserve="2">/models/checkpoints/production/model.bin</nve-format-truncate> | ||
| </div> | ||
| ` | ||
| }; |
29 changes: 29 additions & 0 deletions
29 projects/core/src/format-truncate/format-truncate.test.axe.ts
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 } from 'vitest'; | ||
| import { createFixture, elementIsStable, removeFixture } from '@internals/testing'; | ||
| import { runAxe } from '@internals/testing/axe'; | ||
| import { FormatTruncate } from '@nvidia-elements/core/format-truncate'; | ||
| import '@nvidia-elements/core/format-truncate/define.js'; | ||
| describe(FormatTruncate.metadata.tag, () => { | ||
| it('should pass axe checks for every truncation position and strategy', async () => { | ||
| const fixture = await createFixture(html` | ||
| <nve-format-truncate position="start">training-pipeline-2026-08-05-production</nve-format-truncate> | ||
| <nve-format-truncate position="end">training-pipeline-2026-08-05-production</nve-format-truncate> | ||
| <nve-format-truncate position="center" strategy="character">experiment-👩🏽💻-0123456789abcdef</nve-format-truncate> | ||
| <nve-format-truncate position="center" strategy="word" bias="start" preserve="3">NVIDIA autonomous vehicle training pipeline</nve-format-truncate> | ||
| <nve-format-truncate position="center" strategy="path" preserve="2">/models/checkpoints/production/model.bin</nve-format-truncate> | ||
| `); | ||
| try { | ||
| await elementIsStable(fixture.querySelector(FormatTruncate.metadata.tag)); | ||
| const results = await runAxe([FormatTruncate.metadata.tag]); | ||
| expect(results.violations.length).toBe(0); | ||
| } finally { | ||
| removeFixture(fixture); | ||
| } | ||
| }); | ||
| }); |
24 changes: 24 additions & 0 deletions
24 projects/core/src/format-truncate/format-truncate.test.lighthouse.ts
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 { describe, expect, test } from 'vitest'; | ||
| import { lighthouseRunner } from '@internals/vite'; | ||
| describe('format-truncate lighthouse report', () => { | ||
| test('format-truncate should meet lighthouse benchmarks', async () => { | ||
| const report = await lighthouseRunner.getReport( | ||
| 'nve-format-truncate', | ||
| /* html */ ` | ||
| <nve-format-truncate position="center" strategy="path" preserve="2">/models/checkpoints/production/model.bin</nve-format-truncate> | ||
| <script type="module"> | ||
| import '@nvidia-elements/core/format-truncate/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(16); | ||
| }); | ||
| }); |
20 changes: 20 additions & 0 deletions
20 projects/core/src/format-truncate/format-truncate.test.ssr.ts
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,20 @@ | ||
| // 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 { FormatTruncate } from '@nvidia-elements/core/format-truncate'; | ||
| import '@nvidia-elements/core/format-truncate/define.js'; | ||
| describe(FormatTruncate.metadata.tag, () => { | ||
| it('should pass baseline ssr check', async () => { | ||
| const result = await ssrRunner.render( | ||
| html`<nve-format-truncate position="center" preserve="4">abcdefghij</nve-format-truncate>` | ||
| ); | ||
| expect(result.includes('shadowroot="open"')).toBe(true); | ||
| expect(result.includes('nve-format-truncate')).toBe(true); | ||
| expect(result.includes('abcdefghij')).toBe(true); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Assert the SSR shadow-content contract.
The host tag and slotted text come from the input template. The test can pass if
FormatTruncate.render()stops emittinginternal-hostor the default slot. Assert the internal host, itsaria-hiddenvalue, and the slot.Proposed fix
expect(result.includes('shadowroot="open"')).toBe(true); expect(result.includes('nve-format-truncate')).toBe(true); expect(result.includes('abcdefghij')).toBe(true); + expect(result.includes('internal-host')).toBe(true);+ expect(result.includes('aria-hidden="true"')).toBe(true);+ expect(result.includes('<slot')).toBe(true);📝 Committable suggestion
🤖 Prompt for AI Agents