Skip to content

Commit

Permalink
feat(table): replace loading with skeleton and make skeleton stronger…
Browse files Browse the repository at this point in the history
… #INFR-9201 (#2799)
  • Loading branch information
minlovehua authored Aug 24, 2023
1 parent 89f5cd0 commit 89d5cd5
Show file tree
Hide file tree
Showing 15 changed files with 504 additions and 167 deletions.
5 changes: 5 additions & 0 deletions src/table/enums/column-skeleton-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum ThyTableColumnSkeletonType {
title = 'title',
member = 'member',
default = 'default'
}
1 change: 1 addition & 0 deletions src/table/enums/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './column-skeleton-type';
18 changes: 9 additions & 9 deletions src/table/examples/pagination/pagination.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
[thyShowTotal]="true"
[thyShowSizeChanger]="true"
[thyLoadingDone]="loadingDone"
[thyColumnSkeletonTypes]="skeletonTypes"
(thyOnPageChange)="onPageChange($event)"
(thyOnPageSizeChange)="onPageSizeChange($event)"
>
<thy-table-column thyTitle="#" thyType="index"> </thy-table-column>
<thy-table-column thyTitle="Id" thyModelKey="id"></thy-table-column>
<thy-table-column thyTitle="Name" thyModelKey="name"></thy-table-column>
<thy-table-column thyTitle="Age" thyModelKey="age"></thy-table-column>
<thy-table-column thyTitle="Job" thyModelKey="job"> </thy-table-column>
<thy-table-column thyTitle="Address" thyModelKey="address"></thy-table-column>
<thy-table-column thyTitle="" thyClassName="thy-operation-links">
(thyOnPageSizeChange)="onPageSizeChange($event)">
<thy-table-column thyTitle="#" thyType="index" thyWidth="80"> </thy-table-column>
<thy-table-column thyTitle="Id" thyModelKey="id" thyWidth="80"></thy-table-column>
<thy-table-column thyTitle="Name" thyModelKey="name" thyWidth="150"></thy-table-column>
<thy-table-column thyTitle="Age" thyModelKey="age" thyWidth="100"></thy-table-column>
<thy-table-column thyTitle="Job" thyModelKey="job" thyWidth="150"> </thy-table-column>
<thy-table-column thyTitle="Address" thyModelKey="address" thyWidth="auto"></thy-table-column>
<thy-table-column thyTitle="" thyClassName="thy-operation-links" thyWidth="150">
<ng-template #cell let-row>
<a class="link-secondary" href="javascript:;">
<thy-icon thyIconName="user-add"></thy-icon>
Expand Down
10 changes: 8 additions & 2 deletions src/table/examples/pagination/pagination.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { ThyMultiSelectEvent, ThyTableRowEvent, ThyTableSize, ThyPageChangedEvent } from 'ngx-tethys/table';
import { ThyTableRowEvent, ThyPageChangedEvent, ThyTableColumnSkeletonType } from 'ngx-tethys/table';
import { of } from 'rxjs';
import { delay, finalize } from 'rxjs/operators';

