import React from 'react'; import { BoxProps, BoxSpace, SilkeBox } from '../silke-box'; import { SilkeIcon, SilkeIcons } from '../silke-icon'; import { SilkeText } from '../silke-text'; import styles from './silke-tag.scss'; export type SilkeTagKind = 'primary' | 'secondary'; export type SilkeTagColor = 'yellow' | 'green' | 'red' | 'gray' | 'blue' | 'purple' | 'dark' | 'ai'; export type SilkeTagSize = 'tiny'; export type SilkeTagProps = { disabled?: boolean; label?: React.ReactNode; kind?: SilkeTagKind; size?: SilkeTagSize; icon?: SilkeIcons; innerGap?: BoxSpace; color?: SilkeTagColor; link?: string; /** * Will add a remove button to tag */ onRemove?: (e: React.MouseEvent) => void; } & Omit; function SilkeTagComp( { className, disabled, kind = 'primary', label, onRemove, size, icon, innerGap = 'xs', color = 'gray', link, ...rest }: SilkeTagProps, ref: any, ) { const cl = [ styles.tag, styles[kind || 'primary'], disabled ? styles.disabled : styles[color || 'gray'], ]; if (className) cl.push(className); if (size) cl.push(styles[size]); if (rest?.onClick) cl.push(styles.selectable); if (link) cl.push(styles.link); const iconOnly = !!icon && !label; const showRemoveAsIcon = !!icon && kind === 'secondary' && onRemove; if (showRemoveAsIcon) cl.push(styles.showRemoveAsIcon); const removeButton = !disabled && onRemove && ( ); return ( {showRemoveAsIcon && removeButton} {icon && ( )} {label && {label}} {!showRemoveAsIcon && removeButton} ); } export const SilkeTag = React.forwardRef(SilkeTagComp); SilkeBox.displayName = 'SilkeTag'; export const SilkeTagDark = ({ color, ...rest }: SilkeTagProps) => { return ; }; export const SilkeTagYellow = ({ color, ...rest }: SilkeTagProps) => { return ; }; export const SilkeTagGreen = ({ color, ...rest }: SilkeTagProps) => { return ; }; export const SilkeTagRed = ({ color, ...rest }: SilkeTagProps) => { return ; }; export const SilkeTagGray = ({ color, ...rest }: SilkeTagProps) => { return ; }; export const SilkeTagBlue = ({ color, ...rest }: SilkeTagProps) => { return ; };