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

@knaussb/scenic-view

v0.2.0

Published

A simple routing library for managing which views are rendered in React.

Downloads

3

Readme

Scenic View

A simple view management library to make managing conditionally rendered components simple. This library is still in early stages so the API is likely to change. This library uses React's context API to control what components get rendered. If you have any questions or suggestions, I'd love to hear them.

Here is a very simple example for demonstration purposes:

import React from 'React'
import { AutoScene, IfView, ElseView } from '@knaussb/scenic-view'

const App = props => (
  <AutoScene
    initialViews={{
      clean: true,
      loading: false,
      submitting: false,
      error: false,
      valid: true,
    }}
  >
    <form>
      <IfView view="error">
        <h3>An error has occurred!</h3>
      </IfView>
      <IfView view="loading">
        <LoadingPanel>
          <h1>Loading... Please wait.</h1>
        </LoadingPanel>
      </IfView>
      <ElseView view="valid">
        <input type="submit" value="Submit" />
      </ElseView>
    </form>
  </AutoScene>
)

Scene

The Scene component is a fully controlled component that requires views and onViewsChange props.

AutoScene

The AutoScene component is the uncontrolled equivalent of the Scene component. It has an initialViews prop that it uses to set the views on mount.

Viewable Type

The Viewable type is the types that functions like toggleViews, unselectViews, etc. can accept which can be resolved to "view objects". It is either a string, array of strings, or plain object.

IfView

The IfView component takes a view prop and children can be react elements or a render function. It will only render it's children when the view is enabled.

const Example = props => (
  <AutoScene initialViews="abc">
    <IfView view="abc">
      <p>This will be rendered because the abc view is enabled.</p>
    </IfView>
    <IfView view="xyz">
      {() => <p>This will not be rendered because xyz is not enabled.</p>}
    </IfView>
  </AutoScene>
)

ElseView

The ElseView component is the opposite of the IfView component in that it takes a view prop and only renders it's children when that view is not selected. It can also take children elements or as a render prop.

const Example = props => (
  <AutoScene initialViews="abc">
    <IfView view="abc">
      <p>This will not be rendered because the abc view is enabled.</p>
    </IfView>
    <IfView view="xyz">
      {() => <p>This will be rendered because xyz is not enabled.</p>}
    </IfView>
  </AutoScene>
)