Skip to content

feat(core): format-bytes - #205

Open
coryrylan wants to merge 1 commit into
mainfrom
topic-format-bytes
Open

feat(core): format-bytes#205
coryrylan wants to merge 1 commit into
mainfrom
topic-format-bytes

Conversation

@coryrylan

@coryrylan coryrylan commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator
  • Introduced nve-format-bytes component to convert byte counts into human-readable decimal or binary units

Summary by CodeRabbit

  • New Features

    • Added a Format Bytes element for displaying byte values in decimal or binary units.
    • Supports automatic or fixed units, short or long labels, locale formatting, and precision controls.
    • Accepts numeric values or text content, with graceful handling of invalid inputs.
  • Documentation

    • Added installation guidance, usage examples, and navigation for the new element.
  • Tests

    • Added accessibility, performance, server-rendering, visual, and functional coverage.

@coryrylan
coryrylan requested a review from johnyanarella July 31, 2026 22:52
@coryrylan coryrylan self-assigned this Jul 31, 2026
Copilot AI lite review requested due to automatic review settings July 31, 2026 22:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added scope(core) scope(docs) dependencies Pull requests that update a dependency file labels Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds the FormatBytes Lit component. It supports locale-aware decimal and binary formatting, configurable units, labels, precision, and value sources. It also adds public exports, custom-element registration, tests, Storybook examples, bundle validation, and documentation.

Changes

Format Bytes component

Layer / File(s) Summary
Formatting component and rendering
projects/core/src/format-bytes/format-bytes.ts, projects/core/src/format-bytes/format-bytes.css
FormatBytes validates options, formats values with locale and precision, renders <data> output, updates slot fallback content, and applies component styling.
Custom-element registration and package exposure
projects/core/src/format-bytes/define.ts, projects/core/src/format-bytes/index.ts, projects/core/package.json, projects/core/src/bundle.ts
The nve-format-bytes element is registered and added to package exports, bundle imports, and public exports.
Examples and validation coverage
projects/core/src/format-bytes/format-bytes.examples.ts, projects/core/src/format-bytes/format-bytes.test.ts, projects/core/src/format-bytes/format-bytes.test.ssr.ts, projects/core/src/format-bytes/format-bytes.test.axe.ts, projects/core/src/format-bytes/format-bytes.test.lighthouse.ts, projects/core/src/format-bytes/format-bytes.test.visual.ts, projects/core/src/index.test.lighthouse.ts
Examples and tests cover formatting options, SSR output, accessibility, Lighthouse scores, visual themes, and bundle size.
Documentation site integration
projects/site/src/_11ty/layouts/common.js, projects/site/src/docs/elements/format-bytes.md
The site navigation and documentation page describe the new element and its supported options.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Consumer
  participant FormatBytes
  participant IntlNumberFormat
  Consumer->>FormatBytes: Set value and formatting properties
  FormatBytes->>IntlNumberFormat: Format value with locale and precision
  IntlNumberFormat-->>FormatBytes: Return localized number
  FormatBytes-->>Consumer: Render formatted value and unit label
Loading

Suggested reviewers: johnyanarella

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(core): format-bytes' directly corresponds to the PR objective of introducing the nve-format-bytes component and is reflected throughout the changeset across component files, tests, documentation, and bundle exports.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch topic-format-bytes

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@projects/core/src/format-bytes/format-bytes.test.axe.ts`:
- Around line 13-26: Update the stability setup in the test around
FormatBytes.metadata.tag to await elementIsStable for all three nve-format-bytes
fixture elements, rather than only the first querySelector result, before
calling runAxe. Preserve the existing fixture cleanup and accessibility
assertion.

In `@projects/core/src/format-bytes/format-bytes.ts`:
- Around line 130-146: Make display sourcing consistent between `#resolveAutoUnit`
and `#formatLabel`. Prefer passing the display value explicitly by updating
`#formatLabel` to accept a display parameter and updating its call in
`#formattedBytes` to pass this.display, while using that parameter for label
selection.
- Around line 148-167: Update `#warnInvalidOption` to remove the rawValue
parameter and return type/value, then adjust its callers in
`#hasValidConfiguration` to pass only the option name and value. Remove rawValue
from `#hasValidConfiguration` as well, and update its call site to invoke it
without arguments while preserving the existing invalid-configuration return
behavior.
- Around line 142-146: Update the formatting flow around `#formattedBytes` and
`#formatLabel` so the value is rounded once using the same fraction-digit settings
as `#formatNumber`, then pass that rounded value to both helpers. Select singular
versus plural in `#formatLabel` based on the rounded value while preserving
short-label behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: b30e9a98-6f6c-4e84-ac6e-c5b9e9faad96

