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-native-sandbox

v0.1.21

Published

A sandbox environment for building, documenting, and presenting components in React Native

Downloads

3,748

Readme

This is a work in progress. Expect frequent breaking changes until the library reaches a stable v1.0.0 version.

Provides a sandbox environment for component development with minor configuration requirements.

Motivation

Storybook is a game-changer for helping to produce, iterate on, and document high-quality and robust UI components. However, support for Storybook in React Native seems to trail behind and the development experience leaves much to be desired. Additionally, many of the powerful plugins in the Storybook ecosystem aren't compatible with React Native development.

react-native-sandbox was built as a lightweight alternative and purpose-built for React Native. It doesn't require any dev servers or environment setup. Just write your sandboxes, render the SandboxRoot, and you're all set. It's also built to feel like a React tool using React Hooks and simple props for configuring most plugins.

Intallation

Open a terminal in your project's folder and run

npm install react-native-sandbox

Usage

First, create a component that will be used in the sandbox. This is what will display in the frame when the sandbox is opened.

import { useText } from 'react-native-sandbox';

export function ButtonSandbox() {
  return <Button text={text} />;
}

Then, create a sandbox group configuration. You can group multiple sandbox components together. This is useful for representing the same components in multiple ways, such as different usage patterns, variations of the same component, etc.; or it can also be useful for colocating similar categories of components together.

export default {
  name: 'Button',
  components: {
    ButtonSandbox,
    'Variations': ButtonVariations
  },
};

Lastly, add a SandboxRoot and connect the sandboxes.

import SandboxRoot from 'react-native-sandbox';

const components = [
  {
    name: 'Button',
    components: {
      ButtonPlayground,
    },
  },
];

function App() {
  return <SandboxRoot components={[Buttons]} />;
}

Auto-loader

Rather than having to manually wire up all of the sandboxes it is highly recommended to use the auto-loader. To do so first, add the following script to the package.json:

{
  "scripts": {
    "sandbox": "sandbox-loader -o ./sandboxFiles.ts",
  },
}

Use the -o or --output option to specify the file to output. This is the file that will be imported in the SandboxRoot.

Next use the naming convention *.sandbox.(js|jsx|tsx) for modules containing sandboxes. These files need to have a default export that is a configuration for the sandbox group. See Usage above for more details.

Now, run the script npm run sandbox. Upon completion you will notice that all files matching the prescribed pattern will not be imported into the output file and re-exported.

Finally, import that file and provide it to the SandboxRoot:

import sandboxes from './sandboxFiles';

// ...

function App() {
  return <SandboxRoot components={sandboxes} />;
}

Now, whenever a new sandbox file is added, just run npm run sandbox again and it will automatically be loaded in.

Theming

Themes allow for control over the styling of the sandbox tool. Out of the box there is a default (light) and a dark theme.

import SandboxRoot, { DefaultTheme, DarkTheme } from 'react-native-sandbox';

// ...

const theme = {
  ...DefaultTheme,
  colors: {
    ...DefaultTheme.colors
    background: 'gray',
  }
}

function App() {
  return <SandboxRoot components={components} theme={theme} />;
}

Currently, the only supported editable theme properties are colors.

| Property | Description | Default | Dark | |---|---|---|---| | text | Default color for text | black | #eee | | background | Default color for background | white | #222 | | surface | Default background color for surfaces | #eee | #111 | | disabled | Color for disabled text | #555 | #777 | | divider | Color for dividers | #ccc | #555 | | info | Color for informational items | #3498db | #3498db | | warning | Color for warning items | #f1c40f | #f1c40f | | error | Color for error items | #e74c3c | #e74c3c | | success | Color for success items | #2ecc71 | #2ecc71 |

Plugins

react-native-sandbox uses a plugin to add additional functionality. They can be downloaded from NPM or custom-built for advanced scenarios. More documentation to come on how to build custom plugins.

Here are a few with first-party support on NPM:

  • @react-native-sandbox/backdrop
  • @react-native-sandbox/controls
  • @react-native-sandbox/docs
  • @react-native-sandbox/grid

To enable a plugin simply import it into the root file, and add it via the plugins prop into SandboxRoot.

import SandboxRoot from 'react-native-sandbox';
import MyPlugin from 'my-plugin';

function App() {
  return <SandboxRoot components={sandboxes} plugins={[MyPlugin]} />;
}

Migrating from 0.1.17

Prior to v0.1.17 controls were part of the core library. In an effort to provide extensibility and scalable controls have been pulled into a separate plugin library @react-native-sandbox/controls. Please see that package for more information about configuring the plugin.

Contributions

Contributions are absolutely welcome! More details will hopefully come soon around how to get into building and extending the tool. At the moment, I am the sole developer of the project and work on it in my free time. Most of my work is intended to support my professional needs. If there is a feature that would benefit your workflows, feel free to reach out.