Skip to content

Commit 06432e2

Browse files
authored
fix(Interface): extend svg attr (#172)
* fix(interface): extends from svg element * fix(native interface): extend from svg native package
1 parent ca628bf commit 06432e2

File tree

6 files changed

+47
-79
lines changed

6 files changed

+47
-79
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ const MyLoader = () => (
115115

116116
Defaults to `true`. Opt-out of animations with `false`
117117

118-
#### **`ariaLabel? string`** - _Web only_
118+
#### **`ariaLabel?: string`** - _Web only_
119119

120120
Defaults to `Loading interface...`. It's used to describe what element it is. Use ''(empty string) to remove.
121121

122-
#### **`baseUrl? string`** - _Web only_
122+
#### **`baseUrl?: string`** - _Web only_
123123

124124
Required if you're using `<base url="/" />` document `<head/>`
125125
Defaults to an empty string. This prop is common used as: `<ContentLoader baseUrl={window.location.pathname} />` which will fill the SVG attribute with the relative path. Related [#93](https://github.com/danilowoz/react-content-loader/issues/93).
@@ -132,27 +132,27 @@ Defaults to `2`. Animation speed in seconds.
132132

133133
Defaults to `0.25`. Interval of time between runs of the animation, as a fraction of the animation speed.
134134

135-
#### **`className? string`**
135+
#### **`className?: string`**
136136

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

139-
#### **`width? number`**
139+
#### **`width?: number`**
140140

141141
Defaults to `400`. It will be set in the viewbox attr in the `<svg />`.
142142

143-
#### **`height? number`**
143+
#### **`height?: number`**
144144

145145
Defaults to `130`. It will be set in the viewbox attr in the `<svg />`.
146146

147147
#### **`viewBox?: string`**
148148

149149
Use viewBox props to set a custom viewBox value. Additionally, pass viewBox props as empty string to remove viewBox.
150150

151-
#### **`gradientRatio? number`** - _Web only_
151+
#### **`gradientRatio?: number`** - _Web only_
152152

153153
Defaults to `2`. Width of the animated gradient as a fraction of the viewbox width.
154154

155-
#### **`rtl? boolean`**
155+
#### **`rtl?: boolean`**
156156

157157
Defaults to `false`. Content right-to-left.
158158

docs/index.stories.tsx

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22

3-
import { Facebook, Instagram } from '../src'
3+
import ContentLoader, { Facebook, Instagram } from '../src'
44

55
export default {
66
title: 'React Content Loader',
@@ -30,7 +30,7 @@ export const ariaLabel = () => {
3030

3131
ariaLabel.story = {
3232
parameters: {
33-
notes: `## \`ariaLabel? string | boolean\`
33+
notes: `## \`ariaLabel?: string | boolean\`
3434
3535
Defaults to \`Loading interface...\`. It's used to describe what element it is. Use \`false\` to remove.
3636
`,
@@ -46,13 +46,28 @@ export const baseURL = () => {
4646

4747
baseURL.story = {
4848
parameters: {
49-
notes: `## \`baseUrl? string\`
49+
notes: `## \`baseUrl?: string\`
5050
5151
Required if you're using \`<base url="/" />\` in the \`<head/>\`. Defaults to an empty string. This prop is common used as: \`<ContentLoader baseUrl={window.location.pathname} />\` which will fill the SVG attribute with the relative path. Related [#93](https://github.com/danilowoz/react-content-loader/issues/93).
5252
`,
5353
},
5454
}
5555

56+
/**
57+
* Children
58+
*/
59+
export const children = () => {
60+
return (
61+
<ContentLoader>
62+
<rect x="0" y="0" rx="5" ry="5" width="70" height="70" />
63+
<rect x="80" y="17" rx="4" ry="4" width="300" height="13" />
64+
<rect x="80" y="40" rx="3" ry="3" width="250" height="10" />
65+
</ContentLoader>
66+
)
67+
}
68+
69+
children.story = { parameters: { notes: `## \`children?: ReactNode\`` } }
70+
5671
/**
5772
* Speed
5873
*/
@@ -97,7 +112,7 @@ export const width = () => {
97112

98113
width.story = {
99114
parameters: {
100-
notes: `## \`width? number\`
115+
notes: `## \`width?: number\`
101116
102117
Defaults to \`400\`. It will be set in the viewbox attr in the \`<svg />\`.`,
103118
},
@@ -112,7 +127,7 @@ export const height = () => {
112127

113128
height.story = {
114129
parameters: {
115-
notes: `## \`height? number\`
130+
notes: `## \`height?: number\`
116131
117132
Defaults to \`130\`. It will be set in the viewbox attr in the \`<svg />\`.`,
118133
},
@@ -140,7 +155,7 @@ export const gradientRatio = () => {
140155

141156
gradientRatio.story = {
142157
parameters: {
143-
notes: `## \`gradientRatio? number\`
158+
notes: `## \`gradientRatio?: number\`
144159
145160
Defaults to \`2\`. Width of the animated gradient as a fraction of the viewbox width.`,
146161
},
@@ -155,7 +170,7 @@ export const RTL = () => {
155170

156171
RTL.story = {
157172
parameters: {
158-
notes: `## \`rtl? boolean\`
173+
notes: `## \`rtl?: boolean\`
159174
160175
Defaults to \`false\`. Content right-to-left.`,
161176
},
@@ -239,15 +254,15 @@ uniqueKey.story = {
239254
/**
240255
* View box
241256
*/
242-
// export const viewBox = () => {
243-
// return <Facebook viewBox="" />
244-
// }
257+
export const viewBox = () => {
258+
return <Facebook viewBox="" />
259+
}
245260

246-
// viewBox.story = {
247-
// parameters: {
248-
// notes: `## \`viewBox?: string\`
261+
viewBox.story = {
262+
parameters: {
263+
notes: `## \`viewBox?: string\`
249264
250-
// Use viewbox props to set viewbox value.
251-
// Additionally, pass viewBox props as empty string to remove viewBox.`,
252-
// },
253-
// }
265+
Use viewbox props to set viewbox value.
266+
Additionally, pass viewBox props as empty string to remove viewBox.`,
267+
},
268+
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,19 @@
1+
import { SVGAttributes } from 'react'
2+
13
import ContentLoader from './Holder'
24

3-
export interface IContentLoaderProps {
5+
export interface IContentLoaderProps extends SVGAttributes<SVGElement> {
46
animate?: boolean
57
ariaLabel?: string
6-
children?: React.ReactNode
78
baseUrl?: string
8-
className?: string
9-
height?: number
10-
preserveAspectRatio?:
11-
| 'none'
12-
| 'xMinYMin meet'
13-
| 'xMidYMin meet'
14-
| 'xMaxYMin meet'
15-
| 'xMinYMid meet'
16-
| 'xMidYMid meet'
17-
| 'xMaxYMid meet'
18-
| 'xMinYMax meet'
19-
| 'xMidYMax meet'
20-
| 'xMaxYMax meet'
21-
| 'xMinYMin slice'
22-
| 'xMidYMin slice'
23-
| 'xMaxYMin slice'
24-
| 'xMinYMid slice'
25-
| 'xMidYMid slice'
26-
| 'xMaxYMid slice'
27-
| 'xMinYMax slice'
28-
| 'xMidYMax slice'
29-
| 'xMaxYMax slice'
309
primaryColor?: string
3110
primaryOpacity?: number
3211
rtl?: boolean
3312
secondaryColor?: string
3413
secondaryOpacity?: number
3514
speed?: number
3615
interval?: number
37-
style?: React.CSSProperties
3816
uniquekey?: string
39-
width?: number
4017
gradientRatio?: number
4118
}
4219

src/native/Svg.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class NativeSvg extends Component<RequiredIContentLoaderProps, State> {
9090
const offset3 = offsetValueBound(this.state.offset + 1)
9191

9292
const rtlStyle = rtl ? { transform: [{ rotateY: '180deg' }] } : {}
93-
const composedStyle = { ...style, ...rtlStyle }
93+
const composedStyle = Object.assign(style, rtlStyle)
9494

9595
// Remove unnecessary keys
9696
delete props.id

src/native/interface.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,11 @@
1-
import * as ReactNative from 'react-native'
1+
import { SvgProps } from 'react-native-svg'
22

3-
export interface IContentLoaderProps {
3+
export interface IContentLoaderProps extends SvgProps {
44
animate?: boolean
55
children?: React.ReactNode
6-
className?: string
7-
height?: number
8-
preserveAspectRatio?:
9-
| 'none'
10-
| 'xMinYMin meet'
11-
| 'xMidYMin meet'
12-
| 'xMaxYMin meet'
13-
| 'xMinYMid meet'
14-
| 'xMidYMid meet'
15-
| 'xMaxYMid meet'
16-
| 'xMinYMax meet'
17-
| 'xMidYMax meet'
18-
| 'xMaxYMax meet'
19-
| 'xMinYMin slice'
20-
| 'xMidYMin slice'
21-
| 'xMaxYMin slice'
22-
| 'xMinYMid slice'
23-
| 'xMidYMid slice'
24-
| 'xMaxYMid slice'
25-
| 'xMinYMax slice'
26-
| 'xMidYMax slice'
27-
| 'xMaxYMax slice'
286
id?: string
297
primaryColor?: string
308
rtl?: boolean
319
secondaryColor?: string
3210
speed?: number
33-
style?: ReactNative.ViewStyle
34-
width?: number
3511
}

0 commit comments

Comments
 (0)