📥 Commits

Reviewing files that changed from the base of the PR and between 651abf3 and b57257b.

⛔ Files ignored due to path filters (2)
  • projects/core/.visual/format-bytes.dark.png is excluded by !**/*.png
  • projects/core/.visual/format-bytes.png is excluded by !**/*.png
📒 Files selected for processing (15)
  • projects/core/package.json
  • projects/core/src/bundle.ts
  • projects/core/src/format-bytes/define.ts
  • projects/core/src/format-bytes/format-bytes.css
  • projects/core/src/format-bytes/format-bytes.examples.ts
  • projects/core/src/format-bytes/format-bytes.test.axe.ts
  • projects/core/src/format-bytes/format-bytes.test.lighthouse.ts
  • projects/core/src/format-bytes/format-bytes.test.ssr.ts
  • projects/core/src/format-bytes/format-bytes.test.ts
  • projects/core/src/format-bytes/format-bytes.test.visual.ts
  • projects/core/src/format-bytes/format-bytes.ts
  • projects/core/src/format-bytes/index.ts
  • projects/core/src/index.test.lighthouse.ts
  • projects/site/src/_11ty/layouts/common.js
  • projects/site/src/docs/elements/format-bytes.md

Comment on lines +13 to +26
const fixture = await createFixture(html`
<nve-format-bytes locale="en-US">1048576</nve-format-bytes>
<nve-format-bytes locale="en-US" display="binary" unit-display="long">1048576</nve-format-bytes>
<nve-format-bytes locale="de-DE" unit="kb">1048576</nve-format-bytes>
`);

try {
await elementIsStable(fixture.querySelector(FormatBytes.metadata.tag));
const results = await runAxe([FormatBytes.metadata.tag]);
expect(results.violations.length).toBe(0);
} finally {
removeFixture(fixture);
}
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Await stability for all three fixture elements, not just the first.

The fixture creates three nve-format-bytes elements. Line 20 only awaits elementIsStable on fixture.querySelector(FormatBytes.metadata.tag), which resolves to the first matching element only. The axe scan on line 21 covers all three elements, but the second and third elements' render cycles are not confirmed stable. This can produce a flaky or false-negative accessibility result if axe scans an element mid-update.

