Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Animated caret not centered; transformation not stable #156

Open
j8jacobs opened this issue Feb 14, 2019 · 4 comments
Open

Animated caret not centered; transformation not stable #156

j8jacobs opened this issue Feb 14, 2019 · 4 comments

Comments

@j8jacobs
Copy link

the animation rotation is working, but its not staying in the center of the row.
it's not centered to begin with, so i feel like there might be some weird margin or transform around the origin making the caret stick to the bottom, and then rotate up to the top of the div
unopened
opened

@j8jacobs
Copy link
Author

also, the active setting color is not being set on the newest version. 3.1.0 (as shown in the pic) isn't highlighting the selected node (active set in the prop), but 2.1.0 and 2.0.3

@tahv0
Copy link

tahv0 commented Feb 19, 2019

Hi!
I had this same issue.
It can be fixed by making custom Toggle decorator.

Mostly copied from source code:

const Toggle = ({style}) => {
  const {height, width} = style;
  const midHeight = height * 0.5;
  const points = `0,0 0,${height} ${width},${midHeight}`;

  return (
      <Div style={style.base}>
          <Div style={{...style.wrapper, display: 'flex'}}>
              <svg height={height} width={width}>
                  <Polygon points={points}
                           style={style.arrow}/>
              </svg>
          </Div>
      </Div>
  );
};
Toggle.propTypes = {
  style: PropTypes.object
};


const myDecorators = {
  ...decorators,
  Toggle: Toggle,
};

... then add your custom decorators to Treebeard:

         <Treebeard
            decorators={myDecorators}
            onToggle={() => {}}
            data={data}
          />

Solution is on line where I add {display: 'flex'} to style.wrapper:
<Div style={{...style.wrapper, display: 'flex'}}>

@j8jacobs
Copy link
Author

Thank you so much! For anyone who wants to see the whole file, including the imports and what not:

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Treebeard, theme, decorators } from 'react-treebeard';
import styled from '@emotion/styled';


// Customized theme for the tree component
theme.tree.base.color = 'black';
theme.tree.base.backgroundColor = 'white';

const Div = styled('div', {
  shouldForwardProp: prop => ['className', 'children'].indexOf(prop) !== -1
})((({ style }) => style));
const Polygon = styled('polygon', {
  shouldForwardProp: prop => ['className', 'children', 'points'].indexOf(prop) !== -1
})((({ style }) => style));

const Toggle = ({style}) => {
  const {height, width} = style;
  const midHeight = height * 0.5;
  const points = `0, 0 0, ${ height } ${ width }, ${ midHeight } `;

  return (
      <Div style={style.base}>
          <Div style={{...style.wrapper, display: 'flex'}}>
              <svg height={height} width={width}>
                  <Polygon points={points}
                           style={style.arrow}/>
              </svg>
          </Div>
      </Div>
  );
};
Toggle.propTypes = {
  style: PropTypes.object
};


const myDecorators = {
  ...decorators,
  Toggle: Toggle,
};

export default class Tree extends Component {
  toggleNode = (node, toggled) => {
    if (this.state.cursor) { 
      this.state.cursor.active = false; 
    }
    node.active = true;
    if (node.children) { node.toggled = toggled; }
    this.setState({ cursor: node });
  }

  render() {
    return (
      <Treebeard 
        data={this.props.data}
        onToggle={this.toggleNode}
        style={theme}
        decorators={myDecorators}
      />
    );
  }
}

@j8jacobs
Copy link
Author

However, the highlighted cursor still isn't displaying and I'm having trouble seeing what's making it do that

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants