11import React from 'react' ;
2- import { action } from '@storybook/addon-actions' ;
3- import { text , select } from '@storybook/addon-knobs' ;
42import {
53 Tabs ,
64 Tab ,
7- TabType ,
85 Icon ,
96 MenuItem ,
107 TabItemRendererProps ,
118} from '../src/scripts' ;
9+ import { ComponentMeta , ComponentStoryObj } from '@storybook/react' ;
1210
11+ /**
12+ *
13+ */
1314function createMenu ( ) {
1415 return [ 1 , 2 , 3 ] . map ( ( i ) => < MenuItem key = { i } > Item #{ i } </ MenuItem > ) ;
1516}
1617
18+ /**
19+ *
20+ */
1721function CustomTabItemContent ( props : TabItemRendererProps ) {
1822 const {
1923 activeKey,
@@ -40,49 +44,30 @@ function CustomTabItemContent(props: TabItemRendererProps) {
4044 onTabKeyDown && eventKey != null && onTabKeyDown ( eventKey , e )
4145 }
4246 >
43- < Icon icon = { icon } size = 'small' />
47+ < Icon icon = { icon as string } size = 'small' />
4448 < span className = 'slds-p-horizontal_x-small' > { title } </ span >
4549 </ a >
4650 ) ;
4751}
4852
49- export default {
53+ /**
54+ *
55+ */
56+ const meta : ComponentMeta < typeof Tabs > = {
5057 title : 'Tabs' ,
51- } ;
52- export const ControlledWithKnobs = {
53- render : ( ) => {
54- const typeOptions = {
55- '(none)' : '' ,
56- default : 'default' ,
57- scoped : 'scoped' ,
58- } ;
59- const type = select ( 'type' , typeOptions , '' ) as TabType ;
60- return (
61- < Tabs
62- type = { type }
63- activeKey = { text ( 'activeKey' , '' ) }
64- onSelect = { action ( 'select' ) }
65- >
66- < Tab eventKey = '1' title = 'Tab 1' >
67- This is in tab #1
68- </ Tab >
69- < Tab eventKey = '2' title = 'Tab 2' >
70- This is in tab #2
71- </ Tab >
72- < Tab eventKey = '3' title = 'Tab 3' >
73- This is in tab #3
74- </ Tab >
75- </ Tabs >
76- ) ;
77- } ,
78- name : 'Controlled with knobs' ,
79- parameters : {
80- info : 'Tabs controlled with knobs' ,
58+ component : Tabs ,
59+ argTypes : {
60+ onSelect : { action : 'select' } ,
8161 } ,
8262} ;
83- export const Default = {
84- render : ( ) => (
85- < Tabs type = 'default' defaultActiveKey = '1' onSelect = { action ( 'select' ) } >
63+ export default meta ;
64+
65+ /**
66+ *
67+ */
68+ export const ControlledWithKnobs : ComponentStoryObj < typeof Tabs > = {
69+ render : ( args ) => (
70+ < Tabs { ...args } >
8671 < Tab eventKey = '1' title = 'Tab 1' >
8772 This is in tab #1
8873 </ Tab >
@@ -94,13 +79,25 @@ export const Default = {
9479 </ Tab >
9580 </ Tabs >
9681 ) ,
82+ name : 'Controlled with knobs' ,
83+ args : {
84+ activeKey : '1' ,
85+ } ,
9786 parameters : {
98- info : 'Default Tabs' ,
87+ docs : {
88+ description : {
89+ story : 'Tabs controlled with knobs' ,
90+ } ,
91+ } ,
9992 } ,
10093} ;
101- export const Scoped = {
102- render : ( ) => (
103- < Tabs type = 'scoped' defaultActiveKey = '1' onSelect = { action ( 'select' ) } >
94+
95+ /**
96+ *
97+ */
98+ export const Default : ComponentStoryObj < typeof Tabs > = {
99+ render : ( args ) => (
100+ < Tabs { ...args } >
104101 < Tab eventKey = '1' title = 'Tab 1' >
105102 This is in tab #1
106103 </ Tab >
@@ -112,13 +109,43 @@ export const Scoped = {
112109 </ Tab >
113110 </ Tabs >
114111 ) ,
112+ args : {
113+ type : 'default' ,
114+ defaultActiveKey : '1' ,
115+ } ,
116+ parameters : {
117+ docs : {
118+ description : {
119+ story : 'Default Tabs' ,
120+ } ,
121+ } ,
122+ } ,
123+ } ;
124+
125+ /**
126+ *
127+ */
128+ export const Scoped : ComponentStoryObj < typeof Tabs > = {
129+ ...Default ,
130+ args : {
131+ type : 'scoped' ,
132+ defaultActiveKey : '1' ,
133+ } ,
115134 parameters : {
116- info : 'Scoped Tabs' ,
135+ docs : {
136+ description : {
137+ story : 'Scoped Tabs' ,
138+ } ,
139+ } ,
117140 } ,
118141} ;
119- export const WithDropdownDefault = {
120- render : ( ) => (
121- < Tabs type = 'default' defaultActiveKey = '1' onSelect = { action ( 'select' ) } >
142+
143+ /**
144+ *
145+ */
146+ export const WithDropdownDefault : ComponentStoryObj < typeof Tabs > = {
147+ render : ( args ) => (
148+ < Tabs { ...args } >
122149 < Tab eventKey = '1' title = 'Tab 1' menuItems = { createMenu ( ) } >
123150 This is in tab #1
124151 </ Tab >
@@ -131,32 +158,44 @@ export const WithDropdownDefault = {
131158 </ Tabs >
132159 ) ,
133160 name : 'With Dropdown (Default)' ,
161+ args : {
162+ type : 'default' ,
163+ defaultActiveKey : '1' ,
164+ } ,
134165 parameters : {
135- info : 'Default tabs with dropdown menu' ,
166+ docs : {
167+ description : {
168+ story : 'Default tabs with dropdown menu' ,
169+ } ,
170+ } ,
136171 } ,
137172} ;
138- export const WithDropdownScoped = {
139- render : ( ) => (
140- < Tabs type = 'scoped' defaultActiveKey = '1' onSelect = { action ( 'select' ) } >
141- < Tab eventKey = '1' title = 'Tab 1' menuItems = { createMenu ( ) } >
142- This is in tab #1
143- </ Tab >
144- < Tab eventKey = '2' title = 'Tab 2' menuItems = { createMenu ( ) } >
145- This is in tab #2
146- </ Tab >
147- < Tab eventKey = '3' title = 'Tab 3' menuItems = { createMenu ( ) } >
148- This is in tab #3
149- </ Tab >
150- </ Tabs >
151- ) ,
173+
174+ /**
175+ *
176+ */
177+ export const WithDropdownScoped : ComponentStoryObj < typeof Tabs > = {
178+ ...WithDropdownDefault ,
152179 name : 'With Dropdown (Scoped)' ,
180+ args : {
181+ type : 'scoped' ,
182+ defaultActiveKey : '1' ,
183+ } ,
153184 parameters : {
154- info : 'Scoped tabs with dropdown menu' ,
185+ docs : {
186+ description : {
187+ story : 'Scoped tabs with dropdown menu' ,
188+ } ,
189+ } ,
155190 } ,
156191} ;
157- export const CustomTabItem = {
158- render : ( ) => (
159- < Tabs type = 'default' defaultActiveKey = '1' onSelect = { action ( 'select' ) } >
192+
193+ /**
194+ *
195+ */
196+ export const CustomTabItem : ComponentStoryObj < typeof Tabs > = {
197+ render : ( args ) => (
198+ < Tabs { ...args } >
160199 < Tab
161200 eventKey = '1'
162201 title = 'Tab 1'
@@ -183,7 +222,15 @@ export const CustomTabItem = {
183222 </ Tab >
184223 </ Tabs >
185224 ) ,
225+ args : {
226+ type : 'default' ,
227+ defaultActiveKey : '1' ,
228+ } ,
186229 parameters : {
187- info : 'Tab with custom tab item content' ,
230+ docs : {
231+ description : {
232+ story : 'Tab with custom tab item content' ,
233+ } ,
234+ } ,
188235 } ,
189236} ;
0 commit comments