Skip to main content

Dialog

A dialog is a pop-up dialog (rectangular panel) that takes focus, and prohibits the user from interacting with the content behind.

Use cases:

  • pop-up notification
  • configuration box

Example​

The example below shows the component in action. Clicking on the Open Dialog button displays a dialog with some simple text. Click in the x in the top right corner to remove the dialog.

Open Dialog

Declaration

<Dialog></Dialog>

Usage

import { Button, Dialog } from '@genesislcap/rapid-design-system/react';

export function MyComponent() {
const dialogRef = useRef(null);

return (
<Button onClick={() => {
dialogRef.current?.removeAttribute('hidden');
dialogRef.current?.show();
}}>
Open Dialog
</Button>

<Dialog
ref={dialogRef}
id="example1"
className="example-dialog"
ariaLabel="Simple modal dialog"
modal="true"
hidden
>
<h2>Dialog</h2>
<p>This is an example dialog.</p>
</Dialog>
)
}

API​

Attributes​

AttributeTypeDescriptionExample
type'default' | 'error' | 'success'The general style of dialog type to show. default type adds no extra styling, error shows a red highlight and success shows a green.
<rapid-dialog type="success">
position'center' | 'left' | 'right'The position of the dialog. Default is center.
<rapid-dialog position="right">
show-close-iconbooleanEnables the close icon in the top right corner of the dialog. Default is true.
<rapid-dialog show-close-icon="false">

Properties​

PropertyTypeDescriptionExample
onShowCallback() => voidFunction that runs before dialog is opened.
<rapid-dialog :onShowCallback="${(x) => () => x.beforeDialogShown()}">
onCloseCallback() => voidFunction that is called after the dialog is closed.
<rapid-dialog :onCloseCallback="${(x) => () => x.afterDialogHide()}">

Methods​

MethodDescriptionExample
showShows the dialog.dialogRef.show()
closeHides the dialog.dialogRef.close()

Slots​

SlotDescription
DefaultAll the content that you want to display on the dialog box when shown.
topCan be used to set a title section for the dialog.
bottomCan be used to set a footer section for the dialog.

Parts​

PartDescription
dialogThe base html dialog tag.
topThe top part of the dialog, which contains the dialog header.
bottomThe bottom part of the dialog, which contains the dialog footer.

Events fired​

EventTypeDescriptionExample
closevoidFired when the dialog is closed, either through the close button or programmatic close.<rapid-dialog @close="${(x) => x.handleDialogClose()}">

Events listened to​

This component doesn't listen to any events.