import { twMerge } from "tailwind-merge"; import { useFocusable, } from "@noriginmedia/norigin-spatial-navigation"; import classNames from "classnames"; import { GamePadButtonCode, useShortcuts } from "@/mainview/scripts/shortcuts"; import { CSSProperties } from "react"; export type ButtonStyle = 'base' | 'accent' | 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'error'; const styles = { base: 'bg-base-200 text-base-content active:bg-base-300! active:text-base-content! active:ring-offset-base-content', accent: "bg-accent text-accent-content active:bg-base-content! active:text-base-content active:ring-offset-accent", primary: "bg-primary text-primary-content active:bg-base-content! active:text-base-content! active:ring-offset-primary", secondary: "bg-secondary text-secondary-content active:bg-base-content! active:text-base-content! active:ring-offset-secondary", info: "bg-info text-info-content active:bg-base-content! active:text-base-content! active:ring-offset-info", success: "bg-success text-success-content active:bg-base-content! active:text-base-content! active:ring-offset-success", warning: "bg-warning text-warning-content active:bg-base-content! active:text-base-content! active:ring-offset-warning", error: "bg-error text-error-content active:bg-base-content! active:text-base-content! active:ring-offset-error", }; export function Button (data: { id: string, children?: any, className?: string, disabled?: boolean, type?: "reset" | "button" | "submit"; style?: ButtonStyle, shortcutLabel?: string; focusClassName?: string; cssStyle?: CSSProperties; } & InteractParams & FocusParams) { const { ref, focused, focusKey } = useFocusable({ focusKey: data.id, onEnterPress: data.onAction, onFocus: (_l, _p, details) => data.onFocus?.(focusKey, ref.current, details), focusable: !data.disabled }); if (data.shortcutLabel) { useShortcuts(focusKey, () => [{ label: data.shortcutLabel, action: data.onAction, button: GamePadButtonCode.A }], [data.shortcutLabel]); } return ; }