-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
158 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { CdkDialogContainer, DialogRef } from "@angular/cdk/dialog"; | ||
import { Directive, HostBinding, Input, OnInit, Optional } from "@angular/core"; | ||
|
||
// Increments for each instance of this component | ||
let nextId = 0; | ||
|
||
@Directive({ | ||
selector: "[bitDialogTitle]", | ||
}) | ||
export class DialogTitleDirective implements OnInit { | ||
@HostBinding("class") get classList() { | ||
return ["tw-mb-0", "tw-grow", "tw-text-lg", "tw-uppercase"]; | ||
} | ||
@HostBinding("id") id = `bitDialogTitle-${nextId++}`; | ||
|
||
@Input("bitDialogClose") dialogResult: any; | ||
|
||
constructor(@Optional() private dialogRef: DialogRef<any>) {} | ||
|
||
ngOnInit(): void { | ||
if (this.dialogRef) { | ||
Promise.resolve().then(() => { | ||
const container = this.dialogRef.containerInstance as CdkDialogContainer; | ||
|
||
if (container && !container._ariaLabelledBy) { | ||
container._ariaLabelledBy = this.id; | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
libs/components/src/dialog/simple-dialog.service.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { DialogModule, DialogRef, DIALOG_DATA } from "@angular/cdk/dialog"; | ||
import { Component, Inject } from "@angular/core"; | ||
import { Meta, moduleMetadata, Story } from "@storybook/angular"; | ||
|
||
import { ButtonModule } from "../button"; | ||
|
||
import { DialogCloseDirective } from "./dialog-close.directive"; | ||
import { DialogTitleDirective } from "./dialog-title.directive"; | ||
import { DialogService } from "./dialog.service"; | ||
import { SimpleDialogComponent } from "./simple-dialog/simple-dialog.component"; | ||
|
||
interface Animal { | ||
animal: string; | ||
} | ||
|
||
@Component({ | ||
selector: "app-story-dialog", | ||
template: `<button bitButton (click)="openDialog()">Open Simple Dialog</button>`, | ||
}) | ||
class StoryDialogComponent { | ||
constructor(public dialogService: DialogService) {} | ||
|
||
openDialog() { | ||
this.dialogService.open(StoryDialogContentComponent, { | ||
data: { | ||
animal: "panda", | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: "story-dialog-content", | ||
template: ` | ||
<bit-simple-dialog> | ||
<h2 bitDialogTitle>Dialog Title</h2> | ||
<span bitDialogContent> | ||
Dialog body text goes here. | ||
<br /> | ||
Animal: {{ animal }} | ||
</span> | ||
<div bitDialogFooter class="tw-flex tw-flex-row tw-gap-2"> | ||
<button bitButton buttonType="primary" (click)="dialogRef.close()">Save</button> | ||
<button bitButton buttonType="secondary" bitDialogClose>Cancel</button> | ||
</div> | ||
</bit-simple-dialog> | ||
`, | ||
}) | ||
class StoryDialogContentComponent { | ||
constructor(public dialogRef: DialogRef, @Inject(DIALOG_DATA) private data: Animal) {} | ||
|
||
get animal() { | ||
return this.data?.animal; | ||
} | ||
} | ||
|
||
export default { | ||
title: "Component Library/Dialogs/Service/Simple", | ||
component: StoryDialogComponent, | ||
decorators: [ | ||
moduleMetadata({ | ||
declarations: [ | ||
DialogCloseDirective, | ||
SimpleDialogComponent, | ||
DialogTitleDirective, | ||
StoryDialogContentComponent, | ||
], | ||
imports: [ButtonModule, DialogModule], | ||
providers: [DialogService], | ||
}), | ||
], | ||
parameters: { | ||
design: { | ||
type: "figma", | ||
url: "https://www.figma.com/file/Zt3YSeb6E6lebAffrNLa0h/Tailwind-Component-Library", | ||
}, | ||
}, | ||
} as Meta; | ||
|
||
const Template: Story<StoryDialogComponent> = (args: StoryDialogComponent) => ({ | ||
props: args, | ||
}); | ||
|
||
export const Default = Template.bind({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters