/* * Copyright (c) 2015 Nordic Semiconductor ASA * * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause */ import React, { type FC, type ReactNode } from 'react'; import classNames from '../utils/classNames'; import './toggle.scss'; export interface Props { id?: string; title?: string; isToggled: boolean; onToggle?: (isToggled: boolean) => void; label?: ReactNode; labelRight?: boolean; variant?: 'primary' | 'secondary'; barColor?: string; barColorToggled?: string; handleColor?: string; handleColorToggled?: string; width?: string; disabled?: boolean; children?: ReactNode; } export const Toggle: FC = ({ id, title, isToggled, onToggle, label, labelRight = false, variant = 'primary', barColor, barColorToggled, handleColor, handleColorToggled, width, disabled = false, children, }) => { const isPrimary = variant === 'primary'; const isSecondary = variant === 'secondary'; const handleToggle = () => { if (onToggle) { onToggle(!isToggled); } }; const [labelText, ...remainingChildren] = Array.isArray(children) ? children : [children || label]; const labelElement = labelText && ( {labelText} ); return (
{remainingChildren.length > 0 && (
{remainingChildren}
)}
); };