import "./Badge.css"; import clsx from "clsx"; import { ComponentChildren, HTMLAttributes } from "preact"; import { useRef } from "preact/hooks"; import Dropdown, { DropdownProps } from "./Dropdown"; import { useStaticTooltip } from "./hooks"; import Icon from "./Icon"; interface SimpleBadgeProps { className?: string; title: ComponentChildren; } interface BadgeProps extends Pick, "onClick" | "style"> { text?: ComponentChildren; icon?: string; className?: string; tooltip?: string; href?: string; } export default function SimpleBadge({ title, className }: SimpleBadgeProps) { return {title}; } export function Badge({ icon, className, text, tooltip, href, ...containerProps }: BadgeProps) { const containerRef = useRef(null); useStaticTooltip(containerRef, { placement: "bottom", fallbackPlacements: [ "bottom" ], animation: false, html: true, title: tooltip }); const content = <> {icon && <> } {text} ; return (
{href ? {content} : {content}}
); } export function BadgeWithDropdown({ text, children, tooltip, className, dropdownOptions, ...props }: BadgeProps & { children: ComponentChildren, dropdownOptions?: Partial }) { return ( {text} } className={className} {...props} />} noDropdownListStyle noSelectButtonStyle hideToggleArrow title={tooltip} titlePosition="bottom" {...dropdownOptions} dropdownOptions={{ ...dropdownOptions?.dropdownOptions, popperConfig: { ...dropdownOptions?.dropdownOptions?.popperConfig, placement: "bottom", strategy: "fixed" } }} >{children} ); }