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'
import videojs from 'video.js'
import 'videojs-youtube'
const Player = (props) => {
const [videoEl, setVideoEl] = useState(null)
const onVideo = useCallback((el) => {
interface PlayerProps {
techOrder: string[]
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)
}, [])
......@@ -25,5 +32,3 @@ const Player = (props) => {
</>
)
}
export default Player
import 'videojs-youtube'
const PlayerCSS = () => {
export default function PlayerCSS() {
return (
<>
<h1>The implementation below is without react functions</h1>
......@@ -17,5 +17,3 @@ const PlayerCSS = () => {
</>
)
}
export default PlayerCSS
......@@ -6,10 +6,17 @@
"start": "next start"
},
"dependencies": {
"next": "^9.1.8-canary.11",
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"video.js": "^6.7.3",
"videojs-youtube": "^2.4.1"
"video.js": "^7.20.3",
"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'
function MyApp({ Component, pageProps }) {
export default function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
export default MyApp
import Player from '../components/Player'
import PlayerCSS from '../components/PlayerCss'
const Index = () => {
export default function Index() {
const videoJsOptions = {
techOrder: ['youtube'],
autoplay: false,
......@@ -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} */
const nextConfig = {
reactStrictMode: true,
compiler: {
styledComponents: true,
},
}
module.exports = nextConfig
......@@ -7,10 +7,15 @@
"lint": "next lint"
},
"dependencies": {
"@gympass/yoga": "^7.28.0",
"@gympass/yoga": "^7.61.0",
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"styled-components": "^4.4.1"
"react-dom": "^18.2.0"
},
"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} */
module.exports = {
const nextConfig = {
basePath: '/blog',
}
module.exports = nextConfig
......@@ -10,5 +10,10 @@
"react": "^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 Image from 'next/image'
export default function Blog() {
return (
......@@ -13,15 +12,7 @@ export default function Blog() {
<Link href="/post/2">Post 2</Link>
</li>
</ul>
<a href="/">Home</a>
<div>
<Image
src="/blog/static/nextjs.png"
alt="Next.js logo"
width={200}
height={160}
/>
</div>
<Link href="/">Home</Link>
</div>
)
}
......@@ -3,6 +3,7 @@ import { useRouter } from 'next/router'
export default function Post() {
const router = useRouter()
return (
<div>
<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
/** @type {import('next').NextConfig} */
module.exports = {
const nextConfig = {
async rewrites() {
return [
{
......@@ -19,3 +19,5 @@ module.exports = {
]
},
}
module.exports = nextConfig
......@@ -10,5 +10,10 @@
"react": "^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 dynamic from 'next/dynamic'
import Image from 'next/image'
const Header = dynamic(import('../components/Header'))
......@@ -15,12 +14,6 @@ export default function Home() {
<div>
<Link href="/about">About us</Link>
</div>
<Image
src="/static/nextjs.png"
alt="Next.js logo"
width={200}
height={160}
/>
</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