Skip to content

Commit b0c0c09

Browse files
authored
Merge pull request #5 from OsirisFrik/main
feat: add loading prop
2 parents ab0ed4b + bfde61b commit b0c0c09

File tree

5 files changed

+59
-30
lines changed

5 files changed

+59
-30
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ This code snippet ensures the generation of precisely proportioned skeletons for
9898
without needing any additional configuration. Moreover, it orchestrates a seamless transition, waiting until the content
9999
is fully loaded before concealing the Skeleton and unveiling the loaded content gracefully.
100100

101+
#### Manual Loading
102+
103+
Use the `loading` prop to manually control the loading state of the skeleton.
104+
105+
```html
106+
<template>
107+
<div class="Home">
108+
<h1>
109+
<Skeleton :loading="loading">{{ data.title }}</Skeleton>
110+
</h1>
111+
<p>
112+
<Skeleton :loading="loading" :rows="3">{{ data.description }}</Skeleton>
113+
</p>
114+
</div>
115+
</template>
116+
```
117+
101118
### :warning: Avoid the creation of dedicated skeleton screens
102119

103120
Instead, craft components equipped with integrated skeleton states.
@@ -147,6 +164,7 @@ Down bellow you can take a look at each prop available.
147164
| circle | `boolean` | Set component `border-radius` to 50%, it replaces borderRadius props | `false` |
148165
| containerClass | `string` | Set component class to skeleton container | `null` |
149166
| childClass | `string` | Set component class to each skeleton child | `null` |
167+
| loading | `boolean` | Set component loading state | `undefined` |
150168

151169
### `<Skeleton>` `<SkeletonTheme>`
152170

package-lock.json

Lines changed: 13 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.vue

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import SkeletonTheme from '@components/SkeletonTheme.vue'
66
const data: any = ref({})
77
88
const loading = ref(true)
9+
const manualLoading = ref(true)
910
1011
const fetchData = () => {
1112
// Title & Description
@@ -59,6 +60,29 @@ onMounted(() => {
5960
</small>
6061
</div>
6162
</section>
63+
<!-- User Profile manually example -->
64+
<h2 class="mb-2">Inline loading with static data</h2>
65+
<section class="user">
66+
<picture class="user-avatar">
67+
<Skeleton :loading="manualLoading" childClass="user-avatar" background-color="#666">
68+
<img :src="data.img" />
69+
</Skeleton>
70+
</picture>
71+
<div class="user-info">
72+
<h3>
73+
<Skeleton :loading="manualLoading" :width="150">{{ data.name }}</Skeleton>
74+
</h3>
75+
<p>
76+
<Skeleton :loading="manualLoading" :width="120">{{ data.role }}</Skeleton>
77+
</p>
78+
<small>
79+
<Skeleton :loading="manualLoading" :width="100">{{ data.email }}</Skeleton>
80+
</small>
81+
</div>
82+
</section>
83+
84+
<button @click="manualLoading = !manualLoading">Toggle Manual Loading</button>
85+
6286
<!-- Inline Elements -->
6387
<section class="inline">
6488
<h2 class="mb-2">Inline loading with static data</h2>

src/components/Skeleton.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const props = withDefaults(defineProps<SkeletonProps>(), {
77
rows: 1,
88
enableAnimation: undefined,
99
inline: undefined,
10+
loading: undefined
1011
})
1112
1213
const theme = inject(ThemeInjection, {})
@@ -19,6 +20,8 @@ const getRows = computed<number>(() => {
1920
const slots: any = useSlots()
2021
2122
const getLoadingStatus = computed<boolean>(() => {
23+
if (props.loading !== undefined) return !props.loading
24+
2225
if (slots.default) return slots.default()[0].children || false
2326
})
2427

src/types/index.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ export interface SkeletonProps extends SkeletonThemeProps {
1515
circle?: boolean
1616
containerClass?: string
1717
childClass?: string
18+
loading?: boolean
1819
}

0 commit comments

Comments
 (0)