Skip to content

Commit c1f5aab

Browse files
authored
refactor(media): change media components api to simplify using static media (#207)
1 parent 437d109 commit c1f5aab

File tree

14 files changed

+68
-27
lines changed

14 files changed

+68
-27
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ Marketing website for Commit (commit.dev)
44
### Importing static images
55

66
**1)** Place the image you want to display in the `/static/` folder
7-
**2)** Display the image with [`<Image>`](./components/media/image.js) component:
7+
**2)** Display the image with [`<StaticImage>`](./components/media/static-image.js) component:
88
```jsx
9-
<Image {...getStaticImage('my-image-name.png')} alt="My image" />
9+
import { StaticImage } from 'components'
10+
11+
<StaticImage name="my-image-name.png" alt="My image" />
1012
```
1113

1214
Images are automatically generated at build time and lazy-loaded at run time.
@@ -34,9 +36,11 @@ Processing ~/path/to/video.mov (13.4 MB)...
3436
-- generated static/videos/video.mp4 (1.28 MB)
3537
```
3638

37-
**3)** Use generated files with [`<BackgroundVideo>`](./components/media/video.js) component:
39+
**3)** Use generated files with [`<StaticBackgroundVideo>`](./components/media/background-video.js) component:
3840
```jsx
39-
<BackgroundVideo {...getStaticVideo('video')} alt="My background video" />
41+
import { StaticBackgroundVideo } from 'components'
42+
43+
<StaticBackgroundVideo name="video" alt="My background video" />
4044
```
4145

4246
Videos are lazy-loaded at run time.

components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export { default as SocialIcons } from './social-icons'
1313
export { default as Testimonials } from './testimonials'
1414
export { default as Text } from './text'
1515
export { default as TextArea } from './textarea'
16+
export * from './media'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Video } from './video'
2+
3+
function BackgroundVideo(props) {
4+
return <Video muted data-autoplay="" loop playsinline {...props} />
5+
}
6+
7+
export { BackgroundVideo }

components/media/image.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ Image.propTypes = {
5656
className: string,
5757
}
5858

59-
export default Image
59+
export { Image }

components/media/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ const GlobalMediaStyles = createGlobalStyle`
1717
${lazyStyles}
1818
`
1919

20-
export { default as Image } from './image'
21-
export { Video, BackgroundVideo } from './video'
20+
export { Image } from './image'
21+
export { StaticImage } from './static-image'
22+
export { Video } from './video'
23+
export { StaticVideo } from './static-video'
24+
export { BackgroundVideo } from './background-video'
25+
export { StaticBackgroundVideo } from './static-background-video'
2226
export { GlobalMediaStyles }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { StaticVideo } from './static-video'
2+
3+
function StaticBackgroundVideo(props) {
4+
return <StaticVideo muted data-autoplay="" loop playsinline {...props} />
5+
}
6+
7+
export { StaticBackgroundVideo }

components/media/static-image.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { string } from 'prop-types'
2+
3+
import { getStaticImage } from './get-static-image'
4+
import { Image } from './image'
5+
6+
function StaticImage({ name, ...otherProps }) {
7+
return <Image {...getStaticImage(name)} {...otherProps} />
8+
}
9+
10+
StaticImage.propTypes = {
11+
name: string,
12+
}
13+
14+
export { StaticImage }

components/media/static-video.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { string } from 'prop-types'
2+
3+
import { getStaticVideo } from './get-static-video'
4+
import { Video } from './video'
5+
6+
function StaticVideo({ name, ...otherProps }) {
7+
return <Video {...getStaticVideo(name)} {...otherProps} />
8+
}
9+
10+
StaticVideo.propTypes = {
11+
name: string,
12+
}
13+
14+
export { StaticVideo }

0 commit comments

Comments
 (0)