@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
127 lines (126 loc) • 4.73 kB
TypeScript
/**
* MSKCC DSM 2021, 2024
*/
import React, { KeyboardEventHandler, MouseEventHandler } from 'react';
import PropTypes from 'prop-types';
type ExcludedAttributes = 'aria-labelledby' | 'aria-checked' | 'type' | 'role' | 'id' | 'size' | 'onClick';
export interface ToggleProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, ExcludedAttributes> {
/**
* Specify another element's id to be used as the label for this toggle
*/
'aria-labelledby'?: string;
/**
* Provide an id that unique represents the underlying `<button>`
*/
id: string;
/**
* Specify the label for the "off" position
*/
labelA?: string | undefined;
/**
* Specify the label for the "on" position
*/
labelB?: string | undefined;
/**
* Provide the text that will be read by a screen reader when visiting this
* control. This should be provided unless 'aria-labelledby' is set instead
* or you use an external <label> element with its "for" attribute set to the
* toggle's id.
*/
labelText?: string | undefined;
/**
* If true, the side labels (props.labelA and props.labelB) will be replaced by
* props.labelText (if passed), so that the toggle doesn't render a top label.
*/
hideLabel?: boolean;
/**
* Provide an event listener that is called when the control is toggled
*/
onClick?: MouseEventHandler<HTMLDivElement> | KeyboardEventHandler<HTMLDivElement> | undefined;
/**
* Provide an event listener that is called when the control is toggled
*/
onToggle?(checked: boolean): void;
/**
* Specify the size of the Toggle. Currently only supports 'sm' or 'md' (default)
*/
size?: 'sm' | 'md' | undefined;
/**
* Whether the toggle should be read-only
*/
readOnly?: boolean | undefined;
/**
* Specify whether the toggle should be on by default
*/
defaultToggled?: boolean | undefined;
/**
* Specify whether the control is toggled
*/
toggled?: boolean | undefined;
}
export declare function Toggle({ 'aria-labelledby': ariaLabelledby, className, defaultToggled, disabled, hideLabel, id, labelA, labelB, labelText, onClick, onToggle, readOnly, size, toggled, ...other }: ToggleProps): JSX.Element;
export declare namespace Toggle {
var propTypes: {
/**
* Specify another element's id to be used as the label for this toggle
*/
'aria-labelledby': PropTypes.Requireable<string>;
/**
* Specify a custom className to apply to the form-item node
*/
className: PropTypes.Requireable<string>;
/**
* Specify whether the toggle should be on by default
*/
defaultToggled: PropTypes.Requireable<boolean>;
/**
* Whether this control should be disabled
*/
disabled: PropTypes.Requireable<boolean>;
/**
* If true, the side labels (props.labelA and props.labelB) will be replaced by
* props.labelText (if passed), so that the toggle doesn't render a top label.
*/
hideLabel: PropTypes.Requireable<boolean>;
/**
* Provide an id that unique represents the underlying `<button>`
*/
id: PropTypes.Validator<string>;
/**
* Specify the label for the "off" position
*/
labelA: PropTypes.Requireable<PropTypes.ReactNodeLike>;
/**
* Specify the label for the "on" position
*/
labelB: PropTypes.Requireable<PropTypes.ReactNodeLike>;
/**
* Provide the text that will be read by a screen reader when visiting this
* control. This should be provided unless 'aria-labelledby' is set instead
* or you use an external <label> element with its "for" attribute set to the
* toggle's id.
*/
labelText: PropTypes.Requireable<string>;
/**
* Provide an event listener that is called when the control is clicked
*/
onClick: PropTypes.Requireable<(...args: any[]) => any>;
/**
* Provide an event listener that is called when the control is toggled
*/
onToggle: PropTypes.Requireable<(...args: any[]) => any>;
/**
* Whether the toggle should be read-only
*/
readOnly: PropTypes.Requireable<boolean>;
/**
* Specify the size of the Toggle. Currently only supports 'sm' or 'md' (default)
*/
size: PropTypes.Requireable<string>;
/**
* Specify whether the control is toggled
*/
toggled: PropTypes.Requireable<boolean>;
};
}
export default Toggle;