React Scenes is a simple way to create/test your react components inside your app.
Live demo at https://react-scenes.doub.co
We tried lots of tools to simplify our in-house react component creation process, most of the tools either has separate build process or not enough feature set. React Scenes is more simple, easy to use, flexible and does not need a separate build process, it is plug and play.
npm install react-scenes --save
Libraries is just a react component that uses Scenes
, you can point any route to any library just like normal pages.
import { Scenes } from "react-scenes";
import * as all from "./scenes";
let scenes = Object.keys(all).map(key => all[key]);
class Library extends Component {
render() {
return (
<Scenes
title="My Library"
config={{
caching: true
}}
scenes={scenes}
/>
);
}
}
Library Title.
Scenes.
This is the default state of caching, can be enable/disable from UI.
check for more: custom actions
check for more: custom panels
check for more: custom devices
Example scene
import { controllers } from "react-scenes";
export default {
title: "Hello",
target: Bar, // or as function ({ props, state, setState }) => {}
controllers: [
{
key: "title",
title: "My title",
controller: controllers.text("hello")
}
],
events: ["onClick"],
options: {
centered: true,
bg: "light" // light, dark, white, black
},
docs: `## Bar
**Hello World**
`
};
Title of your component.
You can also make titles nested like Buttons>Normal.
Your Component. You can either give your component directly or you can pass a functions.
target: ({props, state, setState, pushEvent}) => {
return (
<div>
<Button {...props}>{props.title}</Button>
</div>
)}
All the controllers your component need. They will be passed to your component as their props.
Events you want to track.
Two options are available.
theme
andcentered
(makes component centered in viewport with flexbox).
Component documentation or notes.
We provide 4 panels; You can also add custom panels check for more: custom panels Every panel can has its own specific actions check for more: custom panel actions
All scenes you have will appear in here.
Conrollers are your main tools to alter your component without direct input.
We provide 10 default controllers; text
,textarea
,select
,boolean
,integer
,float
,range
,object
,array
,color
controllers.text("Hello World")
controllers.textarea("Hello \n World")
controllers.select("primary", ["primary", "destructive"])
or you can add as key,value
controllers.select("primary", [
{key:"Primary, value:"primary"},
{key:"Positive, value:"positive"}
])
controllers.boolean(true, true)
> if you set second argument it will includenull
to controller cycle.
controllers.integer(42)
controllers.float(42.1)
controllers.range(42.1)
controllers.object({foo:"bar"})
controllers.array([1,2,3])
controllers.color("#000","hex" // hex, rgb, rgba)
Track your components events, just add event props to your scenes as an array.
This converts your components code to string for easy sharing.
Docs are can be component documentation or any other notes. (markdown supported).
We exposed all props internally so you can access to alter anything you like.
<Scenes
...
panels={[
{
_id: "my-apples",
component: MyApples,
active: ({ get }) => get("active").panel == "my-panel",
icon: "π",
actions: [
{
_id: "toggle-apple-color",
icon: ({ get })=> get("config").options.apple == "green" ? "π" : "π",
active: ({ get }) => get("config").options.apple == "green",
onClick: ({ set }) => {
set("config",{
options:{
...get("config").options,
centered: props.options.apple == "green" ? "red" : "green"
}
});
}
}
]
}
]}
/>
Example: myApp/.../myCustomController.js
import React, { Component } from "react";
export default (initialValue, foo, bar) => {
return {
type: "customController",
initialValue,
process: val => val,
input: (value, set, title, state, setState) => {
return (
<div className="custom-controller">
<input
value={value}
onChange={e => set(e.target.value)}
onFocus={e => setState({ focused: true })}
onBlur={e => setState({ focused: false })}
/>
{focused ? "Focused" : "Not Focused"}
</div>
);
}
};
};
There is 4 props you can use;
-
type
string
is just and identifier. -
initialValue
anything
is the initial value of the input. -
process
function
can be use to alter the input value. -
input
function
hasvalue
,set
,title
,state
,setState
to update your data and state of your controller.
Example: someScene.js
import customController from "../myCustomController";
export default {
title: "Hello",
target: Bar,
controllers: [
{
key: "data",
title: "My Data",
controller: customController("hello", "foo", "bar")
}
]
};
to add custom device sizes, inject it to Scenes
like below.
<Scenes
...
devices={{
iphonex: {
title: "iPhone X",
width: 375,
height: 812
},
iphoneflex: {
title: "iPhone Flex",
width: "375px",
height: "100%",
unit: ""
}
}}
/>
Pull requests are welcome and please submit bugs π.
- Follow @doubco on Twitter
- Follow @doubco on Facebook
- Follow @doubco on Instagram
- Email mailto:[email protected]