-
-
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(design)!: change daffSkeletonMixin to a directive (#2923)
BREAKING CHANGE: daffSkeletonMixin has been removed in favor of DaffSkeletonableDirective. Update usage by using the hostDirective feature.
- Loading branch information
Showing
11 changed files
with
126 additions
and
156 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
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 @@ | ||
export { DaffSkeletonable } from './skeletonable'; | ||
export { daffSkeletonableMixin } from './skeletonable-mixin'; | ||
export { DaffSkeletonableDirective } from './skeletonable.directive'; |
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
libs/design/src/core/skeletonable/skeletonable.directive.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,72 @@ | ||
import { | ||
Component, | ||
DebugElement, | ||
} from '@angular/core'; | ||
import { | ||
waitForAsync, | ||
ComponentFixture, | ||
TestBed, | ||
} from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { DaffSkeletonableDirective } from './skeletonable.directive'; | ||
|
||
@Component({ | ||
template: ` | ||
<div daffSkeletonable | ||
[skeleton]="skeleton"> | ||
</div>`, | ||
}) | ||
|
||
class WrapperComponent { | ||
skeleton: boolean; | ||
} | ||
|
||
describe('@daffodil/design | DaffSkeletonableDirective', () => { | ||
let wrapper: WrapperComponent; | ||
let de: DebugElement; | ||
let fixture: ComponentFixture<WrapperComponent>; | ||
let directive: DaffSkeletonableDirective; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
WrapperComponent, | ||
], | ||
imports: [ | ||
DaffSkeletonableDirective, | ||
], | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(WrapperComponent); | ||
wrapper = fixture.componentInstance; | ||
de = fixture.debugElement.query(By.css('[daffSkeletonable]')); | ||
directive = de.injector.get(DaffSkeletonableDirective); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(wrapper).toBeTruthy(); | ||
expect(directive).toBeTruthy(); | ||
}); | ||
|
||
it('should take skeleton as an input', () => { | ||
expect(directive.skeleton).toEqual(wrapper.skeleton); | ||
}); | ||
|
||
it('should add a class of "daff-skeleton" to the host element when skeleton is true', () => { | ||
wrapper.skeleton = true; | ||
fixture.detectChanges(); | ||
|
||
expect(de.classes).toEqual(jasmine.objectContaining({ | ||
'daff-skeleton': true, | ||
})); | ||
}); | ||
|
||
it('should not add a class of "daff-skeleton" to the host element when skeleton is false', () => { | ||
expect(de.classes['daff-skeleton']).toBeUndefined(); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
libs/design/src/core/skeletonable/skeletonable.directive.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,24 @@ | ||
import { | ||
Directive, | ||
HostBinding, | ||
Input, | ||
} from '@angular/core'; | ||
|
||
/** | ||
* The `DaffSkeletonableDirective` allows a component to display a skeleton loading | ||
* state by conditionally applying a CSS class. This is useful for indicating to | ||
* users that content is loading or being processed. This directive can be used to | ||
* apply a skeleton loading state to any component by toggling the `skeleton` | ||
* input property. When `skeleton` is `true`, the `daff-skeleton` CSS class | ||
* is applied, which should style the component to look like a loading placeholder. | ||
* | ||
* The styles for the`daff-skeleton` class should be defined component's | ||
* stylesheets to display the loading state as desired. | ||
*/ | ||
@Directive({ | ||
selector: '[daffSkeletonable]', | ||
standalone: true, | ||
}) | ||
export class DaffSkeletonableDirective { | ||
@Input() @HostBinding('class.daff-skeleton') skeleton = false; | ||
} |
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