Last active
September 16, 2021 06:10
-
-
Save jhades/9e58cd0c8f3f777b215d9bd1841540ef to your computer and use it in GitHub Desktop.
Content Projection
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
@Component({ | |
selector: 'app-root', | |
template: ` | |
<h1>FA Input</h1> | |
<fa-input icon="envelope" (value)="onNewValue($event)"></fa-input> | |
<fa-input icon="lock" (value)="onNewValue($event)"></fa-input> | |
` | |
}) | |
export class AppComponent { | |
onNewValue(val) { | |
console.log(val); | |
} | |
} |
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
@Component({ | |
selector: 'fa-input', | |
template: ` | |
<i class="fa" [ngClass]="classes"></i> | |
<input (focus)="inputFocus = true" (blur)="inputFocus = false" | |
(keyup)="value.emit(input.value)" #input> | |
`, | |
styleUrls: ['./fa-input.component.css'] | |
}) | |
export class FaInputComponent { | |
@Input() icon: string; | |
@Output() value = new EventEmitter<string>(); | |
inputFocus = false; | |
get classes() { | |
const cssClasses = { | |
fa: true | |
}; | |
cssClasses['fa-' + this.icon] = true; | |
return cssClasses; | |
} | |
@HostBinding('class.focus') | |
get focus() { | |
console.log(this.inputFocus); | |
return this.inputFocus; | |
} | |
} | |
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
:host { | |
border: 1px solid grey; | |
} | |
input { | |
border: none; | |
outline: none; | |
} | |
:host(.focus) { | |
border: 1px solid blue; | |
} |
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
<input type="email" autocomplete="off" placeholder='Email'> |
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
@Component({ | |
selector: 'fa-input', | |
template: ` | |
<i class="fa" [ngClass]="classes"></i> | |
<input (focus)="inputFocus = true" (blur)="inputFocus = false" | |
(keyup)="value.emit(input.value)" #input | |
[placeholder]="placeholder" | |
[type]="type", | |
[autocomplete]="autocomplete"> | |
` | |
}) | |
export class FaInputComponent { | |
... | |
@Input() placeholder:string; | |
@Input() type:string; | |
@Input() autocomplete: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
@Component({ | |
selector: 'app-root', | |
template: ` | |
<h1>FA Input</h1> | |
<fa-input icon="envelope"> | |
<input type="email" placeholder="Email"> | |
</fa-input> | |
`}) | |
export class AppComponent { | |
} | |
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
<select> | |
<option value="volvo">Volvo</option> | |
<option value="saab">Saab</option> | |
<option value="mercedes">Mercedes</option> | |
<option value="audi">Audi</option> | |
</select> | |
<ul> | |
<li>Coffee</li> | |
<li>Tea</li> | |
<li>Milk</li> | |
</ul> |
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
@Component({ | |
selector: 'fa-input', | |
template: ` | |
<i class="fa" [ngClass]="classes"></i> | |
<ng-content></ng-content> | |
`, | |
styleUrls: ['./fa-input.component.css'] | |
}) | |
export class FaInputComponent { | |
@Input() icon: string; | |
get classes() { | |
const cssClasses = { | |
fa: true | |
}; | |
cssClasses['fa-' + this.icon] = true; | |
return cssClasses; | |
} | |
} |
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
:host ::ng-deep input { | |
border: none; | |
outline: none; | |
} |
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
input { | |
border: none; | |
outline: none; | |
} |
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
input[_ngcontent-c0] { | |
border: none; | |
outline: none; | |
} |
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
<fa-input icon="envelope" _nghost-c0=""> | |
<i _ngcontent-c0="" class="fa fa-envelope"></i> | |
<input placeholder="Email" type="email"> | |
</fa-input> |
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
[_nghost-c0] input { | |
border: none; | |
outline: none; | |
} |
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
@Directive({ | |
selector: '[inputRef]' | |
}) | |
export class InputRefDirective { | |
focus = false; | |
@HostListener("focus") | |
onFocus() { | |
this.focus = true; | |
} | |
@HostListener("blur") | |
onBlur() { | |
this.focus = false; | |
} | |
} |
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
<h1>FA Input</h1> | |
<fa-input icon="envelope"> | |
<input inputRef type="email" placeholder="Email"> | |
</fa-input> |
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
@Component({ | |
selector: 'fa-input', | |
template: ` | |
<i class="fa" [ngClass]="classes"></i> | |
<ng-content></ng-content> | |
`, | |
styleUrls: ['./fa-input.component.css'] | |
}) | |
export class FaInputComponent { | |
@Input() icon: string; | |
@ContentChild(InputRefDirective) | |
input: InputRefDirective; | |
@HostBinding("class.focus") | |
get focus() { | |
return this.input ? this.input.focus : false; | |
} | |
get classes() { | |
const cssClasses = { | |
fa: true | |
}; | |
cssClasses['fa-' + this.icon] = true; | |
return cssClasses; | |
} | |
} |
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
<fa-input icon="envelope"> | |
<i class="fa fa-envelope"></i> | |
<input inputRef type="email" placeholder="Email"> | |
</fa-input> |
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
@Component({ | |
selector: 'fa-input', | |
template: ` | |
<ng-content select="i"></ng-content> | |
<ng-content select="input"></ng-content> | |
`}) | |
export class FaInputComponent { | |
... | |
} |
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
<ng-content select="input.test-class"></ng-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
@Component({ | |
selector: 'fa-input', | |
template: ` | |
<ng-content select="i"></ng-content> | |
<ng-content></ng-content> | |
`}) | |
export class FaInputComponent { | |
... | |
} | |
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
:host { | |
border: 1px solid grey; | |
} | |
input { | |
border: none; | |
outline: none; | |
} | |
:host(.focus) { | |
border: 1px solid blue; | |
} | |
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
:host { | |
border: 1px solid grey; | |
} | |
input { | |
border: none; | |
outline: none; | |
} | |
:host(.focus) { | |
border: 1px solid blue; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment