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

react-dev-tabs

v0.4.2

Published

React UI helper for development

Downloads

12

Readme

In development! (alpha)


React-Dev-Tabs is a small and lightweight library, that helps organize developers UI library, make components demos, and play with their properties. Also it allows to create assets (images) library.

Motivation

Common situation - you are open components folder, and see something like this:

components
|- ...
|- Dropzone
|- DropzoneField
|- DropArea
|- FileInput
|- ...

What are these components? How do they look? What's the difference between some of them? Another case is adding an image from a design, when you are not sure whether this image has already been used in the project or not.

In both cases it would be nice to have a place with all the components demos, or a list of all the images used in a project.

Step-by-step

DevTabs

First of all you need to add DevTabs somewhere in your project:

import DevTabs from 'react-dev-tabs';

// Assuming this is your application root component
const App = () => (
  <div>
    {/* Other components here */}

    <DevTabs />
  </div>
);

Now you need to press and hold both Shifts on your keyboard for 500ms to show React-Dev-Tabs overlap. At this moment it will show "No tabs provided".

React-Dev-Tabs designed to exclude its content from main bundle. By default it will show up and load its content with React.Suspense only if process.env.NODE_ENV === 'development'.

You can pass your own condition (boolean) with visible property, or simply render <DevTabs /> by condition.

Adding components demos

Each component demo is a usual React component. It is up to you how it will look like. But to add all of your demos you have to use barrel exports pattern. That means you have some folder with index.js inside of it with all your demos re-exported. E.g.:

// [src/demo/index.js]
export { Button } from './Button';
export { Tabs } from './Tabs';
// or
export { default as Card } from './Card';
export { default as Avatar } from './Avatar';

Using with DevTabs component:

<DevTabs
  tabs={[
    {
      type: 'components',
      label: 'Basic Components',
      modules: () => import('./demo'),
    },
  ]}
/>

Using dynamic import allows you to exclude your demo components from the main package. Don't accidentally import them somewhere else.

You can have more tabs of components type.

Adding assets (images)

It is almost the same as for components, and yes, you still need to use barrel exports pattern. E.g.:

// [src/assets/index.js]

export { default as logo } from './logo.png';
export { default as bg_decoration } from './bg-decoration.gif';

export * from './icons';
export * from './examples';

Adding to DevTabs component:

<DevTabs
  tabs={[
    {
      type: 'assets',
      label: 'Images',
      size: 150 // optional, 300 by default
      modules: () => import('./images'),
    },
  ]}
/>

Writing demo component

As mentioned above, demo component is usual React component. But React-Dev-Tabs also has several additional tools that will help expand the capabilities of the demo component.

Fieldset, Field

<Fieldset /> component gives an ability to play with component properties:

// [src/demo/Button/index.jsx]
import { useState } from 'react';
import { Fieldset, Field } from 'react-dev-tabs';
import Button from 'components/Button';

export default () => {
  const [color, setColor] = useState();
  const [size, setSize] = useState();
  const [disabled, setDisabled] = useState();

  return (
    <div>
      <Fieldset>
        <Field
          legend="color"
          value={color}
          onChange={setColor}
          options={[undefined, 'primary', 'secondary']}
          default="primary"
        />
        <Field
          legend="size"
          value={size}
          onChange={setSize}
          options={[undefined, 'small', 'medium', 'large']}
        />
        <Field
          legend="disabled"
          value={disabled}
          onChange={setDisabled}
          options={[undefined, true, false]}
        />
      </Fieldset>

      <div>
        <Button color={color} size={size} disabled={disabled}>
          Button Demo
        </Button>
      </div>
    </div>
  );
};

<Field /> component also available as <Fieldset.Field />.

Code

Creates code example block. Assepts a string as a children. It will do its best to properly format the code offsets.

// [src/demo/Button/index.jsx]
import { useState } from 'react';
import { Fieldset, Field, Code } from 'react-dev-tabs';
import Button from 'components/Button';

export default () => {
  const [color, setColor] = useState();
  const [size, setSize] = useState();
  const [disabled, setDisabled] = useState();

  return (
    <div>
      <Fieldset>
        <Field
          legend="color"
          value={color}
          onChange={setColor}
          options={[undefined, 'primary', 'secondary']}
          default="primary"
        />
        <Field
          legend="size"
          value={size}
          onChange={setSize}
          options={[undefined, 'small', 'medium', 'large']}
        />
        <Field
          legend="disabled"
          value={disabled}
          onChange={setDisabled}
          options={[undefined, true, false]}
        />
      </Fieldset>

      <Code>
        {`
          <Button
            color={${color}}
            size={${size}}
            disabled={${disabled}}
          >
            Button Demo
          </Button>
        `}
      </Code>

      <div>
        <Button color={color} size={size} disabled={disabled}>
          Button Demo
        </Button>
      </div>
    </div>
  );
};