@@ -15,8 +15,10 @@ import {
1515 useAccordion
1616} from '@zendeskgarden/container-accordion' ;
1717
18- interface IComponentProps extends IUseAccordionReturnValue {
19- sections : number [ ] ;
18+ type ISectionValue = number ;
19+
20+ interface IComponentProps < T = ISectionValue > extends IUseAccordionReturnValue < T > {
21+ sections : IUseAccordionProps < T > [ 'sections' ] ;
2022}
2123
2224const Component = ( {
@@ -28,18 +30,17 @@ const Component = ({
2830 getPanelProps
2931} : IComponentProps ) => (
3032 < div style = { { width : 300 } } >
31- { sections . map ( ( section , index ) => {
32- const disabled = disabledSections . indexOf ( index ) !== - 1 ;
33- const hidden = expandedSections . indexOf ( index ) === - 1 ;
33+ { sections . map ( ( value , index ) => {
34+ const disabled = disabledSections . indexOf ( value ) !== - 1 ;
35+ const hidden = expandedSections . indexOf ( value ) === - 1 ;
3436
3537 return (
36- < div key = { section } >
37- < div { ...getHeaderProps ( { ariaLevel : 2 } ) } >
38+ < div key = { value } >
39+ < div { ...getHeaderProps ( { 'aria-level' : 2 } ) } >
3840 < button
3941 { ...getTriggerProps ( {
40- index ,
42+ value ,
4143 role : null ,
42- tabIndex : null ,
4344 disabled
4445 } ) }
4546 className = "text-left w-full"
@@ -50,7 +51,7 @@ const Component = ({
5051 </ div >
5152 < section
5253 { ...getPanelProps ( {
53- index ,
54+ value ,
5455 role : null ,
5556 hidden
5657 } ) }
@@ -65,38 +66,33 @@ const Component = ({
6566 </ div >
6667) ;
6768
68- interface IProps extends IUseAccordionProps {
69- sections : number [ ] ;
70- }
71-
72- const Container = ( { sections, ...props } : IProps ) => (
69+ const Container = ( props : IAccordionContainerProps < ISectionValue > ) => (
7370 < AccordionContainer { ...props } >
74- { containerProps => < Component sections = { sections } { ...containerProps } /> }
71+ { /* eslint-disable-next-line react/destructuring-assignment */ }
72+ { containerProps => < Component sections = { props . sections } { ...containerProps } /> }
7573 </ AccordionContainer >
7674) ;
7775
78- const Hook = ( { sections , ... props } : IProps ) => {
76+ const Hook = ( props : IUseAccordionProps < ISectionValue > ) => {
7977 const hookProps = useAccordion ( props ) ;
8078
81- return < Component sections = { sections } { ...hookProps } /> ;
79+ // eslint-disable-next-line react/destructuring-assignment
80+ return < Component sections = { props . sections } { ...hookProps } /> ;
8281} ;
8382
84- interface IArgs extends IAccordionContainerProps {
83+ interface IArgs extends IAccordionContainerProps < ISectionValue > {
8584 as : 'hook' | 'container' ;
86- sections : number ;
8785}
8886
89- export const AccordionStory : Story < IArgs > = ( { as, sections , ...props } : IArgs ) => {
87+ export const AccordionStory : Story < IArgs > = ( { as, ...props } : IArgs ) => {
9088 const Accordion = ( ) => {
91- const _sections = Array . from ( { length : sections } , ( _ , index ) => index ) ;
92-
9389 switch ( as ) {
9490 case 'container' :
95- return < Container sections = { _sections } { ...props } /> ;
91+ return < Container { ...props } /> ;
9692
9793 case 'hook' :
9894 default :
99- return < Hook sections = { _sections } { ...props } /> ;
95+ return < Hook { ...props } /> ;
10096 }
10197 } ;
10298
0 commit comments