Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kit): Skeleton add new directive #6934

Merged
merged 4 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions projects/addon-doc/components/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TUI_DOC_ICONS} from '@taiga-ui/addon-doc/tokens';
import {TuiSwipeService} from '@taiga-ui/cdk';
import type {TuiBrightness} from '@taiga-ui/core';
import {TuiModeDirective} from '@taiga-ui/core';
import {distinctUntilChanged, map, share, startWith} from 'rxjs';
import {distinctUntilChanged, map, shareReplay, startWith} from 'rxjs';

@Component({
selector: 'tui-doc-main',
Expand All @@ -38,7 +38,7 @@ export class TuiDocMainComponent {
startWith(null),
map(() => this.night.value),
distinctUntilChanged(),
share(),
shareReplay({bufferSize: 1, refCount: true}),
);

protected readonly theme = inject(TuiThemeService);
Expand Down
2 changes: 1 addition & 1 deletion projects/addon-doc/components/main/main.template.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<tui-theme-night *ngIf="theme.isDefaultTheme && night.useDefaultNightTheme && (night$ | async)" />
<tui-root>
<tui-root [attr.tuiTheme]="theme.isDefaultTheme && night.useDefaultNightTheme && (night$ | async) ? 'night' : null">
<div class="tui-doc-page">
<tui-doc-navigation class="tui-doc-navigation">
<ng-content select="tuiDocNavigation" />
Expand Down
17 changes: 9 additions & 8 deletions projects/demo/src/modules/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,15 @@ export const ROUTES: Routes = [
title: 'Sensitive',
},
},
{
path: 'directives/skeleton',
loadChildren: async () =>
(await import('../directives/skeleton/skeleton.module'))
.ExampleTuiSkeletonModule,
data: {
title: 'Skeleton',
},
},
{
path: 'components/input-inline',
loadChildren: async () =>
Expand Down Expand Up @@ -1344,14 +1353,6 @@ export const ROUTES: Routes = [
title: 'Shadows',
},
},
{
path: 'skeleton',
loadChildren: async () =>
(await import('../markup/skeleton/skeleton.module')).SkeletonModule,
data: {
title: 'Skeleton',
},
},
{
path: 'spaces',
loadChildren: async () =>
Expand Down
13 changes: 7 additions & 6 deletions projects/demo/src/modules/app/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@ export const pages: TuiDocPages = [
keywords: 'верстка, markup, таблицы, tables',
route: '/tables',
},
{
section: 'Foundations',
title: 'Skeleton',
keywords: 'верстка, markup, скелетон, loader, загрузка, skeleton',
route: '/skeleton',
},
{
section: 'Foundations',
title: 'Form',
Expand Down Expand Up @@ -1381,6 +1375,13 @@ export const pages: TuiDocPages = [
keywords: 'sensitive, pixel, mask, пиксель, маска',
route: '/directives/sensitive',
},
{
section: 'Tools',
title: 'Skeleton',
keywords:
'верстка, markup, скелетон, loader, загрузка, skeleton, shimmer',
route: 'directives/skeleton',
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<label tuiLabel>
<input
tuiToggle
type="checkbox"
[(ngModel)]="skeleton"
/>
Show skeleton
</label>
<p>
<tui-avatar
src="AI"
[tuiSkeleton]="skeleton"
></tui-avatar>
<tui-avatar
src="https://avatars.githubusercontent.com/u/11832552"
[tuiSkeleton]="skeleton"
></tui-avatar>
<tui-avatar
src="❤️"
[tuiSkeleton]="skeleton"
></tui-avatar>
<tui-avatar
appearance="primary"
src="$"
[tuiSkeleton]="skeleton"
></tui-avatar>
</p>
nsbarsukov marked this conversation as resolved.
Show resolved Hide resolved
<section
tuiCardLarge
tuiSurface="flat"
[tuiSkeleton]="skeleton"
>
<h2 tuiHeader>
<span tuiTitle>
Card
<span tuiSubtitle>Subtitle</span>
</span>
</h2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua.
</section>
<p>
<button
tuiButton
[tuiSkeleton]="skeleton"
>
Awesome
</button>
<button
appearance="secondary"
tuiButton
[tuiSkeleton]="skeleton"
>
Cool
</button>
</p>
<p>
<tui-chip [tuiSkeleton]="skeleton">Chip</tui-chip>
<tui-badge [tuiSkeleton]="skeleton">Dale</tui-badge>
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
p {
display: flex;
gap: 1rem;
align-items: center;
justify-content: center;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';

@Component({
selector: 'tui-skeleton-example-1',
templateUrl: './index.html',
styleUrls: ['./index.less'],
encapsulation,
changeDetection,
})
export class TuiSkeletonExample1 {
protected skeleton = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<label tuiLabel>
<input
tuiToggle
type="checkbox"
[(ngModel)]="skeleton"
/>
Show skeleton
</label>

<p>
<span
[tuiSkeleton]="
skeleton
? 'This text serves as the content behind the skeleton and depending on its length, the skeleton will adjust to fit it.'
: ''
"
>
{{ skeleton ? '' : 'This text will be replaced by a placeholder.' }}
</span>
</p>
Comment on lines +10 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this additional nesting is really required ?

Could we simplify example ?

Suggested change
<p>
<span
[tuiSkeleton]="
skeleton
? 'This text serves as the content behind the skeleton and depending on its length, the skeleton will adjust to fit it.'
: ''
"
>
{{ skeleton ? '' : 'This text will be replaced by a placeholder.' }}
</span>
</p>
<p
[tuiSkeleton]="
skeleton
? 'This text serves as the content behind the skeleton and depending on its length, the skeleton will adjust to fit it.'
: ''
"
>
{{ skeleton ? '' : 'This text will be replaced by a placeholder.' }}
</p>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is there so the background is only where the text is — span is inline.


<span [tuiSkeleton]="skeleton && 20">
{{ skeleton ? '' : 'This text will be replaced by a skeleton made of 20 random length non-breaking spaces.' }}
</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';

@Component({
selector: 'tui-skeleton-example-2',
templateUrl: './index.html',
encapsulation,
changeDetection,
})
export class TuiSkeletonExample2 {
protected skeleton = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```ts
import {NgModule} from '@angular/core';
import {TuiSkeletonDirective} from '@taiga-ui/kit';
// ...

@NgModule({
imports: [
// ...
TuiSkeletonDirective,
],
})
export class MyModule {}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```html
<span [tuiSkeleton]="true">Loading..</span>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';

@Component({
selector: 'skeleton',
templateUrl: './skeleton.template.html',
changeDetection,
})
export class ExampleTuiSkeletonComponent {
protected readonly import = import('./examples/import/import.md?raw');
protected readonly template = import('./examples/import/insert.md?raw');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {TuiExamplePipe, TuiSetupComponent} from '@demo/utils';
import {tuiGetDocModules} from '@taiga-ui/addon-doc';
import {TuiNotificationModule} from '@taiga-ui/core';
import {
TuiButtonModule,
TuiCardModule,
TuiChipModule,
TuiHeaderDirective,
TuiLabelDirective,
TuiSurfaceModule,
TuiTitleModule,
TuiToggleModule,
} from '@taiga-ui/experimental';
import {TuiAvatarComponent, TuiBadgeDirective, TuiSkeletonDirective} from '@taiga-ui/kit';

import {TuiSkeletonExample1} from './examples/1';
import {TuiSkeletonExample2} from './examples/2';
import {ExampleTuiSkeletonComponent} from './skeleton.component';

@NgModule({
imports: [
CommonModule,
FormsModule,
tuiGetDocModules(ExampleTuiSkeletonComponent),
TuiSetupComponent,
TuiExamplePipe,
TuiLabelDirective,
TuiToggleModule,
TuiAvatarComponent,
TuiCardModule,
TuiTitleModule,
TuiSurfaceModule,
TuiHeaderDirective,
TuiButtonModule,
TuiChipModule,
TuiBadgeDirective,
TuiSkeletonDirective,
TuiNotificationModule,
],
declarations: [ExampleTuiSkeletonComponent, TuiSkeletonExample1, TuiSkeletonExample2],
exports: [ExampleTuiSkeletonComponent],
})
export class ExampleTuiSkeletonModule {}
waterplea marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<tui-doc-page
header="Skeleton"
package="KIT"
type="directives"
>
<ng-template pageTab>
<tui-doc-example
id="components"
heading="Components"
[content]="1 | tuiExample: 'html'"
>
<tui-skeleton-example-1></tui-skeleton-example-1>
</tui-doc-example>

<tui-doc-example
id="text"
heading="Text"
[content]="2 | tuiExample: 'html'"
[description]="description"
>
<ng-template #description>
You can pass
<code>boolean</code>
to toggle skeleton for elements. For multi line text you can use
<code>string</code>
to serve as a placeholder underneath the text skeleton or a
<code>number</code>
to generate this many random sized words, while your actual text is loading
</ng-template>
<tui-skeleton-example-2></tui-skeleton-example-2>
</tui-doc-example>
</ng-template>

<ng-template pageTab="Setup">
<tui-setup
[import]="import"
[template]="template"
></tui-setup>
</ng-template>
</tui-doc-page>
Loading
Loading