Skip to content
Open
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
26 changes: 25 additions & 1 deletion packages/widgets/src/feedback/Skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { timerPoolSubscribe } from '@termuijs/motion';

export interface SkeletonOptions {
variant?: 'pulse' | 'shimmer';
speed?: 'slow' | 'normal' | 'fast';
shape?: 'text' | 'card' | 'table' | 'list';
intervalMs?: number;
chars?: [string, string];
color?: Color;
Expand All @@ -13,6 +15,7 @@ export class Skeleton extends Widget {
private _frame = 0;
private _shimmerPos = 0;
private _variant: 'pulse' | 'shimmer';
private _shape: 'text' | 'card' | 'table' | 'list';
private _chars: [string, string];
private _intervalMs: number;
private _unsubscribe?: () => void;
Expand All @@ -21,6 +24,17 @@ export class Skeleton extends Widget {
super(style);

this._variant = opts.variant ?? 'pulse';
this._shape = opts.shape ?? 'text';

const speeds = {
slow: 1000,
normal: 600,
fast: 300,
};

this._intervalMs =
opts.intervalMs ??
speeds[opts.speed ?? 'normal'];
this._intervalMs = opts.intervalMs ?? 600;

this._chars = opts.chars ?? (caps.unicode ? ['░', '▒'] : ['-', '#']);
Expand All @@ -41,7 +55,17 @@ export class Skeleton extends Widget {

protected _renderSelf(screen: Screen): void {
const rect = this._getContentRect();
const { x, y, width, height } = rect;
const { x, y, width } = rect;

let height = rect.height;

if (this._shape === 'text') {
height = Math.min(height, 3);
} else if (this._shape === 'list') {
height = Math.min(height, 5);
} else if (this._shape === 'table') {
height = Math.min(height, 6);
}

if (width <= 0 || height <= 0) return;

Expand Down
Loading