'use client'; import type { ContentKitButton } from '@gitbook/api'; import { Icon } from '@gitbook/icons'; import React from 'react'; import classNames from 'classnames'; import { useContentKitClientContext } from './context'; import type { ContentKitClientElementProps } from './types'; export function ElementButton( props: ContentKitClientElementProps & { icon: React.ReactNode | null; trailingIcon: React.ReactNode | null; } ) { const { element, icon, trailingIcon } = props; const clientContext = useContentKitClientContext(); const [loading, setLoading] = React.useState(false); const [confirm, setConfirm] = React.useState(false); const wrapLoading = React.useCallback(async (fn: Promise | (() => Promise)) => { setLoading(true); try { return fn instanceof Promise ? await fn : await fn(); } finally { setLoading(false); } }, []); return ( <> {element.confirm && confirm ? ( { setConfirm(false); wrapLoading( async () => await clientContext.dispatchAction(element.onPress) ); }} onCancel={() => setConfirm(false)} /> ) : null} ); } function ConfirmDialog({ open, onCancel, onConfirm, style, title, text, confirm }: any) { return (
{ event.stopPropagation(); }} >
{title ?

{title}

: null} {text ?
{text}
: null}
); }