-
Notifications
You must be signed in to change notification settings - Fork 27.2k
feat(docs-infra): add getting started widgets #26059
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
Closed
brandonroberts
wants to merge
1
commit into
angular:master
from
brandonroberts:getting-started-widgets
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
39 changes: 39 additions & 0 deletions
39
aio/src/app/custom-elements/getting-started/container/container.component.spec.ts
This file contains hidden or 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,39 @@ | ||
| import { Component } from '@angular/core'; | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { ContainerComponent } from './container.component'; | ||
|
|
||
| @Component({ | ||
| template: ` | ||
| <aio-gs-container> | ||
| <ng-container class="template">Template</ng-container> | ||
| <ng-container class="data">Data</ng-container> | ||
| <ng-container class="result">Result</ng-container> | ||
| </aio-gs-container> | ||
| ` | ||
| }) | ||
| export class TestComponent {} | ||
|
|
||
| describe('Getting Started Container Component', () => { | ||
| let fixture: ComponentFixture<ContainerComponent>; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| declarations: [ ContainerComponent, TestComponent ] | ||
| }); | ||
|
|
||
| fixture = TestBed.createComponent(TestComponent); | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should project the content into the appropriate areas', () => { | ||
| const compiled = fixture.debugElement.nativeElement; | ||
| const pre = compiled.querySelector('pre'); | ||
| const code = compiled.querySelector('code'); | ||
| const tabledata = compiled.querySelectorAll('td'); | ||
|
|
||
| expect(pre.textContent).toContain('Template'); | ||
| expect(code.textContent).toContain('Data'); | ||
| expect(tabledata[2].textContent).toContain('Result'); | ||
| }); | ||
| }); |
80 changes: 80 additions & 0 deletions
80
aio/src/app/custom-elements/getting-started/container/container.component.ts
This file contains hidden or 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,80 @@ | ||
| import { Component } from '@angular/core'; | ||
|
|
||
| @Component({ | ||
| selector: 'aio-gs-container', | ||
| template: ` | ||
| <table> | ||
| <thead> | ||
| <tr> | ||
| <th>Template</th> | ||
| <th>Data</th> | ||
| <th>Result</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr> | ||
| <td> | ||
| <pre><ng-content select=".template"></ng-content></pre> | ||
| </td> | ||
| <td> | ||
| <code><ng-content select=".data"></ng-content></code> | ||
| </td> | ||
| <td><ng-content select=".result"></ng-content></td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| `, | ||
| styles: [ | ||
| ` | ||
| pre { | ||
| margin: 0; | ||
| } | ||
|
|
||
| code { | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
|
|
||
| @media only screen and (max-width: 760px), | ||
| (min-device-width: 768px) and (max-device-width: 1024px) { | ||
| /* Force table to not be like tables anymore */ | ||
| table, thead, tbody, th, td, tr { | ||
| display: block; | ||
| } | ||
|
|
||
| /* Hide table headers (but not display: none;, for accessibility) */ | ||
| thead tr { | ||
| position: absolute; | ||
| top: -9999px; | ||
| left: -9999px; | ||
| } | ||
|
|
||
| tr { border: 1px solid #ccc; } | ||
|
|
||
| td { | ||
| /* Behave like a "row" */ | ||
| border: none; | ||
| border-bottom: 1px solid #eee; | ||
| position: relative; | ||
| padding-top: 10%; | ||
| } | ||
|
|
||
| td:before { | ||
| /* Now like a table header */ | ||
| position: absolute; | ||
| /* Top/left values mimic padding */ | ||
| top: 6px; | ||
| left: 6px; | ||
| width: 45%; | ||
| padding-right: 10px; | ||
| } | ||
|
|
||
| /* Label the data */ | ||
| td:nth-of-type(1):before { content: "Template"; } | ||
| td:nth-of-type(2):before { content: "Data"; } | ||
| td:nth-of-type(3):before { content: "Result"; } | ||
| } | ||
| ` | ||
| ] | ||
| }) | ||
| export class ContainerComponent { } |
10 changes: 10 additions & 0 deletions
10
aio/src/app/custom-elements/getting-started/container/container.module.ts
This file contains hidden or 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,10 @@ | ||
| import { NgModule } from '@angular/core'; | ||
| import { CommonModule } from '@angular/common'; | ||
| import { ContainerComponent } from './container.component'; | ||
|
|
||
| @NgModule({ | ||
| imports: [ CommonModule ], | ||
| declarations: [ ContainerComponent ], | ||
| exports: [ ContainerComponent ] | ||
| }) | ||
| export class ContainerModule { } |
46 changes: 46 additions & 0 deletions
46
aio/src/app/custom-elements/getting-started/event-binding/event-binding.component.spec.ts
This file contains hidden or 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,46 @@ | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { ContainerModule } from '../container/container.module'; | ||
| import { EventBindingComponent } from './event-binding.component'; | ||
| import { createCustomEvent } from '../../../../testing/dom-utils'; | ||
|
|
||
| describe('Getting Started Event Binding Component', () => { | ||
| let component: EventBindingComponent; | ||
| let fixture: ComponentFixture<EventBindingComponent>; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| imports: [ ContainerModule ], | ||
| declarations: [ EventBindingComponent ] | ||
| }); | ||
|
|
||
| fixture = TestBed.createComponent(EventBindingComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
|
|
||
| spyOn(window, 'alert'); | ||
| }); | ||
|
|
||
| it('should update the name property on input change', () => { | ||
| const text = 'Hello Angular'; | ||
| const compiled = fixture.debugElement.nativeElement; | ||
| const input: HTMLInputElement = compiled.querySelector('input'); | ||
|
|
||
|
|
||
| input.value = text; | ||
| input.dispatchEvent(createCustomEvent(document, 'input', '')); | ||
|
|
||
| fixture.detectChanges(); | ||
|
|
||
| expect(component.name).toBe(text); | ||
| }); | ||
|
|
||
| it('should display an alert when the button is clicked', () => { | ||
| const compiled = fixture.debugElement.nativeElement; | ||
| const button: HTMLButtonElement = compiled.querySelector('button'); | ||
|
|
||
| button.click(); | ||
|
|
||
| expect(window.alert).toHaveBeenCalledWith('Hello, Angular!'); | ||
| }); | ||
| }); |
30 changes: 30 additions & 0 deletions
30
aio/src/app/custom-elements/getting-started/event-binding/event-binding.component.ts
This file contains hidden or 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,30 @@ | ||
| import { Component } from '@angular/core'; | ||
|
|
||
| @Component({ | ||
| selector: 'aio-gs-event-binding', | ||
| template: ` | ||
| <aio-gs-container> | ||
| <ng-container class="template"><button (click)="greet(name)"> | ||
| Greet | ||
| </button></ng-container> | ||
|
|
||
| <ng-container class="data"> | ||
| name = '<input #input (input)="name = input.value" [value]="name">'; | ||
| </ng-container> | ||
|
|
||
| <ng-container class="result"> | ||
| <button (click)="greet(name)"> | ||
| Greet | ||
| </button> | ||
| </ng-container> | ||
| </aio-gs-container> | ||
| `, | ||
| preserveWhitespaces: true | ||
| }) | ||
| export class EventBindingComponent { | ||
| name = 'Angular'; | ||
|
|
||
| greet(name: string) { | ||
| window.alert(`Hello, ${name}!`); | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
aio/src/app/custom-elements/getting-started/event-binding/event-binding.module.ts
This file contains hidden or 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,15 @@ | ||
| import { NgModule, Type } from '@angular/core'; | ||
| import { CommonModule } from '@angular/common'; | ||
| import { WithCustomElementComponent } from '../../element-registry'; | ||
| import { EventBindingComponent } from './event-binding.component'; | ||
| import { ContainerModule } from '../container/container.module'; | ||
|
|
||
| @NgModule({ | ||
| imports: [ CommonModule, ContainerModule ], | ||
| declarations: [ EventBindingComponent ], | ||
| exports: [ EventBindingComponent ], | ||
| entryComponents: [ EventBindingComponent ] | ||
| }) | ||
| export class EventBindingModule implements WithCustomElementComponent { | ||
| customElementComponent: Type<any> = EventBindingComponent; | ||
| } |
41 changes: 41 additions & 0 deletions
41
aio/src/app/custom-elements/getting-started/interpolation/interpolation.component.spec.ts
This file contains hidden or 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,41 @@ | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { InterpolationComponent } from './interpolation.component'; | ||
| import { ContainerModule } from '../container/container.module'; | ||
| import { createCustomEvent } from '../../../../testing/dom-utils'; | ||
|
|
||
| describe('Getting Started Interpolation Component', () => { | ||
| let component: InterpolationComponent; | ||
| let fixture: ComponentFixture<InterpolationComponent>; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| imports: [ ContainerModule ], | ||
| declarations: [ InterpolationComponent ] | ||
| }); | ||
|
|
||
| fixture = TestBed.createComponent(InterpolationComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should update the siteName property on input change', () => { | ||
| const text = 'Hello Angular'; | ||
| const compiled = fixture.debugElement.nativeElement; | ||
| const input: HTMLInputElement = compiled.querySelector('input'); | ||
|
|
||
| input.value = text; | ||
| input.dispatchEvent(createCustomEvent(document, 'input', '')); | ||
|
|
||
| fixture.detectChanges(); | ||
|
|
||
| expect(component.siteName).toBe(text); | ||
| }); | ||
|
|
||
| it('should display the siteName', () => { | ||
| const compiled = fixture.debugElement.nativeElement; | ||
| const header: HTMLHeadingElement = compiled.querySelector('h1'); | ||
|
|
||
| expect(header.textContent).toContain('My Store'); | ||
| }); | ||
| }); |
20 changes: 20 additions & 0 deletions
20
aio/src/app/custom-elements/getting-started/interpolation/interpolation.component.ts
This file contains hidden or 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,20 @@ | ||
| import { Component } from '@angular/core'; | ||
|
|
||
|
|
||
| @Component({ | ||
| selector: 'aio-gs-interpolation', | ||
| template: ` | ||
| <aio-gs-container> | ||
| <ng-container class="template"><h1>Welcome to {{'{'+'{'}}siteName{{'}'+'}'}}<h1></ng-container> | ||
|
|
||
| <ng-container class="data"> | ||
| siteName = '<input #input (input)="siteName = input.value" [value]="siteName">'; | ||
| </ng-container> | ||
|
|
||
| <ng-container class="result"><h1>Welcome to {{ siteName }}</h1></ng-container> | ||
| </aio-gs-container> | ||
| ` | ||
| }) | ||
| export class InterpolationComponent { | ||
| siteName = 'My Store'; | ||
| } |
15 changes: 15 additions & 0 deletions
15
aio/src/app/custom-elements/getting-started/interpolation/interpolation.module.ts
This file contains hidden or 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,15 @@ | ||
| import { NgModule, Type } from '@angular/core'; | ||
| import { CommonModule } from '@angular/common'; | ||
| import { WithCustomElementComponent } from '../../element-registry'; | ||
| import { InterpolationComponent } from './interpolation.component'; | ||
| import { ContainerModule } from '../container/container.module'; | ||
|
|
||
| @NgModule({ | ||
| imports: [ CommonModule, ContainerModule ], | ||
| declarations: [ InterpolationComponent ], | ||
| exports: [ InterpolationComponent ], | ||
| entryComponents: [ InterpolationComponent ] | ||
| }) | ||
| export class InterpolationModule implements WithCustomElementComponent { | ||
| customElementComponent: Type<any> = InterpolationComponent; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.