Files
tanami-admin-panel/src/Components/SwitchButton.jsx

79 lines
2.2 KiB
React
Raw Normal View History

2024-08-08 19:37:14 +05:30
import { Box, Text } from "@chakra-ui/react";
import React, { useRef } from "react";
import audioClick from "../assets/click-151673.mp3";
2024-07-19 18:36:47 +05:30
const SwitchButton = ({ isSwitchOn, setIsSwitchOn }) => {
2024-08-08 19:37:14 +05:30
// const [isSwitchOn, setIsSwitchOn] = useState(false);
const audio = useRef();
2024-07-19 18:36:47 +05:30
const switch_onChange_handle = () => {
setIsSwitchOn(!isSwitchOn);
2024-08-08 19:37:14 +05:30
if (audio.current) {
audio.current.play();
}
2024-07-19 18:36:47 +05:30
};
return (
<Box display="flex" alignItems="center">
2024-07-22 14:56:29 +05:30
<Box
as="button"
display="flex"
2024-07-22 16:52:45 +05:30
justifyContent="normal"
2024-07-22 14:56:29 +05:30
alignItems="center"
2024-07-22 16:52:45 +05:30
// justifyContent={isSwitchOn ? "flex-end" : "flex-start"}
width="90px"
2024-08-08 19:37:14 +05:30
height="25px"
2024-07-22 14:56:29 +05:30
borderRadius="20px"
2024-07-22 16:52:45 +05:30
backgroundColor={isSwitchOn ? "#004118" : "#ef0000"}
2024-07-22 14:56:29 +05:30
onClick={switch_onChange_handle}
position="relative"
2024-07-22 16:52:45 +05:30
fontSize="13px"
fontWeight="100"
2024-07-22 14:56:29 +05:30
transition="background-color 0.2s"
_before={{
2024-08-08 19:37:14 +05:30
// content: '""',
// position: "absolute",
// width: "20px",
// height: "20px",
// borderRadius: "50%",
// backgroundColor: "#FFF",
// boxShadow: "0 2px 4px rgba(0, 0, 0, 0.2)",
// transform: isSwitchOn ? "translateX(65px)" : "translateX(0)",
// transition: "transform 0.2s",
// left:'2px'
2024-07-22 14:56:29 +05:30
content: '""',
position: "absolute",
2024-08-08 19:37:14 +05:30
height: "25px",
width: "25px",
left: "0px",
background:
"conic-gradient(rgb(104, 104, 104), white, rgb(104, 104, 104), white, rgb(104, 104, 104))",
2024-07-22 14:56:29 +05:30
borderRadius: "50%",
2024-08-08 19:37:14 +05:30
transitionDuration: ".3s",
boxShadow: " 5px 2px 7px rgba(8, 8, 8, 0.308)",
2024-07-22 16:52:45 +05:30
transform: isSwitchOn ? "translateX(65px)" : "translateX(0)",
2024-07-19 18:36:47 +05:30
}}
2024-07-22 14:56:29 +05:30
>
<Text
2024-07-22 16:52:45 +05:30
// color="#FFF"
fontWeight="400"
2024-07-22 14:56:29 +05:30
zIndex={1}
position="absolute"
2024-07-22 16:52:45 +05:30
mb={0}
color={isSwitchOn ? "#fff" : "#fff"}
2024-07-22 14:56:29 +05:30
left={isSwitchOn ? "10px" : "auto"}
right={isSwitchOn ? "auto" : "10px"}
>
2024-08-08 19:37:14 +05:30
{isSwitchOn ? "Active" : "InActive"}
2024-07-22 14:56:29 +05:30
</Text>
</Box>
2024-08-08 19:37:14 +05:30
<audio ref={audio} src={audioClick} />
2024-07-19 18:36:47 +05:30
</Box>
);
};
export default SwitchButton;