npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@crystallize/reactjs-components

v2.0.2

Published

This brings Image, Grid and Content Transformer component to ease your rendering when using React JS.

Downloads

1,703

Readme

React JS Components

This brings Image, Grid and Content Transformer component to ease your rendering when using React JS.

Installation

With NPM:

npm install @crystallize/reactjs-components

With Yarn:

yarn add @crystallize/reactjs-components

Image

This output an img tag with different source variations from Crystallize using srcset. Use this to easily build responsive images powered by Crystallize.

import { Image } from '@crystallize/reactjs-components/dist/image';
const imageFromCrystallize = {
    url: '...',
    variants: [...]
}

<Image
    {...imageFromCrystallize}
    sizes="(max-width: 400px) 300w, 700px"
/>

There is a live demo: https://crystallizeapi.github.io/libraries/reactjs-components/image

Video

This output videos from Crystallize using the native video element.

import { Video } from '@crystallize/reactjs-components/dist/video';
import '@crystallize/reactjs-components/assets/video/styles.css';
const videoFromCrystallize = {
    playlists: [...],
    thumbnails: [...]
}

<Video
    {...videoFromCrystallize}
    thumbnmailProps={{ sizes: "(max-width: 700px) 90vw, 700px" }}
/>

There is a live demo: https://crystallizeapi.github.io/libraries/reactjs-components/video

Grid

That makes it easy to render Crystallize grids with React JS. In order to use the grid renderer you'll need to have fetched your grid model. This can be fetched fairly easily from Crystallize's API via GraphQL.

At the minimum you will need to fetch layout of each column and some properties on the item. Your query might look something like this:

query grid($id: Int!, $language: String!) {
    grid(id: $id, language: $language) {
        rows {
            columns {
                layout {
                    rowspan
                    colspan
                    colIndex
                    rowIndex
                }
                item {
                    name
                }
            }
        }
    }
}

Then, inside your component, render the Grid, passing through the grid model as a prop. By default, the grid is rendered using CSS grid but it could also be a Table.

<GridRenderer grid={grid} type={GridRenderingType.Div} cellComponent={Cell} />
<GridRenderer grid={grid} type={GridRenderingType.Table} cellComponent={Cell} />
<GridRenderer grid={grid} type={GridRenderingType.RowCol} cellComponent={Cell} />

There is a live demo: https://crystallizeapi.github.io/libraries/reactjs-components/grid

To go further

If you want full control over each of the cells, you can instead supply a function as the children of the grid component. This will allow you to iterate over each of the cells and mutate them as you please.

const children = ({ cells }) => {
    return cells.map((cell) => (
        <div
            style={{
                gridColumn: `span ${cell.layout.colspan}`,
                gridRow: `span ${cell.layout.rowspan}`,
            }}
        >
            {cell.item.name}
        </div>
    ));
};

return (
    <GridRenderer grid={grid} type={GridRenderingType.Div} cellComponent={Cell}>
        {children}
    </GridRenderer>
);

Content Transformer

This helps you to transform Crystallize rich text json to React html components.

const overrides: Overrides = {
    link: (props: NodeProps) => (
        <a href={props.metadata?.href}>
            <NodeContent {...props} />
        </a>
    ),
};

<ContentTransformer json={richTextJson} overrides={overrides} />;

There is a live demo: https://crystallizeapi.github.io/libraries/reactjs-components/content-transformer