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-me

v0.3.4

Published

Enhanced components for react

Downloads

8

Readme

React Made Easy

A library of common react components to boost productivity.

Installation

This library can simply be installed using npm:

npm install react-me

Routing

In order to use the routing components you will need to wrap your top level component with the withMeRouter directive as shown below:

ReactDOM.render(withMeRouter(<App />), document.querySelector("#root"));

Then, simple routing can easily be achieved as shown in the code snippet below

const Routes = (({none, path}) => {
  login: new MeRoute(MePath.then("login")),
  home: new MeRoute(MePath.then("public").then("home")),
  notFound: new MeRoute(none, path("path")),
})(MePath);

<MeRouter routes = {[
  Routes.login.callback(() => <h1>Login</h1>),
  Routes.home.callback(() => <h1>Home</h1>),
  Routes.notFound.callback(() => <h1>Not Found</h1>),
]} />

The routing classes support the capture of parameters and leverage the full power of typescript to enforce strict naming and type checks:

const Routes = (({num, str}) => {
  userView: new MeRoute(MePath.then("user").then(num("id")).then(str("view")))
})(MePath);

<MeRouter routes = {[
  Routes.userView.callback((params) => <div>{params.id} / {params.view}</div>),
]} />

Nested routing can also be achieved as shown below:

const Routes = (({num, path}) => {
  admin: new MeRoute(MePath.then("admin"), path("path")),
  list: new MeRoute(MePath.then("list").then("all")),
  edit: new MeRoute(MePath.then("edit").then(num("userID"))),
})(MePath);

<MeRouter routes = {[
  Routes.admin.callback((params) => 
    // Nested admin routing 
    <MeRouter path={`/${params.path || ""}`} routes = {[
      Routes.list.callback(() =>
        // User list here...
      ),
      Routes.edit.callback((params) =>
        // User form here...
      ),
    ]} />
  ),
]} />

Once application routes have been defined, routing to one of them can be easily achieved using the application routing context:

const Routes = (({num}) => ({
    userDetails: new MeRoute(MePath.then("user").then(num("id")))
}))(MePath);

const router = useContext(MeRouterContext);
<button onClick={() =>
    router.route(Routes.userDetails.format({id: 123456}))}>
  Click me!
</button>

Flow

This component let's you chain multiple components all together to easily pass data from one to another

const MyForm = new MeFlow<number>()
        .then<number>((value, next) => <div onClick={() => next(String(value * 2))}>I am {value}, click to double me</div>)
        .then<string>((value, next, previous) => <div onClick={() => previous(Number(value) / 2)}>I am {value}, click to half me</div>)
        .render(8);

<MyForm />

Table

This component simplifies the creation of tables which is usually quite verbose. From the following given data set for example:

const people = [
    { name: "Nannie", surname: "Reid", age: 23 },
    { name: "Ernest", surname: "Avila", age: 64 },
    { name: "Elwood", surname: "Harding", age: 32 },
  ];

One can create a table as simply as:

<MeTable values={people} columns={columnsFrom("name", "surname", "age")} />

Columns customisation

It is possible to customise column's headers and how cells are being rendered by defining each column indvidually as shown below:

<MeTable values={people} columns={[
  {label: "Full Name", render: (person, index) => <span> #{index}: {person.name} {person.surname}</span>},
  {label: "Age", render: renderField("age")},
]} />

Select

The select components define a concise interface in order to easily pick one or multiple entries from a pre-defined list of objects. Given the following list of products for example:

const products = [
    { name: "Apple", id: 345768 },
    { name: "Orange", id: 287456 },
    { name: "Pear", id: 124632 },
  ];

Single

<MeSingleSelect options={products} value={products[0]}
  getKey={(product) => String(product.id)}
  getLabel={(product) => product.name}
  onChange={(product) => alert("You've selected: " + product.name)} />

Multiple

<MeMultipleSelect options={products} value={[products[0], products[1]]}
  getKey={(product) => String(product.id)}
  getLabel={(product) => product.name}
  onChange={(products) => alert("You've selected: " + products.map((product) => product.name).join(","))} />

Fader

This component will automatically run a fade in and out animation whenever one of its direct children changes:

const [flag, setFlag] = React.useState(true);
<MeFader>
  {flag ? <h1>A view</h1> : <h1> Another view</h1>}
  <button onClick={() => setFlag((old) => !old)}>Click me!</button>
</MeFader>

License

This software is licensed under the MIT license

Copyright © 2019 All rights reserved. XdevL