Skip to main content

Overview

The RuleExampleTabs component provides a tabbed interface for showing valid and invalid code examples for ESLint rules. Features syntax highlighting, error messages, and optional descriptions for each example.
This is a client component ("use client") and uses React state for tab management.

Import

Basic Usage

Props

CodeExample[]
required
Array of valid code examples.
CodeExample[]
required
Array of invalid code examples.
string
default:"typescript"
The programming language for syntax highlighting.
string
Additional CSS classes to apply.
The RuleExampleTabs component extends HTMLAttributes<HTMLDivElement>, so all standard div attributes are supported.

CodeExample Type

Each example in the valid or invalid arrays has the following structure:
string
required
The code to display.
string
Optional description of the example, displayed above the code.
string[]
Array of error messages to display below the code (typically used for invalid examples).

Tab Indicators

The component displays two tabs with distinct visual indicators:
  • Valid tab: Green checkmark icon (✓) with green accent when active
  • Invalid tab: Red cross icon (✗) with red accent when active
Each active tab shows a colored indicator bar at the bottom.

Examples

Rule with Multiple Examples

JavaScript Examples

With Custom Styling

Design Details

  • Tab buttons use 12px (xs) font with medium weight
  • Active tab has colored text and bottom indicator
  • Inactive tabs have muted text with hover effect
  • Error messages displayed in destructive color with monospace font
  • Examples separated by subtle dividers
  • Code blocks use the CodeBlock component with syntax highlighting
  • Tab list has raised surface background

Accessibility

  • Uses proper ARIA attributes (role="tab", role="tablist", role="tabpanel", aria-selected)
  • Focus visible outline on tab buttons
  • Keyboard navigation support (inherited from button element)

Error Display

Invalid examples can include error messages that appear below the code block:
Errors are displayed in a destructive-colored strip with an arrow indicator (↳) before each message.

Component Definition

Location: packages/gadget-ui/src/components/rule-example-tabs.tsx:78 The component uses CodeBlock internally for syntax highlighting and manages tab state with useState.