@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
107 lines (106 loc) • 3.52 kB
TypeScript
/**
* MSKCC DSM 2021, 2023
*/
import PropTypes from 'prop-types';
import React, { HTMLAttributes, ReactElement } from 'react';
interface SwitchEventHandlersParams {
index?: number;
name?: string | number;
text?: string;
key?: string | number;
}
export interface ContentSwitcherProps extends Omit<HTMLAttributes<HTMLElement>, 'onChange'> {
/**
* Pass in Switch components to be rendered in the ContentSwitcher
*/
children?: ReactElement[];
/**
* Specify an optional className to be added to the container node
*/
className?: string;
/**
* `true` to use the light version.
*
* @deprecated The `light` prop for `ContentSwitcher` has
* been deprecated in favor of the new `Layer` component. It will be removed in the next major release.
*/
light?: boolean;
/**
* Specify an `onChange` handler that is called whenever the ContentSwitcher
* changes which item is selected
*/
onChange: (params: SwitchEventHandlersParams) => void;
/**
* Specify a selected index for the initially selected content
*/
selectedIndex: number;
/**
* Choose whether or not to automatically change selection on focus
*/
selectionMode: 'automatic' | 'manual';
/**
* Specify the size of the Content Switcher. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
*/
size: 'sm' | 'md' | 'lg';
}
interface ContentSwitcherState {
selectedIndex?: number;
}
export default class ContentSwitcher extends React.Component<ContentSwitcherProps, ContentSwitcherState> {
/**
* The DOM references of child `<Switch>`.
* @type {Array<Element>}
* @private
*/
_switchRefs: HTMLButtonElement[];
state: {
selectedIndex: undefined;
};
static propTypes: {
/**
* Pass in Switch components to be rendered in the ContentSwitcher
*/
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
/**
* Specify an optional className to be added to the container node
*/
className: PropTypes.Requireable<string>;
/**
* `true` to use the light variant.
*/
light: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
/**
* Specify an `onChange` handler that is called whenever the ContentSwitcher
* changes which item is selected
*/
onChange: PropTypes.Validator<(...args: any[]) => any>;
/**
* Specify a selected index for the initially selected content
*/
selectedIndex: PropTypes.Requireable<number>;
/**
* Choose whether or not to automatically change selection on focus
*/
selectionMode: PropTypes.Requireable<string>;
/**
* Specify the size of the Content Switcher. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
*/
size: PropTypes.Requireable<string>;
};
static contextType: React.Context<string>;
static defaultProps: {
selectedIndex: number;
selectionMode: string;
onChange: () => void;
};
static getDerivedStateFromProps({ selectedIndex }: {
selectedIndex: any;
}, state: any): {
selectedIndex: any;
prevSelectedIndex: any;
} | null;
handleItemRef: (index: any) => (ref: any) => void;
handleChildChange: (data: any) => void;
render(): JSX.Element;
}
export {};