11import React from 'react' ;
22import { ContentSwitcher , Switch } from '@carbon/react' ;
3- import { CssClasses } from '../types' ;
3+ import { CssClasses , SendSignal } from '../types' ;
44import { stringToCssClassName } from '../utils' ;
55import { commonSlots } from '../common-slots' ;
66
@@ -9,6 +9,7 @@ export interface ContentSwitcherState {
99 items : [ ] ;
1010 size : [ ] ;
1111 selectedIndex : number ;
12+ id : string | number ;
1213 disabled ?: boolean ;
1314 hidden ?: boolean ;
1415 cssClasses ?: CssClasses [ ] ;
@@ -21,14 +22,15 @@ export interface ContentSwitcherState {
2122export const type = 'content-switcher' ;
2223
2324export const slots = {
24- ...commonSlots
25+ ...commonSlots ,
26+ selectedIndex : 'number'
2527} ;
2628
27- export const UIContentSwitcher = ( { state } : {
29+ export const UIContentSwitcher = ( { state, sendSignal } : {
2830 state : ContentSwitcherState ;
2931 setState : ( state : any ) => void ;
3032 setGlobalState : ( state : any ) => void ;
31- sendSignal : ( id : number | string , signal : string ) => void ;
33+ sendSignal : SendSignal ;
3234} ) => {
3335 if ( state . type !== 'content-switcher' ) {
3436 // eslint-disable-next-line react/jsx-no-useless-fragment
@@ -47,7 +49,10 @@ export const UIContentSwitcher = ({ state }: {
4749 return < ContentSwitcher
4850 size = { state . size }
4951 selectedIndex = { state . selectedIndex }
50- className = { cssClasses } >
52+ className = { cssClasses }
53+ onChange = { ( { index } : any ) => {
54+ sendSignal ( state . id , 'change' , [ index ] , { ...state , selectedIndex : index } ) ;
55+ } } >
5156 {
5257 state . items . map ( ( step : any , index : number ) => < Switch
5358 className = { step . className }
0 commit comments