Skip to content

Commit

Permalink
Refactor #4602 - for Skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
habubey committed Jul 6, 2023
1 parent 87af55d commit b15b62c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 48 deletions.
33 changes: 0 additions & 33 deletions components/lib/skeleton/Skeleton.css

This file was deleted.

23 changes: 9 additions & 14 deletions components/lib/skeleton/Skeleton.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import * as React from 'react';
import { classNames, mergeProps } from '../utils/Utils';
import { SkeletonBase } from './SkeletonBase';
import { PrimeReactContext } from '../api/Api';
import { useStyle } from '../hooks/Hooks';
import { mergeProps } from '../utils/Utils';
import { SkeletonBase } from './SkeletonBase';

export const Skeleton = React.memo(
React.forwardRef((inProps, ref) => {
const context = React.useContext(PrimeReactContext);

useStyle(SkeletonBase.css.styles, { name: 'primereact_skeleton_style' });

const props = SkeletonBase.getProps(inProps, context);
const { ptm } = SkeletonBase.setMetaData({
const { ptm, cx, sx } = SkeletonBase.setMetaData({
props
});

const elementRef = React.useRef(null);
const style = props.size ? { width: props.size, height: props.size, borderRadius: props.borderRadius } : { width: props.width, height: props.height, borderRadius: props.borderRadius };
const className = classNames(
'p-skeleton p-component',
{
'p-skeleton-circle': props.shape === 'circle',
'p-skeleton-none': props.animation === 'none'
},
props.className
);

React.useImperativeHandle(ref, () => ({
props,
Expand All @@ -30,8 +25,8 @@ export const Skeleton = React.memo(
const rootProps = mergeProps(
{
ref: elementRef,
className,
style
className: cx('root'),
style: sx('root')
},
SkeletonBase.getOtherProps(props),
ptm('root')
Expand Down
52 changes: 52 additions & 0 deletions components/lib/skeleton/SkeletonBase.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentBase } from '../componentbase/ComponentBase';
import { classNames } from '../utils/utils';

export const SkeletonBase = ComponentBase.extend({
defaultProps: {
Expand All @@ -11,5 +12,56 @@ export const SkeletonBase = ComponentBase.extend({
animation: 'wave',
style: null,
className: null
},
css: {
classes: {
root: ({ props }) =>
classNames(
'p-skeleton p-component',
{
'p-skeleton-circle': props.shape === 'circle',
'p-skeleton-none': props.animation === 'none'
},
props.className
)
},
inlineStyles: {
root: ({ props }) => (props.size ? { width: props.size, height: props.size, borderRadius: props.borderRadius } : { width: props.width, height: props.height, borderRadius: props.borderRadius })
},
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-circle {
border-radius: 50%;
}
.p-skeleton-none::after {
animation: none;
}
@keyframes p-skeleton-animation {
from {
transform: translateX(-100%);
}
to {
transform: translateX(100%);
}
}
`
}
});
5 changes: 5 additions & 0 deletions components/lib/skeleton/skeleton.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export interface SkeletonProps extends Omit<React.DetailedHTMLProps<React.HTMLAt
* @type {SkeletonPassThroughOptions}
*/
pt?: SkeletonPassThroughOptions;
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
}

/**
Expand Down
1 change: 0 additions & 1 deletion styles/primereact.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
@import "../components/lib/avatar/Avatar.css";
@import "../components/lib/avatargroup/AvatarGroup.css";
@import "../components/lib/tag/Tag.css";
@import "../components/lib/skeleton/Skeleton.css";
@import "../components/lib/divider/Divider.css";
@import "../components/lib/knob/Knob.css";
@import "../components/lib/splitter/Splitter.css";
Expand Down

0 comments on commit b15b62c

Please sign in to comment.