Skip to content

Commit ff2daf5

Browse files
feat: adding validation for appearance in dev loop
1 parent e118a55 commit ff2daf5

File tree

5 files changed

+60
-10
lines changed

5 files changed

+60
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
- if `count` is not a numeric value, it will use the default value as `1`
1414
- if `animation` is not a valid attribute, it will use the default value as `progress`
1515
- PS: The other values alredy have a fallback, so nothing to worry here
16+
- Adding error feedback for `appearance` attribute in case of wrong configuration. Now it will show a error message on the console in case of receiving a wrong value
1617

1718
### Updated
1819

1920
- Adding `ngOnChange` to validate `count` input in case of changes via binding
21+
- Updating `README.md` with information about `appearance` and `theme` usage.
2022

2123
## [2.8.0][] - 2021-02-18
2224

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ export class YourAppComponent {}
118118

119119
- loadingText - _default_ `Loading...`: attribute that defines the text value for `aria-valuetext` attribute. Defaults to "Loading..."
120120

121+
## Appearance
122+
123+
You can also define which appearance want to use in your skeleton loader by passing the options in your component via `[appearance]` attribute.
124+
125+
### Options
126+
127+
- `''` - _default_: it will use it `''` as appearance. At the end, it will render like a line, but line is not a expected appearance to be passed;
128+
- `circle`: it will use `circle` as appearance. Great for avatar skeletons, for example :);
129+
121130
## Animations
122131

123132
You can also define which CSS animation you want to use - even not use any, if it's the case - in your skeleton loader by passing the options in your component via `[animation]` attribute.
@@ -178,6 +187,24 @@ you need to apply the style changes on the
178187
</div>
179188
```
180189

190+
The [theme] attribute now accepts the same configuration as `ngStyle` as well. That means you can manage to use like you're doing with the built-in directive, having a pleasure and beautiful experience
191+
192+
```html
193+
<!--
194+
Note that we are using a combination of styles and ngStyle inside theme object,
195+
having `height.px` receiving a number and `background-color` receiving a HEX Color
196+
-->
197+
<div style="background: #FF0001; padding: 10px;">
198+
<ngx-skeleton-loader
199+
count="5"
200+
[theme]="{
201+
'height.px': 50,
202+
'background-color': '#992929'
203+
}"
204+
></ngx-skeleton-loader>
205+
</div>
206+
```
207+
181208
### ⚠️ This is here only as a documentation, but it's not encouraged to be used. Please consider use it with caution ⚠️
182209

183210
Also, you can use CSS to add theme styles into your component. However, there are some implications:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"bundlesize": [
5050
{
5151
"path": "./dist/ngx-skeleton-loader/bundles/ngx-skeleton-loader.umd.min.js",
52-
"maxSize": "1.6KB"
52+
"maxSize": "1.7KB"
5353
}
5454
],
5555
"dependencies": {

projects/ngx-skeleton-loader/src/lib/ngx-skeleton-loader.component.spec.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ import { NgxSkeletonLoaderComponent } from './ngx-skeleton-loader.component';
4343
<ngx-skeleton-loader [count]="invalidValueIncount"></ngx-skeleton-loader>
4444
</div>
4545
46+
<div class="skeletons-appearance-invalid-option">
47+
<ngx-skeleton-loader appearance="invalid-appearance"></ngx-skeleton-loader>
48+
</div>
49+
4650
<div class="skeletons-with-count">
4751
<ngx-skeleton-loader count="2"></ngx-skeleton-loader>
4852
</div>
@@ -78,8 +82,8 @@ describe('NgxSkeletonLoaderComponent', () => {
7882
}),
7983
);
8084

81-
it('should console 2 errors if `animation` and `count` receives invalid options and is running in development mode', () => {
82-
expect(console.error).toHaveBeenCalledTimes(2);
85+
it('should console 3 errors if `animation`, `appearance` and `count` receives invalid options and is running in development mode', () => {
86+
expect(console.error).toHaveBeenCalledTimes(3);
8387
});
8488

8589
it('should console errors if `animation` is an invalid option and is running in development mode', () => {
@@ -89,20 +93,27 @@ describe('NgxSkeletonLoaderComponent', () => {
8993
);
9094
});
9195

92-
it('should console errors if `animation` is an invalid option and is running in development mode', () => {
96+
it('should console errors if `count` is an invalid option and is running in development mode', () => {
9397
expect(console.error).toHaveBeenCalledWith(
9498
// tslint:disable-next-line: max-line-length
9599
`\`NgxSkeletonLoaderComponent\` need to receive 'count' a numeric value. Forcing default to "1".`,
96100
);
97101
});
98102

103+
it('should console errors if `appearance` is an invalid option and is running in development mode', () => {
104+
expect(console.error).toHaveBeenCalledWith(
105+
// tslint:disable-next-line: max-line-length
106+
`\`NgxSkeletonLoaderComponent\` need to receive 'appearance' as: circle or empty string. Forcing default to "''".`,
107+
);
108+
});
109+
99110
it('should add all relevant WAI-ARIA `aria-` attributes in all ngx-skeleton-loader', () => {
100-
expect(fixture.nativeElement.querySelectorAll('[aria-busy="true"]').length).toBe(13);
101-
expect(fixture.nativeElement.querySelectorAll('[aria-valuemin="0"]').length).toBe(13);
102-
expect(fixture.nativeElement.querySelectorAll('[aria-valuemax="100"]').length).toBe(13);
103-
expect(fixture.nativeElement.querySelectorAll('[aria-valuetext]').length).toBe(13);
104-
expect(fixture.nativeElement.querySelectorAll('[role="progressbar"]').length).toBe(13);
105-
expect(fixture.nativeElement.querySelectorAll('[tabindex="0"]').length).toBe(13);
111+
expect(fixture.nativeElement.querySelectorAll('[aria-busy="true"]').length).toBe(14);
112+
expect(fixture.nativeElement.querySelectorAll('[aria-valuemin="0"]').length).toBe(14);
113+
expect(fixture.nativeElement.querySelectorAll('[aria-valuemax="100"]').length).toBe(14);
114+
expect(fixture.nativeElement.querySelectorAll('[aria-valuetext]').length).toBe(14);
115+
expect(fixture.nativeElement.querySelectorAll('[role="progressbar"]').length).toBe(14);
116+
expect(fixture.nativeElement.querySelectorAll('[tabindex="0"]').length).toBe(14);
106117
});
107118

108119
it('should use progress as default animation if `animation` is not passed as component attribute', () => {

projects/ngx-skeleton-loader/src/lib/ngx-skeleton-loader.component.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ export class NgxSkeletonLoaderComponent implements OnInit, AfterViewInit, OnDest
7676
}
7777
this.animation = 'progress';
7878
}
79+
80+
if (['circle', ''].indexOf(String(this.appearance)) === -1) {
81+
// Shows error message only in Development
82+
if (isDevMode()) {
83+
console.error(
84+
`\`NgxSkeletonLoaderComponent\` need to receive 'appearance' as: circle or empty string. Forcing default to "''".`,
85+
);
86+
}
87+
this.appearance = '';
88+
}
7989
}
8090

8191
ngOnChanges(changes: SimpleChanges) {

0 commit comments

Comments
 (0)