npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-dnd-menu-builder

v0.0.8

Published

React DnD Menu Builder

Downloads

100

Readme

React DND Menu Builder 🚀

React DND Menu Builder is a user-friendly drag-and-drop menu builder for React, inspired by the simplicity and flexibility of the WordPress menu builder. It allows you to create and customize menus by dragging and dropping items from a list of available options, just like in WordPress. Easily add, remove, and rearrange items to suit your needs.

WordPress-Like Menu Builder for React and Nextjs

🖥 Demo

Check out a live demo.

📦 Installation

To go with the latest version please copy and paste in your terminal the following steps:

npm install react-dnd-menu-builder
# or
yarn add react-dnd-menu-builder
# or
pnpm install react-dnd-menu-builder

⚠️ NextJS Import ⚠️

import dynamic from "next/dynamic";

const MenuBuilder = dynamic(() => import("react-dnd-menu-builder"), {
  ssr: false,
});

Basic Usage

import { useState } from "react";
import MenuBuilder from "react-dnd-menu-builder";

function App() {
  const [menus, setMenus] = useState(initialMenus);
  const [formData, setFormData] = useState(initialFormData);

  const addMenu = () => {
    setMenus([
      ...menus,
      {
        ...formData,
        id: Math.random().toString(36).substring(7),
      },
    ]);
    setFormData({ id: "", name: "", href: "", children: [] });
  };

  return (
    <div
      style={{
        display: "flex",
        flexDirection: "column",
      }}
    >
      <button
        onClick={() => {
          addMenu();
        }}
      >
        Add Menu
      </button>
      <input
        placeholder="Home"
        value={formData.name}
        onChange={(e) => setFormData({ ...formData, name: e.target.value })}
      />
      <input
        placeholder="/home"
        value={formData.href}
        onChange={(e) => setFormData({ ...formData, href: e.target.value })}
      />
      <MenuBuilder items={menus} setItems={setMenus} />
    </div>
  );
}

export default App;

const initialMenus = [
  {
    id: "Home",
    name: "Home",
    href: "/home",
    children: [],
  },
  {
    id: "Collections",
    href: "/collections",
    name: "Collections",
    children: [
      {
        id: "Spring",
        name: "Spring",
        href: "/spring",
        children: [],
      },
    ],
  },
];

const initialFormData = {
  id: "",
  name: "",
  href: "",
  children: [],
};

Props Documentation

| Property | Types | Defaults | Description | | -------- | -------- | -------- | ------------------------------------------ | | style | enum | null | "bordered" or "shadow" | | items | MenuItem | {} | Menu Items | | setItems | function | null | Just pass the setState setItems={setMenus} |

type MenuItem = {
  id: string,
  name: string,
  href: string,
  children?: undefined,
};

🤝 Contributing

Let’s create great products together! We encourage and welcome collaboration and any type of contribution.

License

MIT