import type { Meta, StoryFn } from '@storybook/react'; import { Box, Settings, Users } from 'lucide-react'; import { ReactStateDeclaration, UIRouter, UIRouterReact, UIView, hashLocationPlugin, servicesPlugin, } from '@uirouter/react'; import { WidgetTabs, Tab } from './WidgetTabs'; // Create a UIRouter instance with a dummy state so `Link to="."` works function withRouter(Story: () => JSX.Element) { const router = new UIRouterReact(); router.plugin(servicesPlugin); router.plugin(hashLocationPlugin); // Register a dummy state that renders the Story const storyState: ReactStateDeclaration = { name: 'storybook', url: '/?tab', component: Story, }; router.stateRegistry.register(storyState); // Set initial state (UIRouter component calls start() automatically) router.urlService.rules.initial({ state: 'storybook' }); router.urlService.rules.otherwise({ state: 'storybook' }); return ( ); } const meta: Meta = { title: 'Components/Widget/WidgetTabs', component: WidgetTabs, decorators: [withRouter], }; export default meta; const defaultTabs: Tab[] = [ { name: 'Overview', widget:
Overview content
, selectedTabParam: 'overview', }, { name: 'Settings', widget:
Settings content
, selectedTabParam: 'settings', }, { name: 'Users', widget:
Users content
, selectedTabParam: 'users', }, ]; const tabsWithIcons: Tab[] = [ { name: 'Overview', icon: Box, widget:
Overview content
, selectedTabParam: 'overview', }, { name: 'Settings', icon: Settings, widget:
Settings content
, selectedTabParam: 'settings', }, { name: 'Users', icon: Users, widget:
Users content
, selectedTabParam: 'users', }, ]; interface StoryArgs { currentTabIndex: number; tabs: Tab[]; useContainer?: boolean; } function Template({ currentTabIndex, tabs, useContainer }: StoryArgs) { return ( ); } export const Default: StoryFn = Template.bind({}); Default.args = { currentTabIndex: 0, tabs: defaultTabs, }; export const WithIcons: StoryFn = Template.bind({}); WithIcons.args = { currentTabIndex: 0, tabs: tabsWithIcons, }; export const SecondTabSelected: StoryFn = Template.bind({}); SecondTabSelected.args = { currentTabIndex: 1, tabs: tabsWithIcons, }; export const WithoutContainer: StoryFn = Template.bind({}); WithoutContainer.args = { currentTabIndex: 0, tabs: tabsWithIcons, useContainer: false, }; export const TwoTabs: StoryFn = Template.bind({}); TwoTabs.args = { currentTabIndex: 0, tabs: [ { name: 'Tab 1', widget:
Tab 1 content
, selectedTabParam: 'tab1', }, { name: 'Tab 2', widget:
Tab 2 content
, selectedTabParam: 'tab2', }, ], };