Photonix

Dialog

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

Preview

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

const [open, setOpen] = useState(false);

return (
  <>
    <Button onClick={() => setOpen(true)}>Open Dialog</Button>
    <Dialog 
      open={open} 
      onClose={() => setOpen(false)}
      title="Basic Dialog" 
      description="A simple dialog with title, description, and actions." 
      actions={[
        { label: 'Cancel', variant: 'secondary', onClick: () => setOpen(false) },
        { label: 'Confirm', onClick: () => setOpen(false) }
      ]} 
    >
      <Box p="lg">Dialog Content</Box>
    </Dialog>
  </>
)

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

A standard dialog with title, content, and action buttons.

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

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

  return (
    <>
      <Button onClick={() => setOpen(true)}>Open Dialog</Button>
      <Dialog
        open={open}
        onClose={() => setOpen(false)}
        title="Confirm Action"
        description="Are you sure you want to proceed?"
        actions={[
          { label: 'Cancel', variant: 'secondary', onClick: () => setOpen(false) },
          { label: 'Confirm', onClick: () => setOpen(false) },
        ]}
      >
        <Box p="lg">Confirm this action</Box>
      </Dialog>
    </>
  );
}

Confirm Dialog

A specialized dialog for taking quick actions or confirmations. It has a narrower width and focused layout.

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

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

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

Specialized Confirmations

Pre-configured confirmation dialogs with fixed illustrated icons for common states: Verify, Warning, Info, and Error.

Specialized Confirmations
import { 
  ConfirmVerifyDialog, 
  ConfirmWarningDialog, 
  ConfirmInfoDialog, 
  ConfirmErrorDialog, 
  Button 
} from '@photonix/ultimate';

// Use them directly without needing to pass an icon
<ConfirmVerifyDialog
  open={open}
  title="Action Successful"
  description="Your changes have been saved."
  actions={[{ label: 'Done', onClick: () => setOpen(false) }]}
/>

Form Submission

Trigger form submission from dialog actions using native form ID. This example uses Photonix TextField and VStack for a clean layout.

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

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

  const handleSubmit = (e) => {
    e.preventDefault();
    const formData = new FormData(e.currentTarget as HTMLFormElement);
    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
<Dialog
  open={open}
  title="Terms & Conditions"
  footerLayout="withCheckbox"
  checkboxProps={{
    label: "I agree to the terms",
    checked: agreed,
    onChange: setAgreed
  }}
  actions={[
    { label: 'Continue', disabled: !agreed, onClick: handleContinue }
  ]}
>
  <Text>Terms content...</Text>
</Dialog>

Sizes & Alignment

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

Sizes & Alignment
<Dialog
  open={open}
  size="large"
  headerAlign="left"
  title="Large Dialog"
  // ...
/>

On this page

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