Tabs

The Tabs component is a navigational element that allows users to switch between different views or sections of content within the same page. Each tab is associated with a content panel, and clicking a tab displays the corresponding panel while hiding others. This component helps organize content efficiently and improves user experience by providing easy access to different sections without leaving the current page.

import { Tabs, useTab } from 'welcome-ui/Tabs'
const Example = () => {
const tab = useTab({ defaultSelectedId: 'tab1' })
return (
<>
<div>
<Tabs aria-label="Tabs" store={tab}>
<Tabs.Tab id="tab1" store={tab}>
Tab 1
</Tabs.Tab>
<Tabs.Tab id="tab2" store={tab}>
Tab 2
</Tabs.Tab>
<Tabs.Tab id="tab3" store={tab}>
Tab 3
</Tabs.Tab>
<Tabs.Tab id="tab4" store={tab}>
Tab 4
</Tabs.Tab>
<Tabs.Tab disabled id="tab5" store={tab}>
Tab 5
</Tabs.Tab>
</Tabs>
</div>
<div className="w-full border border-neutral-20 p-lg rounded-md">
<Tabs.Panel store={tab} tabId="tab1">
Content for Tab 1
</Tabs.Panel>
<Tabs.Panel store={tab} tabId="tab2">
Content for Tab 2
</Tabs.Panel>
<Tabs.Panel store={tab} tabId="tab3">
Content for Tab 3
</Tabs.Panel>
<Tabs.Panel store={tab} tabId="tab4">
Content for Tab 4
</Tabs.Panel>
<Tabs.Panel store={tab} tabId="tab5">
Content for Tab 5
</Tabs.Panel>
</div>
</>
)
}
export default Example

Sizes

Size is set on Tabs. Available sizes are sm and md. By default size is set to md.

With a badge

Add a badge with passing a string or number to badge props.

Icon

Add icon using icon="folder" and use a bunch of colors with iconColor props: blue, green, teal, pink, orange. Or use a custom icon with an Icon component.

useTab

We use useTab from Ariakit Tab for the state of the Tab.

Pass options to useTab:

  • defaultSelectedId: e.g. const store = useTab({ defaultSelectedId: 'tab2' })