react-dock icon indicating copy to clipboard operation
react-dock copied to clipboard

Dynamically changing page content

Open firaskrichi opened this issue 8 years ago • 2 comments

Is there a way to make content in the rest of the page scale dynamically based on the width of the dock?

firaskrichi avatar Dec 20 '16 18:12 firaskrichi

Yes, I would also be interested in that.

csillag avatar Jan 23 '17 11:01 csillag

Hey friends,

whats about this solution:

Link to dynamic main content width example

const styles = {
  main: {
    width: '100%',
    height: '150%',
    display: 'flex',
    flexDirection: 'column',
    alignItems: 'top',
    paddingTop: '0',
    marginLeft: '0'
  }
}

@Radium
export default class PmbMainContent extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    const { children, className, ...reactProps } = this.props;
    if (this.props.isSidebarVisible){
        styles.main.width = (1 - this.props.size) * 100 + '%';
        styles.main.marginLeft =  this.props.size * 100 + '%';
    } else {
        styles.main.width = '100%';
        styles.main.marginLeft =  '0';
    }
    return (
        <div style={[styles.main]}>
          {children}
        </div>
    );
  }
}

Im passing the state and the width (size) of the sidebar component down to the main content component and calculating the new width dependent on the current width (size) of the sidebar. This calculated size is added as "left margin" to the main content component. Hope this solution is clean enough??? Thanks in advance

sufius avatar Apr 11 '17 14:04 sufius