-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demo): add "old" example to the demo
- Loading branch information
Showing
13 changed files
with
255 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<div class="c-button__loading-indicator" *ngIf="loading()"></div> | ||
<div class="c-button__loading-indicator" *ngIf="isLoading()"></div> | ||
<ng-content></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
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
2 changes: 2 additions & 0 deletions
2
apps/demo/src/app/components/old-button/old-button.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,2 @@ | ||
<div class="c-button__loading-indicator" *ngIf="isLoading"></div> | ||
<ng-content></ng-content> |
Empty file.
21 changes: 21 additions & 0 deletions
21
apps/demo/src/app/components/old-button/old-button.component.spec.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,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { OldButtonComponent } from './old-button.component'; | ||
|
||
describe('OldButtonComponent', () => { | ||
let component: OldButtonComponent; | ||
let fixture: ComponentFixture<OldButtonComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [OldButtonComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(OldButtonComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
97 changes: 97 additions & 0 deletions
97
apps/demo/src/app/components/old-button/old-button.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,97 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Attribute, Component, ElementRef, HostBinding, inject, OnInit, Renderer2 } from '@angular/core'; | ||
|
||
/** | ||
* A demo button without using @bynary/composables | ||
* | ||
* Has the same functionality as the {@link ButtonComponent} component. | ||
*/ | ||
@Component({ | ||
selector: 'demo-old-button', | ||
standalone: true, | ||
imports: [ CommonModule ], | ||
templateUrl: './old-button.component.html', | ||
styleUrls: ['../button/button.component.scss'], | ||
host: { | ||
class: 'c-button' | ||
} | ||
}) | ||
export class OldButtonComponent implements OnInit { | ||
@HostBinding('attr.type') | ||
type: string; | ||
|
||
isDisabled: boolean; | ||
|
||
@HostBinding('class.c-button--is-loading') | ||
isLoading = false; | ||
|
||
private _appearance?: 'solid' | 'outline'; | ||
private _color?: 'red' | 'green'; | ||
private readonly _renderer = inject(Renderer2); | ||
private readonly _elementRef = inject(ElementRef); | ||
|
||
constructor(@Attribute('type') type: string, @Attribute('disabled') disabled: string) { | ||
this.type = type ?? 'button'; | ||
this.isDisabled = disabled != null; | ||
} | ||
|
||
@HostBinding('attr.disabled') | ||
get disabledAttr() { | ||
return this.isDisabled ? '' : null; | ||
} | ||
|
||
@HostBinding('attr.tabindex') | ||
get tabIndex() { | ||
return this.isDisabled ? '-1' : '0'; | ||
} | ||
|
||
get appearance(): 'solid' | 'outline' | undefined { | ||
return this._appearance; | ||
} | ||
|
||
set appearance(value: 'solid' | 'outline' | undefined) { | ||
if (this._appearance === value) { | ||
return; | ||
} | ||
|
||
this._renderer.removeClass( | ||
this._elementRef.nativeElement, | ||
`c-button--${this._appearance}` | ||
); | ||
this._appearance = value; | ||
this._renderer.addClass( | ||
this._elementRef.nativeElement, | ||
`c-button--${this._appearance}` | ||
); | ||
} | ||
|
||
get color(): 'red' | 'green' | undefined { | ||
return this._color; | ||
} | ||
|
||
set color(value: 'red' | 'green' | undefined) { | ||
if (this._color === value) { | ||
return; | ||
} | ||
|
||
if (this._color) { | ||
this._renderer.removeClass( | ||
this._elementRef.nativeElement, | ||
`c-button--color-${this._color}` | ||
); | ||
} | ||
|
||
this._color = value; | ||
|
||
if (this._color) { | ||
this._renderer.addClass( | ||
this._elementRef.nativeElement, | ||
`c-button--color-${this._color}` | ||
); | ||
} | ||
} | ||
|
||
ngOnInit() { | ||
this.appearance = 'solid'; | ||
} | ||
} |
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
Oops, something went wrong.