Skip to main content

Dialog

The Dialog component is a versatile and customizable dialog element used to display content on top of the current page. It can be positioned relative to a target element and configured to have various properties such as a backdrop, custom width and height, and different scroll strategies. Uses Angular's CDK Overlay

Import

import { DialogComponent } from '@chit-chat/ngx-emoji-picker/lib/components/dialog';

Basic Usage

<div [style.height.px]="450" class="showcase-container row-showcase justify-center">
<div class="align-bottom">
<ch-button label="Click me!" (onClick)="handleClick($event)"></ch-button>
</div>
</div>
<ch-dialog cssClass="emoji-picker-dialog"
backdropClass="cdk-overlay-transparent-backdrop"
[(visible)]="visible"
[target]="buttonElement()?.nativeElement"
[positions]="dialogPositions"
(onOpened)="handleOnOpened($event)">
<ng-container content>
<ch-emoji-picker [height]="350" [width]="350"></ch-emoji-picker>
</ng-container>
</ch-dialog>

Templates

Dialogs can be customized using header and footer templates.

<div [style.height.px]="400" class="showcase-container row-showcase justify-center align-center">
<ch-button label="Show" (onClick)="handleClick($event)"></ch-button>
</div>
<ch-dialog [(visible)]="visible" [width]="350" [closeOnBackdropClick]="false">
<ng-container header>
<div class="header flex-container">
<div class="header-before title">Personal information</div>
<div class="flex-end">
<ch-button
[icon]="closeIconConfig"
[height]="28"
[width]="28"
shape="round"
fill="clear"
type="contrast"
(onClick)="close($event)">
</ch-button>
</div>
</div>
</ng-container>
<ng-container content>
<div class="content-container">
<div class="form-item">
<div class="label">Username:</div>
<ch-text-box></ch-text-box>
</div>
<div class="form-item">
<div class="label">Password:</div>
<ch-text-box mode="password"></ch-text-box>
</div>
</div>
</ng-container>
<ng-container footer>
<div class="footer flex-container flex-end">
<ch-button
label="Cancel"
[height]="35"
(onClick)="close($event)"
fill="clear">
</ch-button>
<ch-button
label="Submit"
[height]="35"
(onClick)="close($event)">
</ch-button>
</div>
</ng-container>
</ch-dialog>

Positions

Positions allows you to control where the dialog appears relative to a target element on the page.

<div [style.height.px]="400" class="showcase-container row-showcase justify-center align-center">
<div class="grid-container">
@for (position of positions; track $index) {
<ch-button #button [label]="position" [width]="150" (onClick)="handleClick(position, button)"></ch-button>
}
</div>
</div>

<ch-dialog [(visible)]="visible" [target]="target()" [positions]="dialogPositions()">
<ng-container content><p>Lorem ipsum dolor ipsam</p> </ng-container>
</ch-dialog>

Drag

Dialog can be dragged around the screen.

<div [style.height.px]="400" class="showcase-container row-showcase justify-center align-center">
<ch-button label="Click & Drag!" [height]="40" (onClick)="handleClick($event)"></ch-button>
</div>

<ch-dialog [(visible)]="visible" [dragEnabled]="true" [width]="500">
<ng-container header><div>Lorem Ipsum</div></ng-container>
<ng-container content
><p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</ng-container>
</ch-dialog>

Scroll

Dialog automatically displays a scrollbar when content overflows the viewport.

<div [style.height.px]="400" class="showcase-container row-showcase justify-center align-center">
<ch-button label="Click me!" [height]="40" (onClick)="handleClick($event)"></ch-button>
</div>

<ch-dialog [(visible)]="visible" [height]="300" [width]="500">
<ng-container header><div>Lorem Ipsum</div></ng-container>
<ng-container content
><p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>

<p>
Phasellus vestibulum lorem sed risus ultricies tristique. Velit dignissim sodales ut eu sem. Nisl pretium fusce id velit ut tortor pretium viverra suspendisse. Feugiat in ante metus dictum at tempor commodo ullamcorper a. Sed vulputate mi
sit amet mauris commodo quis imperdiet massa. Nunc sed velit dignissim sodales ut eu sem integer vitae justo.
</p>

<p>
Amet est placerat in egestas erat imperdiet sed euismod nisi. Faucibus a pellentesque sit amet porttitor eget dolor morbi non. Nisl nisi scelerisque eu ultrices vitae auctor eu augue ut. Quam adipiscing vitae proin sagittis nisl rhoncus
mattis rhoncus urna. Eget egestas purus viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor eu augue ut.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>

<p>
Phasellus vestibulum lorem sed risus ultricies tristique. Velit dignissim sodales ut eu sem. Nisl pretium fusce id velit ut tortor pretium viverra suspendisse. Feugiat in ante metus dictum at tempor commodo ullamcorper a. Sed vulputate mi
sit amet mauris commodo quis imperdiet massa. Nunc sed velit dignissim sodales ut eu sem integer vitae justo.
</p>

<p>
Amet est placerat in egestas erat imperdiet sed euismod nisi. Faucibus a pellentesque sit amet porttitor eget dolor morbi non. Nisl nisi scelerisque eu ultrices vitae auctor eu augue ut. Quam adipiscing vitae proin sagittis nisl rhoncus
mattis rhoncus urna. Eget egestas purus viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor eu augue ut.
</p>
</ng-container>
</ch-dialog>

Properties

PropertyTypeDescriptionDefault
visiblebooleanSpecifies whether the dialog is visible. This is a two-way binding property.false
heightnumber | stringSpecifies the height of the dialog.'auto'
widthnumber | stringSpecifies the width of the dialog.'auto'
dragEnabledbooleanSpecifies wheter the dialog can be draggable. Only applies when the header is specified.true
targetHTMLElementSpecifies the target element relative to which the dialog should be positioned.undefined
hasBackdropbooleanSpecifies whether the dialog should display a backdrop behind it.true
backdropClassstring | string[]Specifies the CSS class or classes to be applied to the backdrop element.'cdk-overlay-dark-backdrop'
closeOnBackdropClickbooleanSpecifies whether the dialog should close when the backdrop is clicked (only relevant if hasBackdrop is true).true
positionsConnectedPosition[]Specifies an array of possible positions for the dialog relative to the target element.[{originX: 'center', originY: 'center', overlayX: 'center', overlayY: 'center'}]
cssClassstring | string[]Specifies the CSS class or classes to be applied to the dialog container element.''
scrollStrategy'block' | 'noop' | 'close' | 'reposition'Defines how overlay elements behave when the user scrolls the page. Since overlays are positioned relative to the viewport or a specific element, controlling their behavior during scrolling is crucial to ensure they remain properly aligned, visible, or hidden as needed.'block'

Events

EventTypeDescription
visibleChangebooleanEmits when the visibility of the dialog changes. true when the dialog becomes visible, false when it is hidden.
onOpenedOverlayRefEmits after the dialog has opened

Methods

MethodDescription
close()Closes the dialog by disposing of the dialog reference and setting the visibility to false.

CSS Custom Properties

PropertyDescription
--ch-background-colorBackground of the dialog content.
--ch-border-colorBorder color of the dialog content.
--ch-text-colorText color of the dialog.
--ch-color-scrollColor of the scrollbar
--ch-color-scroll-hoverColor of the scrollbar when hovering over the scrollbar