Examples
Examples are stateless HTML templates demonstrating UI patterns for the Elements design system. Well defined examples are critical for providing a portable documentation format for the CLI, MCP, and documentation site. This document provides guidance on creating well-written example templates. (*.examples.ts).
Core Principles
Example Title
The example title name should be no more than three words. This name references the function and renders in API/Documentation endpoints.
Naming Format
- Use PascalCase for all example names (for example,
Default,StatusFlat,FormSubmit) - Names should describe what the example shows, not how it works; explain how in the summary.
Single-Word Names
Use single words for basic API features and properties:
| Pattern | Examples |
|---|---|
| Default/basic usage | Default |
| API properties | Status, Size, Color, Position, Alignment |
| Container variants | Flat, Inline |
| States | Pressed, Selected, Disabled |
| Slots/content | Content, Actions |
| Features | Closable, Events, Overflow |
Compound Names (2-3 words)
Use compound PascalCase for combinations or specific features and patterns:
| Pattern | Examples |
|---|---|
| Property + variant | StatusFlat, StatusIcon, SelectedFlat |
| Feature + modifier | OpenDelay, DynamicTrigger, ScrollContent |
| Concept + variant | GroupStatus, FormSubmit, FormControl |
| Layout variants | VerticalTabs, BorderlessTabs |
Special Prefixes
| Prefix | Usage | Examples |
|---|---|---|
Legacy | Deprecated patterns | LegacyTrigger, LegacyBehaviorTrigger |
Invalid | Anti-patterns | InvalidLinkButton |
Valid | Correct patterns (when contrasting with invalid) | ValidLinkButton |
What to Avoid
- ❌ Component names in titles: Use
StatusnotBadgeStatus - ❌ Implementation details: Use
ScrollContentnotOverflowAutoScrollContent - ❌ Vague names: Use
DynamicTriggernotExample1 - ❌ Overly long names: Keep to 3 words max
Examples
When the build produces examples for API consumption, it automatically attaches extra metadata such as the associated element/component reference and a UUID to ensure each example has a unique identifier across all projects.
Use @summary JSDoc Comments
Every example must include a @summary JSDoc comment that explains:
- Descriptions must be concise one or two sentences only.
- What the example demonstrates
- Why this pattern is useful
- When to use this approach
- How it improves the user experience
When appropriate use NVIDIA or NVIDIA Autonomous Vehicle program for UX use cases
Stateless Examples by Default
Examples should be stateless when possible, focusing on demonstrating the component's capabilities rather than complex interactions:
Use Plain HTML/CSS/JS
Examples should use standard web technologies without unnecessary abstractions:
Example Structure Patterns
Basic Component Examples
Status/Variant Examples
Interactive Examples (When Necessary)
Complex Component Examples (Grid, Tables, etc.)
Summary Writing Guidelines
Good Summaries
- Specific and actionable: "Use for simple non-interactive labels or status indicators"
- Context-aware: "Ideal for showing job status, task progress, or system states"
- UX-focused: "Perfect for dense layouts or when you want less visual weight"
- Accessibility-conscious: "using aria-label for accessibility"
Summary Structure
- Opening: What the example demonstrates
- Context: When/why to use this pattern
- Benefits: How it improves UX or solves problems
- Technical notes: Any important implementation details
Examples of Well-Written Summaries
Anti-Patterns to Avoid
Avoid Poor Summaries or Unclear Use Cases
Summaries should provide UX intent. Do not describe what the reader can already infer from the source code.
Avoid Overly Complex State
Avoid complex/stateful examples. Use cases vary widely across frameworks/tools so simple stateless examples are necessary to support all users.
Best Practices Summary
- Always include
@summary- Every example needs clear documentation - Keep examples stateless - Focus on component capabilities, not complex interactions
- Use plain HTML/CSS/JS - Avoid unnecessary abstractions
- Write descriptive summaries - Explain what, why, when, and how
- Include accessibility notes - Use ARIA attributes when appropriate
- Provide context - Explain the UX benefits and use cases
- Keep examples focused - One clear concept per example
- Use semantic naming - Example names should show their purpose
Example Checklist
Before submitting an example, ensure:
- [ ] Example includes a title
- [ ]
@summaryJSDoc comment is present and comprehensive - [ ] Description explains the UX intent and use cases
- [ ] Example is stateless (unless demonstrating specific state patterns)
- [ ] Uses plain HTML/CSS/JS without unnecessary abstractions
- [ ] Includes accessibility considerations when relevant