Skip to content

Commit 2563ed0

Browse files
committed
Add missing signals and slots to content switcher
Signed-off-by: Zvonimir Fras <zvonimir@zvonimirfras.com>
1 parent 56f2dd3 commit 2563ed0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

player/react/src/lib/components/ui-content-switcher.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { ContentSwitcher, Switch } from '@carbon/react';
3-
import { CssClasses } from '../types';
3+
import { CssClasses, SendSignal } from '../types';
44
import { stringToCssClassName } from '../utils';
55
import { 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 {
2122
export const type = 'content-switcher';
2223

2324
export 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

Comments
 (0)