-
Notifications
You must be signed in to change notification settings - Fork 23
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
1 parent
b86d682
commit fe5a421
Showing
26 changed files
with
740 additions
and
6 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...ook/src/app/examples/alert-experimental-example/alert-experimental-example.component.html
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,8 @@ | ||
<button kirby-button (click)="showAlert()">Show alert</button> | ||
<button kirby-button (click)="showAlertWithIcon()">Show alert with icon</button> | ||
<button kirby-button (click)="showAlertWithoutCancel()">Show alert without cancel</button> | ||
<button kirby-button (click)="showDestructiveAlert()" class="destructive"> | ||
Show destructive alert | ||
</button> | ||
<button kirby-button (click)="showAlertWithNewline()">Show alert with newline</button> | ||
<button kirby-button (click)="showAlertWithDynamicValues()">Show alert with dynamic values</button> |
193 changes: 193 additions & 0 deletions
193
...kbook/src/app/examples/alert-experimental-example/alert-experimental-example.component.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,193 @@ | ||
import { Component } from '@angular/core'; | ||
import { of, Subject, timer } from 'rxjs'; | ||
import { map, takeUntil, takeWhile } from 'rxjs/operators'; | ||
|
||
import { | ||
AlertExperimentalConfig, | ||
AlertExperimentalController, | ||
} from '@kirbydesign/designsystem/alert-experimental'; | ||
import { ToastConfig, ToastController } from '@kirbydesign/designsystem'; | ||
|
||
const alertConfigWithIcon: AlertExperimentalConfig = { | ||
title: 'Alert With Icon', | ||
message: 'This is an alert with an icon.', | ||
okButton: 'I agree', | ||
cancelButton: 'Take me back', | ||
icon: { name: 'warning', themeColor: 'warning' }, | ||
}; | ||
|
||
export const observableCodeSnippet = `showAlert() { | ||
const alert = this.alertController.showAlert(config); | ||
alert.onWillDismiss.subscribe((response) => { | ||
const { role, data } = response; | ||
... | ||
}); | ||
alert.onDidDismiss.subscribe((response) => { | ||
const { role, data } = response; | ||
... | ||
}); | ||
}`; | ||
|
||
@Component({ | ||
selector: 'cookbook-alert-experimental-example', | ||
templateUrl: './alert-experimental-example.component.html', | ||
styles: [':host { display: block; }'], | ||
}) | ||
export class AlertExperimentalExampleComponent { | ||
static readonly alertConfigWithIcon = `const config: AlertExperimentalConfig = ${AlertExperimentalExampleComponent.stringify( | ||
alertConfigWithIcon | ||
)} | ||
this.alertController.showAlert(config);`; | ||
|
||
private static stringify(value: any): string { | ||
return JSON.stringify(value, null, '\t') | ||
.replace(/"(\w+)\":/g, '$1:') | ||
.replace(/"/g, "'"); | ||
} | ||
|
||
private alertClose$: Subject<void> = new Subject<void>(); | ||
|
||
static readonly alertConfigWithDynamicValues = `const title$ = of('Need more time?'); | ||
const message$ = remainingSeconds$.pipe( | ||
map((remainingSeconds) => \`Time remaining: \${remainingSeconds}\`) | ||
); | ||
const config: AlertExperimentalConfig = { | ||
title: title$, | ||
icon: { | ||
name: 'clock', | ||
themeColor: 'warning', | ||
}, | ||
message: message$, | ||
okBtn: 'Logout', | ||
cancelBtn: 'Take me back', | ||
}; | ||
this.alertController.showAlert(config);`; | ||
constructor( | ||
private alertController: AlertExperimentalController, | ||
private toastController: ToastController | ||
) {} | ||
|
||
showAlert() { | ||
const config: AlertExperimentalConfig = { | ||
title: 'Default Alert', | ||
message: 'The default alert is just a title, a message, an OK and (optional) cancel button', | ||
okButton: 'I agree', | ||
cancelButton: 'Take me back', | ||
}; | ||
|
||
const alert = this.alertController.showAlert(config); | ||
|
||
alert.onDidDismiss.subscribe((result) => { | ||
this.onAlertClosed(result.data); | ||
}); | ||
} | ||
|
||
showAlertWithIcon() { | ||
const alert = this.alertController.showAlert(alertConfigWithIcon); | ||
|
||
alert.onDidDismiss.subscribe((result) => { | ||
this.onAlertClosed(result.data); | ||
}); | ||
} | ||
|
||
showAlertWithoutCancel() { | ||
const config: AlertExperimentalConfig = { | ||
title: 'Alert Without Cancel', | ||
message: 'This is an alert that can only be acknowledged (no cancel option)', | ||
okButton: 'I understand', | ||
}; | ||
|
||
const alert = this.alertController.showAlert(config); | ||
|
||
alert.onDidDismiss.subscribe((result) => { | ||
this.onAlertClosed(result.data); | ||
}); | ||
} | ||
|
||
showDestructiveAlert() { | ||
const config: AlertExperimentalConfig = { | ||
title: 'Desctructive Alert', | ||
message: | ||
'This is to indicate that something destructive will happen when clicking the OK button', | ||
cancelButton: 'Get me out of here', | ||
okButton: { text: 'Confirm', isDestructive: true }, | ||
}; | ||
|
||
const alert = this.alertController.showAlert(config); | ||
|
||
alert.onDidDismiss.subscribe((result) => { | ||
this.onAlertDestructiveClosed(result.data); | ||
}); | ||
} | ||
|
||
showAlertWithNewline() { | ||
const config: AlertExperimentalConfig = { | ||
title: 'Alert with newline', | ||
message: 'This is message one.\n\nThis is message two.', | ||
okButton: 'I agree', | ||
cancelButton: 'Take me back', | ||
}; | ||
|
||
const alert = this.alertController.showAlert(config); | ||
|
||
alert.onDidDismiss.subscribe((result) => { | ||
this.onAlertClosed(result.data); | ||
}); | ||
} | ||
|
||
showAlertWithDynamicValues() { | ||
const countdownTimeInSeconds = 60; | ||
const countdownTimeInMs = countdownTimeInSeconds * 1000; | ||
const intervalInMs = 1000; | ||
const toRemainingTimeInMs = (count: number) => countdownTimeInMs - count * intervalInMs; | ||
const toSeconds = (timeInMs: number) => Math.ceil(timeInMs / 1000); | ||
|
||
const remainingTime$ = timer(0, intervalInMs).pipe( | ||
map(toRemainingTimeInMs), | ||
takeUntil(this.alertClose$), | ||
takeWhile((countdownTimeInMs) => countdownTimeInMs >= 0) | ||
); | ||
|
||
const title$ = of('Need more time?'); | ||
const message$ = remainingTime$.pipe( | ||
map((remainingTimeInMs) => `Time remaining: ${toSeconds(remainingTimeInMs)}`) | ||
); | ||
const config: AlertExperimentalConfig = { | ||
title: title$, | ||
icon: { | ||
name: 'clock', | ||
themeColor: 'warning', | ||
}, | ||
message: message$, | ||
okButton: 'Logout', | ||
cancelButton: 'Take me back', | ||
}; | ||
|
||
const alert = this.alertController.showAlert(config); | ||
|
||
alert.onDidDismiss.subscribe((result) => { | ||
this.onAlertClosed(result.data); | ||
}); | ||
} | ||
|
||
private onAlertClosed(result?: boolean) { | ||
const config: ToastConfig = { | ||
message: `Alert selection: ${result}`, | ||
messageType: result ? 'success' : 'warning', | ||
durationInMs: 1500, | ||
}; | ||
this.toastController.showToast(config); | ||
this.alertClose$.next(); | ||
} | ||
|
||
private onAlertDestructiveClosed(result?: boolean) { | ||
const config: ToastConfig = { | ||
message: result ? 'Message deleted' : 'Nothing happened', | ||
messageType: result ? 'warning' : 'success', | ||
durationInMs: 1500, | ||
}; | ||
this.toastController.showToast(config); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
...k/src/app/showcase/alert-experimental-showcase/alert-experimental-showcase.component.html
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,44 @@ | ||
<div class="example"> | ||
<cookbook-alert-experimental-example></cookbook-alert-experimental-example> | ||
<p> </p> | ||
<p> | ||
To show an alert, inject the Kirby | ||
<code>AlertExperimentalController</code> | ||
in your constructor, create an | ||
<code>AlertExperimentalConfig</code> | ||
and pass it to | ||
<code>alertController.showAlert</code> | ||
. | ||
<cookbook-code-viewer [ts]="alertConfigWithIcon"></cookbook-code-viewer> | ||
</p> | ||
<p> | ||
<code>title</code> | ||
and | ||
<code>message</code> | ||
properties in | ||
<code>AlertExperimentalConfig</code> | ||
also accept an Observable for dynamic values: | ||
<br /> | ||
<em> | ||
(see "Example on github" for implementation details of the | ||
<code>remainingSeconds$</code> | ||
timer) | ||
</em> | ||
: | ||
<cookbook-code-viewer [ts]="alertConfigWithDynamicValues"></cookbook-code-viewer> | ||
</p> | ||
<p> | ||
<em>[Optional]</em> | ||
If you need to obtain data back from the alert, you can subscribe to the | ||
<code>onWillDismiss</code> | ||
and | ||
<code>onDidDismiss</code> | ||
events like this: | ||
<!-- prettier-ignore --> | ||
<cookbook-code-viewer [ts]="observableCodeSnippet"></cookbook-code-viewer> | ||
</p> | ||
<h4>Alert config properties:</h4> | ||
<cookbook-api-description-properties | ||
[properties]="properties" | ||
></cookbook-api-description-properties> | ||
</div> |
49 changes: 49 additions & 0 deletions
49
...ook/src/app/showcase/alert-experimental-showcase/alert-experimental-showcase.component.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,49 @@ | ||
import { Component } from '@angular/core'; | ||
import { | ||
AlertExperimentalExampleComponent, | ||
observableCodeSnippet, | ||
} from '../../examples/alert-experimental-example/alert-experimental-example.component'; | ||
import { ApiDescriptionProperty } from '../../shared/api-description/api-description-properties/api-description-properties.component'; | ||
@Component({ | ||
selector: 'cookbook-alert-showcase', | ||
templateUrl: './alert-experimental-showcase.component.html', | ||
preserveWhitespaces: true, | ||
}) | ||
export class AlertExperimentalShowcaseComponent { | ||
alertConfigWithIcon: string = AlertExperimentalExampleComponent.alertConfigWithIcon; | ||
alertConfigWithDynamicValues: string = | ||
AlertExperimentalExampleComponent.alertConfigWithDynamicValues; | ||
observableCodeSnippet: string = observableCodeSnippet; | ||
|
||
properties: ApiDescriptionProperty[] = [ | ||
{ | ||
name: 'title', | ||
description: 'The title of the alert', | ||
type: ['string | Observable<string>'], | ||
}, | ||
{ | ||
name: 'message', | ||
description: | ||
"(Optional) The message shown under the title (or icon if specified). Use '\\n' for newline.", | ||
type: ['string | Observable<string>'], | ||
}, | ||
{ | ||
name: 'icon', | ||
description: '(Optional) Icon to be shown below the title', | ||
type: ['{ name: string }', '{ name: string, themeColor: string }'], | ||
}, | ||
{ | ||
name: 'okBtn', | ||
description: | ||
'(Optional) Defines the text that will appear on the OK button and if it should be destructive', | ||
defaultValue: 'OK', | ||
type: ['string', '{ text: string, isDestructive: boolean }'], | ||
}, | ||
{ | ||
name: 'cancelBtn', | ||
description: | ||
'(Optional) The text that will appear on the cancel button. If not defined the cancel button will not be shown.', | ||
type: ['string'], | ||
}, | ||
]; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src/index'; |
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 @@ | ||
{} |
Oops, something went wrong.