├── .gitignore ├── .travis.yml ├── .prettierrc ├── src ├── index.js ├── __tests__ │ ├── MagicHat.test.js │ └── __snapshots__ │ │ └── MagicHat.test.js.snap ├── lib │ └── flipMoveOptions.js ├── MagicHatNoState.js └── MagicHat.js ├── test.setup.js ├── .vscode ├── settings.json └── launch.json ├── .eslintrc ├── .babelrc ├── rollup.config.js ├── stateless-version.md ├── package.json ├── README.md └── LICENSE.md /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | coverage -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '8' -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "bracketSpacing": false, 4 | "semi": false, 5 | "printWidth": 80 6 | } 7 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import MagicHatNoState from './MagicHatNoState' 2 | import MagicHat from './MagicHat' 3 | 4 | export {MagicHatNoState} 5 | 6 | export default MagicHat 7 | -------------------------------------------------------------------------------- /test.setup.js: -------------------------------------------------------------------------------- 1 | const Enzyme = require('enzyme') 2 | const EnzymeAdapter = require('enzyme-adapter-react-16') 3 | 4 | Enzyme.configure({adapter: new EnzymeAdapter()}) 5 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "javascript.format.enable": false, 4 | "prettier.eslintIntegration": true, 5 | "npm-scripts.showStartNotification": false 6 | } -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "extends": ["eslint:recommended", "plugin:react/recommended"], 4 | "globals": { 5 | "describe": true, 6 | "beforeAll": true, 7 | "beforeEach": true, 8 | "afterAll": true, 9 | "afterEach": true, 10 | "test": true, 11 | "it": true, 12 | "expect": true, 13 | "jest": true, 14 | "window": true, 15 | "require": true 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "env", 5 | { 6 | "targets": { 7 | "browsers": ["last 2 versions", "safari >= 7"] 8 | }, 9 | "modules": false 10 | } 11 | ], 12 | "react" 13 | ], 14 | "env": { 15 | "test": { 16 | "presets": [["env"], "react"], 17 | "plugins": [ 18 | ["transform-class-properties", {"spec": true}], 19 | "transform-object-rest-spread" 20 | ] 21 | } 22 | }, 23 | "plugins": [ 24 | ["transform-class-properties", {"spec": true}], 25 | "transform-object-rest-spread" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /src/__tests__/MagicHat.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-debugger */ 2 | import React from 'react' 3 | import {mount} from 'enzyme' 4 | import toJson from 'enzyme-to-json' 5 | import MagicHat from '../MagicHat' 6 | 7 | class Dummy extends React.Component { 8 | render() { 9 | return 'hello' 10 | } 11 | } 12 | 13 | describe('MagicHat', () => { 14 | it('should match the snapshot', () => { 15 | const wrapper = mount( } />) 16 | expect(toJson(wrapper)).toMatchSnapshot() 17 | }) 18 | 19 | it('invoke startAnimation', () => { 20 | const mockCallback = jest.fn() 21 | 22 | mount( 23 | } onStartAnimation={mockCallback} /> 24 | ) 25 | 26 | expect(mockCallback.mock.calls.length).toBe(1) 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import resolve from 'rollup-plugin-node-resolve' 2 | import babel from 'rollup-plugin-babel' 3 | import uglify from 'rollup-plugin-uglify' 4 | import commonJS from 'rollup-plugin-commonjs' 5 | import pkg from './package.json' 6 | 7 | export default { 8 | input: 'src/index.js', 9 | output: [ 10 | { 11 | name: pkg.module, 12 | file: pkg.module, 13 | format: 'es' 14 | }, 15 | { 16 | name: pkg.main, 17 | file: pkg.main, 18 | format: 'umd', 19 | sourcemap: false 20 | } 21 | ], 22 | plugins: [ 23 | resolve(), 24 | commonJS({ 25 | include: 'node_modules/**' 26 | }), 27 | babel({ 28 | presets: ['react'], 29 | exclude: 'node_modules/**', 30 | plugins: ['external-helpers'] 31 | }), 32 | uglify() 33 | ], 34 | external: ['react', 'react-dom'] 35 | } 36 | -------------------------------------------------------------------------------- /stateless-version.md: -------------------------------------------------------------------------------- 1 | # React Magic Hat - stateless 2 | 3 | ## Usage 4 | 5 | ```jsx 6 | import {MagicHatNoState} from 'react-magic-hat' 7 | import {ComponentA, ComponentB} from 'components' 8 | 9 | const renderFrame = ({id, page, activePage, state, actions}) => { 10 | const Frame = id === 'componentA' ? ComponentA : ComponentB 11 | return 12 | } 13 | 14 | const options = { 15 | pages: [ 16 | { 17 | id: 'componentA' 18 | }, 19 | { 20 | id: 'componentB' 21 | } 22 | ], 23 | activePage: 1, 24 | renderFrame 25 | } 26 | 27 | const Layout = () => ( 28 |
29 | 30 |
31 | ) 32 | ``` 33 | 34 | ## Maintainers 35 | 36 | [@albinotonnina](https://github.com/albinotonnina) 37 | 38 | ## Contribute 39 | 40 | PRs accepted. 41 | 42 | ## License 43 | 44 | MIT © 2018 Albino Tonnina 45 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Jest All", 11 | "program": "${workspaceFolder}/node_modules/jest/bin/jest", 12 | "args": ["--runInBand"], 13 | "console": "integratedTerminal", 14 | "internalConsoleOptions": "neverOpen" 15 | }, 16 | { 17 | "type": "node", 18 | "request": "launch", 19 | "name": "Jest Current File", 20 | "program": "${workspaceFolder}/node_modules/jest/bin/jest", 21 | "args": ["${file}"], 22 | "console": "integratedTerminal", 23 | "internalConsoleOptions": "neverOpen" 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /src/lib/flipMoveOptions.js: -------------------------------------------------------------------------------- 1 | const appearAnimation = { 2 | from: { 3 | transform: 'scaleX(0) scaleY(1)', 4 | transformOrigin: '50% 50%' 5 | }, 6 | to: { 7 | transform: '' 8 | } 9 | } 10 | 11 | const enterAnimation = { 12 | from: { 13 | transform: 'scaleX(0) scaleY(0.4)', 14 | opacity: 0.1 15 | }, 16 | to: { 17 | transform: '' 18 | } 19 | } 20 | 21 | const leaveAnimationDefault = { 22 | from: { 23 | transform: '' 24 | }, 25 | to: { 26 | transform: 'scaleX(0) scaleY(0.8)', 27 | opacity: 0.1 28 | } 29 | } 30 | 31 | const leaveAnimationInitial = { 32 | from: { 33 | transform: '', 34 | transformOrigin: '50% 50%' 35 | }, 36 | to: { 37 | transform: 'scaleX(0) scaleY(0.8)', 38 | opacity: 0.1 39 | } 40 | } 41 | 42 | const delay = 0 43 | const duration = 400 44 | const staggerDurationBy = 0 45 | const staggerDelayBy = 0 46 | const disableAllAnimations = false 47 | const typeName = null 48 | const easing = 'cubic-bezier(0.39, 0.575, 0.565, 1)' 49 | 50 | const defaultOptions = { 51 | delay, 52 | duration, 53 | staggerDurationBy, 54 | staggerDelayBy, 55 | disableAllAnimations, 56 | typeName, 57 | easing, 58 | appearAnimation, 59 | enterAnimation, 60 | leaveAnimationDefault 61 | } 62 | 63 | export const getFlipMoveOptions = ({ 64 | flipMoveOptions, 65 | visiblePagesLength, 66 | pagesLength, 67 | singleFrame 68 | }) => { 69 | const openingSecondFrame = 70 | !singleFrame && visiblePagesLength === 2 && pagesLength === 2 71 | 72 | const closingSecondFrame = 73 | !singleFrame && visiblePagesLength <= 1 && pagesLength <= 2 74 | 75 | const _duration = 76 | openingSecondFrame || closingSecondFrame ? duration : duration * 1.5 77 | 78 | const _leaveAnimation = closingSecondFrame 79 | ? leaveAnimationInitial 80 | : leaveAnimationDefault 81 | 82 | const _staggerDelayBy = openingSecondFrame ? duration / 2 : 0 83 | 84 | return { 85 | ...defaultOptions, 86 | duration: _duration, 87 | staggerDelayBy: _staggerDelayBy, 88 | leaveAnimation: _leaveAnimation, 89 | ...flipMoveOptions({ 90 | pagesLength, 91 | visiblePagesLength, 92 | singleFrame 93 | }) 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/MagicHatNoState.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import PropTypes from 'prop-types' 3 | import FlipMove from 'react-flip-move' 4 | import {getFlipMoveOptions} from './lib/flipMoveOptions' 5 | 6 | export default class MagicHatNoState extends React.Component { 7 | static propTypes = { 8 | pages: PropTypes.array.isRequired, 9 | activePage: PropTypes.number.isRequired, 10 | renderFrame: PropTypes.func.isRequired, 11 | 12 | onStartAnimation: PropTypes.func, 13 | onEndAnimation: PropTypes.func, 14 | flipMoveOptions: PropTypes.func, 15 | singleFrame: PropTypes.bool, 16 | moveSeed: PropTypes.string 17 | } 18 | 19 | static defaultProps = { 20 | activePage: 0, 21 | onStartAnimation: () => null, 22 | onEndAnimation: () => null, 23 | flipMoveOptions: () => null, 24 | moveSeed: '' 25 | } 26 | 27 | getPageElement = ({page, id}) => { 28 | const {activePage, renderFrame, moveSeed} = this.props 29 | 30 | const key = '' + page + id + moveSeed 31 | 32 | return React.cloneElement( 33 | renderFrame({ 34 | id, 35 | page, 36 | activePage 37 | }), 38 | { 39 | key 40 | } 41 | ) 42 | } 43 | 44 | getOneFrame = (page, activePage) => page && activePage - page === 0 45 | 46 | getTwoFrames = (page, activePage) => 47 | page && (activePage - page === 1 || activePage - page === 0) 48 | 49 | getVisiblePages = () => { 50 | const {getOneFrame, getTwoFrames, getPageElement, props} = this 51 | const {pages, singleFrame, activePage} = props 52 | 53 | return pages 54 | .filter( 55 | ({page}) => 56 | singleFrame 57 | ? getOneFrame(page, activePage) 58 | : getTwoFrames(page, activePage) 59 | ) 60 | .map(getPageElement) 61 | } 62 | 63 | render() { 64 | const {props, getVisiblePages} = this 65 | 66 | const { 67 | pages, 68 | onStartAnimation, 69 | onEndAnimation, 70 | singleFrame, 71 | flipMoveOptions 72 | } = props 73 | 74 | const visiblePages = getVisiblePages() 75 | 76 | return ( 77 | 88 | ) 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-magic-hat", 3 | "version": "1.1.1", 4 | "description": "A kind of UI engine", 5 | "main": "dist/magicHat.js", 6 | "module": "dist/magicHat.esm.js", 7 | "source": "src/index.js", 8 | "size-limit": [ 9 | { 10 | "limit": "8 KB", 11 | "path": "dist/magicHat.js" 12 | }, 13 | { 14 | "limit": "8 KB", 15 | "path": "dist/magicHat.esm.js" 16 | } 17 | ], 18 | "scripts": { 19 | "build": "rollup -c", 20 | "dev": "rollup -c -w", 21 | "size": "size-limit", 22 | "prepare": "npm run build", 23 | "test": "jest", 24 | "test:updateSnapshots": "jest --updateSnapshot" 25 | }, 26 | "author": "Albino Tonnina (http://www.albinotonnina.com)", 27 | "license": "MIT", 28 | "repository": { 29 | "type": "git", 30 | "url": "https://github.com/albinotonnina/react-magic-hat.git" 31 | }, 32 | "keywords": [ 33 | "react", 34 | "react-dom", 35 | "animation", 36 | "flip", 37 | "ui", 38 | "react-component", 39 | "stack", 40 | "web-animations" 41 | ], 42 | "peerDependencies": { 43 | "react": ">=0.13.x <=16.x.x", 44 | "react-dom": ">=0.13.x <=16.x.x" 45 | }, 46 | "dependencies": {}, 47 | "files": [ 48 | "dist", 49 | "src" 50 | ], 51 | "devDependencies": { 52 | "babel-core": "^6.26.0", 53 | "babel-eslint": "^8.2.2", 54 | "babel-plugin-external-helpers": "^6.22.0", 55 | "babel-plugin-transform-class-properties": "^6.24.1", 56 | "babel-plugin-transform-object-rest-spread": "^6.26.0", 57 | "babel-preset-env": "^1.6.1", 58 | "babel-preset-react": "^6.24.1", 59 | "enzyme": "^3.3.0", 60 | "enzyme-adapter-react-16": "^1.1.1", 61 | "enzyme-to-json": "^3.3.3", 62 | "eslint": "^4.18.2", 63 | "eslint-plugin-react": "^7.7.0", 64 | "jest": "^22.4.3", 65 | "prettier": "^1.11.1", 66 | "prettier-eslint": "^8.8.1", 67 | "prop-types": "^15.6.1", 68 | "react": "^16.2.0", 69 | "react-dom": "^16.2.0", 70 | "react-flip-move": "https://github.com/albinotonnina/react-flip-move.git#push_not_splice", 71 | "rollup": "^0.57.0", 72 | "rollup-plugin-babel": "^3.0.3", 73 | "rollup-plugin-commonjs": "^9.1.0", 74 | "rollup-plugin-node-resolve": "^3.2.0", 75 | "rollup-plugin-uglify": "^3.0.0", 76 | "size-limit": "^0.17.0" 77 | }, 78 | "jest": { 79 | "collectCoverage": true, 80 | "coverageReporters": [ 81 | "html" 82 | ], 83 | "snapshotSerializers": [ 84 | "enzyme-to-json/serializer" 85 | ], 86 | "setupTestFrameworkScriptFile": "/test.setup.js" 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/MagicHat.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import PropTypes from 'prop-types' 3 | import MagicHatNoState from './MagicHatNoState' 4 | 5 | export default class MagicHat extends React.Component { 6 | static propTypes = { 7 | renderFrame: PropTypes.func.isRequired, 8 | onStartAnimation: PropTypes.func, 9 | onEndAnimation: PropTypes.func, 10 | flipMoveOptions: PropTypes.func, 11 | singleFrame: PropTypes.bool, 12 | moveSeed: PropTypes.string 13 | } 14 | 15 | state = { 16 | activePage: 1, 17 | pages: [ 18 | { 19 | id: '', 20 | page: 1, 21 | state: {} 22 | } 23 | ] 24 | } 25 | 26 | getFrame = page => { 27 | return this.state.pages[page - 1] || {} 28 | } 29 | 30 | setContent = (page, payload = {}, isActive) => { 31 | this.setState(prevState => { 32 | const pages = [...prevState.pages] 33 | const pageIndex = page - 1 34 | 35 | const currentPage = pages[pageIndex] || {id: '', state: {}} 36 | 37 | const nextState = { 38 | page, 39 | id: payload.id ? payload.id : currentPage.id, 40 | state: payload.state 41 | ? {...currentPage.state, ...payload.state} 42 | : currentPage.state 43 | } 44 | 45 | pages.splice(pageIndex, 1, nextState) 46 | 47 | return { 48 | pages, 49 | activePage: isActive ? page : prevState.activePage 50 | } 51 | }) 52 | } 53 | 54 | sliceFrame = page => { 55 | this.setState(prevState => { 56 | const pages = [...prevState.pages] 57 | const pageIndex = page - 1 58 | 59 | pages.splice(pageIndex, 1, {}) 60 | 61 | return { 62 | pages: pages.slice(0, pageIndex + 1, {}), 63 | activePage: page - 1 64 | } 65 | }) 66 | } 67 | 68 | connectFrame = ({page, activePage}) => { 69 | const {setContent, getFrame, sliceFrame} = this 70 | 71 | const frame = getFrame(page) 72 | 73 | const nextPage = page + 1 74 | 75 | const actions = { 76 | setCurrentFrame: (state, isActive = false) => 77 | setContent(page, {state}, isActive), 78 | getCurrentFrame: () => getFrame(page), 79 | closeCurrentFrame: () => sliceFrame(page), 80 | 81 | setNextFrame: (id, state, isActive = true) => 82 | setContent(nextPage, {id, state}, isActive), 83 | getNextFrame: () => getFrame(nextPage), 84 | closeNextFrame: () => sliceFrame(nextPage), 85 | 86 | setFrame: (page, id, state, isActive = false) => 87 | setContent(page, {id, state}, isActive), 88 | getFrame: page => getFrame(page), 89 | closeFrame: page => sliceFrame(page) 90 | } 91 | 92 | return this.props.renderFrame({ 93 | activePage, 94 | ...frame, 95 | actions 96 | }) 97 | } 98 | 99 | onEndAnimation = (childElements, domElements) => { 100 | this.setState( 101 | prevState => { 102 | return { 103 | pages: prevState.pages.filter(page => page.page) 104 | } 105 | }, 106 | () => this.props.onEndAnimation(childElements, domElements, this.state) 107 | ) 108 | } 109 | 110 | render = () => ( 111 | 117 | ) 118 | } 119 | -------------------------------------------------------------------------------- /src/__tests__/__snapshots__/MagicHat.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`MagicHat should match the snapshot 1`] = ` 4 | 7 | 24 | 83 | 147 | 150 | hello 151 | 152 | 153 | 154 | 155 | 156 | `; 157 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Dependency Up-to-dateness][david-image]][david-url] 2 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/5cac2b7c18984c8d9626e904be3def71)](https://app.codacy.com/app/albinotonnina/react-magic-hat?utm_source=github.com&utm_medium=referral&utm_content=albinotonnina/react-magic-hat&utm_campaign=badger) 3 | [![Build Status](https://travis-ci.org/albinotonnina/react-magic-hat.svg?branch=master)](https://travis-ci.org/albinotonnina/react-magic-hat) 4 | 5 | # React Magic Hat 🎩✨ 6 | 7 | > A kind of UI technique 8 | 9 | React implementation of what I call the [**Magic Hat UI technique**](https://medium.com/@albinotonnina/magic-hat-technique-408a3fa590bb) [[DEMO](https://albinotonnina.github.io/demo-magic-hat)]. 10 | 11 |

12 | 13 |

14 | 15 | [david-image]: https://david-dm.org/albinotonnina/react-magic-hat.svg 16 | [david-url]: https://david-dm.org/albinotonnina/react-magic-hat 17 | 18 | ## Features 19 | 20 | 🚀 [Blazing fast](https://twitter.com/acdlite/status/974390255393505280). 60+ FPS hardware-accelerated CSS transforms, using the [FLIP technique](https://medium.com/r/?url=https%3A%2F%2Faerotwist.com%2Fblog%2Fflip-your-animations%2F%23the-general-approach). Fluid and performant. Thanks to [react-flip-move](https://github.com/joshwcomeau/react-flip-move) for that. 21 | 22 | 🎈Extra light, only 6.5kb and no dependencies. 23 | 24 | 🧘‍Flexible, stateful or stateless (you get both components) it’s UI-less, you do the layouting and styling. 25 | 26 | 🎛 Highly configurable, check the [API](#api) 27 | 28 | ## Table of Contents 29 | 30 | * [Background](#background) 31 | * [Install](#install) 32 | * [Usage](#usage) 33 | * [API](#api) 34 | * [Demos](#demos) 35 | * [Maintainers](#maintainers) 36 | * [Contribute](#contribute) 37 | * [License](#license) 38 | 39 | ## Background 40 | 41 | The Magic Hat is a technique with the purpose of reducing the the total amount of mental effort that is required to complete a task involving processing of information, in short cognitive load, by limiting the amount of UI on the screen in favour of a runtime like linked list of sequential self sufficient UIs called MUVs (Minimum Usable Views) 42 | It's called like this because in a view the user can pick the next thing to put on screen. It’s pretty much it. 43 | 44 | [Read the article on medium.com](https://medium.com/@albinotonnina/magic-hat-technique-408a3fa590bb) 45 | 46 | ## Install 47 | 48 | ``` 49 | yarn add react-magic-hat 50 | ``` 51 | 52 | ## Usage 53 | 54 | ```jsx 55 | import YourMagicContainer from 'react-magic-hat' 56 | import ComponentA, {id as CompA} from 'components' 57 | import ComponentB from 'components' 58 | 59 | const renderFrame = pageObject => { 60 | // Please check the renderFrame(pageObject) documentation for all the properties passed to the pageObject. 61 | const {id, actions, state} = pageObject 62 | 63 | // We get the Component that is going to be rendered, the following is probably the most naive way. 64 | const Muv = id === CompA ? ComponentA : ComponentB 65 | 66 | // Another way to do it in the demo, using import-glob 67 | // https://github.com/albinotonnina/demo-magic-hat/blob/master/src/Demo.js#L5-L21 68 | 69 | return 70 | } 71 | 72 | const Layout = () => ( 73 |
74 | 75 |
76 | ) 77 | ``` 78 | 79 | ## API 80 | 81 | ### Prop Types 82 | 83 | | Property | Type | Required? | Arguments | Description | 84 | | :--------------- | :------- | :-------: | :--------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------- | 85 | | renderFrame | Function | ✓ | [Documentation](#renderframepageobject) | Callback invoked when rendering the visible pages. | 86 | | onStartAnimation | Function | | [childElements, domElements](https://github.com/joshwcomeau/react-flip-move/blob/master/documentation/api_reference.md#onstartall), pageProps | | 87 | | onEndAnimation | Function | | [childElements, domElements](https://github.com/joshwcomeau/react-flip-move/blob/master/documentation/api_reference.md#onfinishall), pageProps | | 88 | | flipMoveOptions | Function | | {pagesLength, visiblePagesLength, singleFrame} | Override [react-flip-move](https://github.com/joshwcomeau/react-flip-move/blob/master/documentation/api_reference.md#api-reference) configuration. | 89 | | singleFrame | Boolean | | | By default show two views. Set this to `true` to show only one. | 90 | | moveSeed | String | | | Change this to force animations, it will be appended to the view keys [read when we need this](https://github.com/joshwcomeau/react-flip-move#gotchas) | 91 | 92 | ### renderFrame(pageObject) 93 | 94 | ```jsx 95 | import getComponentById from './your-components' 96 | 97 | const renderFrame = pageObject => { 98 | const { 99 | id, // 'my-component-id' 100 | page, // 4 101 | activePage, // 5 102 | state, // { roses: 'blue', violets: 'red', pass:'whetever', pleases: 'you' } 103 | actions // see next paragraph for the actions methods 104 | } = pageObject 105 | 106 | const Muv = getComponentById(id) // return a Component 107 | 108 | return 109 | } 110 | ``` 111 | 112 | ### {actions} API 113 | 114 | | Method | Description | 115 | | :--------------------------------------------- | :-------------------------------------------- | 116 | | setCurrentFrame(props:object) | Merge props on the current page | 117 | | getCurrentFrame():object | Get props of the current page | 118 | | closeCurrentFrame() | Close the current page | 119 | | setNextFrame(id:string, props:object ) | Merge the next page and optionally pass props | 120 | | getNextFrame() | Get props of the next page | 121 | | closeNextFrame() | Close the next page | 122 | | setFrame(page:number, id:string, props:object) | Merge the next page | 123 | | getFrame(page:number):props | Get props of a page | 124 | | closeFrame(page:number) | Close a page | 125 | 126 | ## Demos 127 | 128 | Basic demo on codesandbox 129 | 130 | https://codesandbox.io/s/r4v7onrpop 131 | 132 | React-create-app Demo 133 | 134 | https://albinotonnina.github.io/demo-magic-hat 135 | 136 | https://github.com/albinotonnina/demo-magic-hat 137 | 138 | ## Maintainers 139 | 140 | [@albinotonnina](https://github.com/albinotonnina) 141 | 142 | ## Contribute 143 | 144 | PRs accepted. 145 | 146 | ## License 147 | 148 | MIT © 2018 Albino Tonnina 149 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------