mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 14:06:59 +00:00
Added USP section styling
This commit is contained in:
parent
861de650f5
commit
b954a14d25
@ -1,46 +1,49 @@
|
|||||||
'use client'
|
'use client';
|
||||||
|
|
||||||
import { Info } from 'lucide-react';
|
import { Info } from 'lucide-react';
|
||||||
import dynamic from 'next/dynamic';
|
import dynamic from 'next/dynamic';
|
||||||
|
|
||||||
import Hero from 'components/modules/hero';
|
import Hero from 'components/modules/hero';
|
||||||
const Slider = dynamic(() => import('components/modules/slider'))
|
const USPSection = dynamic(() => import('components/ui/usp-section'));
|
||||||
const BlurbSection = dynamic(() => import('components/modules/blurb-section'))
|
const Slider = dynamic(() => import('components/modules/slider'));
|
||||||
const FilteredProductList = dynamic(
|
const BlurbSection = dynamic(() => import('components/modules/blurb-section'));
|
||||||
() => import('components/modules/filtered-product-list')
|
const FilteredProductList = dynamic(() => import('components/modules/filtered-product-list'));
|
||||||
)
|
|
||||||
|
|
||||||
interface getContentComponentProps {
|
interface getContentComponentProps {
|
||||||
_type: string
|
_type: string;
|
||||||
_key: number
|
_key: number;
|
||||||
disabled: boolean
|
disabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getContentComponent = ({
|
|
||||||
_type,
|
|
||||||
_key,
|
|
||||||
disabled,
|
|
||||||
...rest
|
|
||||||
}: getContentComponentProps) => {
|
|
||||||
let Component: any
|
|
||||||
|
|
||||||
|
|
||||||
|
const getContentComponent = ({ _type, _key, disabled, ...rest }: getContentComponentProps) => {
|
||||||
|
let Component: any;
|
||||||
|
console.log('type', _type)
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case 'hero':
|
case 'hero':
|
||||||
Component = Hero
|
Component = Hero;
|
||||||
break
|
break;
|
||||||
case 'slider':
|
case 'slider':
|
||||||
Component = Slider
|
Component = Slider;
|
||||||
break
|
break;
|
||||||
case 'filteredProductList':
|
case 'filteredProductList':
|
||||||
Component = FilteredProductList
|
Component = FilteredProductList;
|
||||||
break
|
break;
|
||||||
case 'blurbSection':
|
case 'blurbSection':
|
||||||
if (disabled !== true) {
|
if (disabled !== true) {
|
||||||
Component = BlurbSection
|
Component = BlurbSection;
|
||||||
} else {
|
} else {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
break
|
break;
|
||||||
|
case 'uspSection':
|
||||||
|
if (disabled !== true) {
|
||||||
|
Component = USPSection;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -49,31 +52,29 @@ const getContentComponent = ({
|
|||||||
}`}
|
}`}
|
||||||
key={`index-${_key}`}
|
key={`index-${_key}`}
|
||||||
>
|
>
|
||||||
<span className="inline-flex items-center bg-red font-bold p-2 text-sm">
|
<span className="inline-flex items-center bg-red p-2 text-sm font-bold">
|
||||||
<Info className="mr-1" />
|
<Info className="mr-1" />
|
||||||
{`No matching component (Type: ${_type})`}
|
{`No matching component (Type: ${_type})`}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Component ? (
|
return Component ? (
|
||||||
<Component key={`index-${_key}`} {...rest} />
|
<Component key={`index-${_key}`} {...rest} />
|
||||||
) : (
|
) : (
|
||||||
<div key={`index-${_key}`}>Something else</div>
|
<div key={`index-${_key}`}>Something else</div>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
interface dynamicContentManagerProps {
|
interface dynamicContentManagerProps {
|
||||||
content: [] | any
|
content: [] | any;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DynamicContentManager = ({ content }: dynamicContentManagerProps) => {
|
const DynamicContentManager = ({ content }: dynamicContentManagerProps) => {
|
||||||
return (
|
return (
|
||||||
<div className="dynamic-content overflow-x-hidden">
|
<div className="dynamic-content overflow-x-hidden">{content?.map(getContentComponent)}</div>
|
||||||
{content?.map(getContentComponent)}
|
);
|
||||||
</div>
|
};
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default DynamicContentManager
|
export default DynamicContentManager;
|
||||||
|
1
components/ui/usp-section/index.ts
Normal file
1
components/ui/usp-section/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { default } from './usp-section';
|
44
components/ui/usp-section/usp-section.tsx
Normal file
44
components/ui/usp-section/usp-section.tsx
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import SanityImage from '../sanity-image'
|
||||||
|
|
||||||
|
interface USPSectionProps {
|
||||||
|
usps: any
|
||||||
|
title: string
|
||||||
|
mobileLayout: string
|
||||||
|
desktopLayout: string
|
||||||
|
imageFormat: 'square' | 'portrait' | 'landscape'
|
||||||
|
}
|
||||||
|
|
||||||
|
const USPSection = ({ usps }: USPSectionProps) => {
|
||||||
|
const desktopGridLayout = `lg:grid-cols-${usps.length}`
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`w-full px-4 lg:px-16 py-16 lg:py-24 grid grid-cols-2 gap-x-4 gap-y-6 lg:gap-x-12 ${desktopGridLayout}`}
|
||||||
|
>
|
||||||
|
{usps.map((usp: any, index: number) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className={`w-full flex flex-col items-center text-center`}
|
||||||
|
>
|
||||||
|
<div className="w-20 h-20 lg:w-24 lg:h-24 mb-4 lg:mb-8">
|
||||||
|
<SanityImage
|
||||||
|
className="object-cover"
|
||||||
|
image={usp?.image}
|
||||||
|
alt={usp.name || 'USP image'}
|
||||||
|
width={96}
|
||||||
|
height={96}
|
||||||
|
sizes="96px"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<h3 className="mb-2 lg:mb-4 text-xl lg:text-2xl">{usp.title}</h3>
|
||||||
|
<p className="text-sm lg:text-base !text-low-contrast max-w-xs">
|
||||||
|
{usp.text}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default USPSection
|
@ -127,6 +127,20 @@ export const modules = `
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
_type == 'uspSection' => {
|
||||||
|
disabled,
|
||||||
|
_type,
|
||||||
|
_key,
|
||||||
|
title,
|
||||||
|
usps[]->{
|
||||||
|
title,
|
||||||
|
text,
|
||||||
|
"locale": language,
|
||||||
|
image {
|
||||||
|
${imageFields}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
// Homepage query
|
// Homepage query
|
||||||
|
Loading…
x
Reference in New Issue
Block a user