Unverified Commit 093354c6 authored by Max Proske's avatar Max Proske Committed by GitHub

Convert `with-videojs`, `with-yoga`, `with-zones` examples to TypeScript (#43280)

parent ee974817
...@@ -2,9 +2,16 @@ import { useCallback, useEffect, useState } from 'react' ...@@ -2,9 +2,16 @@ import { useCallback, useEffect, useState } from 'react'
import videojs from 'video.js' import videojs from 'video.js'
import 'videojs-youtube' import 'videojs-youtube'
const Player = (props) => { interface PlayerProps {
const [videoEl, setVideoEl] = useState(null) techOrder: string[]
const onVideo = useCallback((el) => { autoplay: boolean
controls: boolean
sources: { src: string; type: string }[]
}
export default function Player(props: PlayerProps) {
const [videoEl, setVideoEl] = useState<HTMLVideoElement | null>(null)
const onVideo = useCallback((el: HTMLVideoElement) => {
setVideoEl(el) setVideoEl(el)
}, []) }, [])
...@@ -25,5 +32,3 @@ const Player = (props) => { ...@@ -25,5 +32,3 @@ const Player = (props) => {
</> </>
) )
} }
export default Player
import 'videojs-youtube' import 'videojs-youtube'
const PlayerCSS = () => { export default function PlayerCSS() {
return ( return (
<> <>
<h1>The implementation below is without react functions</h1> <h1>The implementation below is without react functions</h1>
...@@ -17,5 +17,3 @@ const PlayerCSS = () => { ...@@ -17,5 +17,3 @@ const PlayerCSS = () => {
</> </>
) )
} }
export default PlayerCSS
...@@ -6,10 +6,17 @@ ...@@ -6,10 +6,17 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"next": "^9.1.8-canary.11", "next": "latest",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"video.js": "^6.7.3", "video.js": "^7.20.3",
"videojs-youtube": "^2.4.1" "videojs-youtube": "^2.6.1"
},
"devDependencies": {
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"@types/video.js": "^7.3.49",
"typescript": "^4.9.3"
} }
} }
import type { AppProps } from 'next/app'
import 'video.js/dist/video-js.css' import 'video.js/dist/video-js.css'
function MyApp({ Component, pageProps }) { export default function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} /> return <Component {...pageProps} />
} }
export default MyApp
import Player from '../components/Player' import Player from '../components/Player'
import PlayerCSS from '../components/PlayerCss' import PlayerCSS from '../components/PlayerCss'
const Index = () => { export default function Index() {
const videoJsOptions = { const videoJsOptions = {
techOrder: ['youtube'], techOrder: ['youtube'],
autoplay: false, autoplay: false,
...@@ -21,5 +21,3 @@ const Index = () => { ...@@ -21,5 +21,3 @@ const Index = () => {
</> </>
) )
} }
export default Index
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "videojs.d.ts"],
"exclude": ["node_modules"]
}
declare module 'videojs-youtube'
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
reactStrictMode: true, reactStrictMode: true,
compiler: {
styledComponents: true,
},
} }
module.exports = nextConfig module.exports = nextConfig
...@@ -7,10 +7,15 @@ ...@@ -7,10 +7,15 @@
"lint": "next lint" "lint": "next lint"
}, },
"dependencies": { "dependencies": {
"@gympass/yoga": "^7.28.0", "@gympass/yoga": "^7.61.0",
"next": "latest", "next": "latest",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0"
"styled-components": "^4.4.1" },
"devDependencies": {
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"typescript": "^4.9.3"
} }
} }
import { ThemeProvider, FontLoader } from '@gympass/yoga'
import { createGlobalStyle } from 'styled-components'
const GlobalStyle = createGlobalStyle`
body {
margin: 20px;
padding: 0;
box-sizing: border-box;
}
`
function MyApp({ Component, pageProps }) {
return (
<ThemeProvider>
<GlobalStyle />
<FontLoader />
<Component {...pageProps} />
</ThemeProvider>
)
}
export default MyApp
import type { AppProps } from 'next/app'
import { ThemeProvider } from '@gympass/yoga'
export default function MyApp({ Component, pageProps }: AppProps) {
return (
<ThemeProvider>
<Component {...pageProps} />
</ThemeProvider>
)
}
import Document from 'next/document'
import { ServerStyleSheet } from 'styled-components'
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const sheet = new ServerStyleSheet()
const originalRenderPage = ctx.renderPage
try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) =>
sheet.collectStyles(<App {...props} />),
})
const initialProps = await Document.getInitialProps(ctx)
return {
...initialProps,
styles: (
<>
{initialProps.styles}
{sheet.getStyleElement()}
</>
),
}
} finally {
sheet.seal()
}
}
}
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "yoga.d.ts"],
"exclude": ["node_modules"]
}
declare module '@gympass/yoga'
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
module.exports = { const nextConfig = {
basePath: '/blog', basePath: '/blog',
} }
module.exports = nextConfig
...@@ -10,5 +10,10 @@ ...@@ -10,5 +10,10 @@
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0" "react-dom": "^18.2.0"
}, },
"license": "MIT" "devDependencies": {
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"typescript": "^4.9.3"
}
} }
import Link from 'next/link' import Link from 'next/link'
import Image from 'next/image'
export default function Blog() { export default function Blog() {
return ( return (
...@@ -13,15 +12,7 @@ export default function Blog() { ...@@ -13,15 +12,7 @@ export default function Blog() {
<Link href="/post/2">Post 2</Link> <Link href="/post/2">Post 2</Link>
</li> </li>
</ul> </ul>
<a href="/">Home</a> <Link href="/">Home</Link>
<div>
<Image
src="/blog/static/nextjs.png"
alt="Next.js logo"
width={200}
height={160}
/>
</div>
</div> </div>
) )
} }
...@@ -3,6 +3,7 @@ import { useRouter } from 'next/router' ...@@ -3,6 +3,7 @@ import { useRouter } from 'next/router'
export default function Post() { export default function Post() {
const router = useRouter() const router = useRouter()
return ( return (
<div> <div>
<h3>Post #{router.query.id}</h3> <h3>Post #{router.query.id}</h3>
......
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
const Header = () => (
<div>
<h2>The Company</h2>
</div>
)
export default Header
export default function Header() {
return (
<div>
<h2>The Company</h2>
</div>
)
}
const { BLOG_URL } = process.env const { BLOG_URL } = process.env
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
module.exports = { const nextConfig = {
async rewrites() { async rewrites() {
return [ return [
{ {
...@@ -19,3 +19,5 @@ module.exports = { ...@@ -19,3 +19,5 @@ module.exports = {
] ]
}, },
} }
module.exports = nextConfig
...@@ -10,5 +10,10 @@ ...@@ -10,5 +10,10 @@
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0" "react-dom": "^18.2.0"
}, },
"license": "MIT" "devDependencies": {
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"typescript": "^4.9.3"
}
} }
import Link from 'next/link'
const About = () => (
<div>
<p>This is the about page.</p>
<div>
<Link href="/">Go Back</Link>
</div>
<img width={200} src="/static/vercel.png" />
</div>
)
export default About
import Link from 'next/link'
export default function About() {
return (
<div>
<p>This is the about page.</p>
<div>
<Link href="/">Go Back</Link>
</div>
</div>
)
}
import Link from 'next/link' import Link from 'next/link'
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
import Image from 'next/image'
const Header = dynamic(import('../components/Header')) const Header = dynamic(import('../components/Header'))
...@@ -15,12 +14,6 @@ export default function Home() { ...@@ -15,12 +14,6 @@ export default function Home() {
<div> <div>
<Link href="/about">About us</Link> <Link href="/about">About us</Link>
</div> </div>
<Image
src="/static/nextjs.png"
alt="Next.js logo"
width={200}
height={160}
/>
</div> </div>
) )
} }
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment