Skip to main content

Dialog

The TkDialog component provides a customizable modal dialog for displaying important information or requesting user input. It supports various configurations including different header types, variants, and customizable content.

import { TkDialog } from '@takeoff-ui/react'

Basic​

The basic usage of TkDialog demonstrates how to create a simple dialog with a header, subheader, and content.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore sed consequuntur error repudiandae numquam deserunt quisquam repellat libero asperiores earum nam nobis, culpa ratione quam perferendis esse, cupiditate neque quas!

View Code
const [showDialog, setShowDialog] = useState(false);

function handleClick() {
setShowDialog(true);
}

return (
<>
<TkButton label="Open Dialog" onTkClick={handleClick} />
<TkDialog
header="Welcome"
subheader="Basic Dialog Example"
visible={showDialog}
onTkVisibleChange={(e) => setShowDialog(e.detail)}
containerStyle={{ width: "450px" }}
>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore
sed consequuntur error repudiandae numquam deserunt quisquam repellat
libero asperiores earum nam nobis, culpa ratione quam perferendis
esse, cupiditate neque quas!
</p>
</TkDialog>
</>
);

Header Types​

TkDialog offers various header types to customize the appearance of the dialog's header.

This example demonstrates the different header types available for the TkDialog component.

View Code
<TkButton label="Open Dialog" onTkClick={() => setShowDialog(true)} />
<TkDialog
header="Header Types"
subheader="This dialog uses the basic header type"
visible={showDialog}
onTkVisibleChange={(e) => setShowDialog(e.detail)}
headerType={"basic"}
containerStyle={{ width: "450px" }}
>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore sed consequuntur error repudiandae numquam deserunt quisquam repellat libero asperiores earum nam nobis, culpa ratione quam perferendis esse, cupiditate neque
quas!
</p>
</TkDialog>

Variants​

Illustrates the different variants available for TkDialog, which affect the dialog's appearance and icon.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore sed consequuntur error repudiandae numquam deserunt quisquam repellat libero asperiores earum nam nobis, culpa ratione quam perferendis esse, cupiditate neque quas!

View Code
<TkButton label="Open Dialog" onTkClick={() => setShowDialog(true)} />
<TkDialog
header="Dialog Variants"
subheader="This is a info dialog"
visible={showDialog}
onTkVisibleChange={(e) => setShowDialog(e.detail)}
variant={"info"}
containerStyle={{ width: "450px" }}
>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore sed consequuntur error repudiandae numquam deserunt quisquam repellat libero asperiores earum nam nobis, culpa ratione quam perferendis esse, cupiditate neque
quas!
</p>
</TkDialog>

Illustrates how to add a footer using the footer-actions slot.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore sed consequuntur error repudiandae numquam deserunt quisquam repellat libero asperiores earum nam nobis, culpa ratione quam perferendis esse, cupiditate neque quas!

View Code
const [showDialog, setShowDialog] = useState(false);

return (
<>
<TkButton label="Open Dialog" onTkClick={() => setShowDialog(true)} />
<TkDialog
header="Dialog with Footer"
subheader="This dialog uses the footer-actions slot"
visible={showDialog}
onTkVisibleChange={(e) => setShowDialog(e.detail)}
containerStyle={{ width: "450px" }}
>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore
sed consequuntur error repudiandae numquam deserunt quisquam repellat
libero asperiores earum nam nobis, culpa ratione quam perferendis
esse, cupiditate neque quas!
</p>
<div slot="footer-actions">
<TkButton
label="Cancel"
variant="neutral"
onTkClick={() => setShowDialog(false)}
type="text"
/>
<TkButton label="Save" variant="primary" />
</div>
</TkDialog>
</>
);

Mask Blur​

Illustrates how to add a blur effect to the mask of the dialog.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore sed consequuntur error repudiandae numquam deserunt quisquam repellat libero asperiores earum nam nobis, culpa ratione quam perferendis esse, cupiditate neque quas!

View Code
const [showDialog, setShowDialog] = useState(false);

function handleClick() {
setShowDialog(true);
}

return (
<>
<TkButton label="Open Dialog" onTkClick={handleClick} />
<TkDialog
header="Welcome"
subheader="Basic Dialog Example"
visible={showDialog}
onTkVisibleChange={(e) => setShowDialog(e.detail)}
containerStyle={{ width: "450px" }}
isMaskBlur={true}
>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore
sed consequuntur error repudiandae numquam deserunt quisquam repellat
libero asperiores earum nam nobis, culpa ratione quam perferendis
esse, cupiditate neque quas!
</p>
</TkDialog>
</>
);

API​

Props​

NameTypeDefaultDescription
anynullThe style attribute of container element
stringnullThe header text
"basic", "dark", "divided", "light", "primary"'basic'Header type
booleanfalseControls whether the backdrop is shown
booleanfalseControls whether the dialog has a blur background
"base", "dark", "darkest", "light", "lightest"'base'Appearance of the mask
booleanfalsePrevents the dialog from being dismissed by clicking outside
booleantrueControls whether the close button is shown
booleantrueControls whether the header is shown
booleantrueControls whether the variant sign is shown
stringnullThe subheader text
"danger", "info", "success", "warning"'info'The variant of the dialog
booleanfalseControls the visibility of the dialog

Events​

NameDescription
tk-closeEvent emitted when the dialog is closed
tk-openEvent emitted when the dialog is opened
tk-visible-changeEvent emitted when the dialog visibility changes

Methods​

NameDescription
closeRequests to close the dialog by emitting a tk-close event. Note: This method only emits an event. The dialog will only close if the parent component listens for this event and updates the 'visible' prop to false.
openRequests to open the dialog by emitting a tk-open event. Note: This method only emits an event. The dialog will only open if the parent component listens for this event and updates the 'visible' prop to true.

Slots​

NameDescription
containerCustom container template.
contentCustom content template.
defaultDefault slot to detect child to inner content.
footerCustom footer template.
footer-actionsCustom actions template to default footer.
headerCustom header template.