Skip to content

Commit f5757f6

Browse files
committed
Clean up & test new animation (#114)
1 parent faa6876 commit f5757f6

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/Skeleton.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import React, { CSSProperties, ReactElement } from 'react'
33
import { SkeletonThemeContext } from './SkeletonThemeContext'
44
import { SkeletonStyleProps } from './SkeletonStyleProps'
55

6-
// If either color is changed, skeleton.css must be updated as well
7-
const defaultBaseColor = '#ebebeb'
8-
const defaultHighlightColor = '#f5f5f5'
9-
106
const defaultEnableAnimation = true
117

128
// For performance & cleanliness, don't add any inline styles unless we have to
@@ -26,8 +22,8 @@ function styleOptionsToCssProperties({
2622
const style: CSSProperties & Record<`--${string}`, string> = {}
2723

2824
if (direction === 'rtl') style['--animation-direction'] = 'reverse'
29-
3025
if (typeof duration === 'number') style['--animation-duration'] = `${duration}s`
26+
if (!enableAnimation) style.backgroundImage = 'none'
3127

3228
if (typeof width === 'string' || typeof width === 'number') style.width = width
3329
if (typeof height === 'string' || typeof height === 'number') style.height = height
@@ -37,12 +33,8 @@ function styleOptionsToCssProperties({
3733

3834
if (circle) style.borderRadius = '50%'
3935

40-
if (typeof baseColor !== 'undefined' || typeof highlightColor !== 'undefined') {
41-
style['--base-color'] = baseColor ?? defaultBaseColor;
42-
style['--highlight-color'] = highlightColor ?? defaultHighlightColor;
43-
}
44-
45-
if (!enableAnimation) style.backgroundImage = 'none'
36+
if (typeof baseColor !== 'undefined') style['--base-color'] = baseColor
37+
if (typeof highlightColor !== 'undefined') style['--highlight-color'] = highlightColor
4638

4739
return style
4840
}

src/__stories__/Skeleton.stories.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ export const Inline: React.VFC = () => (
3030
</SideBySide>
3131
)
3232

33+
export const InlineWithText: React.VFC = () => (
34+
<div>
35+
Some random text <Skeleton width={150} inline /> Some more random text
36+
</div>
37+
)
38+
3339
export const BlockWrapper: React.VFC = () => (
3440
<SideBySide>
3541
<Skeleton count={5} wrapper={Box} />
@@ -51,13 +57,12 @@ export const InlineWrapper: React.VFC = () => (
5157
<SideBySide>
5258
<div>
5359
{[0, 1, 2, 3].map((i) => (
54-
<div>
60+
<div key={i}>
5561
<Skeleton
5662
count={4}
5763
width={75}
5864
inline
5965
wrapper={InlineWrapperWithMargin}
60-
key={i}
6166
/>
6267
</div>
6368
))}
@@ -73,7 +78,7 @@ export const InlineWrapper: React.VFC = () => (
7378
)
7479

7580
export const DifferentDurations: React.VFC = () => (
76-
<div>
81+
<div style={{ width: 500 }}>
7782
<Skeleton duration={1} />
7883
<Skeleton duration={2} />
7984
<Skeleton duration={3} />
@@ -107,6 +112,7 @@ export const CustomStyles: React.VFC = () => (
107112

108113
export const Circle: React.VFC = () => <Skeleton height={50} width={50} circle />
109114

115+
// Use https://bennettfeely.com/clippy/ to try out other shapes
110116
const StarWrapper: React.FC = ({ children }) => (
111117
<div
112118
style={{
@@ -121,7 +127,6 @@ const StarWrapper: React.FC = ({ children }) => (
121127
</div>
122128
)
123129

124-
// Use https://bennettfeely.com/clippy/ to try out other shapes
125130
export const Stars: React.VFC = () => (
126131
<Skeleton
127132
height="100%"

src/skeleton.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
}
66

77
.react-loading-skeleton {
8-
/* If either color is changed, Skeleton.tsx must be updated as well */
98
--base-color: #ebebeb;
109
--highlight-color: #f5f5f5;
1110
--animation-duration: 1.5s;

0 commit comments

Comments
 (0)