Tab Component Examples

This page demonstrates how to use the Tabs component inside documentation.

Basic Usage

<!DOCTYPE html>
<html>
  <head>
    <title>Hello World</title>
  </head>
  <body>
    <h1>Hello, world!</h1>
  </body>
</html>

Package Manager Instructions

Great for showing steps across different tools:

# Install packages
npm install @our-package/core

# Add development dependency
npm install --save-dev @our-package/dev-tools

# Run scripts
npm run dev

Configuration Examples

Compare environments or frameworks:

// development.config.js
export default {
  debug: true,
  apiUrl: 'http://localhost:3000/api',
  database: {
    host: 'localhost',
    port: 5432,
    name: 'myapp_dev'
  },
  logging: {
    level: 'debug',
    console: true
  }
};

Language-Specific Examples

Show implementations by language:

class User {
  constructor(name, email) {
    this.name = name;
    this.email = email;
  }
  
  greet() {
    return `Hello, ${this.name}!`;
  }
  
  getProfile() {
    return {
      name: this.name,
      email: this.email
    };
  }
}

const user = new User('Taro Tanaka', 'tanaka@example.com');
console.log(user.greet());

Platform-Specific Steps

Provide OS-specific instructions:

# Verify Node.js installation
node --version
npm --version

# Project setup
mkdir my-project
cd my-project
npm init -y

# Install dependencies
npm install express

# Start the app
npm start

API Response Formats

Display responses in multiple formats:

{
  "status": "success",
  "data": {
    "id": 1,
    "name": "Taro Tanaka",
    "email": "tanaka@example.com",
    "profile": {
      "age": 30,
      "department": "Engineering",
      "position": "Developer"
    },
    "preferences": {
      "language": "ja",
      "theme": "dark",
      "notifications": true
    }
  },
  "meta": {
    "timestamp": "2025-01-27T16:00:00Z",
    "version": "1.0"
  }
}

Technical Details

Props

Tabs

PropTypeDefaultDescription
childrenReactNodeTabItem components (required)
defaultValuestringFirst tabTab selected by default
classNamestringAdditional CSS classes

TabItem

PropTypeDefaultDescription
labelstringTab label (required)
valuestringlabelTab identifier
childrenReactNodeContent rendered for the tab

Using Tabs in MDX

---
title: "My Document"
---

import { Tabs, TabItem } from '@docs/ui';

# Code Samples

<Tabs>
  <TabItem label="JavaScript">
    {/* JavaScript sample */}
    console.log('Hello, World!');
  </TabItem>
  <TabItem label="Python">
    {/* Python sample */}
    print('Hello, World!')
  </TabItem>
</Tabs>

Best Practices

Organizing Tabs

  • Logical grouping: Keep related content together
  • Consistent labels: Use clear, predictable names
  • Reasonable count: Limit to roughly five to seven tabs

Accessibility

  • Keyboard navigation: Support arrow keys and Tab navigation
  • Screen readers: Provide proper ARIA roles and labels
  • Focus management: Ensure visible focus indicators

Performance

  • Lazy loading: Load heavy content when needed
  • Content size: Keep tab contents concise

Next Steps

After mastering Tabs: