Skip to content

Commit 145d771

Browse files
committed
chore: make example work with codesandbox ci
1 parent 623839c commit 145d771

File tree

6 files changed

+101
-10
lines changed

6 files changed

+101
-10
lines changed

.codesandbox/ci.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"buildCommand": "compile"
2+
"buildCommand": "compile",
3+
"sandboxes": ["/example"]
34
}

.gitignore

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
node_modules
1+
node_modules/
22
npm-debug.log
3-
dist
4-
es
5-
.vscode/*
6-
.cache/*
7-
build/*
3+
dist/
4+
.vscode/
5+
.cache/
6+
build/

example/index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<meta charset="utf-8" />
54
<title>react-youtube example</title>
5+
<meta charset="UTF-8" />
66
</head>
7+
78
<body>
8-
<div id="root"></div>
9-
<script src="./example.js"></script>
9+
<div id="app"></div>
10+
11+
<script src="src/index.js"></script>
1012
</body>
1113
</html>

example/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "react-youtube-example",
3+
"version": "1.0.0",
4+
"description": "react-youtube example starter project",
5+
"main": "index.html",
6+
"scripts": {
7+
"start": "parcel index.html --open",
8+
"build": "parcel build index.html"
9+
},
10+
"dependencies": {
11+
"react": "16.13.1",
12+
"react-dom": "16.13.1",
13+
"react-youtube": "7.11.2"
14+
},
15+
"devDependencies": {
16+
"@babel/core": "7.2.0",
17+
"parcel-bundler": "^1.6.1"
18+
},
19+
"keywords": [
20+
"javascript",
21+
"starter"
22+
]
23+
}

example/src/index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React, { useState } from 'react';
2+
import ReactDOM from 'react-dom';
3+
import YouTube from 'react-youtube';
4+
5+
import './styles.css';
6+
7+
const VIDEOS = ['XxVg_s8xAms', '-DX3vJiqxm4'];
8+
9+
function YouTubeComponentExample() {
10+
const [player, setPlayer] = useState(0);
11+
const [videoIndex, setVideoIndex] = useState(0);
12+
const [width, setWidth] = useState(600);
13+
const [hidden, setHidden] = useState(false);
14+
const [autoplay, setAutoplay] = useState(false);
15+
16+
return (
17+
<div className="App">
18+
<div style={{ display: 'flex', marginBottom: '1em' }}>
19+
<button type="button" onClick={() => player.seekTo(120)}>
20+
Seek to 2 minutes
21+
</button>
22+
<button type="button" onClick={() => setVideoIndex((videoIndex + 1) % VIDEOS.length)}>
23+
Change video
24+
</button>
25+
<label>
26+
<input
27+
type="range"
28+
min="300"
29+
max="1080"
30+
value={width}
31+
onChange={(event) => setWidth(event.currentTarget.value)}
32+
/>
33+
Width ({width}px)
34+
</label>
35+
<button type="button" onClick={() => setHidden(!hidden)}>
36+
{hidden ? 'Show' : 'Hide'}
37+
</button>
38+
<label>
39+
<input type="checkbox" value={autoplay} onChange={(event) => setAutoplay(event.currentTarget.checked)} />
40+
Autoplaying
41+
</label>
42+
</div>
43+
44+
{hidden ? (
45+
'mysterious'
46+
) : (
47+
<YouTube
48+
videoId={VIDEOS[videoIndex]}
49+
autoplay={autoplay}
50+
width={width}
51+
height={width * (9 / 16)}
52+
className="container"
53+
onReady={(event) => setPlayer(event.target)}
54+
/>
55+
)}
56+
</div>
57+
);
58+
}
59+
60+
ReactDOM.render(<YouTubeComponentExample />, document.getElementById('app'));

example/src/styles.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#app {
2+
font-family: sans-serif;
3+
display: flex;
4+
align-items: center;
5+
flex-direction: column;
6+
}

0 commit comments

Comments
 (0)