🐛 Proposed fix to await stability for every element
     try {
-      await elementIsStable(fixture.querySelector(FormatBytes.metadata.tag));
+      await Promise.all(
+        [...fixture.querySelectorAll(FormatBytes.metadata.tag)].map((el) => elementIsStable(el))
+      );
       const results = await runAxe([FormatBytes.metadata.tag]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const fixture = await createFixture(html`
<nve-format-bytes locale="en-US">1048576</nve-format-bytes>
<nve-format-bytes locale="en-US" display="binary" unit-display="long">1048576</nve-format-bytes>
<nve-format-bytes locale="de-DE" unit="kb">1048576</nve-format-bytes>
`);
try {
await elementIsStable(fixture.querySelector(FormatBytes.metadata.tag));
const results = await runAxe([FormatBytes.metadata.tag]);
expect(results.violations.length).toBe(0);
} finally {
removeFixture(fixture);
}
});
const fixture = await createFixture(html`
<nve-format-bytes locale="en-US">1048576</nve-format-bytes>
<nve-format-bytes locale="en-US" display="binary" unit-display="long">1048576</nve-format-bytes>
<nve-format-bytes locale="de-DE" unit="kb">1048576</nve-format-bytes>
`);
try {
await Promise.all(
[...fixture.querySelectorAll(FormatBytes.metadata.tag)].map((el) => elementIsStable(el))
);
const results = await runAxe([FormatBytes.metadata.tag]);
expect(results.violations.length).toBe(0);
} finally {
removeFixture(fixture);
}
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@projects/core/src/format-bytes/format-bytes.test.axe.ts` around lines 13 -
26, Update the stability setup in the test around FormatBytes.metadata.tag to
await elementIsStable for all three nve-format-bytes fixture elements, rather
than only the first querySelector result, before calling runAxe. Preserve the
existing fixture cleanup and accessibility assertion.

Comment thread projects/core/src/format-bytes/format-bytes.ts
Comment thread projects/core/src/format-bytes/format-bytes.ts
Comment thread projects/core/src/format-bytes/format-bytes.ts Outdated
- Introduced `nve-format-bytes` component to convert byte counts into human-readable decimal or binary units

Signed-off-by: Cory Rylan <crylan@nvidia.com>
Copilot AI review requested due to automatic review settings August 4, 2026 14:31
@coryrylan
coryrylan force-pushed the topic-format-bytes branch from b57257b to 351a0f2 Compare August 4, 2026 14:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated no new comments.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@projects/core/src/index.test.lighthouse.ts`:
- Line 18: The FormatBytes component definition import is missing from the
js-modules list used in the benchmark, so the new component is not included in
the aggregate payload measurement. Add the
`@nvidia-elements/core/format-bytes/define.js` import to the module-import list in
the test setup. After adding the import, run the benchmark to measure the actual
payload. Update the 134.5 KB threshold in the expect assertion only if the
measured payload for index.js exceeds the current limit.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 660ec1ed-b543-4228-96dd-5fab6d84b4ae

📥 Commits

Reviewing files that changed from the base of the PR and between b57257b and 351a0f2.

⛔ Files ignored due to path filters (2)
  • projects/core/.visual/format-bytes.dark.png is excluded by !**/*.png
  • projects/core/.visual/format-bytes.png is excluded by !**/*.png
📒 Files selected for processing (15)
  • projects/core/package.json
  • projects/core/src/bundle.ts
  • projects/core/src/format-bytes/define.ts
  • projects/core/src/format-bytes/format-bytes.css
  • projects/core/src/format-bytes/format-bytes.examples.ts
  • projects/core/src/format-bytes/format-bytes.test.axe.ts
  • projects/core/src/format-bytes/format-bytes.test.lighthouse.ts
  • projects/core/src/format-bytes/format-bytes.test.ssr.ts
  • projects/core/src/format-bytes/format-bytes.test.ts
  • projects/core/src/format-bytes/format-bytes.test.visual.ts
  • projects/core/src/format-bytes/format-bytes.ts
  • projects/core/src/format-bytes/index.ts
  • projects/core/src/index.test.lighthouse.ts
  • projects/site/src/_11ty/layouts/common.js
  • projects/site/src/docs/elements/format-bytes.md

expect(report.scores.accessibility).toBe(100);
expect(report.scores.bestPractices).toBe(100);
expect(report.payload.javascript.requests['index.js'].kb).toBeLessThan(133.6);
expect(report.payload.javascript.requests['index.js'].kb).toBeLessThan(134.5);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

Include FormatBytes in the module-import bundle benchmark.

@nvidia-elements/core/format-bytes/define.js is absent from the js-modules import list. The benchmark does not measure the new component in the aggregate direct-import payload. Add the definition import. Adjust the 82 KB limit only if the measured payload requires it.

Proposed change
         import '`@nvidia-elements/core/file/define.js`';
+        import '`@nvidia-elements/core/format-bytes/define.js`';
         import '`@nvidia-elements/core/forms/define.js`';
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@projects/core/src/index.test.lighthouse.ts` at line 18, The FormatBytes
component definition import is missing from the js-modules list used in the
benchmark, so the new component is not included in the aggregate payload
measurement. Add the `@nvidia-elements/core/format-bytes/define.js` import to the
module-import list in the test setup. After adding the import, run the benchmark
to measure the actual payload. Update the 134.5 KB threshold in the expect
assertion only if the measured payload for index.js exceeds the current limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file scope(core) scope(docs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants