Refactor #3965 - For Skeleton

pull/3997/head
Bahadır Sofuoğlu 2023-05-24 13:36:51 +03:00
parent a686bd42e7
commit 0a105eb0f2
3 changed files with 102 additions and 74 deletions

View File

@ -0,0 +1,94 @@
<script>
import BaseComponent from 'primevue/basecomponent';
import { useStyle } from 'primevue/usestyle';
const styles = `
.p-skeleton {
position: relative;
overflow: hidden;
}
.p-skeleton::after {
content: '';
animation: p-skeleton-animation 1.2s infinite;
height: 100%;
left: 0;
position: absolute;
right: 0;
top: 0;
transform: translateX(-100%);
z-index: 1;
}
.p-skeleton.p-skeleton-circle {
border-radius: 50%;
}
.p-skeleton-none::after {
animation: none;
}
@keyframes p-skeleton-animation {
from {
transform: translateX(-100%);
}
to {
transform: translateX(100%);
}
}
`;
const classes = {
root: ({ props }) => [
'p-skeleton p-component',
{
'p-skeleton-circle': props.shape === 'circle',
'p-skeleton-none': props.animation === 'none'
}
]
};
const { load: loadStyle } = useStyle(styles, { id: 'primevue_skeleton_style', manual: true });
export default {
name: 'BaseSkeleton',
extends: BaseComponent,
props: {
shape: {
type: String,
default: 'rectangle'
},
size: {
type: String,
default: null
},
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '1rem'
},
borderRadius: {
type: String,
default: null
},
animation: {
type: String,
default: 'wave'
}
},
css: {
classes
},
watch: {
isUnstyled: {
immediate: true,
handler(newValue) {
!newValue && loadStyle();
}
}
}
};
</script>

View File

@ -73,6 +73,11 @@ export interface SkeletonProps {
* @type {SkeletonPassThroughOptions}
*/
pt?: SkeletonPassThroughOptions;
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
}
/**

View File

@ -1,49 +1,14 @@
<template>
<div :style="containerStyle" :class="containerClass" aria-hidden="true" v-bind="ptm('root')"></div>
<div :style="containerStyle" :class="cx('root')" aria-hidden="true" v-bind="ptm('root')"></div>
</template>
<script>
import BaseComponent from 'primevue/basecomponent';
import BaseSkeleton from './BaseSkeleton.vue';
export default {
name: 'Skeleton',
extends: BaseComponent,
props: {
shape: {
type: String,
default: 'rectangle'
},
size: {
type: String,
default: null
},
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '1rem'
},
borderRadius: {
type: String,
default: null
},
animation: {
type: String,
default: 'wave'
}
},
extends: BaseSkeleton,
computed: {
containerClass() {
return [
'p-skeleton p-component',
{
'p-skeleton-circle': this.shape === 'circle',
'p-skeleton-none': this.animation === 'none'
}
];
},
containerStyle() {
if (this.size) return { width: this.size, height: this.size, borderRadius: this.borderRadius };
else return { width: this.width, height: this.height, borderRadius: this.borderRadius };
@ -51,39 +16,3 @@ export default {
}
};
</script>
<style>
.p-skeleton {
position: relative;
overflow: hidden;
}
.p-skeleton::after {
content: '';
animation: p-skeleton-animation 1.2s infinite;
height: 100%;
left: 0;
position: absolute;
right: 0;
top: 0;
transform: translateX(-100%);
z-index: 1;
}
.p-skeleton.p-skeleton-circle {
border-radius: 50%;
}
.p-skeleton-none::after {
animation: none;
}
@keyframes p-skeleton-animation {
from {
transform: translateX(-100%);
}
to {
transform: translateX(100%);
}
}
</style>