Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Next.js Image Component example (#160)
* feat: Add Next.js Image Component example * docs: Fix URL
- Loading branch information
Jonathan Steele
committed
Oct 29, 2020
1 parent
364604f
commit 31da81e
Showing
10 changed files
with
6,131 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# GraphCMS ⨯ Next.js Image Component | ||
|
||
[Join our Slack](https://slack.graphcms.com) | ||
|
||
This example demonstrates how to use the [Next.js Image Component](https://nextjs.org/docs/api-reference/next/image) with your GraphCMS assets. | ||
|
||
• [Demo](https://graphcms-with-nextjs-image.vercel.app) | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/GraphCMS/graphcms-examples/tree/master/with-nextjs-image) | ||
|
||
## How to Use | ||
|
||
### Download Manually | ||
|
||
```bash | ||
npx degit graphcms/graphcms-examples/with-nextjs-image with-nextjs-image | ||
``` | ||
|
||
Install & Run: | ||
|
||
```bash | ||
cd with-nextjs-image | ||
npm install | ||
npm run dev | ||
# or | ||
cd with-nextjs-image | ||
yarn | ||
yarn dev | ||
``` | ||
|
||
### Run on Codesandbox | ||
|
||
[![Develop with Codesandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/GraphCMS/graphcms-examples/tree/master/with-nextjs-image) |
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,5 @@ | ||
module.exports = { | ||
images: { | ||
domains: ['media.graphcms.com'], | ||
}, | ||
}; |
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,21 @@ | ||
{ | ||
"name": "graphcms-with-nextjs-image", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "next", | ||
"build": "next build", | ||
"start": "next start" | ||
}, | ||
"dependencies": { | ||
"graphql": "15.4.0", | ||
"graphql-request": "3.3.0", | ||
"next": "10.0.0", | ||
"react": "17.0.1", | ||
"react-dom": "17.0.1" | ||
}, | ||
"devDependencies": { | ||
"postcss-preset-env": "6.7.0", | ||
"tailwindcss": "1.9.6" | ||
} | ||
} |
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,11 @@ | ||
import '../styles/tailwind.css'; | ||
|
||
function App({ Component, pageProps }) { | ||
return ( | ||
<div className="max-w-5xl mx-auto p-6"> | ||
<Component {...pageProps} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
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,49 @@ | ||
import Image from 'next/image'; | ||
import { GraphQLClient, gql } from 'graphql-request'; | ||
|
||
function IndexPage({ products }) { | ||
return ( | ||
<div className="gap-6 grid grid-cols-1 md:grid-cols-3"> | ||
{products.map((product) => ( | ||
<div key={product.id}> | ||
<Image | ||
src={product.image.url} | ||
width={product.image.width} | ||
height={product.image.height} | ||
/> | ||
<h2 className="font-semibold text-lg">{product.name}</h2> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export async function getStaticProps() { | ||
const graphcms = new GraphQLClient( | ||
'https://api-eu-central-1.graphcms.com/v2/ck8sn5tnf01gc01z89dbc7s0o/master' | ||
); | ||
|
||
const { products } = await graphcms.request( | ||
gql` | ||
{ | ||
products { | ||
id | ||
image { | ||
height | ||
url | ||
width | ||
} | ||
name | ||
} | ||
} | ||
` | ||
); | ||
|
||
return { | ||
props: { | ||
products, | ||
}, | ||
}; | ||
} | ||
|
||
export default IndexPage; |
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,3 @@ | ||
module.exports = { | ||
plugins: ['postcss-preset-env', 'tailwindcss'], | ||
}; |
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,5 @@ | ||
/* purgecss start ignore */ | ||
@tailwind base; | ||
@tailwind components; | ||
/* purgecss end ignore */ | ||
@tailwind utilities; |
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 @@ | ||
module.exports = { | ||
purge: ['./pages/**/*.js'], | ||
future: { | ||
removeDeprecatedGapUtilities: true, | ||
purgeLayersByDefault: true, | ||
}, | ||
}; |
Oops, something went wrong.