{"id":13515497,"url":"https://github.com/albinotonnina/react-magic-hat","last_synced_at":"2025-04-07T13:06:16.415Z","repository":{"id":57334190,"uuid":"125409952","full_name":"albinotonnina/react-magic-hat","owner":"albinotonnina","description":"🎩✨Library to implement the Magic Hat technique, blazingly fast 🚀","archived":false,"fork":false,"pushed_at":"2019-02-18T00:19:50.000Z","size":121,"stargazers_count":311,"open_issues_count":4,"forks_count":15,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-31T09:05:56.175Z","etag":null,"topics":["library","motion","react","ui","ux","ux-patterns","ux-research"],"latest_commit_sha":null,"homepage":"https://albinotonnina.github.io/demo-magic-hat","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/albinotonnina.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-15T18:27:31.000Z","updated_at":"2025-03-07T02:37:57.000Z","dependencies_parsed_at":"2022-09-03T19:32:21.922Z","dependency_job_id":null,"html_url":"https://github.com/albinotonnina/react-magic-hat","commit_stats":null,"previous_names":["albinotonnina/stacky"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albinotonnina%2Freact-magic-hat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albinotonnina%2Freact-magic-hat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albinotonnina%2Freact-magic-hat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albinotonnina%2Freact-magic-hat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/albinotonnina","download_url":"https://codeload.github.com/albinotonnina/react-magic-hat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657276,"owners_count":20974344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","motion","react","ui","ux","ux-patterns","ux-research"],"created_at":"2024-08-01T05:01:12.008Z","updated_at":"2025-04-07T13:06:16.396Z","avatar_url":"https://github.com/albinotonnina.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"[![Dependency Up-to-dateness][david-image]][david-url]\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5cac2b7c18984c8d9626e904be3def71)](https://app.codacy.com/app/albinotonnina/react-magic-hat?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=albinotonnina/react-magic-hat\u0026utm_campaign=badger)\n[![Build Status](https://travis-ci.org/albinotonnina/react-magic-hat.svg?branch=master)](https://travis-ci.org/albinotonnina/react-magic-hat)\n\n# React Magic Hat 🎩✨\n\n\u003e A kind of UI technique\n\nReact 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)].\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://albinotonnina.github.io/demo-magic-hat/demo.gif\"\u003e\n\u003c/p\u003e\n\n[david-image]: https://david-dm.org/albinotonnina/react-magic-hat.svg\n[david-url]: https://david-dm.org/albinotonnina/react-magic-hat\n\n## Features\n\n🚀 [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.\n\n🎈Extra light, only 6.5kb and no dependencies.\n\n🧘‍Flexible, stateful or stateless (you get both components) it’s UI-less, you do the layouting and styling.\n\n🎛 Highly configurable, check the [API](#api)\n\n## Table of Contents\n\n* [Background](#background)\n* [Install](#install)\n* [Usage](#usage)\n* [API](#api)\n* [Demos](#demos)\n* [Maintainers](#maintainers)\n* [Contribute](#contribute)\n* [License](#license)\n\n## Background\n\nThe 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)\nIt's called like this because in a view the user can pick the next thing to put on screen. It’s pretty much it.\n\n[Read the article on medium.com](https://medium.com/@albinotonnina/magic-hat-technique-408a3fa590bb)\n\n## Install\n\n```\nyarn add react-magic-hat\n```\n\n## Usage\n\n```jsx\nimport YourMagicContainer from 'react-magic-hat'\nimport ComponentA, {id as CompA} from 'components'\nimport ComponentB from 'components'\n\nconst renderFrame = pageObject =\u003e {\n  // Please check the renderFrame(pageObject) documentation for all the properties passed to the pageObject.\n  const {id, actions, state} = pageObject\n\n  // We get the Component that is going to be rendered, the following is probably the most naive way.\n  const Muv = id === CompA ? ComponentA : ComponentB\n\n  // Another way to do it in the demo, using import-glob\n  // https://github.com/albinotonnina/demo-magic-hat/blob/master/src/Demo.js#L5-L21\n\n  return \u003cMuv {...actions} {...state} /\u003e\n}\n\nconst Layout = () =\u003e (\n  \u003cdiv\u003e\n    \u003cYourMagicContainer renderFrame={renderFrame} /\u003e\n  \u003c/div\u003e\n)\n```\n\n## API\n\n### Prop Types\n\n| Property         | Type     | Required? |                                                                   Arguments                                                                    | Description                                                                                                                                            |\n| :--------------- | :------- | :-------: | :--------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------- |\n| renderFrame      | Function |     ✓     |                                                    [Documentation](#renderframepageobject)                                                     | Callback invoked when rendering the visible pages.                                                                                                     |\n| onStartAnimation | Function |           | [childElements, domElements](https://github.com/joshwcomeau/react-flip-move/blob/master/documentation/api_reference.md#onstartall), pageProps  |                                                                                                                                                        |\n| onEndAnimation   | Function |           | [childElements, domElements](https://github.com/joshwcomeau/react-flip-move/blob/master/documentation/api_reference.md#onfinishall), pageProps |                                                                                                                                                        |\n| 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.     |\n| singleFrame      | Boolean  |           |                                                                                                                                                | By default show two views. Set this to `true` to show only one.                                                                                        |\n| 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) |\n\n### renderFrame(pageObject)\n\n```jsx\nimport getComponentById from './your-components'\n\nconst renderFrame = pageObject =\u003e {\n  const {\n    id, // 'my-component-id'\n    page, // 4\n    activePage, // 5\n    state, // { roses: 'blue', violets: 'red', pass:'whetever', pleases: 'you' }\n    actions // see next paragraph for the actions methods\n  } = pageObject\n\n  const Muv = getComponentById(id) // return a Component\n\n  return \u003cMuv {...state} {...actions} /\u003e\n}\n```\n\n### {actions} API\n\n| Method                                         | Description                                   |\n| :--------------------------------------------- | :-------------------------------------------- |\n| setCurrentFrame(props:object)                  | Merge props on the current page               |\n| getCurrentFrame():object                       | Get props of the current page                 |\n| closeCurrentFrame()                            | Close the current page                        |\n| setNextFrame(id:string, props:object )         | Merge the next page and optionally pass props |\n| getNextFrame()                                 | Get props of the next page                    |\n| closeNextFrame()                               | Close the next page                           |\n| setFrame(page:number, id:string, props:object) | Merge the next page                           |\n| getFrame(page:number):props                    | Get props of a page                           |\n| closeFrame(page:number)                        | Close a page                                  |\n\n## Demos\n\nBasic demo on codesandbox\n\nhttps://codesandbox.io/s/r4v7onrpop\n\nReact-create-app Demo\n\nhttps://albinotonnina.github.io/demo-magic-hat\n\nhttps://github.com/albinotonnina/demo-magic-hat\n\n## Maintainers\n\n[@albinotonnina](https://github.com/albinotonnina)\n\n## Contribute\n\nPRs accepted.\n\n## License\n\nMIT © 2018 Albino Tonnina\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbinotonnina%2Freact-magic-hat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falbinotonnina%2Freact-magic-hat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbinotonnina%2Freact-magic-hat/lists"}