Giter Site home page Giter Site logo

Comments (11)

alexcurtis avatar alexcurtis commented on August 20, 2024

@bkniffler That makes sense to me. The only problem is, we will have to push the onClick to the toggle component as well, which makes it more complicated overall. Especially when you have custom toggle and header decorators, you will have to remember to use onClick twice. What do you think?

from react-treebeard.

bkniffler avatar bkniffler commented on August 20, 2024

I think it would make sense to join header and toggle decorators, this would give us more flexibility. What do you think about that?

from react-treebeard.

bkniffler avatar bkniffler commented on August 20, 2024

Just as an example, this is how my header looks like now. It checks weather its a terminal node to insert the caret. Also, it checks for active state for bold font. And if a 'code' is present, an additional link is displayed.

const {id, toggled, code, name, active, terminal} = props.node;
<div onClick={toggle} style={{...props.style.base}}>
   {!terminal ? <strong style={{display: 'table-cell', width:'20px'}}>
      <i className={"icon caret " + (toggled ? 'down' : 'right')} style={{position:'absolute', top:'1px'}}></i>
   </strong> : <strong style={{display: 'table-cell', width:'20px'}}> </strong>}
   {code ? <a onClick={activate} href="javascript:;" style={{display: 'table-cell', minWidth: '27px', paddingRight:'10px', whiteSpace: 'nowrap'}}>{code}</a> : null}
   <span style={{display: 'table-cell', fontWeight: active?'bold':'initial'}}>{name}</span>
</div>

from react-treebeard.

alexcurtis avatar alexcurtis commented on August 20, 2024

Its a difficult one. Because a lot of times you will want to use another header, but keep the toggle the same, as a lot of people will be happy with the default toggle decorator. But the header must be changed for simple things like icons. I'll have a think about it.

from react-treebeard.

bkniffler avatar bkniffler commented on August 20, 2024

Its true. So why not adding a 'row' decorator? The default one would just render the default toggle and header.

{row: [toggle, header]}
Row could be something like renderRow(props, onToggle, DefaultToggle, DefaultHeader). onToggle could also live within the props object.

Also you could think about handing the decorators one by one as props, e.g. renderToggle, renderHeader, renderRow, renderLoader. Your current approach only allows for all or nothing.

from react-treebeard.

gbmhunter avatar gbmhunter commented on August 20, 2024

+1 I was looking for this exact functionality! Otherwise parts of the tree get toggled when all the user wants to do is select a particular item.

from react-treebeard.

alexcurtis avatar alexcurtis commented on August 20, 2024

@bkniffler @gbmhunter I agree with you guys. I'm going to look into this issue in more depth, to find a good balance between extensibility and out-of-the-box usability. I'll take some ideas from @bkniffler's work and try to get a good mix.

from react-treebeard.

alexcurtis avatar alexcurtis commented on August 20, 2024

@bkniffler @gbmhunter. I have release 1.1.0 to npm. This includes a new decorator called Container which should allow you to fully rewrite a node. It also pulls down the onClick event. Most of this comes from @bkniffler's work, so id like to say thanks to him for helping out with this one!

from react-treebeard.

bkniffler avatar bkniffler commented on August 20, 2024

Cool, couldn't be happier with your new version

import {Treebeard, decorators} from 'react-treebeard';
import TreeStyle from './tree-style';

var Container = (props)=>{
    // Handle node render with inline loading indicator, custom toggle and header
}

const Loading = (props) => <div></div>;

<Treebeard data={lists} decorators={{...decorators, Loading, Container}} onToggle={updateTreeItem} style={TreeStyle} animations={false}/>

Separating the decorators as multiple props would still make this a bit better. But it works great!

from react-treebeard.

bkniffler avatar bkniffler commented on August 20, 2024

ps. Feel free to remove my pull requests as soon as you're done incorporating the parts you like.

from react-treebeard.

eladfrn avatar eladfrn commented on August 20, 2024

We also need to be able to expand/collapse the tree only by the toggle icon.
Can anyone please share their solution?
Thanks

from react-treebeard.

Related Issues (20)

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.