/**
* Router-aware anchor styled as a Kumo button.
*
* Wraps TanStack Router's `Link` so it routes client-side, but matches the
* Kumo `Button` API surface for `variant` / `size` / `shape` / `icon`. Use
* this anywhere you'd reach for `... ` (which
* is invalid HTML — renders ``).
*
* Inherits TanStack Router's typed `to` / `params` / `search` / `preload`
* props by spreading them through to the underlying ` `.
*
* @example
* ```tsx
* } />
*
*
* {t`Edit post`}
*
* ```
*
* For external links (or anything that needs `target="_blank"`), use Kumo's
* `LinkButton` directly with `external`.
*/
import { type LinkButtonProps, buttonVariants } from "@cloudflare/kumo";
import { type Icon } from "@phosphor-icons/react";
import { Link, type LinkProps } from "@tanstack/react-router";
import * as React from "react";
import { cn } from "../lib/utils";
type ButtonStyleProps = Pick;
export type RouterLinkButtonProps = Omit &
ButtonStyleProps & {
className?: string;
children?: React.ReactNode;
};
export function RouterLinkButton({
className,
variant,
size,
shape,
icon,
children,
...linkProps
}: RouterLinkButtonProps) {
const iconNode = renderIcon(icon);
return (
{iconNode}
{children}
);
}
function renderIcon(icon: Icon | React.ReactNode | undefined): React.ReactNode {
if (!icon) return null;
if (React.isValidElement(icon)) return icon;
const Comp = icon as React.ComponentType>;
return ;
}