import Link from 'next/link'; import { type FC, type ReactElement, type ReactNode } from 'react'; import styles from './Switch.module.css'; import { Icon, type IconProp } from '../../icons'; import { Tip } from '../Tip/Tip'; import { Composite, CompositeItem } from '../Focus/Composite'; export interface SwitchProps { children: ReactElement[], } export type SwitchControlProps = { children?: ReactNode, active?: boolean, clickAction?: () => void, icon?: IconProp, tip?: ReactNode, } & ( | { type?: 'button', href?: never, replace?: never, scroll?: never, clickAction: () => void, name?: string, value?: string } | { type: 'link', href: string, replace?: boolean, scroll?: boolean, name?: never, value?: never } | { type: 'radio', href?: never, replace?: never, scroll?: never, name: string, value: string } ); export const Switch: FC & { Control: FC } = ({ children }: SwitchProps) => { return ( {children} ); }; Switch.Control = ({ children, active, type = 'button', href, clickAction, name, value, icon, tip, replace, scroll }: SwitchControlProps) => { const Element = type === 'link' ? Link : type === 'radio' ? 'label' : 'button'; const element = ( {type === 'radio' && } {icon && ()} {children && ({children})} ); return tip ? : ; }; Switch.Control.displayName = 'Switch.Control';