@@ -29,6 +29,7 @@ import urlFor from '../../utils/imageUrl.js'
2929 * the resource.
3030 * @param {string } [size='compact-card'] - The size of the card.
3131 * Defaults to 'compact-card'.
32+ * - 'chip': Uses the smallest image size (50px max width).
3233 * - 'compact-card': Uses a smaller image size (125px max width).
3334 * - 'full-card': Uses a larger image size (375px max width).
3435 *
@@ -37,21 +38,43 @@ import urlFor from '../../utils/imageUrl.js'
3738export default ( resource , size = 'compact-card' ) => {
3839 const image = resource . heroImage
3940 const srcset =
40- size == 'compact-card' // if size is compact-card, use smaller image sizes
41- ? [ 125 , 250 ] // compact card image sizes (max-width: 125px)
42- : [ 375 , 750 ] // full card image sizes (max-width: 375px)
41+ size == 'chip'
42+ ? [ 50 , 100 ] // chip card image sizes (max-width: 50px)
43+ : size == 'compact-card'
44+ ? [ 125 , 250 ] // compact card image sizes (max-width: 125px)
45+ : [ 375 , 750 ] // full card image sizes (max-width: 375px)
4346 const sizes =
44- size == 'compact-card'
45- ? '125px' // compact card image max width
46- : '375px' // full card max width
47+ size == 'chip'
48+ ? '50px' // chip card image max width
49+ : size == 'compact-card'
50+ ? '125px' // compact card image max width
51+ : '375px' // full card max width
4752 const srcSetContent = srcset
4853 . map ( ( size ) => {
4954 const url = urlFor ( resource . heroImage ) . width ( size ) . height ( size ) . auto ( 'format' ) . url ( )
5055 return `${ url } ${ size } w`
5156 } )
5257 . join ( ',' )
5358
54- return `<li class="card ${ size } ">
59+ if ( size === "chip" ) {
60+ return `<li class="chip" data-slug="${ resource . slug } ">
61+ <a href="/${ resource . type } /${ resource . slug } /">
62+ <h3>${ resource . title } </h3>
63+ <div class="tooltip">
64+ <img src="${ urlFor ( image ) . width ( srcset [ 0 ] ) } "
65+ srcset="${ srcSetContent } "
66+ sizes="${ sizes } "
67+ max-width="${ srcset [ 0 ] } "
68+ max-height="${ srcset [ 0 ] } "
69+ loading="lazy"
70+ alt="${ image . altText } ">
71+ <p>${ resource . metaDescription } </p>
72+ </div>
73+ </a>
74+ </li>` ;
75+ }
76+
77+ return `<li class="card ${ size } " data-slug="${ resource . slug } ">
5578 <a href="/${ resource . type } /${ resource . slug } /">
5679 <img src="${ urlFor ( image ) . width ( srcset [ 0 ] ) } "
5780 srcset="${ srcSetContent } "
0 commit comments