-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' into fix/edge-runtime-not-found
- Loading branch information
Showing
19 changed files
with
1,352 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Experimental `@next/third-parties` | ||
|
||
`@next/third-parties` is a collection of components and utilities that can be used to efficiently load third-party libraries into your Next.js application. | ||
|
||
> Note: `@next/third-parties` is still experimental and under active development. | ||
# Usage | ||
|
||
## Google Third-Parties | ||
|
||
### YouTube Embed | ||
|
||
The `YoutubeEmbed` component is used to load and display a YouTube embed. This component loads faster by using [lite-youtube-embed](https://github.com/paulirish/lite-youtube-embed) under the hood. | ||
|
||
```js | ||
import { YoutubeEmbed } from '@next/third-parties/google' | ||
|
||
export default function Page() { | ||
return <YoutubeEmbed videoid="ogfYd705cRs" height={400} /> | ||
} | ||
``` | ||
|
||
### Google Maps Embed | ||
|
||
The `GoogleMapsEmbed` component can be used to add a [Google Maps Embed](https://developers.google.com/maps/documentation/embed/get-started) to your page. By default, it uses the `loading` attribute to lazy-load below the fold. | ||
|
||
```js | ||
import { GoogleMapsEmbed } from '@next/third-parties/google' | ||
|
||
export default function Page() { | ||
return ( | ||
<GoogleMapsEmbed | ||
apiKey="XYZ" | ||
height={200} | ||
width="100%" | ||
mapMode="place" | ||
parameters="q=Brooklyn+Bridge,New+York,NY" | ||
/> | ||
) | ||
} | ||
``` | ||
|
||
To get a better idea of how these components work, take a look at this [demo](https://test-next-script-housseindjirdeh.vercel.app/). <!--- TODO: Replace with a better demo page --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* This is an autogenerated file by update-third-parties.js | ||
*/ | ||
import React from 'react' | ||
import Script from 'next/script' | ||
|
||
import ThirdPartyScriptEmbed from '../ThirdPartyScriptEmbed' | ||
import * as Types from '../types/google' | ||
|
||
// Embed a Google Maps embed on your webpage | ||
export function GoogleMapsEmbed(args: Types.GoogleMapsEmbed) { | ||
return ( | ||
<ThirdPartyScriptEmbed | ||
height={args.height || null} | ||
width={args.width || null} | ||
content={`<iframe loading="lazy" src="https://www.google.com/maps/embed/v1/${args.mapMode}?key=${args.apiKey}&${args.parameters}" width=${args.width} height=${args.height} style=${args.style} allowfullscreen=${args.allowfullscreen} referrerpolicy="no-referrer-when-downgrade"></iframe>`} | ||
dataNtpc="GoogleMapsEmbed" | ||
></ThirdPartyScriptEmbed> | ||
) | ||
} | ||
// Embed a YouTube embed on your webpage. | ||
export function YoutubeEmbed(args: Types.YoutubeEmbed) { | ||
return ( | ||
<ThirdPartyScriptEmbed | ||
height={args.height || null} | ||
width={args.width || null} | ||
content={`<lite-youtube videoid=${args.videoid} playlabel=${args.playlabel}></lite-youtube>`} | ||
dataNtpc="YoutubeEmbed" | ||
> | ||
<Script | ||
src={`https://cdn.jsdelivr.net/gh/paulirish/lite-youtube-embed@master/src/lite-yt-embed.js`} | ||
strategy="lazyOnload" | ||
// @ts-ignore | ||
stylesheets={[ | ||
'https://cdn.jsdelivr.net/gh/paulirish/lite-youtube-embed@master/src/lite-yt-embed.css', | ||
]} | ||
/> | ||
</ThirdPartyScriptEmbed> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export type GoogleMapsEmbed = { | ||
height?: number | ||
width?: number | ||
mapMode: 'place' | 'view' | 'directions' | 'streetview' | 'search' | ||
apiKey: string | ||
parameters: string | ||
style: string | ||
allowfullscreen: boolean | ||
loading: 'eager' | 'lazy' | ||
} | ||
|
||
export type YoutubeEmbed = { | ||
height?: number | ||
width?: number | ||
videoid: string | ||
playlabel?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
test/e2e/app-dir/third-parties/app/google-maps-embed/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { GoogleMapsEmbed } from '@next/third-parties/google' | ||
|
||
const Page = () => { | ||
return ( | ||
<div class="container"> | ||
<h1>Google Maps Embed</h1> | ||
<GoogleMapsEmbed | ||
apiKey="XYZ" | ||
height={200} | ||
width="100%" | ||
mapMode="place" | ||
parameters="q=Brooklyn+Bridge,New+York,NY" | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Root({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { YoutubeEmbed } from '@next/third-parties/google' | ||
|
||
const Page = () => { | ||
return ( | ||
<div class="container"> | ||
<h1>Youtube Embed</h1> | ||
<YoutubeEmbed videoid="ogfYd705cRs" height={400} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'@next/third-parties basic usage', | ||
{ | ||
files: __dirname, | ||
dependencies: { | ||
'@next/third-parties': 'canary', | ||
}, | ||
}, | ||
({ next }) => { | ||
it('renders YoutubeEmbed', async () => { | ||
const $ = await next.render$('/youtube-embed') | ||
|
||
const baseContainer = $('[data-ntpc="YoutubeEmbed"]') | ||
const youtubeContainer = $('lite-youtube') | ||
expect(baseContainer.length).toBe(1) | ||
expect(youtubeContainer.length).toBe(1) | ||
}) | ||
|
||
it('renders GoogleMapsEmbed', async () => { | ||
const $ = await next.render$('/google-maps-embed') | ||
|
||
const baseContainer = $('[data-ntpc="GoogleMapsEmbed"]') | ||
const mapContainer = $( | ||
'[src="https://www.google.com/maps/embed/v1/place?key=XYZ&q=Brooklyn+Bridge,New+York,NY"]' | ||
) | ||
expect(baseContainer.length).toBe(1) | ||
expect(mapContainer.length).toBe(1) | ||
}) | ||
} | ||
) |
Oops, something went wrong.