-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ddesign): change daffSizeMixin to a directive
- Loading branch information
Showing
12 changed files
with
191 additions
and
216 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Directive } from '@angular/core'; | ||
|
||
import { | ||
DaffSizableDirective, | ||
DaffSizeLargeType, | ||
DaffSizeMediumType, | ||
DaffSizeSmallType, | ||
} from '@daffodil/design'; | ||
|
||
/** | ||
* The DaffSizable {@link DaffSizable } types that the DaffButtonComponent can implement. | ||
*/ | ||
export type DaffButtonSize = DaffSizeSmallType | DaffSizeMediumType | DaffSizeLargeType; | ||
|
||
@Directive({ | ||
standalone: true, | ||
}) | ||
|
||
export class DaffButtonSizableDirective extends DaffSizableDirective<DaffButtonSize> {} | ||
|
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,3 @@ | ||
export { DaffButtonComponent } from './button/button.component'; | ||
export { DaffButtonModule } from './button.module'; | ||
export { DaffButtonSizableDirective } from './button/button-sizable.directive'; |
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 was deleted.
Oops, something went wrong.
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, | ||
DebugElement, | ||
} from '@angular/core'; | ||
import { | ||
waitForAsync, | ||
ComponentFixture, | ||
TestBed, | ||
} from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { DaffSizeAllType } from './sizable'; | ||
import { DaffSizableDirective } from './sizable.directive'; | ||
|
||
@Component({ | ||
template: ` | ||
<div daffSizable [size]="size"></div>`, | ||
}) | ||
|
||
class WrapperComponent { | ||
size: string; | ||
} | ||
|
||
describe('@daffodil/design | DaffSizableDirective', () => { | ||
let wrapper: WrapperComponent; | ||
let de: DebugElement; | ||
let fixture: ComponentFixture<WrapperComponent>; | ||
let directive: DaffSizableDirective<DaffSizeAllType>; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
WrapperComponent, | ||
], | ||
imports: [ | ||
DaffSizableDirective, | ||
], | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(WrapperComponent); | ||
wrapper = fixture.componentInstance; | ||
de = fixture.debugElement.query(By.css('[daffSizable]')); | ||
|
||
directive = de.injector.get(DaffSizableDirective); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(wrapper).toBeTruthy(); | ||
expect(directive).toBeTruthy(); | ||
}); | ||
|
||
it('should take size as an input', () => { | ||
expect(directive.size).toEqual(wrapper.size); | ||
}); | ||
|
||
it('should add a class of .daff-md to the host element if size is set to md', () => { | ||
wrapper.size = 'md'; | ||
fixture.detectChanges(); | ||
|
||
expect(directive.class).toEqual(jasmine.objectContaining({ | ||
'daff-md': true, | ||
})); | ||
}); | ||
}); |
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,57 @@ | ||
import { | ||
Directive, | ||
HostBinding, | ||
Input, | ||
OnChanges, | ||
OnInit, | ||
SimpleChanges, | ||
} from '@angular/core'; | ||
|
||
import { | ||
DaffSizable, | ||
DaffSizableEnum, | ||
DaffSizeAllType, | ||
} from './sizable'; | ||
|
||
@Directive({ | ||
selector: '[daffSizable]', | ||
standalone: true, | ||
}) | ||
|
||
export class DaffSizableDirective<T extends DaffSizeAllType> implements DaffSizable<T>, OnChanges, OnInit { | ||
/** | ||
* @docs-private | ||
*/ | ||
@HostBinding('class') get class() { | ||
return { | ||
'daff-xs': this.size === DaffSizableEnum.XSmall, | ||
'daff-sm': this.size === DaffSizableEnum.Small, | ||
'daff-md': this.size === DaffSizableEnum.Medium, | ||
'daff-lg': this.size === DaffSizableEnum.Large, | ||
'daff-xl': this.size === DaffSizableEnum.XLarge, | ||
}; | ||
} | ||
|
||
/** | ||
* Sets the size on a component. | ||
*/ | ||
@Input() size: T; | ||
|
||
/** | ||
* Sets a default size. | ||
*/ | ||
defaultSize: T; | ||
|
||
ngOnChanges(changes: SimpleChanges) { | ||
if(!changes.size.currentValue) { | ||
this.size = this.defaultSize; | ||
} | ||
} | ||
|
||
ngOnInit() { | ||
if(!this.size) { | ||
this.size = this.defaultSize; | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.