Skip to content

Commit

Permalink
feat: skeleton updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NateWaldschmidt committed Jun 25, 2024
1 parent 9d506ea commit 5b0cd3a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v2.0.79

- Improve `Skeleton` loading within `Tile` component

## v2.0.77

- Add `Skeleton` loading to `Tile` and `Pagination` components
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lob/ui-components",
"version": "2.0.77",
"version": "2.0.78",
"engines": {
"node": ">=20.2.0",
"npm": ">=10.2.0"
Expand Down
1 change: 0 additions & 1 deletion src/components/Tile/Tile.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export const Primary: StoryObj<typeof Tile> = {
template: `
<Tile v-bind="args">
<template #header>Total Volume</template>
<template #default>193,038,282</template>
</Tile>
`
})
Expand Down
10 changes: 7 additions & 3 deletions src/components/Tile/Tile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
>
<template #header>
<slot name="header" />
<LoadingSpinnerIcon v-if="$slots.default && loading" />
<LoadingSpinnerIcon v-if="isSlotEmpty($slots.default) && loading" />
</template>

<template #icons>
Expand All @@ -24,8 +24,11 @@
</template>

<template #default>
<template v-if="!$slots.default && loading">
<Skeleton :height="size === TileSize.LG ? '32px' : '28px'" />
<template v-if="!isSlotEmpty($slots.default) && loading">
<Skeleton
:height="size === TileSize.LG ? '32px' : '28px'"
width="50%"
/>
</template>
<Alert v-else-if="error" variant="error">
{{ error }}
Expand All @@ -50,6 +53,7 @@
import Alert from '@/components/Alert/Alert.vue';
import ConditionalClickWrapper from '@/utils/ConditionalClickWrapper.vue';
import Panel from 'primevue/panel';
import { isSlotEmpty } from '@/utils/isSlotEmpty';
import { computed } from 'vue';
import { TileColor, TileSize } from './constants';
Expand Down
20 changes: 20 additions & 0 deletions src/utils/isSlotEmpty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Comment, Text, Slot, VNode } from 'vue';

/** https://github.com/vuejs/core/issues/4733#issuecomment-1024816095 */
export const isSlotEmpty = (
slot: Slot | undefined,
slotProps = {}
): boolean => {
if (!slot) return false;

return slot(slotProps).some((vnode: VNode) => {
if (vnode.type === Comment) return false;

if (Array.isArray(vnode.children) && !vnode.children.length) return false;

return (
vnode.type !== Text ||
(typeof vnode.children === 'string' && vnode.children.trim() !== '')
);
});
};

0 comments on commit 5b0cd3a

Please sign in to comment.