File tree Expand file tree Collapse file tree 6 files changed +65
-107
lines changed
sanity/schemaTypes/modules Expand file tree Collapse file tree 6 files changed +65
-107
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ export default defineType({
1010 type : 'object' ,
1111 groups : [
1212 { name : 'content' , default : true } ,
13- { name : 'image ' } ,
13+ { name : 'asset ' } ,
1414 { name : 'options' } ,
1515 ] ,
1616 fields : [
@@ -49,38 +49,24 @@ export default defineType({
4949 group : 'content' ,
5050 } ) ,
5151 defineField ( {
52- name : 'image' ,
53- type : 'image' ,
54- options : {
55- hotspot : true ,
56- } ,
57- group : 'image' ,
58- fields : [
59- defineField ( {
60- name : 'alt' ,
61- type : 'string' ,
62- } ) ,
63- defineField ( {
64- name : 'faded' ,
65- type : 'boolean' ,
66- initialValue : true ,
67- } ) ,
68- defineField ( {
69- name : 'loading' ,
70- type : 'string' ,
71- options : {
72- list : [ 'lazy' , 'eager' ] ,
73- layout : 'radio' ,
74- } ,
75- initialValue : 'lazy' ,
76- } ) ,
77- ] ,
52+ name : 'assets' ,
53+ title : 'Assets' ,
54+ type : 'array' ,
55+ of : [ { type : 'img' } ] ,
56+ validation : ( Rule ) => Rule . max ( 1 ) ,
57+ group : 'asset' ,
58+ } ) ,
59+ defineField ( {
60+ name : 'assetFaded' ,
61+ type : 'boolean' ,
62+ initialValue : true ,
63+ group : 'asset' ,
7864 } ) ,
7965 ] ,
8066 preview : {
8167 select : {
8268 content : 'content' ,
83- media : 'image' ,
69+ media : 'assets.0. image' ,
8470 } ,
8571 prepare : ( { content, media } ) => ( {
8672 title : getBlockText ( content ) ,
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ export default defineType({
1515 type : 'object' ,
1616 groups : [
1717 { name : 'content' , default : true } ,
18- { name : 'image ' } ,
18+ { name : 'asset ' } ,
1919 { name : 'options' } ,
2020 ] ,
2121 fieldsets : [ alignmentFieldset , { name : 'image' , options : { columns : 2 } } ] ,
@@ -44,50 +44,12 @@ export default defineType({
4444 group : 'content' ,
4545 } ) ,
4646 defineField ( {
47- name : 'bgImage' ,
48- title : 'Background image' ,
49- type : 'image' ,
50- options : {
51- hotspot : true ,
52- } ,
53- fields : [
54- defineField ( {
55- name : 'alt' ,
56- type : 'string' ,
57- } ) ,
58- defineField ( {
59- name : 'loading' ,
60- type : 'string' ,
61- options : {
62- list : [ 'lazy' , 'eager' ] ,
63- layout : 'radio' ,
64- } ,
65- initialValue : 'lazy' ,
66- } ) ,
67- ] ,
68- group : 'image' ,
69- fieldset : 'image' ,
70- } ) ,
71- defineField ( {
72- name : 'bgImageMobile' ,
73- title : 'Background image (mobile)' ,
74- type : 'image' ,
75- options : {
76- hotspot : true ,
77- } ,
78- fields : [
79- defineField ( {
80- name : 'loading' ,
81- type : 'string' ,
82- options : {
83- list : [ 'lazy' , 'eager' ] ,
84- layout : 'radio' ,
85- } ,
86- initialValue : 'lazy' ,
87- } ) ,
88- ] ,
89- group : 'image' ,
90- fieldset : 'image' ,
47+ name : 'assets' ,
48+ title : 'Assets' ,
49+ type : 'array' ,
50+ of : [ { type : 'img' } ] ,
51+ validation : ( Rule ) => Rule . max ( 1 ) ,
52+ group : 'asset' ,
9153 } ) ,
9254 defineField ( {
9355 ...alignItems ,
@@ -101,7 +63,7 @@ export default defineType({
10163 preview : {
10264 select : {
10365 content : 'content' ,
104- media : 'bgImage.asset ' ,
66+ media : 'assets.0.image ' ,
10567 } ,
10668 prepare : ( { content, media } ) => ( {
10769 title : getBlockText ( content ) ,
Original file line number Diff line number Diff line change @@ -9,14 +9,16 @@ type ImgProps = { alt?: string } & Omit<ImageProps, 'src' | 'alt'>
99
1010export function ResponsiveImg ( {
1111 img,
12+ className,
13+ imgClassName,
1214 ...props
13- } : { img ?: Sanity . Img } & ImgProps ) {
15+ } : { img ?: Sanity . Img ; imgClassName ?: string } & ImgProps ) {
1416 if ( ! img ) return null
1517
1618 return (
17- < picture >
19+ < picture className = { className } >
1820 { img . responsive ?. map ( ( r , key ) => < Source { ...r } key = { key } /> ) }
19- < Img image = { img . image } { ...props } />
21+ < Img image = { img . image } { ...props } className = { imgClassName } />
2022 </ picture >
2123 )
2224}
Original file line number Diff line number Diff line change 11import moduleProps from '@/lib/moduleProps'
2- import { Img , Source } from '@/ui/Img'
2+ import { ResponsiveImg } from '@/ui/Img'
33import { PortableText , stegaClean } from 'next-sanity'
44import CTAList from '@/ui/CTAList'
55import Pretitle from '@/ui/Pretitle'
@@ -11,22 +11,21 @@ export default function Hero({
1111 pretitle,
1212 content,
1313 ctas,
14- bgImage,
15- bgImageMobile,
14+ assets,
1615 textAlign = 'center' ,
1716 alignItems,
1817 ...props
1918} : Partial < {
2019 pretitle : string
2120 content : any
2221 ctas : Sanity . CTA [ ]
23- bgImage : Sanity . Image
24- bgImageMobile : Sanity . Image
22+ assets : Sanity . Img [ ]
2523 textAlign : React . CSSProperties [ 'textAlign' ]
2624 alignItems : React . CSSProperties [ 'alignItems' ]
2725} > &
2826 Sanity . Module ) {
29- const hasImage = ! ! bgImage ?. asset
27+ const hasImage = ! ! assets ?. [ 0 ]
28+ const asset = assets ?. [ 0 ]
3029
3130 return (
3231 < section
@@ -37,15 +36,12 @@ export default function Hero({
3736 { ...moduleProps ( props ) }
3837 >
3938 { hasImage && (
40- < picture >
41- < Source image = { bgImageMobile } width = { 1200 } />
42- < Img
43- className = "max-h-fold size-full object-cover"
44- image = { bgImage }
45- width = { 2400 }
46- draggable = { false }
47- />
48- </ picture >
39+ < ResponsiveImg
40+ img = { asset }
41+ imgClassName = "max-h-fold size-full object-cover"
42+ width = { 2400 }
43+ draggable = { false }
44+ />
4945 ) }
5046
5147 { content && (
Original file line number Diff line number Diff line change @@ -5,24 +5,26 @@ import Code from './RichtextModule/Code'
55import CustomHTML from './CustomHTML'
66import Reputation from '@/ui/Reputation'
77import CTAList from '@/ui/CTAList'
8- import { Img } from '@/ui/Img'
8+ import { ResponsiveImg } from '@/ui/Img'
99import { cn } from '@/lib/utils'
1010
1111export default function HeroSaaS ( {
1212 pretitle,
1313 content,
1414 ctas,
15- image,
15+ assets,
16+ assetFaded,
1617 ...props
1718} : Partial < {
1819 pretitle : string
1920 content : any
2021 ctas : Sanity . CTA [ ]
21- image : Sanity . Image & {
22- faded ?: boolean
23- }
22+ assets : Sanity . Img [ ]
23+ assetFaded ?: boolean
2424} > &
2525 Sanity . Module ) {
26+ const asset = assets ?. [ 0 ]
27+
2628 return (
2729 < section className = "section space-y-8 text-center" { ...moduleProps ( props ) } >
2830 < div className = "richtext mx-auto max-w-2xl text-balance" >
@@ -51,15 +53,25 @@ export default function HeroSaaS({
5153 < CTAList ctas = { ctas } className = "!mt-8 justify-center" />
5254 </ div >
5355
54- < Img
55- className = { cn (
56- 'anim-fade-to-t w-full [animation-duration:1s]' ,
57- image ?. faded && '[mask:linear-gradient(to_top,transparent,#000_50%)]' ,
58- ) }
59- image = { image }
60- width = { 2400 }
61- draggable = { false }
62- />
56+ { ( ( ) => {
57+ switch ( asset ?. _type ) {
58+ case 'img' :
59+ return (
60+ < ResponsiveImg
61+ img = { asset }
62+ className = { cn (
63+ 'anim-fade-to-t w-full [animation-duration:1s]' ,
64+ assetFaded &&
65+ '[mask:linear-gradient(to_top,transparent,#000_50%)]' ,
66+ ) }
67+ width = { 2400 }
68+ draggable = { false }
69+ />
70+ )
71+ default :
72+ return null
73+ }
74+ } ) ( ) }
6375 </ section >
6476 )
6577}
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ export default function HeroSplit({
3636 switch ( asset ?. _type ) {
3737 case 'img' :
3838 return (
39- < ResponsiveImg img = { asset } className = "w-full" width = { 1200 } />
39+ < ResponsiveImg img = { asset } imgClassName = "w-full" width = { 1200 } />
4040 )
4141 default :
4242 return null
You can’t perform that action at this time.
0 commit comments