Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 allow updating the config via dialog ref #115

Merged
merged 6 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,33 @@ export class HelloWorldComponent {
}
```

- `ref.updateConfig` - An update function for the config, a common use case would be a reusable component setting its own common properties:

```ts
import { DialogService, DialogRef } from '@ngneat/dialog';

@Component({
template: `
<h1>{{ ref.data.title }}</h1>
<button (click)="ref.close()">Close</button>
`,
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MyVeryCommonDialogComponent {
ref: DialogRef<Data> = inject(DialogRef);

constructor() {
this.ref.updateConfig({
height: '200px',
width: '400px',
});
}
}
```

> You can only update the config before the dialog is opened in the component's constructor.

The library also provides the `dialogClose` directive helper, that you can use to close the modal:

```ts
Expand Down Expand Up @@ -273,7 +300,11 @@ bootstrapApplication(AppComponent, {

For each dialog instance you open you can specify all the global options and also the following 3 options.

- `id` - The modal unique id (defaults to random id).
- `id` - The modal's unique id, the defaults are:
- If a component is passed - the component's name (e.g. `MyCustomDialog`).
- Otherwise, a random id is given.
> [!Note]
> while not required, it is recommended to set an id in order to prevent unwanted multiple instances of the same dialog.
- `vcr` - A custom `ViewContainerRef` to use.
- `data` - A `data` object that will be passed to the modal template or component.

Expand Down Expand Up @@ -311,21 +342,21 @@ The default `sizes` config is:
sizes: {
sm: {
height: 'auto',
width: '400px',
width: '400px',
},
md: {
height: 'auto',
width: '560px',
width: '560px',
},
lg: {
height: 'auto',
width: '800px',
width: '800px',
},
fullScreen: {
height: '100%',
width: '100%',
width: '100%',
},
}
}
}
```

Expand Down
4 changes: 2 additions & 2 deletions apps/playground/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class AppComponent {

const ref = this.dialog.open(compOrTemplate as any, this.cleanConfig);

ref.backdropClick$.subscribe({
ref?.backdropClick$.subscribe({
next: () => (this.backDropClicked = true),
});

Expand Down Expand Up @@ -119,7 +119,7 @@ export class AppComponent {
this.openDialog(compOrTemplate, {
...config,
data,
}).afterClosed$.subscribe({
})?.afterClosed$.subscribe({
next: (message?: string) => {
if (typeof message === 'string') {
this.messageFromDialog = message;
Expand Down
Loading