Tabs
Use these responsive tabs components to create a secondary navigational hierarchy for your website or toggle content inside a container
The tabs component can be used either as an extra navigational hierarchy complementing the main navbar or you can also use it to change content inside a container just below the tabs using the data attributes from Flowbite.
Setup
<script>
import { Tabs, InteractiveTabHead, TabContent } from 'flowbite-svelte';
</script>
Default tabs
Use the following default tabs component example to show a list of links that the user can navigate from on your website.
1-1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
<script>
import { let tabs1 = [
{
name: 'Profile5',
id: 1,
content:
'1-1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '
},
{
name: 'Dashboard',
id: 2,
content:
'1-2 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '
},
{
name: 'Settings',
id: 3,
content:
'1-3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '
},
{
name: 'Users',
id: 4,
content:
'1-4Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '
}
];
</script>
<Tabs tabId="defaultTab" tabs={tabs1} />
Tabs with underline
Use this alternative tabs component style with an underline instead of a background when hovering and being active on a certain page.
1-1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
<Tabs tabId="underlineTab" tabs={tabs1} tabStyle="underline" />
Tabs with icons
This is an example of the tabs component where you can also use a SVG powered icon to complement the text within the navigational tabs.
1-1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
<Tabs tabId="iconTab" tabs={iconTabs} tabStyle="icon" />
Pills tabs
If you want to use pills as a style for the tabs component you can do so by using this example.
1-1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
<Tabs tabId="pillTab" tabs={tabs1} tabStyle="pill" />
Full width tabs
If you want to show the tabs on the full width relative to the parent element you can do so by using the full width tabs component example.
1-1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
<Tabs tabId="fullTab" tabs={tabs1} tabStyle="full" />
Disabled tabs
Use disabled: true
to disable a tab.
1-1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
<script>
let disabledTabs = [
{
name: 'Profile',
id: 1,
content:
'1-1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '
},
{
name: 'Dashboard',
id: 2,
content:
'1-2 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '
},
{
name: 'Disabled 1',
id: 3,
disabled: true,
content:
'1-3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '
},
{
name: 'Disabled 2',
id: 4,
disabled: true,
content:
'1-4Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '
}
];
</script>
<Tabs tabId="disabledTabs" tabs={disabledTabs} />
Components in tab contents
By using InteractiveTabHead
and TabContent
you can add other components to the InteractiveTabs
component. Here we are adding a timeline component in the tab 1:
-
Lorem ipsum dolor sit amet
Consectetur adipiscing elit...
Learn more -
Lorem ipsum dolor sit amet
Consectetur adipiscing elit...
-
Lorem ipsum dolor sit amet
Consectetur adipiscing elit...
<script>
import { InteractiveTabHead, TabContent, Card, Timeline,
TimelineItem, }from 'flowbite-svelte';
let tab1 = { name: 'Tab1', id: 1 };
let tab2 = { name: 'Tab2', id: 2 };
let tab3 = { name: 'Tab3', id: 3 };
let tabhead = [tab1, tab2, tab3];
let timelineItems = [
{
date: 'February 2022',
title: 'Lorem ipsum dolor sit amet',
href: '/',
linkname: 'Learn more',
text: 'Consectetur adipiscing elit...'
},
{
date: 'March 2022',
title: 'Lorem ipsum dolor sit amet',
text: 'Consectetur adipiscing elit...'
},
{
date: 'February 2022',
title: 'Lorem ipsum dolor sit amet',
text: 'Consectetur adipiscing elit...'
}
];
</script>
<InteractiveTabHead tabs={tabhead}>
<TabContent tab={tab1}>
<Timeline>
<TimelineItem {timelineItems} />
</Timeline>
</TabContent>
<TabContent tab={tab2}>
<p>Test 2 content here</p>
</TabContent>
<TabContent tab={tab3}>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla distinctio.</p>
</TabContent>
</InteractiveTabHead>
Props
The component has the following props, type, and default values. See types page for type information.
Tabs
Name | Type | Default |
---|---|---|
tabStyle | 'default' | 'full' | 'icon' | 'pill' | 'underline' | 'custom' | 'default' |
tabId | string | 'myTab' |
tabLabel | string | 'Full-width tabs' |
activeTabValue | number | 1 |
tabs | InteractiveTabType[] | |
customDivClass | string | '' |
customUlClass | string | '' |
customLiClass | string | '' |
customActiveClass | string | '' |
customInActiveClass | string | '' |
iconClass | string | 'mr-2 w-5 h-5 text-gray-400 group-hover:text-gray-500 dark:text-gray-500 dark:group-hover:text-gray-300' |
contentDivClass | string | 'p-4 bg-gray-50 rounded-lg dark:bg-gray-800' |
fullSelectClass | string | 'bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500' |
InteractiveTabHead
Name | Type | Default |
---|---|---|
tabs | TabHeadType[] | |
tabId | string | 'myTab' |
activeTabValue | number | 1 |
disabled | boolean | false |
divClass | string | 'mb-4 border-b border-gray-200' |
ulClass | string | 'flex flex-wrap -mb-px text-sm font-medium text-center' |
liClass | string | 'mr-2' |
btnClass | string | 'inline-block py-4 px-4 text-sm font-medium text-center rounded-t-lg border-b-2 border-transparent' |
activeClass | string | 'text-blue-600 hover:text-blue-600 dark:text-blue-500 dark:hover:text-blue-400 border-blue-600 dark:border-blue-500' |
inactiveClasses | string | 'text-gray-500 hover:text-gray-600 dark:text-gray-400 border-gray-100 hover:border-gray-300 dark:border-gray-700 dark:hover:text-gray-300' |
TabContent
Name | Type | Default |
---|---|---|
divClass | string | 'p-4 rounded-lg dark:bg-gray-800' |
tab | TabHeadType |