{"id":16907886,"url":"https://github.com/timc1/react-animated-menu","last_synced_at":"2026-03-08T22:32:44.172Z","repository":{"id":34931666,"uuid":"191652731","full_name":"timc1/react-animated-menu","owner":"timc1","description":"A React component that handles all logic for managing visual state for menus and lists.","archived":false,"fork":false,"pushed_at":"2022-02-12T01:56:56.000Z","size":1948,"stargazers_count":12,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T23:33:09.494Z","etag":null,"topics":["higher-order-component","javascript","react","render-props"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timc1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-12T22:24:19.000Z","updated_at":"2022-05-26T10:15:11.000Z","dependencies_parsed_at":"2022-08-08T03:00:35.782Z","dependency_job_id":null,"html_url":"https://github.com/timc1/react-animated-menu","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timc1%2Freact-animated-menu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timc1%2Freact-animated-menu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timc1%2Freact-animated-menu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timc1%2Freact-animated-menu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timc1","download_url":"https://codeload.github.com/timc1/react-animated-menu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248433047,"owners_count":21102498,"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":["higher-order-component","javascript","react","render-props"],"created_at":"2024-10-13T18:49:14.171Z","updated_at":"2026-03-08T22:32:39.137Z","avatar_url":"https://github.com/timc1.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\r\n  react-animated-menu \r\n\u003c/h1\u003e\r\n\u003cp align=\"center\" style=\"font-size: 1.5rem;\"\u003e\r\n  Simple primitives to build dynamic menu and list components. ☰\r\n\u003c/p\u003e\r\n\r\n\r\n\r\n\u003cp align=\"center\"\u003e\r\n\u003cimg src=\"https://github.com/timc1/react-animated-menu/blob/master/demo.gif\" alt=\"demo\" /\u003e\r\n\u003c/p\u003e\r\n\r\n## Introduction\r\nYou want to build a sidebar for your app's dashboard — maybe create a table of contents for your documentation page.\r\nWhen you click on a link in the sidebar you want to expand the contents. \r\n\r\nYou also want to use a simple plug and play API that controls the opening/closing of menus items, lets you control \r\nthe ease and duration of the menu animation, and allows you flexibility to build your UI however you'd like.\r\n\r\n## This approach\r\n\r\n`react-animated-menu` manages all menu state and user interactions for you so you can simply focus on building your UI.\r\n\r\nIt uses a single [compound component](https://kentcdodds.com/blog/compound-components-with-react-hooks) \r\npaired with a [render prop](https://reactjs.org/docs/render-props.html) to provide maximum flexibility, exposing only props\r\nthat are valuable for you.\r\n\r\n\u003e NOTE: This solution transforms the menu's `height` property. \r\n\u003e Typically we should be animating CSS transforms; however,\r\n\u003e in this particular case, using plain Javascript to transition\r\n\u003e height is a lot simpler.\r\n\r\n## Installation\r\n\r\nInstall this module as a dependency using `npm` or `yarn`\r\n\r\n```\r\nnpm install --save react-animated-menu\r\n```\r\nor \r\n```\r\nyarn add -D react-animated-menu\r\n```\r\n\r\n## Usage\r\n\r\nThere are 2 components that this module provides - simply use them like this:\r\n\r\n```js\r\nimport DynamicMenu, { MenuItem } from 'react-animated-menu'\r\n\r\nexport default function Menu() {\r\n  return (\r\n    \u003caside\u003e\r\n      {/* Wrap the menu in a Higher Ordered Component */}\r\n      \u003cDynamicMenu\r\n        initialOpenIndex={0}\r\n        easeDuration={150}\r\n        numberOfMenusThatCanBeOpenedAtOnce={1}\r\n      \u003e\r\n      \r\n        {/* Each menu toggler and the menu list content must be wrapped by a MenuItem\r\n            render prop - and spreading the prop getters to their respective sections. */}\r\n        \u003cMenuItem\u003e\r\n          {({ isOpen, getToggleProps, getMenuProps, getLinkProps }) =\u003e (\r\n            \u003c\u003e\r\n              \u003cbutton {...getToggleProps()} isOpen={isOpen}\u003e\r\n                Dashboard\r\n              \u003c/button\u003e\r\n              \u003cul {...getMenuProps()}\u003e\r\n                {dashboardPaths.map(p =\u003e (\r\n                  \u003cli key={p.route}\u003e\r\n                    \u003cLink to={`/${p.route}/`} {...getLinkProps()}\u003e\r\n                      {p.name}\r\n                    \u003c/Link\u003e\r\n                  \u003c/li\u003e\r\n                ))}\r\n              \u003c/ul\u003e              \r\n            \u003c/\u003e\r\n          )}\r\n        \u003c/MenuItem\u003e\r\n        \r\n        {/* Same as above MenuItem! */}\r\n        \u003cMenuItem\u003e\r\n          {({ isOpen, getToggleProps, getMenuProps, getLinkProps }) =\u003e (\r\n            \u003c\u003e\r\n              \u003cbutton {...getToggleProps()} isOpen={isOpen}\u003e\r\n                Settings\r\n              \u003c/button\u003e\r\n              \u003cul {...getMenuProps()}\u003e\r\n                {settingPaths.map(p =\u003e (\r\n                  \u003cli key={p.route}\u003e\r\n                    \u003cLink to={`/${p.route}/`} {...getLinkProps()}\u003e\r\n                      {p.name}\r\n                    \u003c/Link\u003e\r\n                  \u003c/li\u003e\r\n                ))}\r\n              \u003c/ul\u003e              \r\n            \u003c/\u003e\r\n          )}\r\n        \u003c/MenuItem\u003e\r\n      \u003c/DynamicMenu\u003e\r\n    \u003c/aside\u003e\r\n  )\r\n}\r\n```\r\n\r\n## Basic Props\r\n\r\n### children\r\nThe nested child elements.\r\n\r\n### initialOpenIndex\r\n\u003e number | number[] - defaults to -1 (all menu items closed)\r\n\r\nThe initial MenuItem that should be open.\r\n\r\n### numberOfMenusThatCanBeOpenedAtOnce\r\n\u003e number - defaults to 1\r\n\r\nThe number of menus that can be opened at once. 😀\r\n\r\n### easeFn\r\n\u003e (t: number) =\u003e number\r\n\r\nAn easing function - see [https://gist.github.com/gre/1650294](https://gist.github.com/gre/1650294) for a list of options.\r\n\r\n### easeDuration\r\n\u003e number - defaults to 150 (ms)\r\n\r\nDuration of the menu transition.\r\n\r\n\r\n## License\r\n\r\nMIT\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimc1%2Freact-animated-menu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimc1%2Freact-animated-menu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimc1%2Freact-animated-menu/lists"}