Concepts
OverviewCompositionTestingLayout
Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrapComponents
AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltipUtilities
Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsThemeThe Prompt Modal is used to prompt the user for input, such as a passkey or confirmation for destructive actions.
import { PromptModal, usePromptModal } from '@cerberus/react'import { PromptModal, usePromptModal } from '@cerberus/react'
function SomeFeature() { const prompt = usePromptModal() const [userValue, setUserValue] = useState<string | null>(null)
const handleClick = useCallback(async () => { const key = 'SUPER_SECRET' const userPrompt = await prompt.show({ heading: 'Enter passkey', description: 'In order to view the super secret stuff you need to enter your passkey.', key, actionText: 'Copy passkey', cancelText: NOPE, }) if (userPrompt === key) setUserValue('Super secret stuff') }, [prompt])
return ( <Button onClick={handleClick}>View passkey</Button> )}
function SomePage() { return( <PromptModal> <SomeFeature /> </PromptModal> )}import { PromptModal, usePromptModal } from '@cerberus/react'
function SomeFeature() { const prompt = usePromptModal() const [userValue, setUserValue] = useState<string | null>(null)
const handleClick = useCallback(async () => { const key = 'DELETE' const userConsent = await prompt.show({ kind: 'destructive', heading: 'Remove payment method?', description: 'This is a permanent action and cannot be undone.', key, actionText: 'Yes, delete', cancelText: NOPE, }) if (userConsent === key) setUserValue('Payment method removed') }, [prompt])
return ( <Button palette="danger" onClick={handleClick}>Delete card</Button> )}
function SomePage() { return( <PromptModal> <SomeFeature /> </PromptModal> )}The PromptModal is an abstraction of the Dialog primitives and does not provide any additional customization. To build your own PromptModal, use the Dialog components.
export interface PromptModalProviderValue { show: (options: PromptModalOptions) => Promise<string>}
define function PromptModal(props: PropsWithChildren<DialogRootProps>): ReactNodeThe PromptModal component is an abstraction of the Dialog and accepts the same
props as the Dialog component.
The show method accepts the following options:
| Name | Default | Description |
|---|---|---|
| kind | non-destructive | The variant used to theme the modal. |
| heading | The heading of the modal. | |
| description | The description of the modal. | |
| key | A string key to test the user input against. | |
| actionText | The text for the action button. | |
| cancelText | The text for the cancel button. |
On this page