-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* ✨ add image for text comp * 🐛 fix review comments
- Loading branch information
1 parent
7deaafe
commit 42c73ab
Showing
7 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { info_circle } from '@equinor/eds-icons' | ||
import { PortableTextBlock, Rule } from 'sanity' | ||
import { EdsIcon } from '../../icons' | ||
import { configureBlockContent } from '../editors/blockContentType' | ||
import type { ImageWithAlt } from './imageWithAlt' | ||
|
||
const blockContentType = configureBlockContent({ | ||
h2: true, | ||
h3: true, | ||
h4: true, | ||
internalLink: false, | ||
externalLink: false, | ||
lists: false, | ||
attachment: false, | ||
smallText: false, | ||
}) | ||
|
||
export type ImageForText = { | ||
_type: 'imageForText' | ||
content?: PortableTextBlock[] | ||
image?: ImageWithAlt | ||
} | ||
|
||
export default { | ||
title: 'Image for text', | ||
name: 'imageForText', | ||
type: 'object', | ||
fields: [ | ||
{ | ||
name: 'content', | ||
title: 'Content', | ||
type: 'array', | ||
of: [blockContentType], | ||
validation: (Rule: Rule) => Rule.required(), | ||
}, | ||
{ | ||
name: 'image', | ||
title: 'Image', | ||
type: 'imageWithAlt', | ||
validation: (Rule: Rule) => Rule.required(), | ||
}, | ||
{ | ||
name: 'aspectRatio', | ||
type: 'string', | ||
description: '', | ||
title: 'Aspect ratio', | ||
options: { | ||
list: [ | ||
{ title: '16:9', value: '16:9' }, | ||
{ title: 'Full width 16:9', value: 'fullWidth' }, | ||
], | ||
}, | ||
initialValue: '16:9', | ||
}, | ||
], | ||
preview: { | ||
select: { | ||
imageUrl: 'image.asset.url', | ||
}, | ||
prepare({ imageUrl }: { title: string; imageUrl: string }) { | ||
return { | ||
title: 'Image for text', | ||
media: imageUrl ? <img src={imageUrl} alt="" style={{ height: '100%' }} /> : EdsIcon(info_circle), | ||
} | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ImageForTextData } from '../../types/types' | ||
import { forwardRef } from 'react' | ||
import Image, { Ratios } from '../../pageComponents/shared/SanityImage' | ||
import Blocks from '../../pageComponents/shared/portableText/Blocks' | ||
|
||
type ImageForTextProps = { | ||
data: ImageForTextData | ||
anchor?: string | ||
} | ||
|
||
const ImageForText = forwardRef<HTMLDivElement, ImageForTextProps>(function ImageForText({ anchor, data }, ref) { | ||
const { content, image, aspectRatio } = data | ||
|
||
return ( | ||
<div ref={ref} id={anchor} className={`${aspectRatio === 'fullWidth' ? 'w-full' : 'px-layout-lg'}`}> | ||
<div className=""> | ||
<Image | ||
image={image} | ||
maxWidth={2000} | ||
{...(aspectRatio === 'fullWidth' && { aspectRatio: Ratios.THREE_TO_TEN })} | ||
sizes={ | ||
aspectRatio === 'fullWidth' | ||
? '100vw' | ||
: '(min-width: 2060px) 920px, (min-width: 440px) calc(34.56vw + 215px), calc(76.67vw + 38px)' | ||
} | ||
aria-hidden | ||
/> | ||
</div> | ||
{content && <Blocks value={content} className="sr-only" />} | ||
</div> | ||
) | ||
}) | ||
|
||
export default ImageForText |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters