"use client"; import { ActionButton, type ActionButtonProps, } from "@suphark/ui/components/shared/button/base/action-button"; import { useUiText } from "@suphark/ui/components/shared/ui-text"; import { cn } from "@suphark/ui/lib/utils"; import { ActionPrint } from "../semantic-icons"; // PrintButtonProps extends ActionButtonProps type PrintButtonProps = ActionButtonProps & { href?: string; target?: string; }; /** * A shared client component that provides a button to trigger the browser's print functionality. * It is built on `ActionButton` and automatically hidden when the page is being printed. * * @param {React.ReactNode} [children] - (Optional) The text to display. Defaults to `UiText.buttons.print` ("พิมพ์"). * @param {React.ReactElement} [icon] - (Optional) Overrides the default icon. * @param {string} [tooltip] - (Optional) Tooltip text to display on hover. * @param {function} [onClick] - (Optional) A custom onClick handler. If not provided, it defaults to `window.print()`. * @param {string} [variant] - (Optional) Button variant. Defaults to "outline". * @param {string} [className] - (Optional) Additional CSS classes. */ export function PrintButton({ children, icon, onClick, className, variant, href, target, ...props }: PrintButtonProps) { const text = useUiText(); // 1. Default values const buttonText = children ?? text.buttons?.print ?? "พิมพ์"; const buttonIcon = icon ?? ; const buttonVariant = variant ?? "outline"; // 2. Default onClick logic // If href is provided, we don't want to trigger window.print() by default const handleClick = onClick ?? (href ? undefined : () => window.print()); const content = ( {buttonText} ); if (href) { return ( {content} ); } return content; }