Skip to content

Commit 6f26e2d

Browse files
alexkirszdanilowoz
authored andcommitted
feat(svg): add an interval prop (#139)
* feat(svg): add an interval prop Add an interval prop that controls the duration of the interval between two animations. For instance, an interval of `.25` and an animation speed of `2` imply that the animation will take 1.5s to complete, and wait 0.5s before starting again. * docs(options): add interval prop
1 parent 21dbad6 commit 6f26e2d

File tree

14 files changed

+1038
-956
lines changed

14 files changed

+1038
-956
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ Defaults to `Loading interface...`. It's used to describe what element it is. Us
7878

7979
Defaults to `2`. Animation speed in seconds.
8080

81+
**`interval?: number`**
82+
83+
Defaults to `0.25`. Interval of time between runs of the animation, as a fraction of the animation speed.
84+
8185
**`className? string`**
8286

8387
Defaults to an empty string. The classname will be set in the `<svg />` element.

docs/intro.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ Defaults to `Loading interface...`. It's used to describe what element it is. Us
7373

7474
Defaults to `2`. Animation speed in seconds.
7575

76+
**`interval?: number`**
77+
78+
Defaults to `0.25`. Interval of time between runs of the animation, as a fraction of the animation speed.
79+
7680
**`className? string`**
7781

7882
Defaults to an empty string. The classname will be set in the `<svg />` element.

docs/usage.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ import FacebookStyle from '../src/stylized/FacebookStyle'
5555
<Playground>
5656
<ContentLoader
5757
height={140}
58-
speed={1}
58+
speed={2}
59+
interval={0.5}
5960
primaryColor={'#333'}
6061
secondaryColor={'#999'}
6162
>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
"babel-jest": "^23.6.0",
5858
"commitizen": "^3.0.5",
5959
"cz-conventional-changelog": "^2.1.0",
60-
"docz": "^0.12.13",
61-
"docz-theme-default": "^0.12.13",
60+
"docz": "^0.13.7",
61+
"docz-theme-default": "^0.13.7",
6262
"husky": "^1.1.2",
6363
"jest": "^23.6.0",
6464
"prettier": "^1.15.3",

src/Holder.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const defaultProps: IContentLoaderProps = {
77
animate: true,
88
ariaLabel: 'Loading interface...',
99
height: 130,
10+
interval: 0.25,
1011
preserveAspectRatio: 'none',
1112
primaryColor: '#f0f0f0',
1213
primaryOpacity: 1,

src/Svg.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import uid from './uid'
66
export default ({
77
rtl,
88
speed,
9+
interval,
910
style,
1011
width,
1112
height,
@@ -24,6 +25,8 @@ export default ({
2425
const idClip = uniquekey ? `${uniquekey}-idClip` : uid()
2526
const idGradient = uniquekey ? `${uniquekey}-idGradient` : uid()
2627
const rtlStyle = rtl ? { transform: 'scaleX(-1)' } : {}
28+
const keyTimes = `0; ${interval}; 1`
29+
const dur = `${speed}s`
2730

2831
return (
2932
<svg
@@ -57,8 +60,9 @@ export default ({
5760
{animate && (
5861
<animate
5962
attributeName="offset"
60-
values="-3; 1"
61-
dur={`${speed}s`}
63+
values={`-2; -2; 1`}
64+
keyTimes={keyTimes}
65+
dur={dur}
6266
repeatCount="indefinite"
6367
/>
6468
)}
@@ -72,8 +76,9 @@ export default ({
7276
{animate && (
7377
<animate
7478
attributeName="offset"
75-
values="-2; 2"
76-
dur={`${speed}s`}
79+
values={`-1; -1; 2`}
80+
keyTimes={keyTimes}
81+
dur={dur}
7782
repeatCount="indefinite"
7883
/>
7984
)}
@@ -87,8 +92,9 @@ export default ({
8792
{animate && (
8893
<animate
8994
attributeName="offset"
90-
values="-1; 3"
91-
dur={`${speed}s`}
95+
values={`0; 0; 3`}
96+
keyTimes={keyTimes}
97+
dur={dur}
9298
repeatCount="indefinite"
9399
/>
94100
)}

src/__tests__/Holder.tests.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('Holder', () => {
3232
<ContentLoader
3333
rtl
3434
speed={10}
35+
interval={0.5}
3536
width={200}
3637
height={200}
3738
animate={false}
@@ -58,6 +59,15 @@ describe('Holder', () => {
5859
expect(propsFromFullfield.speed).toBe(10)
5960
})
6061

62+
it("`interval` is a number and it's used", () => {
63+
// defaultProps
64+
expect(typeof propsFromEmpty.interval).toBe('number')
65+
expect(propsFromEmpty.interval).toBe(0.25)
66+
// custom props
67+
expect(typeof propsFromFullfield.interval).toBe('number')
68+
expect(propsFromFullfield.interval).toBe(0.5)
69+
})
70+
6171
it("`height` is a number and it's used", () => {
6272
// defaultProps
6373
expect(typeof propsFromEmpty.height).toBe('number')

src/__tests__/stylized/__snapshots__/BulletListStyle.test.tsx.snap

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ exports[`BulletListStyle renders correctly 1`] = `
9191
<animate
9292
attributeName="offset"
9393
dur="20s"
94+
keyTimes="0; 0.25; 1"
9495
repeatCount="indefinite"
95-
values="-3; 1"
96+
values="-2; -2; 1"
9697
/>
9798
</stop>
9899
<stop
@@ -103,8 +104,9 @@ exports[`BulletListStyle renders correctly 1`] = `
103104
<animate
104105
attributeName="offset"
105106
dur="20s"
107+
keyTimes="0; 0.25; 1"
106108
repeatCount="indefinite"
107-
values="-2; 2"
109+
values="-1; -1; 2"
108110
/>
109111
</stop>
110112
<stop
@@ -115,8 +117,9 @@ exports[`BulletListStyle renders correctly 1`] = `
115117
<animate
116118
attributeName="offset"
117119
dur="20s"
120+
keyTimes="0; 0.25; 1"
118121
repeatCount="indefinite"
119-
values="-1; 3"
122+
values="0; 0; 3"
120123
/>
121124
</stop>
122125
</linearGradient>

src/__tests__/stylized/__snapshots__/CodeStyle.test.tsx.snap

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ exports[`CodeStyle renders correctly 1`] = `
111111
<animate
112112
attributeName="offset"
113113
dur="20s"
114+
keyTimes="0; 0.25; 1"
114115
repeatCount="indefinite"
115-
values="-3; 1"
116+
values="-2; -2; 1"
116117
/>
117118
</stop>
118119
<stop
@@ -123,8 +124,9 @@ exports[`CodeStyle renders correctly 1`] = `
123124
<animate
124125
attributeName="offset"
125126
dur="20s"
127+
keyTimes="0; 0.25; 1"
126128
repeatCount="indefinite"
127-
values="-2; 2"
129+
values="-1; -1; 2"
128130
/>
129131
</stop>
130132
<stop
@@ -135,8 +137,9 @@ exports[`CodeStyle renders correctly 1`] = `
135137
<animate
136138
attributeName="offset"
137139
dur="20s"
140+
keyTimes="0; 0.25; 1"
138141
repeatCount="indefinite"
139-
values="-1; 3"
142+
values="0; 0; 3"
140143
/>
141144
</stop>
142145
</linearGradient>

src/__tests__/stylized/__snapshots__/FacebookStyle.test.tsx.snap

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ exports[`FacebookStyle renders correctly 1`] = `
8484
<animate
8585
attributeName="offset"
8686
dur="20s"
87+
keyTimes="0; 0.25; 1"
8788
repeatCount="indefinite"
88-
values="-3; 1"
89+
values="-2; -2; 1"
8990
/>
9091
</stop>
9192
<stop
@@ -96,8 +97,9 @@ exports[`FacebookStyle renders correctly 1`] = `
9697
<animate
9798
attributeName="offset"
9899
dur="20s"
100+
keyTimes="0; 0.25; 1"
99101
repeatCount="indefinite"
100-
values="-2; 2"
102+
values="-1; -1; 2"
101103
/>
102104
</stop>
103105
<stop
@@ -108,8 +110,9 @@ exports[`FacebookStyle renders correctly 1`] = `
108110
<animate
109111
attributeName="offset"
110112
dur="20s"
113+
keyTimes="0; 0.25; 1"
111114
repeatCount="indefinite"
112-
values="-1; 3"
115+
values="0; 0; 3"
113116
/>
114117
</stop>
115118
</linearGradient>

0 commit comments

Comments
 (0)