import type { HtmlEscapedString } from 'hono/utils/html'
export const buttonPrefix = {
link: '_l',
mint: '_m',
redirect: '_r',
reset: '_c',
transaction: '_t',
}
export type ButtonProps = {
children: string | string[]
}
export type ButtonRootProps = ButtonProps & {
action?: string | undefined
value?: string | undefined
}
ButtonRoot.__type = 'button'
export function ButtonRoot({
action,
children,
// @ts-ignore - private
index = 1,
value,
}: ButtonRootProps) {
return [
,
,
action && (
),
] as unknown as HtmlEscapedString
}
export type ButtonLinkProps = ButtonProps & {
href: string
}
ButtonLink.__type = 'button'
export function ButtonLink({
children,
// @ts-ignore - private
index = 1,
href,
}: ButtonLinkProps) {
return [
,
,
,
] as unknown as HtmlEscapedString
}
export type ButtonMintProps = ButtonProps & {
target: string
}
ButtonMint.__type = 'button'
export function ButtonMint({
children,
// @ts-ignore - private
index = 1,
target,
}: ButtonMintProps) {
return [
,
,
,
] as unknown as HtmlEscapedString
}
export type ButtonRedirectProps = ButtonProps & {
location: string
}
ButtonRedirect.__type = 'button'
export function ButtonRedirect({
children,
// @ts-ignore - private
index = 1,
location,
}: ButtonRedirectProps) {
return [
,
,
// TODO: Add `target` prop so folks can `'post_redirect'` to a different frame
// ,
] as unknown as HtmlEscapedString
}
export type ButtonResetProps = ButtonProps
ButtonReset.__type = 'button'
export function ButtonReset({
children,
// @ts-ignore - private
index = 1,
}: ButtonResetProps) {
return (
)
}
export type ButtonTransactionProps = ButtonProps & {
action?: string | undefined
target: string
}
ButtonTransaction.__type = 'button'
export function ButtonTransaction({
action,
children,
// @ts-ignore - private
index = 1,
target,
}: ButtonTransactionProps) {
return [
,
,
,
action && (
),
] as unknown as HtmlEscapedString
}
export const Button = Object.assign(ButtonRoot, {
Link: ButtonLink,
Mint: ButtonMint,
Redirect: ButtonRedirect,
Reset: ButtonReset,
Transaction: ButtonTransaction,
})
function normalizeChildren(children: string | string[]) {
return Array.isArray(children) ? children.join('') : children
}