UNPKG

@lunit/oui

Version:

Lunit Oncology UI components

24 lines (23 loc) 1.63 kB
import { createElement as _createElement } from "react"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { v4 as uuidV4 } from 'uuid'; import { ToggleControlGroupContainer } from './ToggleControlGroup.styled'; import ToggleControl from '../ToggleControl/ToggleControl'; const ToggleControlGroup = ({ componentType = 'toggleGroup', size = 'medium', title, tooltip = [], bar, childToggles, disabled, checked, behavior = 'multi', isDimmed = false, onChange, }) => { if (!componentType) throw new Error("The 'componentType' prop is required."); if (!title) throw new Error("The 'title' prop is required."); if (checked === undefined) throw new Error("The 'checked' prop is required."); if (typeof checked !== 'boolean') throw new Error("The 'checked' prop must be a boolean."); if (!childToggles.length) throw new Error("The 'childToggles' prop must contain at least one child toggle."); return (_jsxs(ToggleControlGroupContainer, { children: [_jsx(ToggleControl, { isParent: true, componentType: "toggle", bar: bar, disabled: disabled, size: size, title: title, tooltip: tooltip, checked: checked, isDimmed: isDimmed, onChange: onChange }), childToggles?.map((child, index) => { return (_createElement(ToggleControl, { ...child, componentType: "toggle", key: uuidV4(), isDimmed: child.isDimmed || isDimmed || !checked, disabled: child.disabled || !checked, onChange: (event) => { child.onChange(event); }, bar: child.bar })); })] })); }; export default ToggleControlGroup;