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

@zengenti/contensis-entry-picker-storybook-addon

v1.0.3

Published

Our Contensis entry picker for Storybook allows you to see your custom Storybook components working with real data coming from entries within your CMS.

Downloads

192

Readme

Contensis entry picker - Storybook addon

Built with React, TypeScript, Storybook, Babel and our Contensis Delivery API

Our Contensis entry picker for Storybook allows you to see your custom Storybook components working with real data coming from entries within your CMS.

Install

You can add the Contensis entry picker addon to you project with:

npm install --save-dev @zengenti/contensis-entry-picker-storybook-addon

Or:

yarn add @zengenti/contensis-entry-picker-storybook-addon -D

Then add the following line into your .storybook/main.js file:

module.exports  =  {
 addons: [
 '@zengenti/contensis-entry-picker-storybook-addon',
],

Configuration

.ENV

Make sure your .env is set up so our custom hook used to get the entries knows where to get these from. Your .env file should have the following properties: ACCESS_TOKEN, PUBLIC_URL, and PROJECT.

Within your Storybook component we will need to grab a entryId from the global variable - to find out more about global variables, go here.

export  const  Template:  ComponentStory<typeof Example>  = (
args:  Props, 
{ globals:  {  entryId  }  }
) =>  {...};

Once we have this, we can use a custom hook to get the entry from this entryId. We can do this like so:

It's important to spread the object so that the component can consume all the props. Remember to import useGetEntryByEntryId from the @zengenti/contensis-entry-picker-storybook-addon

import  { useGetEntryByEntryId }  from  '@zengenti/contensis-entry-picker-storybook-addon';

export  const  Template:  ComponentStory<typeof Example>  = (
args:  Props,
{ globals:  {  entryId  }  }
) =>  {
const  entry  =  useGetEntryByEntryId(entryId);
return  <Example  {...{  ...args,  ...entry }}  />;
};

Great, your Storybook component is almost there, we can now use the Template.args to specify what entries we'd like to bring back. We do this with the contentTypes arg.

Important that the contentTypes arg is an array of strings

Template.args =  {
 contentTypes: ['blogPost', 'pot', 'plant'],
}

Now we are all set up, we can now go ahead and run storybook with npm run storybook or yarn storybook. When this opens in the browser go over to the Contensis entry picker tab. Here you will see a drop down with entries to choose from. Clicking one of these will allow your component to consume its data. 🎉