Photonix

Dialog

A modal window that appears in front of app content to provide critical information or ask for a decision.

Preview

Usage
"use client";

import { useState } from 'react';
import { Button, Dialog, Stack, Text } from '@photonix/ultimate';

export default function DialogBasicExample() {
    const [open, setOpen] = useState(false);

    return (
        <Stack gap="md">
            <Button variant="primary" onClick={() => setOpen(true)}>Open Dialog</Button>
            <Dialog
                open={open}
                onClose={() => setOpen(false)}
                title="Confirm changes"
                description="Review the details before applying this update."
                actions={[
                    { label: 'Cancel', variant: 'secondary', onClick: () => setOpen(false) },
                    { label: 'Confirm', variant: 'primary', onClick: () => setOpen(false) },
                ]}
            >
                <Text variant="body-md" color="secondary">
                    This action will update the selected workspace settings.
                </Text>
            </Dialog>
        </Stack>
    );
}

Component API

Dialog

Prop
Type
Default
Description
open
boolean
-
Whether the dialog is open
onClose
(() => void)
-
Callback when dialog should close
title
string
-
Dialog title
description
string
-
Optional description below title
size
DialogSize
'medium'
Dialog size - default 'medium'
headerAlign
DialogHeaderAlign
'center'
Header text alignment - default 'center'
showCloseButton
boolean
true
Whether to show close button in header
footerLayout
DialogFooterLayout
'horizontal'
Footer layout - default 'horizontal'
actions
DialogAction[]
[]
Action buttons
checkboxProps
{ label: React.ReactNode; checked?: boolean; onChange?: (checked: boolean) => void; }
-
Checkbox props for 'withCheckbox' footer layout
children
React.ReactNode
-
Dialog content
contentPadding
boolean
true
Whether content has padding - default true
className
string
-
Additional class name for root
closeOnOverlayClick
boolean
true
Close on overlay click - default true
closeOnEscape
boolean
true
Close on Escape key press - default true
initialFocusRef
React.RefObject<HTMLElement>
-
Element to focus when dialog opens

ConfirmDialog

Prop
Type
Default
Description
open
boolean
-
Whether the dialog is open
onClose
(() => void)
-
Callback when dialog should close
icon
React.ReactNode
-
Icon to display at top
title
string
-
Dialog title
description
string
-
Description text
size
"small" | "large"
'small'
Dialog size - default 'small' (360px), 'large' (600px)
showCloseButton
boolean
false
Whether to show close button
actions
ConfirmDialogAction[]
[]
Action buttons
className
string
-
Additional class name for root
closeOnOverlayClick
boolean
true
Close on overlay click - default true
closeOnEscape
boolean
true
Close on Escape key press - default true
initialFocusRef
React.RefObject<HTMLElement>
-
Element to focus when dialog opens

Variants

Basic Dialog

The source includes the same open state, trigger, content, and actions used by the preview.

Basic Dialog
"use client";

import { useState } from 'react';
import { Button, Dialog, Stack, Text } from '@photonix/ultimate';

export default function DialogBasicExample() {
    const [open, setOpen] = useState(false);

    return (
        <Stack gap="md">
            <Button variant="primary" onClick={() => setOpen(true)}>Open Dialog</Button>
            <Dialog
                open={open}
                onClose={() => setOpen(false)}
                title="Confirm changes"
                description="Review the details before applying this update."
                actions={[
                    { label: 'Cancel', variant: 'secondary', onClick: () => setOpen(false) },
                    { label: 'Confirm', variant: 'primary', onClick: () => setOpen(false) },
                ]}
            >
                <Text variant="body-md" color="secondary">
                    This action will update the selected workspace settings.
                </Text>
            </Dialog>
        </Stack>
    );
}

Confirm Dialog

A specialized dialog for taking quick actions or confirmations.

Confirm Dialog
"use client";

import { useState } from 'react';
import { Box, Button, ConfirmDialog } from '@photonix/ultimate';
import { Warning } from '@photonix/icons/illustrated';

export default function DialogConfirmExample() {
    const [open, setOpen] = useState(false);

    return (
        <Box>
            <Button variant="secondary" onClick={() => setOpen(true)}>Delete Selected Items</Button>
            <ConfirmDialog
                open={open}
                onClose={() => setOpen(false)}
                icon={<Warning />}
                title="Confirm Deletion"
                description="Are you sure you want to delete these 5 items? This action cannot be undone and these items will be permanently removed."
                actions={[
                    { label: 'Cancel', variant: 'secondary', onClick: () => setOpen(false) },
                    { label: 'Delete Anyway', variant: 'primary', onClick: () => setOpen(false) },
                ]}
            />
        </Box>
    );
}

Specialized Confirmations

Pre-configured confirmation dialogs with fixed illustrated icons for common states.

Specialized Confirmations
"use client";

import { useState } from 'react';
import { Button, ConfirmErrorDialog, ConfirmInfoDialog, ConfirmVerifyDialog, ConfirmWarningDialog, Stack } from '@photonix/ultimate';

