Skip to content

Commit

Permalink
Merge branch 'malj/1752' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
millianapia committed Mar 12, 2024
2 parents a0ef789 + 8249dfa commit b839f3b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 32 deletions.
12 changes: 12 additions & 0 deletions sanityv3/schemas/objects/figure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ export default {
},
],
fields: [
{
name: 'aspectRatio',
type: 'string',
title: 'Aspect ratio',
options: {
list: [
{ title: 'original', value: 'original' },
{ title: '16:9', value: '16:9' },
],
},
initialValue: '16:9',
},
{
name: 'figure',
title: 'Image',
Expand Down
8 changes: 2 additions & 6 deletions web/lib/queries/common/pageContentFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,15 @@ _type == "keyNumbers" =>{
_type == "figure"=>{
"type": _type,
"id": _key,
// For these images, we don't want crop and hotspot
// because we don't know the aspect ratio
"figure": figure{
_type,
"image": {
"asset": image.asset,
"alt": image.alt,
},
image,
attribution,
caption
},
"designOptions": {
${background}
"aspectRatio": coalesce(aspectRatio, '16:9'),
},
},
_type == "textWithIconArray"=>{
Expand Down
9 changes: 1 addition & 8 deletions web/pageComponents/shared/Hero/FiftyFiftyHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,7 @@ export const FiftyFiftyHero = ({ title, ingress, link, background, figure, isBig
<StyledHero background={{ backgroundColor: background }}>
<StyledMedia>
{figure && (
<Image
maxWidth={4096}
sizes="(min-width: 760px) 50vw, 100vw"
image={figure.image}
fill
style={{ objectFit: 'cover' }}
priority
/>
<Image maxWidth={4096} sizes="(min-width: 760px) 50vw, 100vw" image={figure.image} fill priority />
)}
</StyledMedia>
<StyledContent>
Expand Down
14 changes: 3 additions & 11 deletions web/pageComponents/shared/SanityImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,7 @@ export enum Ratios {
const DEFAULT_SIZES = '(max-width: 800px) 100vw, 800px'
const DEFAULT_MAX_WIDTH = 1440

const Image = ({
image,
aspectRatio,
sizes = DEFAULT_SIZES,
maxWidth = DEFAULT_MAX_WIDTH,
fill,
style,
...rest
}: Props) => {
const Image = ({ image, aspectRatio, sizes = DEFAULT_SIZES, maxWidth = DEFAULT_MAX_WIDTH, fill, ...rest }: Props) => {
const imageProps = useSanityLoader(image, maxWidth, aspectRatio)
if (!image?.asset) return <></>
const { width, height, src } = imageProps
Expand All @@ -41,14 +33,14 @@ const Image = ({
// Layout fill
props = {
fill,
style: { ...style, objectFit: 'cover' },
style: { objectFit: 'cover' },
}
} else {
// Layout responsive
props = {
width,
height,
style: { ...style, display: 'flex', width: '100%', height: 'auto' },
style: { display: 'flex', width: '100%', height: 'auto' },
}
}

Expand Down
17 changes: 10 additions & 7 deletions web/pageComponents/topicPages/Figure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FigureData } from '../../types/types'
import styled from 'styled-components'
import { BackgroundContainer, FigureCaption } from '@components'
import { StyledTextBlockWrapper } from './TextBlock'
import Image from '../shared/SanityImage'
import Image, { Ratios } from '../shared/SanityImage'

type TeaserProps = {
data: FigureData
Expand Down Expand Up @@ -35,15 +35,18 @@ const FullWidthImage = ({ data, anchor }: TeaserProps) => {
if (!figure?.image) return null

const { image, caption, attribution } = figure

const { aspectRatio } = designOptions
// If we add more ratios, create a switch statement for the sanity ratios, for now we only have 9:16
const sizes = '(min-width: 2060px) 920px, (min-width: 440px) calc(34.56vw + 215px), calc(76.67vw + 38px)'
return (
<StyledFigureWrapper background={designOptions?.background} id={anchor}>
<StyledFigure>
<Image
image={image}
maxWidth={920}
sizes="(min-width: 2060px) 920px, (min-width: 440px) calc(34.56vw + 215px), calc(76.67vw + 38px)"
/>
{aspectRatio !== 'original' ? (
<Image image={image} aspectRatio={Ratios.NINE_TO_SIXTEEN} maxWidth={920} sizes={sizes} />
) : (
<Image image={image} maxWidth={920} sizes={sizes} />
)}

{(caption || attribution) && (
<FigureCaption>
{caption && <FigureCaption.Caption>{caption}</FigureCaption.Caption>}
Expand Down
3 changes: 3 additions & 0 deletions web/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ export type DesignOptions = {
backgroundOption?: BackgroundOption
utility: string
dark: boolean
aspectRatio?: FigureRatio
}

export type TextBlockData = {
Expand Down Expand Up @@ -392,6 +393,8 @@ export type FullWidthVideoData = {

export type FullWidthVideoRatio = 'fullScreen' | 'narrow' | '2:1'

export type FigureRatio = 'original' | '9:16'

export type FigureData = {
type: string
id: string
Expand Down

0 comments on commit b839f3b

Please sign in to comment.