import React, { HTMLAttributes, useMemo, useState } from "react"; import { Colors } from "../colors"; /** * @TODO needs state A and B other variations */ export interface SwitchIconProps extends HTMLAttributes{ anim?: 'fade' | 'scale' | 'flip' | 'slide-left' | 'slide-down' | 'slide-right'; stateA: Colors | 'muted'; stateB: Colors | 'muted'; iconA: React.ReactNode iconB: React.ReactNode defaultActive?: boolean; onStateChange?: (state: boolean) => void; } const SwitchIcon = ({ anim, iconA, iconB, stateA, stateB, defaultActive = false, className, onClick, onStateChange, ...props }: SwitchIconProps) => { const [active, setActive] = useState(defaultActive); const classes = useMemo(() => { return [ 'switch-icon', anim && `switch-icon-${anim}`, active && 'active', className ].filter(Boolean).join(' ') }, [anim, active, className]); const classesA = useMemo(() => { return [ 'switch-icon-a', stateA && `text-${stateA}` ].join(' '); }, [stateA]); const classesB = useMemo(() => { return [ 'switch-icon-b', stateB && `text-${stateB}` ].join(' '); }, [stateB]) const onButtonClick = (ev: React.MouseEvent) => { setActive(!active); onStateChange && onStateChange(!active); onClick && onClick(ev); } return ( ) } export default SwitchIcon;