Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SFCC example to use TypeScript + @next/font #42865

Merged
merged 5 commits into from Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/basic-features/font-optimization.md
Expand Up @@ -169,12 +169,13 @@ In the example below, we use the font `Inter` from `@next/font/google` (You can
import { Inter } from '@next/font/google'

const inter = Inter({
subsets: ['latin'],
variable: '--font-inter',
})

export default function MyApp({ Component, pageProps }) {
return (
<main className={inter.variable}>
<main className={`${inter.variable} font-sans`}>
<Component {...pageProps} />
</main>
)
Expand Down
14 changes: 14 additions & 0 deletions examples/with-sfcc/components/Footer.tsx
@@ -0,0 +1,14 @@
export default function Footer() {
return (
<footer className="center mt-5 flex justify-center space-x-4 bg-[#E7E8EF] p-4 text-xs">
<p>Powered by Next.js, Salesforce Commerce Cloud, and Vercel </p>
<span>|</span>
<a
href="https://github.com/vercel/next.js/tree/canary/examples/with-sfcc"
className="font-medium text-orange-600"
>
Source code
</a>
</footer>
)
}
@@ -1,4 +1,5 @@
import Image from 'next/image'
import img from '../public/hero.jpg'

export default function Header({ scrollHandler }) {
return (
Expand All @@ -11,7 +12,8 @@ export default function Header({ scrollHandler }) {
priority
fill
className="h-full w-full object-cover"
src="/hero.jpg"
src={img}
placeholder="blur"
alt="Coffee grinder"
/>
<div className="absolute inset-0 bg-orange-100 mix-blend-multiply" />
Expand Down
Expand Up @@ -13,7 +13,7 @@ export default function ProductCard({ product }) {
<Link href={`/products/${product.id}`} className="group">
<div className="aspect-w-1 aspect-h-1 w-full overflow-hidden rounded-lg bg-gray-200 xl:aspect-w-7 xl:aspect-h-8">
<Image
alt=""
alt="product image"
src={product.imageGroups[0].images[0].link}
fill
className={cn(
Expand Down
17 changes: 0 additions & 17 deletions examples/with-sfcc/components/layout.js

This file was deleted.

2 changes: 1 addition & 1 deletion examples/with-sfcc/next.config.js
@@ -1,6 +1,6 @@
module.exports = {
reactStrictMode: true,
images: {
domains: ['zzte-003.sandbox.us02.dx.commercecloud.salesforce.com'],
domains: ['zzte-003.dx.commercecloud.salesforce.com'],
},
}
7 changes: 4 additions & 3 deletions examples/with-sfcc/package.json
Expand Up @@ -6,18 +6,19 @@
"start": "next start"
},
"dependencies": {
"@next/font": "latest",
"commerce-sdk": "^2.8.0",
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@tailwindcss/aspect-ratio": "^0.4.0",
"@types/node": "17.0.4",
"@types/react": "17.0.38",
"@types/node": "18.11.9",
"@types/react": "18.0.25",
"autoprefixer": "^10.4.0",
"postcss": "^8.4.5",
"tailwindcss": "^3.0.7",
"typescript": "4.5.4"
"typescript": "4.8.4"
}
}
18 changes: 0 additions & 18 deletions examples/with-sfcc/pages/_app.js

This file was deleted.

23 changes: 23 additions & 0 deletions examples/with-sfcc/pages/_app.tsx
@@ -0,0 +1,23 @@
import '../styles/globals.css'
import Footer from '../components/Footer'
import Head from 'next/head'
import { Montserrat } from '@next/font/google'

const montserrat = Montserrat({
subsets: ['latin'],
variable: '--font-montserrat',
})

export default function MyApp({ Component, pageProps }) {
return (
<>
<Head>
<title>The Coffee House</title>
</Head>
<main className={`${montserrat.variable} font-sans`}>
<Component {...pageProps} />
<Footer />
</main>
</>
)
}
Expand Up @@ -8,13 +8,8 @@ export default function Document() {
name="description"
content="The premiere coffee delivery service."
/>
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet"
/>
</Head>

<body>
<body className="font-sans">
leerob marked this conversation as resolved.
Show resolved Hide resolved
leerob marked this conversation as resolved.
Show resolved Hide resolved
<Main />
<NextScript />
</body>
Expand Down
Expand Up @@ -4,10 +4,11 @@ import ProductCard from '../components/ProductCard'
import getProducts from '../sfcc.js'

export default function Gallery({ data }) {
let coffeeRef = useRef()
let coffeeRef = useRef<HTMLParagraphElement>()

const scrollHandler = (e) => {
e.preventDefault()
// @ts-ignore
coffeeRef.scrollIntoView({
behavior: 'smooth',
block: 'start',
Expand All @@ -22,7 +23,7 @@ export default function Gallery({ data }) {
<div className="text-center">
<p
className="mt-1 text-4xl font-bold uppercase text-gray-900 sm:text-5xl sm:tracking-tight lg:text-5xl"
ref={(element) => (coffeeRef = element)}
ref={coffeeRef}
>
Crafted by us, for you
</p>
Expand Down
Expand Up @@ -33,9 +33,8 @@ export default function Product({ product }) {

export async function getStaticProps({ params }) {
const searchResults = await getProducts(params.slug)
console.log('search Results are: ', searchResults)

const coffeeProduct = searchResults[0]

return {
props: {
product: coffeeProduct,
Expand All @@ -44,11 +43,9 @@ export async function getStaticProps({ params }) {
}

export async function getStaticPaths() {
const searchResults = await getProducts('coffee')

let coffeeProducts = searchResults

const coffeeProducts = await getProducts('coffee')
let fullPaths = []

for (let product of coffeeProducts) {
fullPaths.push({ params: { slug: product.id } })
}
Expand Down
4 changes: 0 additions & 4 deletions examples/with-sfcc/styles/globals.css
@@ -1,7 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

* {
font-family: Montserrat, sans-serif;
}
9 changes: 9 additions & 0 deletions examples/with-sfcc/tailwind.config.js
@@ -1,7 +1,16 @@
/** @type {import('tailwindcss').Config} \*/
module.exports = {
content: [
'./pages/**/*.{js,ts,jsx,tsx}',
'./components/**/*.{js,ts,jsx,tsx}',
],
theme: {
fontFamily: {
sans: ['var(--font-montserrat)'],
},
},
future: {
hoverOnlyWhenSupported: true,
},
plugins: [require('@tailwindcss/aspect-ratio')],
}
20 changes: 20 additions & 0 deletions examples/with-sfcc/tsconfig.json
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}