From b954a14d25f19749060a5012c563cd3afc1514c1 Mon Sep 17 00:00:00 2001 From: Martin Westerlund Date: Mon, 8 May 2023 11:49:40 +0200 Subject: [PATCH] Added USP section styling --- .../dynamic-content-manager.tsx | 73 ++++++++++--------- components/ui/usp-section/index.ts | 1 + components/ui/usp-section/usp-section.tsx | 44 +++++++++++ lib/sanity/queries.tsx | 14 ++++ 4 files changed, 96 insertions(+), 36 deletions(-) create mode 100644 components/ui/usp-section/index.ts create mode 100644 components/ui/usp-section/usp-section.tsx diff --git a/components/layout/dynamic-content-manager/dynamic-content-manager.tsx b/components/layout/dynamic-content-manager/dynamic-content-manager.tsx index 0dfbe6883..78148f90c 100644 --- a/components/layout/dynamic-content-manager/dynamic-content-manager.tsx +++ b/components/layout/dynamic-content-manager/dynamic-content-manager.tsx @@ -1,46 +1,49 @@ -'use client' +'use client'; import { Info } from 'lucide-react'; import dynamic from 'next/dynamic'; import Hero from 'components/modules/hero'; -const Slider = dynamic(() => import('components/modules/slider')) -const BlurbSection = dynamic(() => import('components/modules/blurb-section')) -const FilteredProductList = dynamic( - () => import('components/modules/filtered-product-list') -) +const USPSection = dynamic(() => import('components/ui/usp-section')); +const Slider = dynamic(() => import('components/modules/slider')); +const BlurbSection = dynamic(() => import('components/modules/blurb-section')); +const FilteredProductList = dynamic(() => import('components/modules/filtered-product-list')); interface getContentComponentProps { - _type: string - _key: number - disabled: boolean + _type: string; + _key: number; + 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) { case 'hero': - Component = Hero - break + Component = Hero; + break; case 'slider': - Component = Slider - break + Component = Slider; + break; case 'filteredProductList': - Component = FilteredProductList - break + Component = FilteredProductList; + break; case 'blurbSection': if (disabled !== true) { - Component = BlurbSection + Component = BlurbSection; } else { - return + return; } - break + break; + case 'uspSection': + if (disabled !== true) { + Component = USPSection; + } else { + return; + } + break; default: return (
- + {`No matching component (Type: ${_type})`}
- ) + ); } return Component ? ( ) : (
Something else
- ) -} + ); +}; interface dynamicContentManagerProps { - content: [] | any + content: [] | any; } const DynamicContentManager = ({ content }: dynamicContentManagerProps) => { return ( -
- {content?.map(getContentComponent)} -
- ) -} +
{content?.map(getContentComponent)}
+ ); +}; -export default DynamicContentManager +export default DynamicContentManager; diff --git a/components/ui/usp-section/index.ts b/components/ui/usp-section/index.ts new file mode 100644 index 000000000..af87fbfc5 --- /dev/null +++ b/components/ui/usp-section/index.ts @@ -0,0 +1 @@ +export { default } from './usp-section'; diff --git a/components/ui/usp-section/usp-section.tsx b/components/ui/usp-section/usp-section.tsx new file mode 100644 index 000000000..3b05f41c4 --- /dev/null +++ b/components/ui/usp-section/usp-section.tsx @@ -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 ( +
+ {usps.map((usp: any, index: number) => ( +
+
+ +
+

{usp.title}

+

+ {usp.text} +

+
+ ))} +
+ ) +} + +export default USPSection \ No newline at end of file diff --git a/lib/sanity/queries.tsx b/lib/sanity/queries.tsx index 9c2c03d1c..0effaac3e 100644 --- a/lib/sanity/queries.tsx +++ b/lib/sanity/queries.tsx @@ -127,6 +127,20 @@ export const modules = ` }, }, }, + _type == 'uspSection' => { + disabled, + _type, + _key, + title, + usps[]->{ + title, + text, + "locale": language, + image { + ${imageFields} + }, + }, + } ` // Homepage query