/** @format */ import React, { useState } from "react"; import styled from "styled-components"; import ReactTooltip from "react-tooltip"; import { ExtraStyleProps } from "../types/genericTypes"; const CheckBoxWrapper = styled.div` position: relative; `; const CheckBoxLabel = styled.label` position: absolute; top: 0; left: 0; width: ${({ width }) => (width ? width : "42px")}; height: ${({ height }) => (height ? height : "26px")}; border-radius: ${({ borderRadius }) => borderRadius ? borderRadius : "15px"}; background: ${({ backgroundColor }) => backgroundColor ? backgroundColor : " #ebdcdc"}; &:disabled { background: #8e1717; } cursor: pointer; &::after { content: ""; display: block; border-radius: 50%; width: 18px; height: 18px; margin: 3px; background: ${({ buttonColor }) => (buttonColor ? buttonColor : "#60a8cf")}; box-shadow: 1px 3px 3px 1px rgba(0, 0, 0, 0.2); transition: 0.2s; } `; const CheckBox = styled.input` opacity: 0; z-index: 1; border-radius: ${({ borderRadius }) => borderRadius ? borderRadius : "15px"}; width: ${({ width }) => (width ? width : "42px")}; height: ${({ height }) => (height ? height : "26px")}; &:disabled { background: #8e1717; } accent-color: green; &:checked + ${CheckBoxLabel} { background: ${({ selectedColor }) => selectedColor ? selectedColor : "#4fbe79"}; &::after { content: ""; display: block; border-radius: 50%; width: 18px; height: 18px; margin-left: 21px; transition: 0.2s; } } `; interface ToggleSwitchProps { backgroundColor?: string; selectedColor?: string; buttonColor?: string; zIndex?: string; borderRadius?: string; disabled?: boolean; width?: string; height?: string; tooltip?: string; callBack?: (status: any) => void; } function ToggleSwitch({ backgroundColor, buttonColor, selectedColor, borderRadius, disabled, width, height, zIndex, tooltip, callBack, }: ToggleSwitchProps) { const [active, setActive] = useState(false); return ( { active ? setActive(false) : setActive(true); callBack ? callBack(active ? false : true) : null; }} /> {tooltip && ( {tooltip} )} ); } export default ToggleSwitch;