Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Skeleton] Delay the animation by 500ms #18913

Merged
merged 12 commits into from
Dec 19, 2019
1 change: 1 addition & 0 deletions docs/pages/api/skeleton.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi

| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">animationDelay</span> | <span class="prop-type">number<br>&#124;&nbsp;string</span> | | Delays the animation of the skeleton. Useful when you have multiple skeletons, and need them to pulse out of phase. |
| <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. |
| <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. |
| <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. |
Expand Down
24 changes: 24 additions & 0 deletions docs/src/pages/components/skeleton/Delay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import Skeleton from '@material-ui/lab/Skeleton';

export default function Variants() {
return (
<div>
<Skeleton variant="rect" width={210} height={118} />
<Skeleton
variant="rect"
width={210}
height={118}
animationDelay="0.1s"
style={{ marginTop: 5 }}
/>
<Skeleton
variant="rect"
width={210}
height={118}
animationDelay="0.2s"
style={{ marginTop: 5 }}
/>
</div>
);
}
24 changes: 24 additions & 0 deletions docs/src/pages/components/skeleton/Delay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import Skeleton from '@material-ui/lab/Skeleton';

export default function Variants() {
return (
<div>
<Skeleton variant="rect" width={210} height={118} />
<Skeleton
variant="rect"
width={210}
height={118}
animationDelay="0.1s"
style={{ marginTop: 5 }}
/>
<Skeleton
variant="rect"
width={210}
height={118}
animationDelay="0.2s"
style={{ marginTop: 5 }}
/>
</div>
);
}
4 changes: 4 additions & 0 deletions docs/src/pages/components/skeleton/skeleton.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ The component supports 3 variants.
## Facebook example

{{"demo": "pages/components/skeleton/Facebook.js", "defaultCodeOpen": false, "bg": true}}

## Delay example
bowann marked this conversation as resolved.
Show resolved Hide resolved

{{"demo": "pages/components/skeleton/Delay.js", "defaultCodeOpen": false}}
1 change: 1 addition & 0 deletions packages/material-ui-lab/src/Skeleton/Skeleton.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { OverridableComponent, OverrideProps } from '@material-ui/core/Overridab

export interface SkeletonTypeMap<P = {}, D extends React.ElementType = 'hr'> {
props: P & {
animationDelay?: string;
disableAnimate?: boolean;
height?: number | string;
variant?: 'text' | 'rect' | 'circle';
Expand Down
8 changes: 8 additions & 0 deletions packages/material-ui-lab/src/Skeleton/Skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const styles = theme => ({
/* Styles applied to the root element if `disabledAnimate={false}`. */
animate: {
animation: '$animate 1.5s ease-in-out infinite',
animationDelay: '0.5s',
bowann marked this conversation as resolved.
Show resolved Hide resolved
},
'@keyframes animate': {
'0%': {
Expand All @@ -47,6 +48,7 @@ export const styles = theme => ({

const Skeleton = React.forwardRef(function Skeleton(props, ref) {
const {
animationDelay,
bowann marked this conversation as resolved.
Show resolved Hide resolved
classes,
className,
component: Component = 'div',
Expand All @@ -72,13 +74,19 @@ const Skeleton = React.forwardRef(function Skeleton(props, ref) {
style={{
width,
height,
animationDelay,
...other.style,
}}
/>
);
});

Skeleton.propTypes = {
/**
* Delays the animation of the skeleton.
* Useful when you have multiple skeletons, and need them to pulse out of phase.
*/
animationDelay: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
Expand Down