Skip to content

Commit

Permalink
docs(dialog/sheet): add close dialog/sheet example (#541)
Browse files Browse the repository at this point in the history
* docs(dialog/sheet): add close dialog example

(#520/#509)

* docs(dialog/sheet): add close dialog/sheet example
  • Loading branch information
Georg632 authored Dec 23, 2024
1 parent c15c095 commit d7f1338
Show file tree
Hide file tree
Showing 4 changed files with 284 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { Component, viewChild } from '@angular/core';
import {
BrnDialogCloseDirective,
BrnDialogComponent,
BrnDialogContentDirective,
BrnDialogTriggerDirective,
} from '@spartan-ng/brain/dialog';
import { HlmButtonDirective } from '@spartan-ng/ui-button-helm';
import {
HlmDialogComponent,
HlmDialogContentComponent,
HlmDialogHeaderComponent,
HlmDialogTitleDirective,
} from '@spartan-ng/ui-dialog-helm';
import { HlmLabelDirective } from '@spartan-ng/ui-label-helm';

@Component({
selector: 'spartan-dialog-close-preview',
standalone: true,
imports: [
BrnDialogTriggerDirective,
BrnDialogContentDirective,
BrnDialogCloseDirective,

HlmDialogComponent,
HlmDialogContentComponent,
HlmDialogHeaderComponent,
HlmDialogTitleDirective,

HlmLabelDirective,
HlmButtonDirective,
],
template: `
<hlm-dialog #dialogRef>
<button id="edit-profile" brnDialogTrigger hlmBtn>Open</button>
<hlm-dialog-content class="sm:max-w-[425px]" *brnDialogContent="let ctx">
<hlm-dialog-header>
<h3 hlmDialogTitle>Dialog</h3>
</hlm-dialog-header>
<div class="grid gap-4 py-4">
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close dialog by directive</label>
<button hlmBtn brnDialogClose>Close</button>
</div>
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close dialog by reference</label>
<button hlmBtn (click)="dialogRef.close({})">Close</button>
</div>
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close dialog by viewchild reference</label>
<button hlmBtn (click)="closeDialog()">Close</button>
</div>
</div>
</hlm-dialog-content>
</hlm-dialog>
`,
})
export class DialogClosePreviewComponent {
public viewchildDialogRef = viewChild(BrnDialogComponent);

closeDialog() {
this.viewchildDialogRef()?.close({});
}
}

export const defaultCloseCode = `
import { Component, viewChild } from '@angular/core';
import {
BrnDialogCloseDirective,
BrnDialogComponent,
BrnDialogContentDirective,
BrnDialogTriggerDirective,
} from '@spartan-ng/brain/dialog';
import { HlmButtonDirective } from '@spartan-ng/ui-button-helm';
import {
HlmDialogComponent,
HlmDialogContentComponent,
HlmDialogHeaderComponent,
HlmDialogTitleDirective,
} from '@spartan-ng/ui-dialog-helm';
import { HlmLabelDirective } from '@spartan-ng/ui-label-helm';
@Component({
selector: 'spartan-dialog-close-preview',
standalone: true,
imports: [
BrnDialogTriggerDirective,
BrnDialogContentDirective,
BrnDialogCloseDirective,
HlmDialogComponent,
HlmDialogContentComponent,
HlmDialogHeaderComponent,
HlmDialogTitleDirective,
HlmLabelDirective,
HlmButtonDirective,
],
template: \`
<hlm-dialog #dialogRef>
<button id="edit-profile" brnDialogTrigger hlmBtn>Open</button>
<hlm-dialog-content class="sm:max-w-[425px]" *brnDialogContent="let ctx">
<hlm-dialog-header>
<h3 hlmDialogTitle>Dialog</h3>
</hlm-dialog-header>
<div class="grid gap-4 py-4">
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close dialog by directive</label>
<button hlmBtn brnDialogClose>Close</button>
</div>
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close dialog by reference</label>
<button hlmBtn (click)="dialogRef.close({})">Close</button>
</div>
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close dialog by viewchild reference</label>
<button hlmBtn (click)="closeDialog()">Close</button>
</div>
</div>
</hlm-dialog-content>
</hlm-dialog>
\`,
})
export class DialogClosePreviewComponent {
public viewchildDialogRef = viewChild(BrnDialogComponent);
closeDialog() {
this.viewchildDialogRef()?.close({});
}
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { SectionSubHeadingComponent } from '../../../../shared/layout/section-su
import { TabsCliComponent } from '../../../../shared/layout/tabs-cli.component';
import { TabsComponent } from '../../../../shared/layout/tabs.component';
import { metaWith } from '../../../../shared/meta/meta.util';
import { DialogClosePreviewComponent, defaultCloseCode } from './dialog-close.preview';
import { DialogContextMenuPreviewComponent, contextMenuCode } from './dialog-context-menu.preview';
import { DialogDeclarativePreviewComponent, declarativeCode } from './dialog-declarative.preview';
import { DialogDynamicComponentPreviewComponent, dynamicComponentCode } from './dialog-dynamic-component.preview';
Expand Down Expand Up @@ -58,6 +59,7 @@ export const routeMeta: RouteMeta = {
HlmAlertIconDirective,
HlmAlertTitleDirective,
DialogDeclarativePreviewComponent,
DialogClosePreviewComponent,
],
providers: [provideIcons({ lucideTriangleAlert })],
template: `
Expand Down Expand Up @@ -164,6 +166,18 @@ export const routeMeta: RouteMeta = {
<spartan-code secondTab [code]="dynamicComponentCode" />
</spartan-tabs>
<spartan-section-sub-heading id="dynamic-component">Close Dialog</spartan-section-sub-heading>
<p class="${hlmP} mb-6">
You can close the dialog by using a directive, a template reference, or a viewchild/contentchild reference to
the dialog.
</p>
<spartan-tabs firstTab="Preview" secondTab="Code">
<div spartanCodePreview firstTab>
<spartan-dialog-close-preview />
</div>
<spartan-code secondTab [code]="defaultCloseCode" />
</spartan-tabs>
<spartan-page-bottom-nav>
<spartan-page-bottom-nav-link href="dropdown-menu" label="Dropdown Menu" />
<spartan-page-bottom-nav-link direction="previous" href="data-table" label="Data Table" />
Expand All @@ -179,4 +193,5 @@ export default class DialogPageComponent {
protected readonly contextMenuCode = contextMenuCode;
protected readonly dynamicComponentCode = dynamicComponentCode;
protected readonly declarativeCode = declarativeCode;
protected readonly defaultCloseCode = defaultCloseCode;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { Component, viewChild } from '@angular/core';
import { provideIcons } from '@ng-icons/core';
import { lucideCross } from '@ng-icons/lucide';
import {
BrnSheetCloseDirective,
BrnSheetComponent,
BrnSheetContentDirective,
BrnSheetTriggerDirective,
} from '@spartan-ng/brain/sheet';
import { HlmButtonDirective } from '@spartan-ng/ui-button-helm';
import { HlmLabelDirective } from '@spartan-ng/ui-label-helm';
import {
HlmSheetComponent,
HlmSheetContentComponent,
HlmSheetHeaderComponent,
HlmSheetTitleDirective,
} from '@spartan-ng/ui-sheet-helm';

@Component({
selector: 'spartan-sheet-close-preview',
standalone: true,
imports: [
BrnSheetTriggerDirective,
BrnSheetContentDirective,
BrnSheetCloseDirective,
HlmSheetComponent,
HlmSheetContentComponent,
HlmSheetHeaderComponent,
HlmSheetTitleDirective,
HlmButtonDirective,
HlmLabelDirective,
],
providers: [provideIcons({ lucideCross })],
template: `
<hlm-sheet #sheetRef side="right">
<button id="edit-profile" variant="outline" brnSheetTrigger hlmBtn>Open</button>
<hlm-sheet-content *brnSheetContent="let ctx">
<hlm-sheet-header>
<h3 hlmSheetTitle>Sheet</h3>
</hlm-sheet-header>
<div class="grid gap-4 py-4">
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close sheet by directive</label>
<button hlmBtn brnSheetClose>Close</button>
</div>
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close sheet by reference</label>
<button hlmBtn (click)="sheetRef.close({})">Close</button>
</div>
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close sheet by viewchild reference</label>
<button hlmBtn (click)="closeSheet()">Close</button>
</div>
</div>
</hlm-sheet-content>
</hlm-sheet>
`,
})
export class SheetClosePreviewComponent {
public viewchildSheetRef = viewChild(BrnSheetComponent);

closeSheet() {
this.viewchildSheetRef()?.close({});
}
}

export const defaultCloseCode = `
import { Component, viewChild } from '@angular/core';
import { provideIcons } from '@ng-icons/core';
import { lucideCross } from '@ng-icons/lucide';
import { BrnSheetCloseDirective, BrnSheetComponent, BrnSheetContentDirective, BrnSheetTriggerDirective } from '@spartan-ng/brain/sheet';
import { HlmButtonDirective } from '@spartan-ng/ui-button-helm';
import { HlmLabelDirective } from '@spartan-ng/ui-label-helm';
import {
HlmSheetComponent,
HlmSheetContentComponent,
HlmSheetHeaderComponent,
HlmSheetTitleDirective,
} from '@spartan-ng/ui-sheet-helm';
@Component({
selector: 'spartan-sheet-close-preview',
standalone: true,
imports: [
BrnSheetTriggerDirective,
BrnSheetContentDirective,
BrnSheetCloseDirective,
HlmSheetComponent,
HlmSheetContentComponent,
HlmSheetHeaderComponent,
HlmSheetTitleDirective,
HlmButtonDirective,
HlmLabelDirective
],
providers: [provideIcons({ lucideCross })],
template: \`
<hlm-sheet #sheetRef side="right">
<button id="edit-profile" variant="outline" brnSheetTrigger hlmBtn>Open</button>
<hlm-sheet-content *brnSheetContent="let ctx">
<hlm-sheet-header>
<h3 hlmSheetTitle>Sheet</h3>
</hlm-sheet-header>
<div class="grid gap-4 py-4">
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close sheet by directive</label>
<button hlmBtn brnSheetClose>Close</button>
</div>
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close sheet by reference</label>
<button hlmBtn (click)="sheetRef.close({})">Close</button>
</div>
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close sheet by viewchild reference</label>
<button hlmBtn (click)="closeSheet()">Close</button>
</div>
</div>
</hlm-sheet-content>
</hlm-sheet>
\`,
})
export class SheetClosePreviewComponent {
public viewchildSheetRef = viewChild(BrnSheetComponent);
closeSheet() {
this.viewchildSheetRef()?.close({});
}
}`;
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TabsCliComponent } from '../../../../shared/layout/tabs-cli.component';
import { TabsComponent } from '../../../../shared/layout/tabs.component';
import { metaWith } from '../../../../shared/meta/meta.util';
import { SheetSidePreviewComponent, sideCode } from './sheet--side.preview';
import { SheetClosePreviewComponent, defaultCloseCode } from './sheet-close.preview';
import { SheetPreviewComponent, defaultCode, defaultImports, defaultSkeleton } from './sheet.preview';

export const routeMeta: RouteMeta = {
Expand All @@ -39,6 +40,7 @@ export const routeMeta: RouteMeta = {
PageBottomNavLinkComponent,
SheetPreviewComponent,
SheetSidePreviewComponent,
SheetClosePreviewComponent,
],
template: `
<section spartanMainSection>
Expand Down Expand Up @@ -76,6 +78,14 @@ export const routeMeta: RouteMeta = {
<spartan-code secondTab [code]="sideCode" />
</spartan-tabs>
<h3 id="examples__sides" class="${hlmH4} mb-2 mt-6">Close Sheet</h3>
<spartan-tabs firstTab="Preview" secondTab="Code">
<div spartanCodePreview firstTab>
<spartan-sheet-close-preview />
</div>
<spartan-code secondTab [code]="defaultCloseCode" />
</spartan-tabs>
<spartan-page-bottom-nav>
<spartan-page-bottom-nav-link href="skeleton" label="Skeleton" />
<spartan-page-bottom-nav-link direction="previous" href="separator" label="Separator" />
Expand All @@ -89,4 +99,5 @@ export default class LabelPageComponent {
protected readonly defaultSkeleton = defaultSkeleton;
protected readonly defaultImports = defaultImports;
protected readonly sideCode = sideCode;
protected readonly defaultCloseCode = defaultCloseCode;
}

0 comments on commit d7f1338

Please sign in to comment.