Code Monkey home page Code Monkey logo

material-ui-tree's Introduction

material-ui-tree v2

npm package npm download github license github issues open github issues closed github language top github stars

NPM

A react tree component with material-ui.
See demo page: Material-ui-tree Demo (v2 version)

Using material-ui on 'bit.dev' ?

npm install @bit/shallinta.material-ui-tree.material-ui-tree --save
npm install @bit/shallinta.material-ui-tree.util --save

What's new with v2 version?

  • Take full use of material-ui ^4.0.0 version. (Including @material-ui/core^4.0.0, @material-ui/styles^4.0.0 and @material-ui/icons^4.0.0.)
  • Take full use of react hooks, which needs react version ^16.8.0.
  • Change some props name to make more sense.
  • Add some props to adapt to more usage scenarios.
  • Use rollup to pack and compress this component.

Migration from material-ui-tree v1.*

  • You should first learn about material-ui@4.* which is the strong dependence. See material-ui
  • If you use material-ui v3 now, see this to migrate to v4. Material UI v4 migration from v3
  • To support the v2 version, you should upgrade your react and react-dom version to at least v16.8.0.
  • Changed properties:
    • title: change type "string" to "string | React Node".
    • labelKey: instead of old labelName
    • valueKey: instead of old valueName
    • childrenKey: instead of old childrenName
    • unfoldFirst: instead of old expandFirst
    • unfoldAll: instead of old expandAll
    • pageSize: instead of old childrenCountPerPage
    • loadMoreIcon: new property
    • renderLoadMoreText: new callback function
  • Changed callback argument names:
    • path: instead of old chdIndex
    • unfoldStatus: instead of old expand
    • toggleFoldStatus: instead of old doExpand
  • Util provided:
    • You can import getNodeDataByPath, { withChildrenKey } from "material-ui-tree/lib/util" which is used to get tree node data with whole tree data and node path and children key.
    • Function signature:
      1. getNodeDataByPath:: (object, array, string) -> object.
      2. withChildrenKey:: string -> (object, array) -> object.

Installation

Available as npm package.

npm install --save material-ui-tree@latest

Ensure to install these packages in your program because material-ui-tree depends on them.

npm install --save
 react
 react-dom
 prop-types
 classnames
 @material-ui/core
 @material-ui/icons
 @material-ui/styles

Usage

See demo page code: (v2)

Edit material-ui-tree v2 demo

Options

All options are not required.

Normal properties:
option name type default value remark
className string '' The className will passed to container Paper component of material-ui.
labelKey string 'label' Label key to show in tree leaf data. If renderLabel option is set, labelKey will be ignored.
valueKey string 'value' Value key in tree leaf data. Used for react children key.
childrenKey string 'children' Children key to render child branch in tree leaf data.
data object {} Initial tree data.
title string or React Node '' Tree title. If not set, title module will not show.
unfoldFirst bool false Whether unfold the first branch of the tree in the beginning.
unfoldAll bool false Whether unfold all branches of the tree in the beginning.
pageSize number 20 Children nodes' count in each branch page. When tree node children data is too big, render them by page.
actionsAlignRight bool false Whether the tree node action buttons aligns to right side. Action buttons will follow behind node label if it's false, or else will be aligned to right side.
foldIcon React OptionalElement <AddCircleOutlineIcon />(@material-ui/icons/AddCircleOutline) Icon of tree node in fold status. You should pass an react element of icon such as <ArrowDownIcon />(@material-ui/icons/KeyboardArrowDown) when you want to modify the icon.
unfoldIcon React OptionalElement <RemoveCircleOutlineIcon />(@material-ui/icons/RemoveCircleOutline) Icon of tree node in unfold status. You should pass an react element of icon such as <ArrowUpIcon />(@material-ui/icons/KeyboardArrowUp) when you want to modify the icon.
loadMoreIcon React OptionalElement <MoreVertIcon />(@material-ui/icons/MoreVert). Icon of "load-more" tree node. You should pass an react element of icon such as <MoreHorizIcon />(@material-ui/icons/MoreHoriz) when you want to modify the icon.
Callback properties:
  • getActionsData: (func) The method to get data to render action buttons, with arguments:
argument name type remark
data object current node data
path array node indices from tree root
unfoldStatus bool node unfold status
toggleFoldStatus func callback to unfold current node's child tree

Should return an array of buttons data including keys: icon, label, hint, onClick, style={}. At least one of label key and icon key are required. If only return one button's data, it's also ok to just return the button data object instead of its array.

  • renderLabel: (func) The method to render tree node label, with arguments:
argument name type remark
data object current node data
unfoldStatus bool current node unfold status

If this is set, labelKey option will be ignored.

  • renderLoadMoreText: (func) The method to render the "load-more" tree node when there are more than one page of children, with arguments:
argument name type remark
page number current loaded page index.
pageSize number children count of each page.
total number total count of children.

Should return text or react elements. The following templete will be returned by default:

`Loaded pages: ${(page + 1)} / Page size: ${pageSize} / Total: ${total}. Click here to load more...`
  • requestChildrenData: (func) The method to request children data of tree node dynamically, with arguments:
argument name type remark
data object current node data.
path array node indices from tree root.
toggleFoldStatus func callback to unfold current node's child tree.

This function will not be called until the current node has no children data.

Recently updated?

Changelog available here

LICENSE

The project is licensed under the terms of MIT license

material-ui-tree's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

material-ui-tree's Issues

