0.2.3 • Published 3 years ago

@otterdev/sanity-react-extra v0.2.3

Weekly downloads
46
License
ISC
Repository
-
Last release
3 years ago

sanity-react-extra

Components for react-based frontends using sanity.io

SanityImg

An image component that will create an image tag for your sanity image. If the query is enriched:

  • Setting width or height will set the other one according to image aspect ratio, ensuring no layout shift occurs during rendering. This helps page performance.
  • srcSets will be set.

To encrich your query, use the withDimensions function in your query:

import groq from "groq"
import { withDimensions } from "@otterdev/sanity-react-extra"

const query =  groq`*[] {
  ...,
  "image": ${withDimensions("image")}
}`

To use the component, you must provide an imageUrlBuilder, from @sanity/client or @otterdev/sanity-next-extra for example, as well as the image.

import { SanityImg } from "@otterdev/saity-react-extra"

  <SanityImg builder={imageUrlBuilder} image={image} 
    //optional, set width or height and the other one will keep aspect
    width={100}
    //optional, will keep aspect
    height={100}
    //optional
    className="image"
    //other img props
    alt="An image"
  />

renderObjectArray

Used to render an array of objects. Useful when your sanity schema is a page broken into sections:

{
 name: "page",
 type: "document",
 fields: [
   {
     name: "sections",
     title: "Sections",
     type: "array",
     of: [
        {type: "header"},
        {type: "body"},
        {type: "footer"},
     ]
   }
 ]
}

Provide components for each type:

import { renderObjectArray } from "@otterdev/saity-react-extra"

renderObjectArray(page.sections, {
  header: Header,
  body: (props)=><div>Body</div>,
  footer: Footer
})

rgba

Render a color picker color from @sanity/color-input to a string for use in css:

import { rgba } from "@otterdev/saity-react-extra"

rgba(color)

// = "rgba(1,0.2,0.3,0.1)"
0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.8

3 years ago

0.1.9

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago