11import React from 'react' ;
2- import { select } from '@storybook/addon-knobs' ;
3- import { Spinner , SpinnerType , SpinnerSize } from '../src/scripts/Spinner' ;
2+ import { Spinner } from '../src/scripts/Spinner' ;
3+ import { ComponentMeta , ComponentStoryObj } from '@storybook/react' ;
4+ import { buildContainerDecorator } from './util' ;
5+
6+ /**
7+ *
8+ */
49const containerStyle = {
510 position : 'relative' as const ,
611 width : 100 ,
@@ -10,91 +15,103 @@ const containerStyle = {
1015const inverseContainerStyle = Object . assign ( { } , containerStyle , {
1116 background : '#16325C' ,
1217} ) ;
13- export default {
18+
19+ /**
20+ *
21+ */
22+ const meta : ComponentMeta < typeof Spinner > = {
1423 title : 'Spinner' ,
24+ component : Spinner ,
1525} ;
16- export const ControlledWithKnobs = {
17- render : ( ) => {
18- // NOTE: Converting empty string to undefined
19- // because we can't assign undefined to options directly
20- // ref. https://github.com/storybookjs/storybook/issues/4487
21- const sizeOptions = {
22- '(none)' : '' ,
23- small : 'small' ,
24- medium : 'medium' ,
25- large : 'large' ,
26- } ;
27- const size = ( select ( 'size' , sizeOptions , '' ) ||
28- undefined ) as unknown as SpinnerSize ;
29- const typeOptions = {
30- '(none)' : '' ,
31- brand : 'brand' ,
32- inverse : 'inverse' ,
33- } ;
34- const type = ( select ( 'type' , typeOptions , '' ) ||
35- undefined ) as unknown as SpinnerType ;
36- return (
37- < div style = { type === 'inverse' ? inverseContainerStyle : containerStyle } >
38- < Spinner size = { size } type = { type } />
39- </ div >
40- ) ;
41- } ,
26+ export default meta ;
27+
28+ /**
29+ *
30+ */
31+ export const ControlledWithKnobs : ComponentStoryObj < typeof Spinner > = {
4232 name : 'Controlled with knobs' ,
33+ decorators : [
34+ buildContainerDecorator ( ( { type } ) =>
35+ type === 'inverse' ? inverseContainerStyle : containerStyle
36+ ) ,
37+ ] ,
4338 parameters : {
44- info : 'Spinner with knobs' ,
39+ docs : {
40+ description : {
41+ story : 'Spinner with knobs' ,
42+ } ,
43+ } ,
4544 } ,
4645} ;
47- export const Default = {
48- render : ( ) => (
49- < div >
46+
47+ /**
48+ *
49+ */
50+ export const Default : ComponentStoryObj < typeof Spinner > = {
51+ render : ( args ) => (
52+ < div { ...args } >
5053 < div style = { containerStyle } >
51- < Spinner size = 'small' />
54+ < Spinner size = 'small' { ... args } />
5255 </ div >
5356 < div style = { containerStyle } >
54- < Spinner size = 'medium' />
57+ < Spinner size = 'medium' { ... args } />
5558 </ div >
5659 < div style = { containerStyle } >
57- < Spinner size = 'large' />
60+ < Spinner size = 'large' { ... args } />
5861 </ div >
5962 </ div >
6063 ) ,
6164 parameters : {
62- info : 'Default spinner with different sizes (small, medium, large)' ,
65+ docs : {
66+ description : {
67+ story : 'Default spinner with different sizes (small, medium, large)' ,
68+ } ,
69+ } ,
6370 } ,
6471} ;
65- export const Brand = {
66- render : ( ) => (
67- < div >
68- < div style = { containerStyle } >
69- < Spinner type = 'brand' size = 'small' />
70- </ div >
71- < div style = { containerStyle } >
72- < Spinner type = 'brand' size = 'medium' />
73- </ div >
74- < div style = { containerStyle } >
75- < Spinner type = 'brand' size = 'large' />
76- </ div >
77- </ div >
78- ) ,
72+
73+ /**
74+ *
75+ */
76+ export const Brand : ComponentStoryObj < typeof Spinner > = {
77+ ...Default ,
78+ args : {
79+ type : 'brand' ,
80+ } ,
7981 parameters : {
80- info : 'Brand spinner with different sizes (small, medium, large)' ,
82+ docs : {
83+ description : {
84+ story : 'Brand spinner with different sizes (small, medium, large)' ,
85+ } ,
86+ } ,
8187 } ,
8288} ;
83- export const Inverse = {
84- render : ( ) => (
89+
90+ /**
91+ *
92+ */
93+ export const Inverse : ComponentStoryObj < typeof Spinner > = {
94+ render : ( args ) => (
8595 < div >
8696 < div style = { inverseContainerStyle } >
87- < Spinner type = 'inverse' size = 'small' />
97+ < Spinner size = 'small' { ... args } />
8898 </ div >
8999 < div style = { inverseContainerStyle } >
90- < Spinner type = 'inverse' size = 'medium' />
100+ < Spinner size = 'medium' { ... args } />
91101 </ div >
92102 < div style = { inverseContainerStyle } >
93- < Spinner type = 'inverse' size = 'large' />
103+ < Spinner size = 'large' { ... args } />
94104 </ div >
95105 </ div >
96106 ) ,
107+ args : {
108+ type : 'inverse' ,
109+ } ,
97110 parameters : {
98- info : 'Inverse spinner with different sizes (small, medium, large)' ,
111+ docs : {
112+ description : {
113+ story : 'Inverse spinner with different sizes (small, medium, large)' ,
114+ } ,
115+ } ,
99116 } ,
100117} ;
0 commit comments