Scraft
React library for JSON configured apps.
Features
- Available as both a function and React Hook
- Supports standard React components
- Dynamic JSON configuration supports string interpolation & function composition
- Handles page routing & layouts
- Logs errors detected in the configuration
Installing
Using npm:
$ npm install --save scraft
Using yarn:
$ yarn add scraft
Usage
App.js
;;; const config = ;const components = AppBar Tabs ColorBlock ;const utils = console ; const App = { const BuiltApp = ; return <BuiltApp />;};
or
;;; const config = ;const components = AppBar Tabs ColorBlock ;const utils = console ; const App = ;
config.json
Configuration API
App
Configures the initial application level state, and containers. These will persist throughout the entire lifetime of the application. Routing within the application is also configured here.
Schema
shape initState: containerIds: routes:
Pages
Configures initial page level state, containers, and widgets. These will persist for as long as the page is mounted. Configuration for widget layout & grid is also available. The widget grid has 12 columns, and the following breakpoints:
- lg: >= 1200px
- md: >= 992px
- sm: >= 768px
- xs: < 768px
Schema
shape id: initState: initLayoutMode: containerIds: widgetIds: layouts: shape lg: md: sm: xs: grid: shape margin: padding: cols: shape lg: md: sm: xs: rowHeight:
Layout Schema
shape i: x: y: w: h: minW: minH: maxW: maxH:
Containers & Widgets
Containers and widgets share the same wrapper component which allows for the interpolation of their props.
Each of these also allows for the composition of functions via the handlers
property. Container components all receive the widgets as children so it's important to pass them down the tree like the following:
const Container = { return <div>propschildren</div>;};
Schema
shape id: initState: handlers: onMount: onUnmount: component: shape type: props: