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

atom-lib

v1.1.2

Published

Personal ReactJS container library

Downloads

11

Readme

ReactJS Container Library

Reusable container components for common React features/functionalities

Install

npm install --save atom-lib


Usage

    import {
    Toggler,
    withToggler, 
    SwitchBoard,
    ... 
    } from "atom-lib";

Container API Reference

Containers are components that have some sort of reusable functionality. Internal state/methods are exposed mainly via children props unless otherwise stated. The children function must always return either a React element or a React component. A corresponding HOC is also provided unless otherwise stated.

§ <Toggler>

Props

Name | Type | Default | Description --- | --- | --- | --- children [required] | Func | N/A | See below on [optional] | Bool | false | Determines initial value of toggler

Children Props

Property | Type | Description --- | --- | --- on | Bool | The value of current state toggle | Func | Callback function which toggles on value

<Toggler on>
    {({on, toggle}) => (
        <div>
            <button onClick={toggle}>{on ? "ON" : "OFF"}</button>
        </div>
    )}
</Toggler>

§ withToggler

Will expose the toggle and on values from above as props to the specified component.

withToggler(config)(component)

config

Properties | Type | Description --- | --- | --- on [optional] |Boolean | Initial value of toggler

import {withToggler} from "atom-lib"

function YourComponent({on, toggle}){
    return (
        // ...
    )
}

export default withToggler({on: false})(YourComponent)

§ <Switchboard>

Props

Name | Type | Default | Description --- | --- | --- | --- children [required] | Func | N/A | See below exclusive [optional] | Bool | false | Determines if switchboard values will be mutually exclusive (Any change in one switch value will result in all other switches being set to the opposite value) flipped [optional] | Bool | false | Inverts the on values for each switch. switches [optional] | Object | {} | Initial values for the switchboard. Key values must be boolean.

Children Props

Property | Type | Description --- | --- | --- toggleExclusive | Func | Toggles the mutually exclusive setting. When set to false, changes to individual switch values won't affect others. flipBoard | Func | Inverts the on values for each switch. exclusive | Bool | Current exclusion state of switchboard. flipped | Bool | Current flip state of switchboard. switches | Object | Current switch values for switchboard.

<Switchboard exclusive>
    {({ flipBoard, toggleExclusive, flipped, exclusive, switches }) => (
      <div>
        <Switch id={"a"}>
          {({ on, toggleSwitch }) => (
            <a style={{
              textDecoration: on ? "underline" :
                "none"
            }} onClick={toggleSwitch}>A</a>
          )}
        </Switch>
        <Switch id={"b"}>
          {({ on, toggleSwitch }) => (
            <a style={{
              textDecoration: on ? "underline" :
                "none"
            }} onClick={toggleSwitch}>B</a>
          )}
          <button onClick={toggleExclusive}>{exclusive ? "Set back to Inclusive" : "Set back to exclusive"}</button>
          <button onClick={flipBoard}>{flipped ? "Reset" : "Invert"}</button>
          <p>Currently, {Object.keys(switches).reduce((total, sw) => switches[sw] ? total + 1 : total, 0)} switches are ON</p>
        </Switch>
      </div>
    )}
  </Switchboard>

§ withSwitchboard

Will expose the children prop values from above as props to the specified component.

withSwitchboard(config)(component)

config accepts the same key-value pairs as the props object to Switchboard except for children.

import {withToggler} from "atom-lib"

function YourComponent({on, toggle}){
    return (
        // ...
    )
}

export default withToggler({on: false})(YourComponent)

§ <Switch>

Switch components must be rendered within a Switchboard component. They are responsible for toggling and containing a particular switch value.

Props

Name | Type | Default | Description --- | --- | --- | --- children [required] | Func | N/A | See below id [required] | String or Number | N/A | Identifies the particular switch across the switchboard

Children Props

Property | Type | Description --- | --- | --- on | Bool | The value of current switch state toggleSwitch | Func | Callback function which toggles on value

<Switch id="a">
    {({on, toggleSwitch}) => (
        <div>
            <button onClick={toggleSwitch}>{on ? "ON" : "OFF"}</button>
        </div>
    )}
</Switch>

§ withSwitch

Will expose the children prop values from above as props to the specified component. Must be rendered within a Switchboard component.

withSwitch(config)(component)

config Properties | Type | Description --- | --- | --- id [required] |String or Number | Identifies the particular switch across the switchboard

const linkComponents = links.map((content, i) => (
    createElement(withSwitch({ id: i })(NavLink), { key: i }, content)
  ))

Changelog

  • 10/14 - Added Toggler, withToggler, Switchboard, and withSwitchboard

Upcoming

  • Loader, Error Handler, SortFilter