diff --git a/components/Tabs.js b/components/Tabs.js
index 225b784..2bf6edc 100644
--- a/components/Tabs.js
+++ b/components/Tabs.js
@@ -1,8 +1,14 @@
-import { useState } from 'react';
+import React, { useState } from 'react';
-export function TabPanels({ tabs = [] }) {
- const [active, setActive] = useState(tabs[0]?.id);
- const activeTab = tabs.find((tab) => tab.id === active) || tabs[0];
+export function Tab({ children }) {
+ return children;
+}
+
+export function TabPanels({ children }) {
+ const tabs = React.Children.toArray(children).filter(
+ (child) => React.isValidElement(child) && child.props.title != null,
+ );
+ const [activeIndex, setActiveIndex] = useState(0);
if (!tabs.length) {
return null;
@@ -11,22 +17,24 @@ export function TabPanels({ tabs = [] }) {
return (
- {tabs.map((tab) => (
+ {tabs.map((tab, index) => (
))}
-
{activeTab?.content}
+
+ {tabs[activeIndex]?.props.children}
+
);
}
diff --git a/components/mdx-components.js b/components/mdx-components.js
index 79308f4..67b7943 100644
--- a/components/mdx-components.js
+++ b/components/mdx-components.js
@@ -20,7 +20,7 @@ import PresetSearch from './PresetSearch';
import SearchBar from './SearchBar';
import Sidebar from './Sidebar';
import Steps from './Steps';
-import Tabs, { TabPanels } from './Tabs';
+import Tabs, { Tab, TabPanels } from './Tabs';
import Table, { Caption, TBody, TD, TH, THead, TR } from './WikiTable';
const mdxComponents = {
@@ -54,6 +54,7 @@ const mdxComponents = {
THead,
TR,
Tabs,
+ Tab,
TabPanels,
caption: (props) => ,
pre: (props) => ,
diff --git a/content/guides/components/tabs.mdx b/content/guides/components/tabs.mdx
index 8b62b12..4bb263e 100644
--- a/content/guides/components/tabs.mdx
+++ b/content/guides/components/tabs.mdx
@@ -5,38 +5,43 @@ description: Tabbed content UI for grouped alternatives.
# Tabs
-`Tabs` exports `TabPanels` for rendering tab groups.
+`TabPanels` renders a tab group. Each `Tab` child represents one tab, with its `title` displayed as the tab button label. Tab content can be any HTML or Markdown.
-## Props (`TabPanels`)
+## Props
+
+### `TabPanels`
| Prop | Type | Required | Description |
| --- | --- | --- | --- |
-| `tabs` | `Array<{ id: string, label: string, content: ReactNode }>` | Yes | Tab definitions. |
+| `children` | `Tab` elements | Yes | One or more `Tab` components. |
+
+### `Tab`
+
+| Prop | Type | Required | Description |
+| --- | --- | --- | --- |
+| `title` | `string` | Yes | Label shown on the tab button. |
+| `children` | `ReactNode` | Yes | Content rendered when the tab is active. |
## Live examples
-
-
-
+
+ npm run dev
+ pnpm dev
+ bun run dev
+
+
+
+ Markdown + MDX content pages.
+ JSON files for navigation and layout behavior.
+
## Code
```mdx
-
+
+ npm run dev
+ pnpm dev
+ bun run dev
+
```
+