common.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import * as React from 'react';
  7. export class ControlGroup extends React.Component<{ header: string, initialExpanded?: boolean }, { isExpanded: boolean }> {
  8. state = { isExpanded: !!this.props.initialExpanded }
  9. toggleExpanded = () => this.setState({ isExpanded: !this.state.isExpanded });
  10. render() {
  11. return <div className='msp-control-group-wrapper'>
  12. <div className='msp-control-group-header'>
  13. <button className='msp-btn msp-btn-block' onClick={this.toggleExpanded}>
  14. <span className={`msp-icon msp-icon-${this.state.isExpanded ? 'collapse' : 'expand'}`} />
  15. {this.props.header}
  16. </button>
  17. </div>
  18. {this.state.isExpanded && <div className='msp-control-offset' style={{ display: this.state.isExpanded ? 'block' : 'none' }}>
  19. {this.props.children}
  20. </div>
  21. }
  22. </div>
  23. }
  24. }
  25. // export const ToggleButton = (props: {
  26. // onChange: (v: boolean) => void,
  27. // value: boolean,
  28. // label: string,
  29. // title?: string
  30. // }) => <div className='lm-control-row lm-toggle-button' title={props.title}>
  31. // <span>{props.label}</span>
  32. // <div>
  33. // <button onClick={e => { props.onChange.call(null, !props.value); (e.target as HTMLElement).blur(); }}>
  34. // <span className={ `lm-icon lm-icon-${props.value ? 'ok' : 'off'}` }></span> {props.value ? 'On' : 'Off'}
  35. // </button>
  36. // </div>
  37. // </div>