Components
Tabs

Tabs

The Tabs component is used to create a tabbed interface. It consists of three main components: Tabs, TabsPanel, and TabsCurrent. Tabs manages the overall state of the tabs and allows you to switch between them. TabsPanel is used to render the tabs themselves, and TabsCurrent is used to display the content of the currently selected tab.

Tabs

The Tabs component is used to manage the state of the tabs and switch between them. It takes the following props:

NameTypeDefaultDescription
initalTabIndexnumber0The index of the initially selected tab.
onChange(index: number) => voidA callback function that is called when the selected tab changes.
tabsTabProps[]An array of tab objects. Each tab object is defined by its props.
childrenstring | ReactElement | ReactElement[]The content of the Tabs component, typically TabsPanel and TabsCurrent.

TabProps

The TabProps type represents the props that can be passed to individual tabs within the Tabs component. These props include:

NameTypeDefaultDescription
labelstring | JSX.Element | React.ReactNode | React.ReactElementThe label of the tab. You can use a string, a JSX element, or a React node.
iconstring | JSX.Element | React.ReactNode | React.ReactElementAn optional icon to display before the label. You can use a string, a JSX element, or a React node.
suffixIconstring | JSX.Element | React.ReactNode | React.ReactElementAn optional icon to display after the label. You can use a string, a JSX element, or a React node.
prefixReactElementAn optional element to display before the tab's content.
suffixReactElementAn optional element to display after the tab's content.
activebooleanfalseWhether the tab is currently active or not.
disabledbooleanfalseIf true, the tab is disabled and cannot be clicked.
onClick() => voidA callback function to execute when the tab is clicked.

TabsPanel

The TabsPanel component is used to render the tabs themselves.

TabsCurrent

The TabsCurrent component is used to display the content of the currently selected tab. It doesn't take any props and should be used as a child of the Tabs component.

Try It

import { Tabs, TabsPanel, TabsCurrent } from '@kloktun/uikit'
import SearchIcon from './search-icon.tsx'
import DuckIcon from './duck-icon.tsx'

export default function TabsExample() {
  return (
    <Tabs
        tabs={
            [
                {
                    label: "First tab",
                    children: <>First section</>,
                },
                {
                    label: "Section 2",
                    children: <>Section 2 content</>,
                },
                {
                    label: "Section 3",
                    icon: <SearchIcon />,
                    children: <>Section 3 content</>,
                },
                {
                    label: "Section 4",
                    disabled: true,
                    children: <>Section 4 content</>,
                },
                {
                    label: "Section 5",
                    suffixIcon: <DuckIcon />,
                    children: <>Section 5 content</>,
                },
            ]
        }
    >
        <TabsPanel />
        <TabsCurrent />
    </Tabs>
  );
}