({ children, isOn })
| 21 | } |
| 22 | |
| 23 | const Label: React.FC<LabelProps> = ({ children, isOn }) => { |
| 24 | const context = useContext(SlideToggleContext) |
| 25 | |
| 26 | if (!context) { |
| 27 | throw new Error('Context Error!') |
| 28 | } |
| 29 | |
| 30 | const { toggled } = context |
| 31 | |
| 32 | return ( |
| 33 | <AnimatePresence initial={false}> |
| 34 | {(isOn && toggled) || (!isOn && !toggled) ? ( |
| 35 | <motion.div |
| 36 | initial={{ |
| 37 | x: isOn ? -20 : 20, |
| 38 | opacity: 0, |
| 39 | }} |
| 40 | animate={{ |
| 41 | x: 0, |
| 42 | opacity: 1, |
| 43 | }} |
| 44 | exit={{ |
| 45 | x: isOn ? -20 : 20, |
| 46 | opacity: 0, |
| 47 | transition: { |
| 48 | type: 'spring', |
| 49 | delay: 0.0, |
| 50 | bounce: 0, |
| 51 | duration: 0.3, |
| 52 | }, |
| 53 | }} |
| 54 | transition={{ |
| 55 | type: 'spring', |
| 56 | delay: 0.1, |
| 57 | bounce: 0, |
| 58 | duration: 0.6, |
| 59 | }} |
| 60 | className={`absolute ${ |
| 61 | isOn ? 'left-0 z-10' : 'right-0' |
| 62 | } p-2 ${isOn ? 'pr-[25px]' : 'pl-[25px]'}`} |
| 63 | > |
| 64 | <span |
| 65 | className={`text-nowrap text-xs font-medium tracking-tight ${ |
| 66 | isOn ? 'text-white' : 'fill-black/40 text-black/40' |
| 67 | }`} |
| 68 | > |
| 69 | {children} |
| 70 | </span> |
| 71 | </motion.div> |
| 72 | ) : null} |
| 73 | </AnimatePresence> |
| 74 | ) |
| 75 | } |
| 76 | |
| 77 | const SlideToggle: React.FC<SlideToggleProps> = ({ |
| 78 | onToggle, |
nothing calls this directly
no outgoing calls
no test coverage detected