Expand All @@ -19,6 +19,12 @@ export class ThyTablePaginationExampleComponent implements OnInit {

loadingDone = false;

skeletonTypes: ThyTableColumnSkeletonType[] = [
ThyTableColumnSkeletonType.default,
ThyTableColumnSkeletonType.default,
ThyTableColumnSkeletonType.member
];

private getRandomIndex(max: number) {
return Math.floor(Math.random() * max);
}
Expand All @@ -37,7 +43,7 @@ export class ThyTablePaginationExampleComponent implements OnInit {
const originalData = [
{ id: 1, name: 'Peter', age: 25, job: 'Engineer', address: 'Beijing Dong Sheng Technology' },
{ id: 2, name: 'James', age: 26, job: 'Designer', address: 'Xian Economic Development Zone' },
{ id: 3, name: 'Tom', age: 30, job: 'Engineer', address: 'New Industrial Park, Shushan, Hefei, Anhui' },
{ id: 3, name: 'Tom', age: 30, job: 'Engineer', address: 'New Industrial Park' },
{ id: 4, name: 'Elyse', age: 31, job: 'Engineer', address: 'Yichuan Ningxia' },
{ id: 5, name: 'Jill', age: 22, job: 'DevOps', address: 'Hangzhou' }
];
Expand Down
18 changes: 17 additions & 1 deletion src/table/examples/skeleton/skeleton.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
<thy-table-skeleton [thyRowCount]="5"> </thy-table-skeleton>
<span>默认:</span>
<div class="mt-2">
<thy-radio-group [(ngModel)]="theme">
<label thyRadio thyLabelText="Default" thyInline thyValue="default"></label>
<label thyRadio thyLabelText="Bordered" thyInline thyValue="bordered"></label>
<label thyRadio thyLabelText="Boxed" thyInline thyValue="boxed"></label>
</thy-radio-group>
</div>
<thy-button-group thySize="sm" thyType="outline-default" class="mb-2">
<button thyButton *ngFor="let item of sizes" (click)="size = item.value" [ngClass]="{ active: item.value === size }">
{{ item.value }}({{ item.height }})
</button>
</thy-button-group>
<thy-table-skeleton [thyRowCount]="5" [thyTheme]="theme" [thySize]="size"> </thy-table-skeleton>

<span class="d-inline-block mt-8">支持配置骨架列的宽度和类型:</span>
<thy-table-skeleton [thyRowCount]="5" [thyColumns]="columns"> </thy-table-skeleton>
41 changes: 37 additions & 4 deletions src/table/examples/skeleton/skeleton.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,49 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';
import { ThyTableColumnSkeletonType, ThyTableSize, ThyTableSkeletonColumn, ThyTableTheme } from 'ngx-tethys/table';

@Component({
selector: 'thy-table-skeleton-example',
templateUrl: './skeleton.component.html'
})
export class ThyTableSkeletonExampleComponent implements OnInit {
export class ThyTableSkeletonExampleComponent {
data = [
{ id: 1, name: 'Peter', age: 25, job: 'Engineer', address: 'Beijing Dong Sheng Technology' },
{ id: 2, name: 'James', age: 26, job: 'Designer', address: 'Xian Economic Development Zone' },
{ id: 3, name: 'Tom', age: 30, job: 'Engineer', address: 'New Industrial Park, Shushan, Hefei, Anhui' }
];
constructor() {}

ngOnInit() {}
theme: ThyTableTheme = 'default';

sizes: { value: ThyTableSize; height: number }[] = [
{
value: 'xs',
height: 44
},
{
value: 'sm',
height: 48
},
{
value: 'md',
height: 52
},
{
value: 'lg',
height: 56
},
{
value: 'xlg',
height: 60
}
];

size: ThyTableSize = 'md';

columns: ThyTableSkeletonColumn[] = [
{ width: '40%', type: ThyTableColumnSkeletonType.title },
{ width: 'auto', type: ThyTableColumnSkeletonType.default },
{ width: 'auto', type: ThyTableColumnSkeletonType.default },
{ width: 'auto', type: ThyTableColumnSkeletonType.default },
{ width: '17%', type: ThyTableColumnSkeletonType.member }
];
}
1 change: 1 addition & 0 deletions src/table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './pipes/drag.pipe';
export * from './table.module';
export * from './table-column.component';
export * from './table-skeleton.component';
export * from './enums';
8 changes: 2 additions & 6 deletions src/table/styles/skeleton.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use "../../styles/variables";
@use '../../styles/variables';

.thy-table-skeleton {
table {
Expand All @@ -8,11 +8,7 @@

td,
th {
border-bottom: variables.$table-border-width solid variables.$gray-200;
text-align: left;
padding: 8px 28px;
height: 52px;
}
}

}
}
150 changes: 79 additions & 71 deletions src/table/table-skeleton.component.html
Original file line number Diff line number Diff line change
@@ -1,79 +1,87 @@
<table>
<thead>
<tr>
<th [width]="i === 0 ? '40%' : i === 1 ? '20%' : 'auto'" *ngFor="let key of columnCount; index as i">
<thy-skeleton-rectangle
[thyRowWidth]="titleWidth"
[thyRowHeight]="titleHeight"
[thyBorderRadius]="thyBorderRadius"
[thyAnimated]="thyAnimated"
[thyAnimatedInterval]="thyAnimatedInterval"
[thyPrimaryColor]="thyPrimaryColor"
[thySecondaryColor]="thySecondaryColor"
></thy-skeleton-rectangle>
</th>
</tr>
</thead>
<tbody>
<ng-template ngFor let-item [ngForOf]="rowCount" let-i="index + 1">
<table [ngClass]="tableClassMap" [style.min-width]="thyMinWidth">
<colgroup>
<col *ngFor="let column of columns; trackBy: trackByFn" [width]="column.width" />
</colgroup>
<ng-container *ngIf="!thyHeadless">
<thead>
<tr>
<td>
<div class="d-flex" style="align-items:center">
<thy-skeleton-rectangle
class="mr-2"
[thyRowWidth]="checkBoxWidth"
[thyRowHeight]="thyRowHeight"
[thyBorderRadius]="thyBorderRadius"
[thyAnimated]="thyAnimated"
[thyAnimatedInterval]="thyAnimatedInterval"
[thyPrimaryColor]="thyPrimaryColor"
[thySecondaryColor]="thySecondaryColor"
></thy-skeleton-rectangle>
<thy-skeleton-rectangle
[thyRowWidth]="i % 3 === 1 ? '70%' : i % 3 === 2 ? '85%' : '60%'"
[thyRowHeight]="thyRowHeight"
[thyBorderRadius]="thyBorderRadius"
[thyAnimated]="thyAnimated"
[thyAnimatedInterval]="thyAnimatedInterval"
[thyPrimaryColor]="thyPrimaryColor"
[thySecondaryColor]="thySecondaryColor"
></thy-skeleton-rectangle>
</div>
</td>
<td>
<div class="d-flex" style="align-items:center">
<thy-skeleton-circle
class="mr-2"
[thySize]="avatarSize"
[thyAnimated]="thyAnimated"
[thyAnimatedInterval]="thyAnimatedInterval"
[thyPrimaryColor]="thyPrimaryColor"
[thySecondaryColor]="thySecondaryColor"
></thy-skeleton-circle>

<thy-skeleton-rectangle
[thyRowWidth]="i % 3 === 1 ? '50%' : i % 3 === 2 ? '60%' : '40%'"
[thyRowHeight]="thyRowHeight"
[thyBorderRadius]="thyBorderRadius"
[thyAnimated]="thyAnimated"
[thyAnimatedInterval]="thyAnimatedInterval"
[thyPrimaryColor]="thyPrimaryColor"
[thySecondaryColor]="thySecondaryColor"
></thy-skeleton-rectangle>
</div>
</td>
<td *ngFor="let item of columnCount.slice(2)">
<th *ngFor="let column of columns; trackBy: trackByFn">
<thy-skeleton-rectangle
[thyRowWidth]="'70%'"
[thyRowHeight]="thyRowHeight"
[thyRowWidth]="titleWidth"
[thyRowHeight]="titleHeight"
[thyBorderRadius]="thyBorderRadius"
[thyAnimated]="thyAnimated"
[thyAnimatedInterval]="thyAnimatedInterval"
[thyPrimaryColor]="thyPrimaryColor"
[thySecondaryColor]="thySecondaryColor"
></thy-skeleton-rectangle>
</td>
[thyPrimaryColor]="thyTheme === 'bordered' || thyTheme === 'boxed' ? '#eee' : thyPrimaryColor"
[thySecondaryColor]="thySecondaryColor"></thy-skeleton-rectangle>
</th>
</tr>
</thead>
</ng-container>
<tbody>
<ng-container *ngFor="let item of rowCount; let i = index">
<tr>
<ng-container *ngFor="let column of columns; trackBy: trackByFn">
<td>
<ng-container
*thyViewOutlet="
column.type === columnType.title
? titleTemplate
: column.type === columnType.member
? memberTemplate
: defaultTemplate;
context:{
trIndex: i,
}
"></ng-container>
</td>
</ng-container>
</tr>
</ng-template>
</ng-container>
</tbody>
</table>

<ng-template #titleTemplate let-trIndex="trIndex">
<div class="d-flex align-items-center">
<thy-skeleton-rectangle
class="mr-2 flex-shrink-0"
[thyRowWidth]="checkBoxWidth"
[thyRowHeight]="thyRowHeight"
[thyBorderRadius]="thyBorderRadius"
[thyAnimated]="thyAnimated"
[thyAnimatedInterval]="thyAnimatedInterval"
[thyPrimaryColor]="thyPrimaryColor"
[thySecondaryColor]="thySecondaryColor"></thy-skeleton-rectangle>

<ng-container
*thyViewOutlet="defaultTemplate;
context:{
rowWidth: trIndex % 3 === 0 ? '75%' : trIndex % 3 === 1 ? '100%' : trIndex % 3 === 2 ? '65%' : '',
}"></ng-container>
</div>
</ng-template>

<ng-template #memberTemplate>
<div class="d-flex align-items-center">
<thy-skeleton-circle
class="mr-2 flex-shrink-0"
[thySize]="avatarSize"
[thyAnimated]="thyAnimated"
[thyAnimatedInterval]="thyAnimatedInterval"
[thyPrimaryColor]="thyPrimaryColor"
[thySecondaryColor]="thySecondaryColor"></thy-skeleton-circle>

<ng-container *thyViewOutlet="defaultTemplate"></ng-container>
</div>
</ng-template>

<ng-template #defaultTemplate let-rowWidth="rowWidth">
<thy-skeleton-rectangle
[thyRowWidth]="rowWidth"
[thyRowHeight]="thyRowHeight"
[thyBorderRadius]="thyBorderRadius"
[thyAnimated]="thyAnimated"
[thyAnimatedInterval]="thyAnimatedInterval"
[thyPrimaryColor]="thyPrimaryColor"
[thySecondaryColor]="thySecondaryColor"></thy-skeleton-rectangle>
</ng-template>
Loading

1 comment on commit 89d5cd5

@vercel
Copy link

@vercel vercel bot commented on 89d5cd5 Aug 24, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

tethys – ./

tethys-vert.vercel.app
tethys-tethys.vercel.app
tethys-git-master-tethys.vercel.app

Please sign in to comment.