Skip to content

Commit b0c7012

Browse files
MariyaVdovenkooliviertassinari
authored andcommitted
[Skeleton] Add wave animation support
1 parent f3218f2 commit b0c7012

File tree

6 files changed

+86
-14
lines changed

6 files changed

+86
-14
lines changed

docs/pages/api/skeleton.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
2424

2525
| Name | Type | Default | Description |
2626
|:-----|:-----|:--------|:------------|
27+
| <span class="prop-name">animation</span> | <span class="prop-type">'pulse'<br>&#124;&nbsp;'wave'<br>&#124;&nbsp;false</span> | <span class="prop-default">'pulse'</span> | The animation. If `false` the animation effect is disabled. |
2728
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
2829
| <span class="prop-name">component</span> | <span class="prop-type">elementType</span> | <span class="prop-default">'div'</span> | The component used for the root node. Either a string to use a DOM element or a component. |
29-
| <span class="prop-name">disableAnimate</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true` the animation effect is disabled. |
3030
| <span class="prop-name">height</span> | <span class="prop-type">number<br>&#124;&nbsp;string</span> | | Height of the skeleton. Useful when you don't want to adapt the skeleton to a text element but for instance a card. |
3131
| <span class="prop-name">variant</span> | <span class="prop-type">'text'<br>&#124;&nbsp;'rect'<br>&#124;&nbsp;'circle'</span> | <span class="prop-default">'text'</span> | The type of content that will be rendered. |
3232
| <span class="prop-name">width</span> | <span class="prop-type">number<br>&#124;&nbsp;string</span> | | Width of the skeleton. Useful when the skeleton is inside an inline element with no width of its own. |
@@ -46,7 +46,8 @@ Any other props supplied will be provided to the root element (native element).
4646
| <span class="prop-name">text</span> | <span class="prop-name">.MuiSkeleton-text</span> | Styles applied to the root element if `variant="text"`.
4747
| <span class="prop-name">rect</span> | <span class="prop-name">.MuiSkeleton-rect</span> | Styles applied to the root element if `variant="rect"`.
4848
| <span class="prop-name">circle</span> | <span class="prop-name">.MuiSkeleton-circle</span> | Styles applied to the root element if `variant="circle"`.
49-
| <span class="prop-name">animate</span> | <span class="prop-name">.MuiSkeleton-animate</span> | Styles applied to the root element if `disabledAnimate={false}`.
49+
| <span class="prop-name">pulse</span> | <span class="prop-name">.MuiSkeleton-pulse</span> | Styles applied to the root element if `animation="pulse"`.
50+
| <span class="prop-name">wave</span> | <span class="prop-name">.MuiSkeleton-wave</span> | Styles applied to the root element if `animation="wave"`.
5051

5152
You can override the style of the component thanks to one of these customization points:
5253

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import Skeleton from '@material-ui/lab/Skeleton';
3+
import { makeStyles } from '@material-ui/core/styles';
4+
5+
const useStyles = makeStyles({
6+
root: {
7+
width: 300,
8+
},
9+
});
10+
11+
export default function Animations() {
12+
const classes = useStyles();
13+
return (
14+
<div className={classes.root}>
15+
<Skeleton />
16+
<Skeleton animation={false} />
17+
<Skeleton animation="wave" />
18+
</div>
19+
);
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import Skeleton from '@material-ui/lab/Skeleton';
3+
import { makeStyles } from '@material-ui/core/styles';
4+
5+
const useStyles = makeStyles({
6+
root: {
7+
width: 300,
8+
},
9+
});
10+
11+
export default function Animations() {
12+
const classes = useStyles();
13+
return (
14+
<div className={classes.root}>
15+
<Skeleton />
16+
<Skeleton animation={false} />
17+
<Skeleton animation="wave" />
18+
</div>
19+
);
20+
}

docs/src/pages/components/skeleton/skeleton.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ For instance:
2222

2323
## Variants
2424

25-
The component supports 3 variants.
25+
The component supports 3 shape variants.
2626

2727
{{"demo": "pages/components/skeleton/Variants.js"}}
2828

29+
## Animations
30+
31+
By default, the skeleton pulsate, but you can change the animation for a wave or disable it entirely.
32+
33+
{{"demo": "pages/components/skeleton/Animations.js"}}
34+
2935
## YouTube example
3036

3137
{{"demo": "pages/components/skeleton/YouTube.js", "defaultCodeOpen": false}}

packages/material-ui-lab/src/Skeleton/Skeleton.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { OverridableComponent, OverrideProps } from '@material-ui/core/Overridab
33

44
export interface SkeletonTypeMap<P = {}, D extends React.ElementType = 'hr'> {
55
props: P & {
6-
disableAnimate?: boolean;
6+
animation?: 'pulse' | 'wave' | false;
77
height?: number | string;
88
variant?: 'text' | 'rect' | 'circle';
99
width?: number | string;

packages/material-ui-lab/src/Skeleton/Skeleton.js

+35-10
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ export const styles = theme => ({
2828
circle: {
2929
borderRadius: '50%',
3030
},
31-
/* Styles applied to the root element if `disabledAnimate={false}`. */
32-
animate: {
33-
animation: '$animate 1.5s ease-in-out 0.5s infinite',
31+
/* Styles applied to the root element if `animation="pulse"`. */
32+
pulse: {
33+
animation: '$pulse 1.5s ease-in-out 0.5s infinite',
3434
},
35-
'@keyframes animate': {
35+
'@keyframes pulse': {
3636
'0%': {
3737
opacity: 1,
3838
},
@@ -43,14 +43,38 @@ export const styles = theme => ({
4343
opacity: 1,
4444
},
4545
},
46+
/* Styles applied to the root element if `animation="wave"`. */
47+
wave: {
48+
position: 'relative',
49+
overflow: 'hidden',
50+
'&::after': {
51+
animation: '$wave 1.5s linear 0.5s infinite',
52+
background: 'linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent)',
53+
content: '""',
54+
position: 'absolute',
55+
bottom: 0,
56+
left: 0,
57+
right: 0,
58+
top: 0,
59+
zIndex: 1,
60+
},
61+
},
62+
'@keyframes wave': {
63+
'0%': {
64+
transform: 'translateX(-100%)',
65+
},
66+
'100%': {
67+
transform: 'translateX(100%)',
68+
},
69+
},
4670
});
4771

4872
const Skeleton = React.forwardRef(function Skeleton(props, ref) {
4973
const {
74+
animation = 'pulse',
5075
classes,
5176
className,
5277
component: Component = 'div',
53-
disableAnimate = false,
5478
height,
5579
variant = 'text',
5680
width,
@@ -64,7 +88,7 @@ const Skeleton = React.forwardRef(function Skeleton(props, ref) {
6488
classes.root,
6589
classes[variant],
6690
{
67-
[classes.animate]: !disableAnimate,
91+
[classes[animation]]: animation !== false,
6892
},
6993
className,
7094
)}
@@ -79,6 +103,11 @@ const Skeleton = React.forwardRef(function Skeleton(props, ref) {
79103
});
80104

81105
Skeleton.propTypes = {
106+
/**
107+
* The animation.
108+
* If `false` the animation effect is disabled.
109+
*/
110+
animation: PropTypes.oneOf(['pulse', 'wave', false]),
82111
/**
83112
* Override or extend the styles applied to the component.
84113
* See [CSS API](#css) below for more details.
@@ -93,10 +122,6 @@ Skeleton.propTypes = {
93122
* Either a string to use a DOM element or a component.
94123
*/
95124
component: PropTypes.elementType,
96-
/**
97-
* If `true` the animation effect is disabled.
98-
*/
99-
disableAnimate: PropTypes.bool,
100125
/**
101126
* Height of the skeleton.
102127
* Useful when you don't want to adapt the skeleton to a text element but for instance a card.

0 commit comments

Comments
 (0)