-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
5 changed files
with
105 additions
and
12 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
code/frameworks/angular/template/components/form.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,37 @@ | ||
import { Component, Output, EventEmitter } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'storybook-form', | ||
template: ` | ||
<form id="interaction-test-form" (submit)="handleSubmit($event)"> | ||
<label> | ||
Enter Value | ||
<input type="text" data-testid="value" [value]="value" required /> | ||
</label> | ||
<button type="submit">Submit</button> | ||
<p *ngIf="complete">Completed!!</p> | ||
</form> | ||
`, | ||
}) | ||
export default class FormComponent { | ||
/** | ||
* Optional success handler | ||
*/ | ||
@Output() | ||
onSuccess = new EventEmitter<string>(); | ||
|
||
value = ''; | ||
|
||
complete = false; | ||
|
||
handleSubmit(event) { | ||
event.preventDefault(); | ||
this.onSuccess.emit(this.value); | ||
setTimeout(() => { | ||
this.complete = true; | ||
}, 500); | ||
setTimeout(() => { | ||
this.complete = false; | ||
}, 1500); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
code/frameworks/angular/template/components/html.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,24 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { DomSanitizer } from '@angular/platform-browser'; | ||
|
||
@Component({ | ||
selector: 'storybook-html', | ||
template: `<div [innerHTML]="safeContent"></div>`, | ||
}) | ||
export default class HtmlComponent { | ||
/** | ||
* The HTML to render | ||
* | ||
* @required | ||
*/ | ||
@Input() | ||
content = ''; | ||
|
||
constructor(private sanitizer: DomSanitizer) { | ||
this.sanitizer = sanitizer; | ||
} | ||
|
||
get safeContent() { | ||
return this.sanitizer.bypassSecurityTrustHtml(this.content); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import globalThis from 'global'; | ||
|
||
import Button from './button.component'; | ||
import Html from './html.component'; | ||
import Pre from './pre.component'; | ||
import Form from './form.component'; | ||
|
||
globalThis.Components = { Button }; | ||
globalThis.Components = { Button, Html, Pre, Form }; |
29 changes: 29 additions & 0 deletions
29
code/frameworks/angular/template/components/pre.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,29 @@ | ||
import { Component, Input } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'storybook-pre', | ||
template: `<pre data-testid="pre" [ngStyle]="style">{{ finalText }}</pre>`, | ||
}) | ||
export default class PreComponent { | ||
/** | ||
* Styles to apply to the component | ||
*/ | ||
@Input() | ||
style = {}; | ||
|
||
/** | ||
* An object to render | ||
*/ | ||
@Input() | ||
object: Object = null; | ||
|
||
/** | ||
* The code to render | ||
*/ | ||
@Input() | ||
text = ''; | ||
|
||
get finalText() { | ||
return this.object ? JSON.stringify(this.object, null, 2) : this.text; | ||
} | ||
} |
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