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

@iyio/any-comp

v0.5.17

Published

A lightweight replacement for Storybook designed to run directly in any React application.

Downloads

800

Readme

AnyComp

A lightweight replacement for Storybook designed to run directly in any React application.

Features

  • Simplified Integration - No complex configuration or build steps. Just run the any-comp CLI and quickly test any of your components.

  • Auto Scanning - All components in your project are automatically registered. No need to define a story for every component you want to test.

  • Persistent Component State - Save and reload the state of your components as you test to quickly recreate specific testing conditions.

The CLI

When running, the watch-any-comp command scans and watches for changes to all of your components and generates a AcCompRegistry. This component registry can then be rendered by the AnyCompBrowser component which renders an interface similar to StoryBook and contains a searchable list of all the components in your project

The example below continuously watches the src/components directly and creates a component registry located at src/testing/all-comps.tsx. The component registry is updated with any changes while the watch-any-comp command is running.

npx watch-any-comp --dir src/components --outDir src/testing

Component Browser

Once your component registry has be created using the watch-any-comp command you can view your components using the AnyCompBrowser component. When using AnyComp with a NexJS project create a new page that renders the AnyCompBrowser component then browse to the newly created page.

NextJs Page example

import { AcCompRegistry, AnyCompBrowser } from '@iyio/any-comp';
import { useEffect, useState } from 'react';

export default function AnyCompExamplePage(){

    const [compReg,setCompReg]=useState<AcCompRegistry|null>(null);

    useEffect(()=>{
        // import dynamically to avoid NextJS server side errors
        import('../testing/all-comps').then(v=>{
            setCompReg(v.anyCompReg as any);
        })
    },[]);

    return (
        <div>
            {compReg && <AnyCompBrowser reg={compReg} rememberCompId/>}
        </div>
    );
};

Installation

AnyComp consists of 2 packages @iyio/any-comp and @iyio/any-comp-cli. @iyio/any-comp contains the AnyCompBrowser component and other supporting code used to render your component for testing. @iyio/any-comp-cli contains the watch-all-comps command used to build component registries.

npm install @iyio/any-comp
npm install @iyio/any-comp-cli --save-dev

Prop Bindings

Prop bindings allow you to connect value props to onChange callbacks. For example if you have a TextInput component with a value prop and an onChange callback called when the value changes you can have these 2 props automatically bound together. With StoryBook you would have to create a custom Template to bind the 2 values together.

By default AnyComp will automatically bind value to onChange and {x} to on{x}Change. You can also use tags defined in JSDoc style comments to define custom bindings that don't fit the auto binding naming convention.

Binding examples:

interface ExampleCompProps
{
    onChange:(value:string)=>void;
    value:string;

    age:number;
    onAgeChange:(value:number)=>void;

    jobTitle:string;
    /**
     * @acBind jobTitle
     */
    onPositionChange:(value:string)=>void;
}

Resulting bindings

onChange -> value
onAgeChange -> value
onPositionChange -> jobTitle

Tags

Tags allow you to customize the behaviour of your components when rendered by AnyComp. Tags are stored as metadata in JSDoc style comments.

  • @acIgnore - Ignores the component or prop the tag is applied to.
  • @acBind targetPropName - Binds a the callback prop to target prop.

Tag examples:

interface ExampleCompProps
{
    sirName:string;
    /**
     * @acBind sirName
     */
    onLastNameChange:(value:string)=>void;

    /**
     * @acIgnore
     */
    secretKey:string;
}

export function ExampleComp({
    sirName,
    onLastNameChange,
    secretKey
}:ExampleCompProps){

    // ...
}


/**
 * @acIgnore
 */
export function UtilityComp()
{

}

CLI Options

| arg | value | description | |----------------------|----------------|------------------------------------------------------------------------------------------------------------------------------------| | --dir | directory path | Path to a directory with components. multiple --dir arguments can be specified | | --outDir | directory path | Directory where to write the all-comps.tsx component registry | | --disableLazyLoading | | By default the component registry uses lazy loading to load component but this can be disabled using the --disableLazyLoading flag | | --debug | | Write debug information to console | | --breakOnDebug | | Causes the process to enter a break point and wait for a debugger to attach when entering debug mode |