Open alexanderflink opened 2 years ago
Might now even be a difficult thing to accomplish as I see it. As stated we already have a few examples of a working Sanity media module, now we only need to pick the best parts and make it into a first module within a new accelerator package. Suggestions to what name the package should have? is @noaignite/sanity
enough or should it have a longer and more detailed name?
I thought about this and I think @noaignite/sanity
is a good name. We can then package the schemas and components together.
Some of the media components that are currently "in the wild":
https://github.com/noaignite/create-ignite-cms/tree/main/src/objects/ResponsiveMedia https://github.com/noaignite/fidelio/blob/main/sanity/src/schemas/objects/media.js https://github.com/noaignite/cake/blob/main/sanity/src/schemas/objects/media.js
@janmysiak Could you create a draft PR with the implementation in A days march?
Some tasks for the Sanity component.
A developer should be able to:
img
, picture
, video
, etc.)
As @adamsoderstrom said, it is a problem that projects each have their own implementation of media props and media input components in Sanity studio. We should create a package with a Sanity schema for media props which all projects use. It would be great to have an accompanying Sanity input component that we can re-use.
Specification
Sanity schemas
(These are pseudo typescript interfaces for illustration purposes only) These schemas should be exported as factory functions which take options (with sensible defaults) as input.
media
Is a wrapper for the different media types available.
image
video
vimeo
This is an example of an additional media type, no need to build this right away
options
This doesn't necessarily need to be an actual schema, but rather a configuration object that is passed when creating the schemas
Sanity GROQ queries
There should be three queries included in the package:
imageQuery
,videoQuery
andmediaQuery
, whereimageQuery
andvideoQuery
are responsible for returningcomponent
,alt
,source
andbreakpoints
.mediaQuery
is the wrapper which simply returns the data of whatever mediaType query is used.Transformer functions
There should be three corresponding transformer functions for the two queries:
transformSanityImage
,transformSanityVideo
andtransformSanityMedia
.transformSanityImage
andtransformSanityVideo
are responsible for transforming the results fromimageQuery
andvideoQuery
into a useablemediaProps
object that can be sent to the ouiMedia
component.transformSanityMedia
is responsible for transforming the result ofmediaQuery
into a useablemediaProps
object that can be sent to the ouiMedia
component. This transformer usestransformSanityImage
internally for transforming the individual images.