Skip to content

Commit b1b27e8

Browse files
committed
Custom highlight background
1 parent d8c1492 commit b1b27e8

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed
17.2 KB
Loading

src/Skeleton.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function styleOptionsToCssProperties({
1818
direction,
1919
duration,
2020
enableAnimation = defaultEnableAnimation,
21+
22+
customHighlightBackground,
2123
}: SkeletonStyleProps & { circle: boolean }): CSSProperties &
2224
Record<`--${string}`, string> {
2325
const style: ReturnType<typeof styleOptionsToCssProperties> = {};
@@ -41,6 +43,9 @@ function styleOptionsToCssProperties({
4143
if (typeof highlightColor !== 'undefined')
4244
style['--highlight-color'] = highlightColor;
4345

46+
if (typeof customHighlightBackground === 'string')
47+
style['--custom-highlight-background'] = customHighlightBackground;
48+
4449
return style;
4550
}
4651

src/SkeletonStyleProps.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ export interface SkeletonStyleProps {
1010
duration?: number;
1111
direction?: 'ltr' | 'rtl';
1212
enableAnimation?: boolean;
13+
14+
customHighlightBackground?: string;
1315
}

src/__stories__/Skeleton.stories.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,34 @@ export const PrefersReducedMotion = () => (
427427
/>
428428
</div>
429429
);
430+
431+
export const HighlightWidth = () => (
432+
<div style={{ width: 500 }}>
433+
<p>Default</p>
434+
<Skeleton
435+
highlightColor="#E0B0FF"
436+
customHighlightBackground="linear-gradient(90deg, var(--base-color) 0%, var(--highlight-color) 50%, var(--base-color) 100%)"
437+
/>
438+
<br />
439+
440+
<p>Narrow highlight</p>
441+
<Skeleton
442+
highlightColor="#E0B0FF"
443+
customHighlightBackground="linear-gradient(90deg, var(--base-color) 40%, var(--highlight-color) 50%, var(--base-color) 60%)"
444+
/>
445+
<br />
446+
447+
<p>Wide highlight</p>
448+
<Skeleton
449+
highlightColor="#E0B0FF"
450+
customHighlightBackground="linear-gradient(90deg, var(--base-color) 0%, var(--highlight-color) 5%, var(--highlight-color) 95%, var(--base-color) 100%)"
451+
/>
452+
<br />
453+
454+
<p>Fun gradient</p>
455+
<Skeleton
456+
highlightColor="#E0B0FF"
457+
customHighlightBackground="linear-gradient(90deg, var(--base-color) 0%, rgba(131,58,180,1) 25%, rgba(253,29,29,1) 50%, rgba(252,176,69,1) 75%, var(--base-color) 100%)"
458+
/>
459+
</div>
460+
);

src/skeleton.css

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@
3232
right: 0;
3333
height: 100%;
3434
background-repeat: no-repeat;
35-
background-image: linear-gradient(
36-
90deg,
37-
var(--base-color),
38-
var(--highlight-color),
39-
var(--base-color)
35+
background-image: var(
36+
--custom-highlight-background,
37+
linear-gradient(
38+
90deg,
39+
var(--base-color) 0%,
40+
var(--highlight-color) 50%,
41+
var(--base-color) 100%
42+
)
4043
);
4144
transform: translateX(-100%);
4245

0 commit comments

Comments
 (0)