export default function DialogSpecializedExample() {
    const [verifyOpen, setVerifyOpen] = useState(false);
    const [warningOpen, setWarningOpen] = useState(false);
    const [infoOpen, setInfoOpen] = useState(false);
    const [errorOpen, setErrorOpen] = useState(false);

    return (
        <Stack gap="md" wrap={true}>
            <Button variant="secondary" onClick={() => setVerifyOpen(true)}>Verify</Button>
            <Button variant="secondary" onClick={() => setWarningOpen(true)}>Warning</Button>
            <Button variant="secondary" onClick={() => setInfoOpen(true)}>Info</Button>
            <Button variant="secondary" onClick={() => setErrorOpen(true)}>Error</Button>

            <ConfirmVerifyDialog
                open={verifyOpen}
                onClose={() => setVerifyOpen(false)}
                title="Account Verified"
                description="Your account has been successfully verified."
                actions={[{ label: 'Done', variant: 'primary', onClick: () => setVerifyOpen(false) }]}
            />
            <ConfirmWarningDialog
                open={warningOpen}
                onClose={() => setWarningOpen(false)}
                title="Are you sure?"
                description="This action cannot be undone."
                actions={[
                    { label: 'Cancel', variant: 'secondary', onClick: () => setWarningOpen(false) },
                    { label: 'Delete', variant: 'primary', onClick: () => setWarningOpen(false) }
                ]}
            />
            <ConfirmInfoDialog
                open={infoOpen}
                onClose={() => setInfoOpen(false)}
                title="New Version Available"
                description="A new update is ready to install."
                actions={[{ label: 'Got it', variant: 'primary', onClick: () => setInfoOpen(false) }]}
            />
            <ConfirmErrorDialog
                open={errorOpen}
                onClose={() => setErrorOpen(false)}
                title="Connection Error"
                description="Failed to connect to the server."
                actions={[{ label: 'Retry', variant: 'primary', onClick: () => setErrorOpen(false) }]}
            />
        </Stack>
    );
}

Form Submission

Trigger form submission from dialog actions using native form ID.

Form Submission
"use client";

import { useState } from 'react';
import { Button, Dialog, TextField, VStack } from '@photonix/ultimate';

export default function DialogFormExample() {
    const [open, setOpen] = useState(false);

    const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
        e.preventDefault();
        const formData = new FormData(e.currentTarget);
        alert(`User ${formData.get('username')} added!`);
        setOpen(false);
    };

    return (
        <>
            <Button onClick={() => setOpen(true)}>Open Form Dialog</Button>
            <Dialog
                open={open}
                onClose={() => setOpen(false)}
                title="Add User"
                description="Enter user details below. Required fields are marked with *."
                actions={[
                    { label: 'Cancel', variant: 'secondary', onClick: () => setOpen(false) },
                    {
                        label: 'Create Account',
                        type: 'submit',
                        form: 'user-form',
                    },
                ]}
            >
                <form id="user-form" onSubmit={handleSubmit} style={{ padding: 'var(--space-md) 0' }}>
                    <VStack gap="md">
                        <TextField
                            name="username"
                            label="Username"
                            placeholder="e.g. hoangthuan"
                            required
                            autoFocus
                        />
                        <TextField
                            name="email"
                            label="Email Address"
                            type="email"
                            placeholder="[email protected]"
                            required
                        />
                    </VStack>
                </form>
            </Dialog>
        </>
    );
}

With Footer Checkbox

Useful for 'Don't show again' or 'I agree' confirmations.

With Footer Checkbox
"use client";

import { useState } from 'react';
import { Box, Button, Dialog, SlotPlaceholder } from '@photonix/ultimate';

export default function DialogCheckboxExample() {
    const [open, setOpen] = useState(false);
    const [agreed, setAgreed] = useState(false);

    return (
        <Box>
            <Button variant="secondary" onClick={() => setOpen(true)}>Open Checkbox Dialog</Button>
            <Dialog
                open={open}
                onClose={() => setOpen(false)}
                title="Terms of Service"
                footerLayout="withCheckbox"
                checkboxProps={{
                    label: "I agree to the terms",
                    checked: agreed,
                    onChange: setAgreed
                }}
                actions={[
                    { label: 'Continue', disabled: !agreed, onClick: () => setOpen(false) }
                ]}
            >
                <SlotPlaceholder title="Dialog Content" description="Confirm this action" minHeight={100} />
            </Dialog>
        </Box>
    );
}

Sizes & Alignment

Customize size ('small', 'large') and headerAlign ('left').

Sizes & Alignment
"use client";

import { useState } from 'react';
import { Box, Button, Dialog, SlotPlaceholder } from '@photonix/ultimate';

export default function DialogLayoutExample() {
    const [open, setOpen] = useState(false);

    return (
        <Box>
            <Button variant="secondary" onClick={() => setOpen(true)}>Open Large Dialog</Button>
            <Dialog
                open={open}
                onClose={() => setOpen(false)}
                size="large"
                headerAlign="left"
                title="Large Dialog"
                actions={[{ label: 'Close', onClick: () => setOpen(false) }]}
            >
                <SlotPlaceholder title="Dialog Content" description="Confirm this action" minHeight={100} />
            </Dialog>
        </Box>
    );
}

On this page

Preview
Component API
Variants
Basic Dialog
Confirm Dialog
Specialized Confirmations
Form Submission
With Footer Checkbox
Sizes & Alignment
Photonix UI - React Components, Templates & Figma Design System