Skip to content

Commit cc13167

Browse files
committed
docs: allow highlighting screenshots with the <Screenshot /> component
1 parent 81dddb1 commit cc13167

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

docs/src/components/Screenshot/index.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
1-
import React from 'react';
1+
import React, { CSSProperties } from 'react';
22
import * as styles from './styles.module.scss';
33

44
interface ScreenshotProps {
55
alt?: string;
66
src: string;
7+
8+
/**
9+
* Use CSS `clip-path` to highlight a specific area of the screenshot.
10+
*
11+
* @example inset(20% 64% 72% 20% round 10px)
12+
*/
13+
highlight?: CSSProperties['clipPath'];
714
}
815

9-
export const Screenshot = ({ alt, src }: ScreenshotProps) => {
16+
const ScreenshotHighlight = ({ highlight, src }: ScreenshotProps) => (
17+
<div
18+
className={styles.highlight}
19+
style={{
20+
backgroundImage: `url(${src})`,
21+
clipPath: highlight,
22+
}}
23+
/>
24+
)
25+
26+
export const Screenshot = (props: ScreenshotProps) => {
1027
return (
1128
<div className={styles.screenshot} style={{ textAlign: 'center'}}>
29+
{props.highlight ? (<ScreenshotHighlight {...props} />) : null}
1230
<img
13-
alt={alt}
14-
src={src}
15-
style={{ border: 'none' }}
31+
alt={props.alt}
32+
src={props.src}
33+
style={{ border: 'none', filter: props.highlight ? 'brightness(0.5)' : 'none' }}
1634
width="100%"
1735
/>
1836
</div>

docs/src/components/Screenshot/styles.module.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@
3333
//transform: scale(.25);
3434
}
3535
}
36+
37+
.highlight {
38+
width: 100%;
39+
height: 100%;
40+
position: absolute;
41+
background-size: contain;
42+
z-index: 9999;
43+
}

0 commit comments

Comments
 (0)