Skip to content

Commit 6f6def3

Browse files
committed
allow custom styles
1 parent 308915c commit 6f6def3

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/index.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,18 @@ it("should render the required number of skeletons", () => {
1717

1818
expect(skeletonElements.length).toBe(4);
1919
});
20+
21+
it("should render a skeleton with styles", () => {
22+
const style = { boarderRadius: 10, height: 50, width: 50 };
23+
const skeleton = mount(<Skeleton style={style} />);
24+
expect(skeleton.find(skeletonSelector).prop("style")).toEqual(style);
25+
});
26+
27+
it("inline style prop should overwrite custom styles", () => {
28+
const style = { boarderRadius: 10, height: 50, width: 50 };
29+
const skeleton = mount(<Skeleton height={100} style={style} />);
30+
expect(skeleton.find(skeletonSelector).prop("style")).toEqual({
31+
...style,
32+
height: 100,
33+
});
34+
});

src/skeleton.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export default function Skeleton({
3636
width,
3737
wrapper: Wrapper,
3838
height,
39-
circle
39+
circle,
40+
style: customStyle,
4041
}) {
4142
const elements = [];
4243

@@ -63,7 +64,10 @@ export default function Skeleton({
6364
${skeletonStyles}
6465
animation: ${skeletonKeyframes} ${duration}s ease-in-out infinite
6566
`}
66-
style={style}
67+
style={{
68+
...customStyle,
69+
...style,
70+
}}
6771
>
6872
&zwnj;
6973
</span>

stories/Skeleton.story.js

+6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ storiesOf("Skeleton", module)
9999
<Skeleton count={1} height="50em" />
100100
</div>
101101
))
102+
.add("Skeleton with styles", () => (
103+
<Skeleton
104+
height="100px"
105+
style={{ boarderRadius: 10, height: 50, width: 50 }}
106+
/>
107+
))
102108
.add("Skeleton displayed as circle", () => (
103109
<div style={{ display: "flex", flexDirection: "column" }}>
104110
<Skeleton count={1} height={50} width={50} circle={true} />

0 commit comments

Comments
 (0)