-
-
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.
Allow optional component declaration (#6346)
Allow optional component declaration
- Loading branch information
Showing
13 changed files
with
421 additions
and
7 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
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
134 changes: 134 additions & 0 deletions
134
...les/angular-cli/src/stories/module-context/__snapshots__/module-context.stories.storyshot
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,134 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Storyshots Custom|Feature Module as Context Component with default providers 1`] = ` | ||
<storybook-dynamic-app-root | ||
cfr={[Function CodegenComponentFactoryResolver]} | ||
data={[Function Object]} | ||
target={[Function ViewContainerRef_]} | ||
> | ||
<storybook-chip | ||
_nghost-a-c15="" | ||
style="background-color: rgb(238, 238, 238);" | ||
> | ||
<span | ||
_ngcontent-a-c15="" | ||
class="text" | ||
> | ||
My Chíp | ||
</span> | ||
<div | ||
_ngcontent-a-c15="" | ||
class="remove" | ||
> | ||
<span | ||
_ngcontent-a-c15="" | ||
class="x" | ||
> | ||
✕ | ||
</span> | ||
</div> | ||
</storybook-chip> | ||
</storybook-dynamic-app-root> | ||
`; | ||
|
||
exports[`Storyshots Custom|Feature Module as Context Component with overridden provider 1`] = ` | ||
<storybook-dynamic-app-root | ||
cfr={[Function CodegenComponentFactoryResolver]} | ||
data={[Function Object]} | ||
target={[Function ViewContainerRef_]} | ||
> | ||
<storybook-chip | ||
_nghost-a-c16="" | ||
style="background-color: yellow;" | ||
> | ||
<span | ||
_ngcontent-a-c16="" | ||
class="text" | ||
> | ||
My Chíp | ||
</span> | ||
<div | ||
_ngcontent-a-c16="" | ||
class="remove" | ||
> | ||
<span | ||
_ngcontent-a-c16="" | ||
class="x" | ||
> | ||
✕ | ||
</span> | ||
</div> | ||
</storybook-chip> | ||
</storybook-dynamic-app-root> | ||
`; | ||
|
||
exports[`Storyshots Custom|Feature Module as Context Component with self and dependencies declared in its feature module 1`] = ` | ||
<storybook-dynamic-app-root | ||
cfr={[Function CodegenComponentFactoryResolver]} | ||
data={[Function Object]} | ||
target={[Function ViewContainerRef_]} | ||
> | ||
<storybook-chips-group | ||
_nghost-a-c13="" | ||
> | ||
|
||
<storybook-chip | ||
_ngcontent-a-c13="" | ||
_nghost-a-c14="" | ||
class="chip" | ||
ng-reflect-display-text="Chip 1" | ||
style="background-color: rgb(238, 238, 238);" | ||
> | ||
<span | ||
_ngcontent-a-c14="" | ||
class="text" | ||
> | ||
Chíp 1 | ||
</span> | ||
<div | ||
_ngcontent-a-c14="" | ||
class="remove" | ||
> | ||
<span | ||
_ngcontent-a-c14="" | ||
class="x" | ||
> | ||
✕ | ||
</span> | ||
</div> | ||
</storybook-chip> | ||
<storybook-chip | ||
_ngcontent-a-c13="" | ||
_nghost-a-c14="" | ||
class="chip" | ||
ng-reflect-display-text="Chip 2" | ||
style="background-color: rgb(238, 238, 238);" | ||
> | ||
<span | ||
_ngcontent-a-c14="" | ||
class="text" | ||
> | ||
Chíp 2 | ||
</span> | ||
<div | ||
_ngcontent-a-c14="" | ||
class="remove" | ||
> | ||
<span | ||
_ngcontent-a-c14="" | ||
class="x" | ||
> | ||
✕ | ||
</span> | ||
</div> | ||
</storybook-chip> | ||
|
||
<div | ||
_ngcontent-a-c13="" | ||
class="remove-all" | ||
> | ||
Remove All | ||
</div> | ||
</storybook-chips-group> | ||
</storybook-dynamic-app-root> | ||
`; |
3 changes: 3 additions & 0 deletions
3
examples/angular-cli/src/stories/module-context/chip-color.token.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,3 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
|
||
export const CHIP_COLOR = new InjectionToken<string>('chip-color'); |
29 changes: 29 additions & 0 deletions
29
examples/angular-cli/src/stories/module-context/chip-text.pipe.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 { Pipe, PipeTransform } from '@angular/core'; | ||
|
||
@Pipe({ | ||
name: 'chipText', | ||
}) | ||
export class ChipTextPipe implements PipeTransform { | ||
transform(value: string): string { | ||
return Array.from(value) | ||
.map(char => this.accentVowel(char)) | ||
.join(''); | ||
} | ||
|
||
accentVowel(char: string): string { | ||
switch (char) { | ||
case 'a': | ||
return 'á'; | ||
case 'e': | ||
return 'é'; | ||
case 'i': | ||
return 'í'; | ||
case 'o': | ||
return 'ó'; | ||
case 'u': | ||
return 'ú'; | ||
default: | ||
return char; | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
examples/angular-cli/src/stories/module-context/chip.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,68 @@ | ||
import { | ||
Component, | ||
Input, | ||
ChangeDetectionStrategy, | ||
Output, | ||
EventEmitter, | ||
Inject, | ||
HostBinding, | ||
} from '@angular/core'; | ||
import { CHIP_COLOR } from './chip-color.token'; | ||
|
||
@Component({ | ||
selector: 'storybook-chip', | ||
template: ` | ||
<span class="text">{{ displayText | chipText }}</span> | ||
<div class="remove" (click)="removeClicked.emit()"> | ||
<span class="x">✕</span> | ||
</div> | ||
`, | ||
styles: [ | ||
` | ||
:host { | ||
display: inline-flex; | ||
cursor: default; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 0.2rem 0.5rem; | ||
border-radius: 1rem; | ||
border: solid 0.1rem transparent; | ||
} | ||
:host:hover { | ||
border-color: black; | ||
} | ||
.text { | ||
font-family: inherit; | ||
} | ||
.remove { | ||
margin-left: 1rem; | ||
background-color: lightgrey; | ||
border-radius: 50%; | ||
width: 1rem; | ||
height: 1rem; | ||
text-align: center; | ||
} | ||
.remove:hover { | ||
background-color: palevioletred; | ||
} | ||
.x { | ||
display: inline-block; | ||
color: #eeeeee; | ||
text-align: center; | ||
vertical-align: baseline; | ||
line-height: 1rem; | ||
} | ||
`, | ||
], | ||
}) | ||
export class ChipComponent { | ||
@Input() displayText: string; | ||
|
||
@Output() removeClicked = new EventEmitter(); | ||
|
||
@HostBinding('style.background-color') backgroundColor: string; | ||
|
||
constructor(@Inject(CHIP_COLOR) chipColor: string) { | ||
this.backgroundColor = chipColor; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
examples/angular-cli/src/stories/module-context/chips-group.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, Input, ChangeDetectionStrategy, Output, EventEmitter } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'storybook-chips-group', | ||
template: ` | ||
<storybook-chip | ||
*ngFor="let chip of chips" | ||
class="chip" | ||
[displayText]="chip.text" | ||
(removeClicked)="removeChipClick.emit(chip.id)" | ||
></storybook-chip> | ||
<div *ngIf="chips.length > 1" class="remove-all" (click)="removeAllChipsClick.emit()"> | ||
Remove All | ||
</div> | ||
`, | ||
styles: [ | ||
` | ||
:host { | ||
display: flex; | ||
align-content: center; | ||
padding: 0.5rem; | ||
background-color: lightgrey; | ||
border-radius: 0.5rem; | ||
width: fit-content; | ||
} | ||
.chip:not(:first-of-type) { | ||
margin-left: 0.5rem; | ||
} | ||
.remove-all { | ||
margin-left: 0.5rem; | ||
padding: 0.2rem 0.5rem; | ||
border: solid 0.1rem #eeeeee; | ||
} | ||
.remove-all:hover { | ||
background-color: palevioletred; | ||
} | ||
`, | ||
], | ||
}) | ||
export class ChipsGroupComponent { | ||
@Input() chips: { | ||
id: number; | ||
text: string; | ||
}[]; | ||
|
||
@Output() removeChipClick = new EventEmitter<number>(); | ||
|
||
@Output() removeAllChipsClick = new EventEmitter(); | ||
} |
Oops, something went wrong.
d0564a2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully aliased the URL https://monorepo-8x8oa5tod.now.sh to the following aliases.