in getActionsData() everything it returns always wrapped by a <button>tag

In the below mention code I want to render TextField next to Leaf element of the tree since the below code is working on chrome but not in Firefox, I dig more and found that textField is wrapped by a button tag so it violates the HTML rules .Reference-> https://stackoverflow.com/questions/33420402/file-input-field-inside-button-doesnt-work-in-firefox. Please give one more tag apart from label and icon which doesn't contain wrapper as a button

return [
          {
            label: <TextField id={chdIndex.join(',')} style={{ marginLeft: 10 }} defaultValue={this.props.mdhJsonpr.tree[parseInt(chdIndex[0])].url.tree[parseInt(chdIndex[1])].url.tree[parseInt(chdIndex[2])].mappingValue} />,
            hint: "Map to Headers",
             onBlur: (event) => {
               const parent = getTreeLeafDataByIndexArray(
                 data, chdIndex,
                 "tree"
               );
               console.log(parent)
               let mapping = event.target.value
               this.props.onMapping(event.target.value, chdIndex, mapping)
               if (event.target.value === "") {
                 this.props.onDeleteIcon(chdIndex)
               }
             }
          },

TypeError: nextCreate is not a function

I'm seeing the following stacktrace when trying to run the sample code. I've even exported the codesandbox example locally and still get the same. Maybe you know what I'm doing wrong or maybe there is an issue somewhere:

TypeError: nextCreate is not a function
react-dom.development.js:13964
    at mountMemo (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:13964:1)
    at Object.useMemo (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:14185:1)
    at useMemo (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react/cjs/react.development.js:1525:1)
at renderWithHooks (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:13449:1)
    at mountIndeterminateComponent (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:15605:1)
    at beginWork (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:16238:1)
    at performUnitOfWork (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:20279:1)
    at workLoop (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:20320:1)
    at renderRoot (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:20400:1)
    at performWorkOnRoot (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:21357:1)
    at performWork (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:21267:1)
    at performSyncWork (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:21241:1)
    at requestWork (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:21096:1)
    at scheduleWork (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:20909:1)
    at dispatchAction (/Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/react-dom/cjs/react-dom.development.js:14118:1)
    at /Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/node_modules/material-ui-tree/lib/index.es.js:260:1
    at /Users/jason.harrell/dev/git/GitHub/aem-dialog-viewer-dev/src/App.js:153:1

Replace HTTP request with CURL request

Hello,

First of all great work! This is not an issue. I am looking to replace your https request that you make here:

data: {
  path: "material-ui-tree",
  type: "tree",
  sha: "b3d36479a033ed6296c34fdf689d5cdbcf7a0136",
  url:
    "https://api.github.com/repos/shallinta/material-ui-tree/git/trees/next"
}

with something that might look like this:

data: {
  path: "material-ui-tree",
  type: "tree",
  sha: "b3d36479a033ed6296c34fdf689d5cdbcf7a0136",
  url: "curl http://localhost:9200/my-elasticsearch-index/_doc/_search?pretty=true"

}

I do not know enough yet to determine if this is possible. Any help is greatly appreciated. Thank you!

Component doesn't re-render with status changing

I'm using material-ui-tree component to list some files & directories and used getTreeLeafActionsData function to make a search in within the list. It works! but then cannot get the list back when I delete my search query.

I'm filtering the children array in within render function, so it supposes to render the whole list again if made any change on the state.

Could you point me the right way to do it if I'm wrong?

data object ,Node names

Hello shalinta, please how I can edit names of nodes (I see you are useing sha encoding ) is there any simple way

Pass event when action button is pushed

In some situations its useful to get the event when an action button is pushed for a leaf of the tree (for example if you want to raise a menu from there).

Can you please change the getBtnClickHandler in tree-node.js to do this? Just need to change line 51 to have onBtnClick(e)

Size is too big because some dependencies are packed in

Import dependencies from path like material-ui/styles, material-ui/List so that some webpack externals config such as material-ui, material-iu-icons don't work. As a result, dependence like material-ui/styles will be packed in library file.
Changing code from

import List from 'material-ui/List';

to

import { List } from 'material-ui';

makes webpack externals config work correctly.

Remove icon on element w/o children

Hello. Do you plan to add possibility to remove expand icon on element without children?
I didn't find workaround to remove them with current version. Maybe smb know how to resolve it =)

How to log selected parent node data?

Hi shallinta,

Firstly thank you for the work you have put into this I was able to build an amazing nice looking tree in no time. The issue I have is in console logging the parent node data when selected from the tree.

If I use getActionsData or renderLabel It displays all items key value pairs in the tree not the selected one.

If requestChildrenData is called it calls the selected which is great but it doesn't trigger if it is a parent node.

Is there something I'm missing?

TypeScript support

Hello! Great library!

But I noticed that there is no @types/material-ui-tree package. As I am writing my project in typescript, the compiler is throwing errors about declaration files and implicit any types.
Would be great adding type declaration files.

Thanks.

Can you give a sample of how the data needs to be provided to the component?

I've been looking at this component and it looks promising for my use case, but I'm not exactly sure how the data is supposed to look coming into the Tree component. The docs say to default to an empty object, but I would like to have default data in there.

Also, from what I can tell, it looks like the github data is coming in ordered in your example code. Does order matter when the tree is built, or can you have random order and still have the items grouped under the repeated parent? It looks like you're using recursion in your sample code - but not sure of the structure of your sample data. What keys are needed in the data prop to get a properly rendered tree?

TIA!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.