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

57 lines
1.5 KiB
React
Raw Normal View History

2024-07-22 14:56:29 +05:30
import { Box, Text } from '@chakra-ui/react';
2024-07-19 18:36:47 +05:30
import React from 'react';
const SwitchButton = ({ isSwitchOn, setIsSwitchOn }) => {
const switch_onChange_handle = () => {
setIsSwitchOn(!isSwitchOn);
};
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"
height="24px"
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={{
content: '""',
position: "absolute",
2024-07-22 16:52:45 +05:30
width: "20px",
height: "20px",
2024-07-22 14:56:29 +05:30
borderRadius: "50%",
backgroundColor: "#FFF",
boxShadow: "0 2px 4px rgba(0, 0, 0, 0.2)",
2024-07-22 16:52:45 +05:30
transform: isSwitchOn ? "translateX(65px)" : "translateX(0)",
2024-07-22 14:56:29 +05:30
transition: "transform 0.2s",
2024-07-22 16:52:45 +05:30
left:'2px'
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-07-22 16:52:45 +05:30
{isSwitchOn ? 'Active' : 'InActive'}
2024-07-22 14:56:29 +05:30
</Text>
</Box>
2024-07-19 18:36:47 +05:30
</Box>
);
};
export default SwitchButton;