Unverified Commit 1d5dd1ba authored by Max Proske's avatar Max Proske Committed by GitHub

Convert amp-story example to TypeScript (#38038)

Converted AMP Story example over to TypeScript to align with the Examples guide.

Note: Requires `v12.1.7-canary.41` or newer to build https://github.com/vercel/next.js/pull/37744#issuecomment-1159573754

## Documentation / Examples

- [X] Make sure the linting passes by running `pnpm lint`
- [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent 8019cf00
// Allow AMP elements to be a property on JSX.IntrinsicElements
// Only the intrinsic elements defined here will be accepted, and only with the attributes defined here
declare namespace JSX {
interface AmpImg {
alt: string
src: string
width?: string
height?: string
layout: string
}
interface AmpVideo {
width: string
height: string
layout: string
poster: string
children: React.ReactNode
autoplay: string
loop?: string
}
interface AmpStory {
standalone: string
title: string
publisher: string
'publisher-logo-src': string
'poster-portrait-src': string
children: React.ReactNode
}
interface AmpStoryPage {
id: string
children: React.ReactNode
}
interface AmpStoryGridLayer {
template: 'fill' | 'vertical' | 'horizontal' | 'thirds'
children: React.ReactNode
}
interface AmpStoryBookend {
src: string
layout?:
| 'fill'
| 'fixed'
| 'fixed-height'
| 'flex-item'
| 'intrinsic'
| 'nodisplay'
| 'responsive'
}
interface IntrinsicElements {
'amp-img': AmpImg
'amp-video': AmpVideo
'amp-story': AmpStory
'amp-story-grid-layer': AmpStoryGridLayer
'amp-story-page': AmpStoryPage
'amp-story-bookend': AmpStoryBookend
}
}
// Only the intrinsic elements defined here will be accepted, attributes don't matter
// declare namespace JSX {
// interface IntrinsicElements {
// 'amp-img': any
// 'amp-video': any
// 'amp-story': any
// 'amp-story-grid-layer': any
// 'amp-story-page': any
// 'amp-story-bookend': any
// }
// }
// All intrinsic elements will be accepted
// declare namespace JSX {
// interface IntrinsicElements {
// [elemName: string]: any
// }
// }
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
......@@ -7,7 +7,13 @@
},
"dependencies": {
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"typescript": "^4.7.4"
}
}
......@@ -2,7 +2,7 @@ import Head from 'next/head'
export const config = { amp: true }
export default function Home() {
const Home = () => {
return (
<>
<Head>
......@@ -38,6 +38,7 @@ export default function Home() {
width="720"
height="1280"
layout="responsive"
alt="Story Dog 2"
/>
</amp-story-grid-layer>
<amp-story-grid-layer template="vertical">
......@@ -74,6 +75,7 @@ export default function Home() {
width="720"
height="1280"
layout="responsive"
alt="Story Dog 4"
/>
</amp-story-grid-layer>
<amp-story-grid-layer template="thirds">
......@@ -96,6 +98,7 @@ export default function Home() {
width="560"
height="420"
layout="responsive"
alt="Story Thirds 1"
/>
<amp-img
grid-area="middle-third"
......@@ -103,6 +106,7 @@ export default function Home() {
width="560"
height="420"
layout="responsive"
alt="Story Thirds 2"
/>
<amp-img
grid-area="lower-third"
......@@ -110,6 +114,7 @@ export default function Home() {
width="560"
height="420"
layout="responsive"
alt="Story Thirds 3"
/>
</amp-story-grid-layer>
</amp-story-page>
......@@ -123,3 +128,5 @@ export default function Home() {
</>
)
}
export default Home
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "amp.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