ngx-skeleton-loader 14.0.0 → 14.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -580
- package/fesm2022/ngx-skeleton-loader-testing.mjs +82 -0
- package/fesm2022/ngx-skeleton-loader-testing.mjs.map +1 -0
- package/fesm2022/ngx-skeleton-loader.mjs.map +1 -1
- package/package.json +11 -1
- package/types/ngx-skeleton-loader-testing.d.ts +34 -0
- package/types/ngx-skeleton-loader.d.ts +5 -3
- package/CHANGELOG.md +0 -751
- package/CODE_OF_CONDUCT.md +0 -77
- package/CONTRIBUTING.md +0 -34
- package/PUBLISHING_HOTFIX.md +0 -102
package/README.md
CHANGED
|
@@ -1,591 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# NgxSkeletonLoader
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
[](https://stackblitz.com/edit/ngx-skeleton-loader-sample)
|
|
5
|
-
[](https://stackblitz.com/edit/ngx-skeleton-loader-user-card-component-sample)
|
|
3
|
+
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.0.0.
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
[](https://npmjs.org/ngx-skeleton-loader)
|
|
5
|
+
## Code scaffolding
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
[](https://bundlephobia.com/result?p=ngx-skeleton-loader)
|
|
13
|
-
[](/LICENSE)
|
|
7
|
+
Run `ng generate component component-name --project ngx-skeleton-loader` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ngx-skeleton-loader`.
|
|
8
|
+
> Note: Don't forget to add `--project ngx-skeleton-loader` or else it will be added to the default project in your `angular.json` file.
|
|
14
9
|
|
|
15
|
-
|
|
10
|
+
## Build
|
|
16
11
|
|
|
17
|
-
|
|
12
|
+
Run `ng build ngx-skeleton-loader` to build the project. The build artifacts will be stored in the `dist/` directory.
|
|
18
13
|
|
|
19
|
-
|
|
14
|
+
## Publishing
|
|
20
15
|
|
|
21
|
-
|
|
16
|
+
After building your library with `ng build ngx-skeleton-loader`, go to the dist folder `cd dist/ngx-skeleton-loader` and run `npm publish`.
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
- Progressive rendering;
|
|
25
|
-
- Any other that you like :)
|
|
18
|
+
## Running unit tests
|
|
26
19
|
|
|
27
|
-
|
|
20
|
+
Run `ng test ngx-skeleton-loader` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
- [Install](#install)
|
|
31
|
-
- [Setup](#setup)
|
|
32
|
-
- [Development](#development)
|
|
33
|
-
- [Contribute](#contribute)
|
|
22
|
+
## Further help
|
|
34
23
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
Try out our demos on Stackblitz!
|
|
38
|
-
|
|
39
|
-
- [Usage: animations, appearance, and themes](https://ngx-skeleton-loader-sample.stackblitz.io)
|
|
40
|
-
- [User Card Component Loading simulation using NGX Skeleton Loader](https://ngx-skeleton-loader-user-card-component-sample.stackblitz.io)
|
|
41
|
-
|
|
42
|
-
## Install
|
|
43
|
-
|
|
44
|
-
You can get it on NPM installing `ngx-skeleton-loader` module as a project dependency.
|
|
45
|
-
|
|
46
|
-
```shell
|
|
47
|
-
npm install ngx-skeleton-loader --save
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## Setup
|
|
51
|
-
|
|
52
|
-
## Standalone Setup
|
|
53
|
-
|
|
54
|
-
Add `ngx-skeleton-loader` to your application's `app.config.ts` providers.
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
// app.config.ts
|
|
58
|
-
|
|
59
|
-
import { ApplicationConfig } from '@angular/core';
|
|
60
|
-
import { provideNgxSkeletonLoader } from 'ngx-skeleton-loader';
|
|
61
|
-
|
|
62
|
-
export const appConfig: ApplicationConfig = {
|
|
63
|
-
providers: [
|
|
64
|
-
provideNgxSkeletonLoader({
|
|
65
|
-
theme: {
|
|
66
|
-
extendsFromRoot: true,
|
|
67
|
-
height: '30px',
|
|
68
|
-
},
|
|
69
|
-
}),
|
|
70
|
-
]
|
|
71
|
-
};
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
After that, you can use the `ngx-skeleton-loader` component in your templates. Optionally you can pass configuration data into the component itself
|
|
75
|
-
|
|
76
|
-
- `ngx-skeleton-loader`: Handle the skeleton animation and the skeleton styles of your app;
|
|
77
|
-
|
|
78
|
-
```html
|
|
79
|
-
<div class="item">
|
|
80
|
-
<ngx-skeleton-loader count="5" appearance="circle" />
|
|
81
|
-
</div>
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## NgModule Setup
|
|
85
|
-
|
|
86
|
-
> ⚠️ `NgxSkeletonLoaderModule` and `NgxSkeletonLoaderModule.forRoot()` are **deprecated** and will be removed in a future major version. `NgxSkeletonLoaderComponent` is standalone: import it directly in your components and use `provideNgxSkeletonLoader()` for global configuration, as described in [Standalone Setup](#standalone-setup). It also works in applications using `NgModule`, by adding `NgxSkeletonLoaderComponent` to the module `imports` and `provideNgxSkeletonLoader()` to the module `providers`.
|
|
87
|
-
|
|
88
|
-
You'll need to add `NgxSkeletonLoaderModule` to your application module. So that, the `<ngx-skeleton-loader>` components will be accessible in your application.
|
|
89
|
-
|
|
90
|
-
```typescript
|
|
91
|
-
...
|
|
92
|
-
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
|
|
93
|
-
...
|
|
94
|
-
|
|
95
|
-
@NgModule({
|
|
96
|
-
declarations: [
|
|
97
|
-
YourAppComponent
|
|
98
|
-
],
|
|
99
|
-
imports: [
|
|
100
|
-
...
|
|
101
|
-
NgxSkeletonLoaderModule,
|
|
102
|
-
...
|
|
103
|
-
],
|
|
104
|
-
providers: [],
|
|
105
|
-
bootstrap: [YourAppComponent]
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
export class YourAppComponent {}
|
|
109
|
-
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
After that, you can use the `ngx-skeleton-loader` components in your templates, passing the configuration data into the component itself.
|
|
113
|
-
|
|
114
|
-
- `ngx-skeleton-loader`: Handle the skeleton animation and the skeleton styles of your app;
|
|
115
|
-
|
|
116
|
-
```html
|
|
117
|
-
<div class="item">
|
|
118
|
-
<ngx-skeleton-loader count="5" appearance="circle" />
|
|
119
|
-
</div>
|
|
120
|
-
<div class="item">
|
|
121
|
-
<!-- It will use `px` as default CSS measure unit -->
|
|
122
|
-
<ngx-skeleton-loader count="5" appearance="square" size="100" />
|
|
123
|
-
</div>
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Using `NgxSkeletonLoaderModule.forRoot()`
|
|
127
|
-
|
|
128
|
-
Also, you can import the module in your app by calling `NgxSkeletonLoaderModule.forRoot()` when adding it. So it will be available across your Angular application.
|
|
129
|
-
|
|
130
|
-
Importing the module this way also allows you to globally configure the default values for the `ngx-skeleton-loader` components in your application, in case you need some different default values for your app.
|
|
131
|
-
|
|
132
|
-
```typescript
|
|
133
|
-
...
|
|
134
|
-
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
|
|
135
|
-
...
|
|
136
|
-
|
|
137
|
-
@NgModule({
|
|
138
|
-
declarations: [
|
|
139
|
-
YourAppComponent
|
|
140
|
-
],
|
|
141
|
-
imports: [
|
|
142
|
-
...
|
|
143
|
-
NgxSkeletonLoaderModule.forRoot({ animation: 'pulse', loadingText: 'This item is actually loading...' }),
|
|
144
|
-
...
|
|
145
|
-
],
|
|
146
|
-
providers: [],
|
|
147
|
-
bootstrap: [YourAppComponent]
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
export class YourAppComponent {}
|
|
151
|
-
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
```html
|
|
155
|
-
<div class="item">
|
|
156
|
-
<ngx-skeleton-loader count="5" appearance="circle" />
|
|
157
|
-
<!-- above line will produce the rendering of 5 circles with the pulse animation and the aria-valuetext attribute set with "This item is actually loading...", since it was
|
|
158
|
-
configured via `NgxSkeletonLoaderModule.forRoot()`-->
|
|
159
|
-
|
|
160
|
-
<!-- It will render a component with `aria-valuetext` attribute set with `Loading section content`,
|
|
161
|
-
since it was passed directly via input attribute `loadingText` -->
|
|
162
|
-
<ngx-skeleton-loader count="5" loadingText="Loading section content" />
|
|
163
|
-
</div>
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
#### Extending `theme` via `NgxSkeletonLoaderModule.forRoot()`
|
|
167
|
-
|
|
168
|
-
> By default when using `NgxSkeletonLoaderModule.forRoot({ theme: /* ...list of CSS atributes */} })` the application is using this value as source of truth, overriding any local theming passed to `<ngx-skeleton-loader>` component via `[theme]` input. Check these steps in case you need to change this behaviour in your app
|
|
169
|
-
|
|
170
|
-
This method is also accepting the option of having a global theme and local theme inputs. You can enable it by passing `NgxSkeletonLoaderModule.forRoot({ theme: { extendsFromRoot: true, /* ...list of CSS atributes */} })` in your module. Quite simple, right? 😄
|
|
171
|
-
|
|
172
|
-
By using that configuration in your application, you should also be aware that:
|
|
173
|
-
|
|
174
|
-
- By default, every `<ngx-skeleton-loader>` component will use `theme` coming from `NgxSkeletonLoaderModule.forRoot()` as the source of truth
|
|
175
|
-
- If there's any CSS attribute on the component locally which overrides the CSS spec, it combines both themes, but overriding global CSS attributes in favor of local ones.
|
|
176
|
-
|
|
177
|
-
As an example:
|
|
178
|
-
|
|
179
|
-
```typescript
|
|
180
|
-
...
|
|
181
|
-
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
|
|
182
|
-
...
|
|
183
|
-
|
|
184
|
-
@NgModule({
|
|
185
|
-
declarations: [
|
|
186
|
-
YourAppComponent
|
|
187
|
-
],
|
|
188
|
-
imports: [
|
|
189
|
-
...
|
|
190
|
-
NgxSkeletonLoaderModule.forRoot({
|
|
191
|
-
theme: {
|
|
192
|
-
// Enabliong theme combination
|
|
193
|
-
extendsFromRoot: true,
|
|
194
|
-
// ... list of CSS theme attributes
|
|
195
|
-
height: '30px',
|
|
196
|
-
},
|
|
197
|
-
}),
|
|
198
|
-
...
|
|
199
|
-
],
|
|
200
|
-
providers: [],
|
|
201
|
-
bootstrap: [YourAppComponent]
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
export class YourAppComponent {}
|
|
205
|
-
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
```html
|
|
209
|
-
<div class="item">
|
|
210
|
-
<ngx-skeleton-loader />
|
|
211
|
-
<!-- above line will produce a skeleton component using `height: 30px;`" -->
|
|
212
|
-
<ngx-skeleton-loader [theme]="{background: 'blue'}" />
|
|
213
|
-
<!-- above line will produce a skeleton component using `height: 30px; background: blue;`" -->
|
|
214
|
-
<ngx-skeleton-loader [theme]="{height: '50px', background: 'red'}" />
|
|
215
|
-
<!-- above line will produce a skeleton component using `height: 50px; background: red;`" -->
|
|
216
|
-
</div>
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
## Angular 17+ Deferrable Views example
|
|
220
|
-
|
|
221
|
-
```html
|
|
222
|
-
<div class="item">
|
|
223
|
-
@defer {
|
|
224
|
-
<my-item-view />
|
|
225
|
-
} @placeholder (minimum 1000ms) {
|
|
226
|
-
<ngx-skeleton-loader />
|
|
227
|
-
}
|
|
228
|
-
</div>
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
## Layout
|
|
233
|
-
|
|
234
|
-
`<ngx-skeleton-loader>` is rendered as a block element (`display: block`), taking the full width of its container. To render skeletons side by side (e.g. an avatar next to a title), use a flex or grid container:
|
|
235
|
-
|
|
236
|
-
```html
|
|
237
|
-
<div style="display: flex; gap: 10px; align-items: center">
|
|
238
|
-
<ngx-skeleton-loader appearance="circle" />
|
|
239
|
-
<ngx-skeleton-loader width="200" />
|
|
240
|
-
</div>
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
## WAI-ARIA values
|
|
244
|
-
|
|
245
|
-
- loadingText - _default_ `Loading...`: attribute that defines the text value for `aria-valuetext` attribute. Defaults to "Loading..."
|
|
246
|
-
- `aria-label` - _default_ `loading`: you can add `ariaLabel` as input of the component to set a different value.
|
|
247
|
-
|
|
248
|
-
WAI-ARIA attributes (`role="progressbar"`, `aria-busy`, `aria-valuemin`, `aria-valuemax`, `aria-label` and `aria-valuetext`) are applied once in the `<ngx-skeleton-loader>` element, so screen readers announce a single progress bar per component - regardless of `count`. The skeleton items inside of it are hidden from assistive technologies via `aria-hidden="true"`.
|
|
249
|
-
|
|
250
|
-
## Appearance
|
|
251
|
-
|
|
252
|
-
You can also define which appearance want to use in your skeleton loader by passing the options in your component via `[appearance]` attribute.
|
|
253
|
-
|
|
254
|
-
### Options
|
|
255
|
-
|
|
256
|
-
- `''` - _default_: it will use it `''` as appearance. At the end, it will render like a line;
|
|
257
|
-
- `line`: it will render like a line. This is the same behavior as passing an empty string;
|
|
258
|
-
- `circle`: it will use `circle` as appearance. Great for avatar skeletons, for example :);
|
|
259
|
-
- `square`: it will use `square` as appearance and render it appropriately. Great for cards and images, for example; It also requires `size` to be passed through the component - `size` has default size of `40px` and it has `measureUnit` as optional way to change default CSS measure unit from `px` to one of the valid options: `px`, `em`, `rem`, `%`, `vh`, `vw`
|
|
260
|
-
- `custom-content`: it will NOT add any appearance. Great for custom content, such as SVG, internal components and such. Although not rendering appearance, animation will be added unless component has `animation="false"` prop;
|
|
261
|
-
|
|
262
|
-
### Appearance props (specific for `square`)
|
|
263
|
-
|
|
264
|
-
When setting `square` as appearance, your component can also use these other input attributes to configure it properly
|
|
265
|
-
- `size` - default _40_: number to be passed as definition for `width` and `height`. If not passed, it defaults to `40`. It accepts decimal values (e.g. `1.5`) and also a CSS measure unit as suffix (e.g. `10rem`), which takes precedence over `measureUnit`
|
|
266
|
-
- `measureUnit` - default _px_: CSS measure unit to be used for `width` and `height`. If not passed, it defaults to `px`. Valid options: `px`, `em`, `rem`, `%`, `vh`, `vw`
|
|
267
|
-
|
|
268
|
-
## Animations
|
|
269
|
-
|
|
270
|
-
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.
|
|
271
|
-
|
|
272
|
-
### Options
|
|
273
|
-
|
|
274
|
-
- `"false"` (as string): it will disable the animation;
|
|
275
|
-
- `false` (as boolean): it will disable the animation. Animation will receive `false` as string when attribute field it's not using binding. Component now can receive `false` (boolean), "false" (string), or any other animation type via binding;
|
|
276
|
-
- `progress` - _default_: it will use it `progress` as animation;
|
|
277
|
-
- `progress-dark`: it will use it `progress-dark` as animation. Recommended if your color schema is darken;
|
|
278
|
-
- `pulse`: it will use `pulse` as animation;
|
|
279
|
-
- `pulse-dark`: it will use `pulse-dark` as animation. Recommended if your color schema is darken;
|
|
280
|
-
- `wave`: it will use `wave` as animation. Similar to `progress`, but with an oblique shimmer;
|
|
281
|
-
|
|
282
|
-
> `progress` is the default animation, used as the single one previously. If you don't pass the animation attribute, it defaults to `progress`.
|
|
283
|
-
|
|
284
|
-
> `progress` and `progress-dark` animations support right-to-left (RTL) layouts: when the skeleton is rendered inside an element with `dir="rtl"` (e.g. `<html dir="rtl">`), the shimmer crosses the skeleton from right to left.
|
|
285
|
-
|
|
286
|
-
```html
|
|
287
|
-
<!--
|
|
288
|
-
If you need to change all the background wrapper
|
|
289
|
-
you need to apply the style changes on the
|
|
290
|
-
`ngx-skeleton-loader` component wrapper
|
|
291
|
-
-->
|
|
292
|
-
<div class="item">
|
|
293
|
-
<!-- Disables the animation -->
|
|
294
|
-
<ngx-skeleton-loader animation="false" />
|
|
295
|
-
<!-- Disables the animation, but receiving boolean value from binding -->
|
|
296
|
-
<!-- Via binding it can receive `false` (boolean), "false" (string), or any other animation type -->
|
|
297
|
-
<ngx-skeleton-loader [animation]="classAttributeWithBooleanFalseValue" />
|
|
298
|
-
<!-- Uses `progress` as animation -->
|
|
299
|
-
<ngx-skeleton-loader animation="progress" />
|
|
300
|
-
<ngx-skeleton-loader />
|
|
301
|
-
<!-- Uses `pulse` as animation -->
|
|
302
|
-
<ngx-skeleton-loader animation="pulse" />
|
|
303
|
-
<!-- Uses `wave` as animation -->
|
|
304
|
-
<ngx-skeleton-loader animation="wave" />
|
|
305
|
-
</div>
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
> You can check the code details in the [Stackblitz Live Demo Link](https://stackblitz.com/edit/ngx-skeleton-loader-sample?file=app%2Fapp.component.html)
|
|
309
|
-
|
|
310
|
-
### Stagger effect
|
|
311
|
-
|
|
312
|
-
You can delay the animation of each skeleton item based on its position, creating a cascade effect, via `--ngx-skeleton-loader-animation-stagger` CSS custom property. It's `0s` by default (no delay), and it can be set in any ancestor element or via `[theme]` attribute.
|
|
313
|
-
|
|
314
|
-
```html
|
|
315
|
-
<!-- Each item starts its animation 150ms after the previous one -->
|
|
316
|
-
<ngx-skeleton-loader count="5" [theme]="{ '--ngx-skeleton-loader-animation-stagger': '150ms' }" />
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
Each item also exposes its index (starting from `0`) via `--ngx-skeleton-loader-index` CSS custom property, so you can use it in [custom animations](#custom-animations) as well:
|
|
320
|
-
|
|
321
|
-
```css
|
|
322
|
-
.skeleton-loader.animation-my-wave {
|
|
323
|
-
animation: my-wave 1.5s ease-in-out infinite;
|
|
324
|
-
animation-delay: calc(var(--ngx-skeleton-loader-index, 0) * 100ms);
|
|
325
|
-
}
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
### Custom animations
|
|
329
|
-
|
|
330
|
-
You can also create your own animations. These are the steps:
|
|
331
|
-
|
|
332
|
-
1. Register your animation name via TypeScript declaration merging, extending `NgxSkeletonLoaderCustomAnimations` interface. The file needs to be a module - that's why it has the `import` statement - otherwise it will replace the module types instead of extending them
|
|
333
|
-
|
|
334
|
-
```ts
|
|
335
|
-
// file: `src/ngx-skeleton-loader.d.ts`
|
|
336
|
-
import 'ngx-skeleton-loader';
|
|
337
|
-
|
|
338
|
-
declare module 'ngx-skeleton-loader' {
|
|
339
|
-
interface NgxSkeletonLoaderCustomAnimations {
|
|
340
|
-
'my-wave': true;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
2. Add your animation styles in a **global stylesheet** (e.g. `styles.css`). The skeleton will receive your animation name as CSS class with `animation-` prefix - in this case, `animation-my-wave`. The prefix avoids collisions with `ngx-skeleton-loader` internal classes, such as `circle` or `progress`
|
|
346
|
-
|
|
347
|
-
```css
|
|
348
|
-
/* file: `styles.css` */
|
|
349
|
-
.skeleton-loader.animation-my-wave {
|
|
350
|
-
will-change: opacity;
|
|
351
|
-
animation: my-wave 1.5s ease-in-out infinite;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
@keyframes my-wave {
|
|
355
|
-
50% {
|
|
356
|
-
opacity: 0.5;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
3. Use it as any other animation
|
|
362
|
-
|
|
363
|
-
```html
|
|
364
|
-
<ngx-skeleton-loader animation="my-wave" />
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
```ts
|
|
368
|
-
provideNgxSkeletonLoader({ animation: 'my-wave' });
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
Some details to be aware of:
|
|
372
|
-
|
|
373
|
-
- **Type checking**: invalid animation names raise a TypeScript error (e.g. `Type '"my-wavee"' is not assignable to type ... Did you mean '"my-wave"'?`). In templates, static attributes such as `animation="my-wave"` are checked only when `strictTemplates` is enabled in your `tsconfig.json` - which is the default for new Angular projects
|
|
374
|
-
- **Global styles**: since component styles are encapsulated by Angular, your animation styles need to be added in a global stylesheet or via `::ng-deep`. Styles added in your component stylesheet won't reach the skeleton
|
|
375
|
-
- **Reduced motion**: custom animations - including the ones applied to `::before` and `::after` pseudo-elements - are disabled automatically when the user enabled the `Reduce Motion` option via operational system and/or browser, as it happens with the built-in animations
|
|
376
|
-
|
|
377
|
-
## Theming
|
|
378
|
-
|
|
379
|
-
You can also define different styles for the skeleton loader by passing an object with the css styles - in dashed case - into the component via `[theme]` attribute.
|
|
380
|
-
|
|
381
|
-
```html
|
|
382
|
-
<!--
|
|
383
|
-
If you need to change all the background wrapper
|
|
384
|
-
you need to apply the style changes on the
|
|
385
|
-
`ngx-skeleton-loader` component wrapper
|
|
386
|
-
-->
|
|
387
|
-
|
|
388
|
-
<div style="background: #FF0001; padding: 10px;">
|
|
389
|
-
<ngx-skeleton-loader
|
|
390
|
-
count="5"
|
|
391
|
-
[theme]="{
|
|
392
|
-
'border-radius': '5px',
|
|
393
|
-
height: '50px',
|
|
394
|
-
'background-color': '#992929',
|
|
395
|
-
border: '1px solid white'
|
|
396
|
-
}"
|
|
397
|
-
/>
|
|
398
|
-
</div>
|
|
399
|
-
```
|
|
400
|
-
|
|
401
|
-
The [theme] attribute now accepts the same configuration as `[style]` as well. That means you can manage to use like you're doing with the built-in directive, having a pleasure and beautiful experience
|
|
402
|
-
|
|
403
|
-
```html
|
|
404
|
-
<!--
|
|
405
|
-
Note that we are using a combination of styles and [style] inside theme object,
|
|
406
|
-
having `height.px` receiving a number and `background-color` receiving a HEX Color
|
|
407
|
-
-->
|
|
408
|
-
<div style="background: #FF0001; padding: 10px;">
|
|
409
|
-
<ngx-skeleton-loader
|
|
410
|
-
count="5"
|
|
411
|
-
[theme]="{
|
|
412
|
-
'height.px': 50,
|
|
413
|
-
'background-color': '#992929'
|
|
414
|
-
}"
|
|
415
|
-
/>
|
|
416
|
-
</div>
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
### `width`, `height` and `borderRadius` shortcuts
|
|
420
|
-
|
|
421
|
-
For the most common theming cases, you can use `width`, `height` and `borderRadius` attributes instead of `[theme]`. They accept the same values as `size` - numbers (e.g. `100`), decimals (e.g. `1.5`) or values with CSS measure unit (e.g. `50%`, `10rem`) - and values without unit use `measureUnit` (`px` by default). They override the same styles passed via `[theme]`.
|
|
422
|
-
|
|
423
|
-
```html
|
|
424
|
-
<!-- Same as [theme]="{ width: '100px', height: '20px', 'border-radius': '8px' }" -->
|
|
425
|
-
<ngx-skeleton-loader width="100" height="20" borderRadius="8" />
|
|
426
|
-
<!-- Using CSS measure units -->
|
|
427
|
-
<ngx-skeleton-loader width="50%" height="1.5" measureUnit="rem" />
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
> For `square` appearance, `size` takes precedence over `width` and `height`.
|
|
431
|
-
|
|
432
|
-
### Theming via CSS custom properties
|
|
433
|
-
|
|
434
|
-
You can also customize skeletons via CSS custom properties (CSS variables). They can be set in any ancestor element - such as `:root`, `body`, a wrapper element in your component stylesheet - or directly via `[theme]` attribute, and they are inherited by every `<ngx-skeleton-loader>` inside of it.
|
|
435
|
-
|
|
436
|
-
| CSS custom property | Default value | Description |
|
|
437
|
-
| --- | --- | --- |
|
|
438
|
-
| `--ngx-skeleton-loader-color-scheme` | `light` | Color scheme used by the skeleton. Use `light dark` to follow the user's preference (automatic dark mode) or `dark` to force dark colors. See [Color scheme (dark mode)](#color-scheme-dark-mode) |
|
|
439
|
-
| `--ngx-skeleton-loader-base-color` | `light-dark(rgb(239, 241, 246), rgb(48, 52, 61))` | Skeleton background color. The dark value is used only when dark mode is enabled |
|
|
440
|
-
| `--ngx-skeleton-loader-light-mode-color` | `light-dark(rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.1))` | Shimmer color used by `progress` and `wave` animations. The dark value is used only when dark mode is enabled |
|
|
441
|
-
| `--ngx-skeleton-loader-light-mode-color-to` | `rgba(255, 255, 255, 0)` | Shimmer edges color used by `progress` animation |
|
|
442
|
-
| `--ngx-skeleton-loader-dark-mode-color` | `rgba(0, 0, 0, 0.2)` | Shimmer color used by `progress-dark` animation and background color used by `pulse-dark` animation |
|
|
443
|
-
| `--ngx-skeleton-loader-dark-mode-color-to` | `transparent` | Shimmer edges color used by `progress-dark` animation |
|
|
444
|
-
| `--ngx-skeleton-loader-animation-duration` | `2s` | Duration of the animations |
|
|
445
|
-
| `--ngx-skeleton-loader-animation-stagger` | `0s` | Delay between the animation of each item. See [Stagger effect](#stagger-effect) |
|
|
446
|
-
| `--ngx-skeleton-loader-background-image-light-mode` | gradient based on `light-mode` colors | Full shimmer `background-image` used by `progress` animation |
|
|
447
|
-
| `--ngx-skeleton-loader-background-image-dark-mode` | gradient based on `dark-mode` colors | Full shimmer `background-image` used by `progress-dark` animation |
|
|
448
|
-
|
|
449
|
-
```css
|
|
450
|
-
/* file: `styles.css` - applying it globally */
|
|
451
|
-
:root {
|
|
452
|
-
--ngx-skeleton-loader-base-color: rgb(224, 231, 255);
|
|
453
|
-
--ngx-skeleton-loader-light-mode-color: rgba(99, 102, 241, 0.25);
|
|
454
|
-
--ngx-skeleton-loader-animation-duration: 1s;
|
|
455
|
-
}
|
|
456
|
-
```
|
|
457
|
-
|
|
458
|
-
```css
|
|
459
|
-
/* file: `my-component.component.css` - applying it only for skeletons inside of `.my-wrapper` element */
|
|
460
|
-
.my-wrapper {
|
|
461
|
-
--ngx-skeleton-loader-base-color: rgb(224, 231, 255);
|
|
462
|
-
}
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
```html
|
|
466
|
-
<!-- applying it to a specific skeleton via `[theme]` attribute -->
|
|
467
|
-
<ngx-skeleton-loader [theme]="{ '--ngx-skeleton-loader-base-color': 'rgb(224, 231, 255)' }" />
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
### Color scheme (dark mode)
|
|
471
|
-
|
|
472
|
-
Skeletons use light colors by default, regardless of the user's color scheme preference - as in previous versions. Dark mode is **opt-in**: you can enable it via `colorScheme` - as component attribute or via `provideNgxSkeletonLoader()`/`NgxSkeletonLoaderModule.forRoot()` config - or via `--ngx-skeleton-loader-color-scheme` CSS custom property.
|
|
473
|
-
|
|
474
|
-
- `light` - _default_: light colors, regardless of the user's color scheme preference;
|
|
475
|
-
- `auto`: follows the user's color scheme preference (OS and/or browser), switching to dark colors automatically;
|
|
476
|
-
- `dark`: forces dark colors;
|
|
477
|
-
|
|
478
|
-
```html
|
|
479
|
-
<!-- Light colors (default) -->
|
|
480
|
-
<ngx-skeleton-loader />
|
|
481
|
-
<!-- Follows the user's color scheme preference -->
|
|
482
|
-
<ngx-skeleton-loader colorScheme="auto" />
|
|
483
|
-
<!-- Forces dark colors -->
|
|
484
|
-
<ngx-skeleton-loader colorScheme="dark" />
|
|
485
|
-
```
|
|
486
|
-
|
|
487
|
-
```ts
|
|
488
|
-
// Enabling automatic dark mode for every skeleton
|
|
489
|
-
provideNgxSkeletonLoader({ colorScheme: 'auto' });
|
|
490
|
-
```
|
|
491
|
-
|
|
492
|
-
```css
|
|
493
|
-
/* Enabling automatic dark mode for every skeleton via CSS */
|
|
494
|
-
:root {
|
|
495
|
-
--ngx-skeleton-loader-color-scheme: light dark;
|
|
496
|
-
}
|
|
497
|
-
```
|
|
498
|
-
|
|
499
|
-
> If your application has its own theme switcher - instead of following the user's preference - use `light` or `dark` based on your application theme.
|
|
500
|
-
|
|
501
|
-
CSS custom properties are applied in both color schemes. When dark mode is enabled, you can use [`light-dark()`](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark) to define different values per color scheme:
|
|
502
|
-
|
|
503
|
-
```css
|
|
504
|
-
:root {
|
|
505
|
-
--ngx-skeleton-loader-color-scheme: light dark;
|
|
506
|
-
--ngx-skeleton-loader-base-color: light-dark(rgb(254, 243, 199), rgb(120, 53, 15));
|
|
507
|
-
}
|
|
508
|
-
```
|
|
509
|
-
|
|
510
|
-
### ⚠️ This is here only as a documentation, but it's not encouraged to be used. Please consider use it with caution ⚠️
|
|
511
|
-
|
|
512
|
-
Also, you can use CSS to add theme styles into your component. However, there are some implications:
|
|
513
|
-
|
|
514
|
-
- You're using `:host` in your stylesheet, which means **you are aware of any possible problem `:host` can create for your app at that level since it's based on [`:host` DOM style scoping](https://developer.mozilla.org/en-US/docs/Web/CSS/:host)**
|
|
515
|
-
- You're adding stylesheet based on `<ngx-skeleton-loader>` internal classes. It means that **class naming changes on module's side will be breaking changes for your application as well**.
|
|
516
|
-
|
|
517
|
-
As an example, your Component file is like this
|
|
518
|
-
|
|
519
|
-
```typescript
|
|
520
|
-
import { Component } from '@angular/core';
|
|
521
|
-
|
|
522
|
-
@Component({
|
|
523
|
-
selector: 'my-ngx-skeleton-loader-with-theming',
|
|
524
|
-
templateUrl: './my-ngx-skeleton-loader-with-theming.component.html',
|
|
525
|
-
styleUrls: ['./my-ngx-skeleton-loader-with-theming.component.css'],
|
|
526
|
-
})
|
|
527
|
-
export class MyNGXSkeletonLoaderWithThemingComponent {
|
|
528
|
-
/* ... code goes here*/
|
|
529
|
-
}
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
And your component HTML code is
|
|
533
|
-
|
|
534
|
-
```html
|
|
535
|
-
<!--
|
|
536
|
-
file: my-ngx-skeleton-loader-with-theming.component.html
|
|
537
|
-
|
|
538
|
-
As an example, it's not using themes via [theme] attributes.
|
|
539
|
-
-->
|
|
540
|
-
|
|
541
|
-
<ngx-skeleton-loader count="5" animation="pulse" />
|
|
542
|
-
```
|
|
543
|
-
|
|
544
|
-
You can apply theme changes in our stylesheet. At the end it will be
|
|
545
|
-
|
|
546
|
-
```css
|
|
547
|
-
/* file: `my-ngx-skeleton-loader-with-theming.component.css`
|
|
548
|
-
*
|
|
549
|
-
* You can find more details about `:host` at
|
|
550
|
-
* Angular Component Style Docs https://angular.io/guide/component-styles#host
|
|
551
|
-
*/
|
|
552
|
-
:host >>> ngx-skeleton-loader .skeleton-loader {
|
|
553
|
-
border-radius: 5px;
|
|
554
|
-
height: 50px;
|
|
555
|
-
background-color: #992929;
|
|
556
|
-
border: 1px solid white;
|
|
557
|
-
}
|
|
558
|
-
```
|
|
559
|
-
|
|
560
|
-
> You should change the styles on the skeleton wrapper element in case you need to change the background color. You can check the code details in the [Stackblitz Live Demo Link](https://stackblitz.com/edit/ngx-skeleton-loader-sample?file=app%2Fapp.component.html) or check it out a content load simulation [in this Stackblitz Live Demo Link](https://stackblitz.com/edit/ngx-skeleton-loader-user-card-component-sample?file=app%2Fapp.component.html)
|
|
561
|
-
|
|
562
|
-
## Development
|
|
563
|
-
|
|
564
|
-
### Run demo locally
|
|
565
|
-
|
|
566
|
-
1. This project uses [Angular CLI](https://cli.angular.io/) as base. That means you just need to run `npm start` and access the link `http://localhost:4200` in your browser
|
|
567
|
-
|
|
568
|
-
### Run tests
|
|
569
|
-
|
|
570
|
-
1. Run `npm test` for run tests. In case you want to test using watch, please use `npm run tdd`
|
|
571
|
-
|
|
572
|
-
### Check minimum peer dependency
|
|
573
|
-
|
|
574
|
-
1. Run `npm run check:min-peer` to build the package and install it in an Angular app using the minimum `peerDependencies` version (`integration/angular-min-peer`). It also runs in CI (GitHub Actions)
|
|
575
|
-
|
|
576
|
-
### Publish
|
|
577
|
-
|
|
578
|
-
this project is using `np` package to publish, which makes things straightforward. EX: `npx np <patch|minor|major> --no-yarn --no-cleanup --contents=dist/ngx-skeleton-loader`
|
|
579
|
-
|
|
580
|
-
> For more details, [please check np package on npmjs.com](https://www.npmjs.com/package/np)
|
|
581
|
-
|
|
582
|
-
## Contribute
|
|
583
|
-
|
|
584
|
-
For any type of contribution, please follow the instructions in [CONTRIBUTING.md](https://github.com/willmendesneto/ngx-skeleton-loader/blob/main/CONTRIBUTING.md) and read [CODE_OF_CONDUCT.md](https://github.com/willmendesneto/ngx-skeleton-loader/blob/main/CODE_OF_CONDUCT.md) and [PUBLISHING_HOTFIX.md](https://github.com/willmendesneto/ngx-skeleton-loader/blob/main/PUBLISHING_HOTFIX.md) files.
|
|
585
|
-
|
|
586
|
-
## Author
|
|
587
|
-
|
|
588
|
-
**Wilson Mendes (willmendesneto)**
|
|
589
|
-
|
|
590
|
-
- <https://instagram.com/willmendesneto>
|
|
591
|
-
- <http://github.com/willmendesneto>
|
|
24
|
+
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
|