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

@rileyy29/react-mindmap

v1.0.4

Published

A simple base framework package intended to assist developers/users with the creation and visualisation of MindMaps in React.

Downloads

11

Readme

react-mindmap

Build Downloads Size

A simple base framework/starter package intended to assist developers with the creation and visualisation of interactive MindMaps in React.

Contents

What is this?

This package is a React component that renders and manages interactive Mindmaps. This is a simple tool in early development which allows users to create draggable, dynamic and interactive Mindmaps simply.

Install

This package is installable with npm or yarn. Supporting the latest versions of Node.js.

npm install @rileyy29/react-mindmap
yarn add @rileyy29/react-mindmap

You may also be required to install peer dependencies if you do not already have them installed.

npm install react-draggable
yarn add react-draggable

Usage

Mindmap Props

  • defaultNodes (Array<NodeStructure>, default: [])
    Use the Mindmap in an uncontrolled state, with state being managed by the Mindmap itself.
  • nodes (Array<NodeStructure>, default: [])
    Use the Mindmap in a controlled state, with the state being managed by yourself. This requires the use of onNodesChange for drag operations etc.
  • onNodesChange (Array<NodeStructure>, default: [])
    Specify a function to be invoked when the node set is changed, during drag operations etc.
  • line (SVGProps<SVGPathElement>, default: undefined)
    Specify props to be passed to the mindmap connector line (pathing).
  • noLine (boolean, default: false)
    Specify whether the mindmap connector line (pathing) should be hidden.
  • nodeClassName (string, default: '')
    Specify a classname for the parent element for each Node.
  • draggable (boolean, default: true)
    Specify whether all nodes should be draggable.
  • draggableFn ((node: NodeStructure) => boolean, default: undefined)
    Specify whether a node should be draggable using a per node reference.
  • renderNode ((node: NodeStructure) => ReactNode | ReactElement | JSX.Element, default: undefined, required)
    Specify a renderer for the node.

Examples

Simple Root and Child

This example shows how to create a simple root -> child Mindmap with draggable functionality. By default, a connecting line will be rendered between the nodes. All styling can be customised with the renderNode prop or the line prop.

This is using the Mindmap in a controlled state, if you do not want to control the state of nodes yourself, you can use the defaultNodes prop instead of nodes and onNodesChange.

import { Mindmap, type NodeStructure } from "@rileyy29/react-mindmap";
import { useState } from "react";

export default function Example() {
    const [nodes, setNodes] = useState<NodeStructure[]>([{
        id: 1,
        x: 455,
        y: 0,
        width: 200,
        height: 100,
        type: "ROOT",
        node: { title: 'Root Node' },
        childNodes: [
            {
                id: 2,
                x: 455,
                y: 150,
                width: 200,
                height: 100,
                type: "CHILD",
                node: { title: 'Child Node' },
                childNodes: []
            }
        ]
    }]);

    return <Mindmap draggable={true} renderNode={(node) => <div>{node.node.title}</div>} nodes={nodes} onNodesChange={setNodes} />
}

Multiple Root and Child Node

This example shows how to create a multi root -> multi child Mindmap with draggable functionality. By default, a connecting line will be rendered between the nodes. All styling can be customised with the renderNode prop or the line prop.

This is using the Mindmap in a controlled state, if you do not want to control the state of nodes yourself, you can use the defaultNodes prop instead of nodes and onNodesChange.

import { Mindmap, type NodeStructure } from "@rileyy29/react-mindmap";
import { useState } from "react";

export default function Example() {
    const [nodes, setNodes] = useState<NodeStructure[]>([
        {
            id: 6,
            x: 455,
            y: 0,
            width: 200,
            height: 100,
            type: "ROOT",
            node: { title: 'Root Node 2' },
            childNodes: [
                {
                    id: 10,
                    x: 455,
                    y: 150,
                    width: 200,
                    height: 100,
                    type: "CHILD",
                    node: { title: 'Child Node 1 (Root 2)' },
                    childNodes: []
                }
            ]
        },
        {
            id: 1,
            x: 225,
            y: 0,
            width: 200,
            height: 100,
            type: "ROOT",
            node: { title: 'Root Node' },
            childNodes: [
                {
                    id: 2,
                    x: 225,
                    y: 150,
                    width: 200,
                    height: 100,
                    type: "CHILD",
                    node: { title: 'Child Node 1' },
                    childNodes: [
                        {
                            id: 3,
                            x: 15,
                            y: 280,
                            width: 200,
                            height: 100,
                            type: "CHILD",
                            node: { title: 'Child Node 2' },
                            childNodes: [],
                        },
                        {
                            id: 4,
                            x: 255,
                            y: 300,
                            width: 200,
                            height: 100,
                            type: "CHILD",
                            node: { title: 'Child Node 3' },
                            childNodes: [
                                {
                                    id: 23,
                                    x: 255,
                                    y: 420,
                                    width: 200,
                                    height: 100,
                                    type: "CHILD",
                                    node: { title: 'Child Node 4' },
                                    childNodes: [
                                        {
                                            id: 33,
                                            x: 255,
                                            y: 540,
                                            width: 125,
                                            height: 55,
                                            type: "CHILD",
                                            node: { title: 'Child Node 5' },
                                            childNodes: [],
                                        },
                                        {
                                            id: 36,
                                            x: 390,
                                            y: 540,
                                            width: 125,
                                            height: 55,
                                            type: "CHILD",
                                            node: { title: 'Child Node 6' },
                                            childNodes: [],
                                        },
                                        {
                                            id: 37,
                                            x: 525,
                                            y: 540,
                                            width: 125,
                                            height: 55,
                                            type: "CHILD",
                                            node: { title: 'Child Node 7' },
                                            childNodes: [],
                                        }
                                    ],
                                }
                            ],
                        }
                    ],
                },
            ],
        }
    ]);

    return <Mindmap draggable={true} renderNode={(node) => <div>{node.node.title}</div>} nodes={nodes} onNodesChange={setNodes} />
}

Screenshots

Nodes Screenshot

License

MIT © Riley Rogerson