import { use, suffixPx } from '../utils'; import { inherit } from '../utils/functional'; // Types import { CreateElement, RenderContext } from 'vue/types'; import { DefaultSlots } from '../utils/types'; export type SkeletonProps = { row: number; title?: boolean; avatar?: boolean; loading: boolean; animate: boolean; avatarSize: string; avatarShape: 'square' | 'round'; titleWidth: number | string; rowWidth: number | string | (number | string)[]; }; const [sfc, bem] = use('skeleton'); const DEFAULT_ROW_WIDTH = '100%'; const DEFAULT_LAST_ROW_WIDTH = '60%'; function Skeleton( h: CreateElement, props: SkeletonProps, slots: DefaultSlots, ctx: RenderContext ) { if (!props.loading) { return slots.default && slots.default(); } function Title() { if (props.title) { return
; } } function Rows() { const Rows = []; const { rowWidth } = props; function getRowWidth(index: number) { if (rowWidth === DEFAULT_ROW_WIDTH && index === props.row - 1) { return DEFAULT_LAST_ROW_WIDTH; } if (Array.isArray(rowWidth)) { return rowWidth[index]; } return rowWidth; } for (let i = 0; i < props.row; i++) { Rows.push(); } return Rows; } function Avatar() { if (props.avatar) { const size = suffixPx(props.avatarSize); return ( ); } } return (