@import '../../../../../assets/sass/theme'.dialog-content display: flex justify-content: center align-items: center width: 45vw height: 65vh.variant-options display: flex gap: 1rem.variant-card text-align: center padding: 1rem width: 100% height: 100% position: relative background-color: transparent.variant-image border-radius: 15px object-fit: scale-down.variant-text font-size: 6rem line-height: normal font-weight: bold position: absolute top: 32% color: #3A3A3A$dialogTheme: dialog-theme( $background: #011627, $title-color: #ecaa53, $message-color: #fefefe, $border-radius: 0.3).overlay1 ::ng-deep @include dialog($dialogTheme)
Hello,
To effectively apply custom styles to the igx-dialog component in your Angular application, it's essential to configure both the SCSS and TypeScript files appropriately. Here's a comprehensive guide:
Ensure you've imported the Ignite UI for Angular theming module correctly. For versions prior to 13, use:
@import '~igniteui-angular/lib/core/styles/themes/index';
For version 13 and above, use:
@use 'igniteui-angular/theming' as *;
Create a custom theme by extending the dialog-theme and setting your desired parameters:
$my-dialog-theme: dialog-theme( $background: #011627, $title-color: #ECAA53, $message-color: #FEFEFE, $border-radius: 0.3 );
To apply the custom theme, include it in your styles. If your component uses Emulated ViewEncapsulation, penetrate this encapsulation using ::ng-deep:
:host { ::ng-deep { @include dialog($my-dialog-theme); } }
If $legacy-support is set to false (default), include the component CSS variables like this:
:host { @include css-vars($my-dialog-theme); }
Since the dialog uses the IgxOverlayService, ensure your custom theme reaches the dialog window by providing a specific outlet in your template:
<div igxOverlayOutlet> <igx-dialog #dialog1> <!-- .... --> </igx-dialog> </div>
Begin by importing the required classes from Angular's core and Ignite UI for Angular:
import { Component, ViewChild, OnInit } from '@angular/core'; import { IgxOverlayOutletDirective, IgxDialogComponent, CloseScrollStrategy, GlobalPositionStrategy } from 'igniteui-angular';
In your component class, use the @ViewChild decorator to reference the overlay outlet directive and the dialog component:
export class YourComponent implements OnInit { @ViewChild(IgxOverlayOutletDirective, { static: true }) public outlet: IgxOverlayOutletDirective; @ViewChild('dialog1', { read: IgxDialogComponent, static: true }) public dialog: IgxDialogComponent; private _dialogOverlaySettings; }
Here:
Within the ngOnInit lifecycle hook, define the overlay settings for your dialog:
public ngOnInit() { this._dialogOverlaySettings = { modal: true, outlet: this.outlet, scrollStrategy: new CloseScrollStrategy(), positionStrategy: new GlobalPositionStrategy() }; }
This configuration ensures that the dialog behaves as a modal, utilizes the specified outlet, and applies the desired scroll and position strategies.
Implement a method to open the dialog with the defined settings:
public openDialog() { this._dialogOverlaySettings.outlet = this.outlet; this.dialog.open(this._dialogOverlaySettings); }
This method assigns the outlet to the overlay settings and opens the dialog accordingly.
Reference Sample for Implementation
For a complete example of how this is implemented, check out this working sample on StackBlitz.
The described scenario could be observed here:
By following these steps, you can effectively control the igx-dialog component programmatically and apply custom styles as needed.
For more detailed information, refer to the official documentation:
These resources provide comprehensive guidance on managing and styling the igx-dialog component in Angular applications.
Regards,
Georgi Anastasov
Associate Software Developer
Infragistics