import { MouseEventHandler, useCallback } from "react"; import { MaterialSymbol } from "material-symbols"; import { Link } from "./Link"; import { Ico } from "components/Ico"; import { cIf, cJoin } from "helpers/className"; import { isDefined, isDefinedAndNotEmpty } from "helpers/asserts"; import { TranslatedProps } from "types/TranslatedProps"; import { useSmartLanguage } from "hooks/useSmartLanguage"; /* * ╭─────────────╮ * ───────────────────────────────────────╯ COMPONENT ╰─────────────────────────────────────────── */ interface Props { id?: string; className?: string; href?: string; active?: boolean; icon?: MaterialSymbol; text?: string | null | undefined; alwaysNewTab?: boolean; onClick?: MouseEventHandler; onMouseUp?: MouseEventHandler; draggable?: boolean; badgeNumber?: number; disabled?: boolean; size?: "normal" | "small"; } // ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ export const Button = ({ draggable, id, onClick, onMouseUp, active = false, className, icon, text, href, alwaysNewTab = false, badgeNumber, disabled, size = "normal", }: Props): JSX.Element => (
!disabled && onClick?.(event)} onMouseUp={onMouseUp} onFocus={(event) => event.target.blur()} className={cJoin( `group grid cursor-pointer select-none grid-flow-col place-content-center place-items-center gap-2 rounded-full border border-dark py-3 px-4 leading-none text-dark transition-all`, cIf(size === "small", "px-3 py-1 text-xs"), cIf(active, "!border-black bg-black !text-light drop-shadow-lg shadow-black"), cIf( disabled, "cursor-not-allowed opacity-50 grayscale", cIf( !active, `shadow-shade hover:bg-dark hover:text-light hover:drop-shadow-lg active:hover:!border-black active:hover:bg-black active:hover:!text-light active:hover:drop-shadow-lg active:hover:shadow-black` ) ), className )}> {isDefined(badgeNumber) && (

{badgeNumber}

)} {isDefinedAndNotEmpty(icon) && ( )} {isDefinedAndNotEmpty(text) &&

{text}

}
); /* * ╭──────────────────────╮ * ───────────────────────────────────╯ TRANSLATED VARIANT ╰────────────────────────────────────── */ export const TranslatedButton = ({ translations, fallback, ...otherProps }: TranslatedProps): JSX.Element => { const [selectedTranslation] = useSmartLanguage({ items: translations, languageExtractor: useCallback((item: { language: string }): string => item.language, []), }); return