PopinFixedHeader.jsx 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React from 'react'
  2. import classnames from 'classnames'
  3. import PropTypes from 'prop-types'
  4. class PopinFixedHeader extends React.Component {
  5. constructor (props) {
  6. super(props)
  7. this.state = {
  8. editTitle: false,
  9. editTitleValue: ''
  10. }
  11. }
  12. componentDidUpdate (prevProps) {
  13. if (prevProps.title !== this.props.title) this.setState({editTitleValue: this.props.title})
  14. }
  15. onChangeTitle = e => {
  16. const newTitle = e.target.value
  17. this.setState({editTitleValue: newTitle})
  18. }
  19. handleClickChangeTitleBtn = () => {
  20. if (this.state.editTitle) this.props.onValidateChangeTitle(this.state.editTitleValue)
  21. this.setState(prevState => ({editTitle: !prevState.editTitle}))
  22. }
  23. render () {
  24. const { customClass, customColor, faIcon, title, onClickCloseBtn } = this.props
  25. return (
  26. <div className={classnames('wsContentGeneric__header', `${customClass}__header`)} style={{backgroundColor: customColor}}>
  27. <div className={classnames('wsContentGeneric__header__icon', `${customClass}__header__icon`)}>
  28. <i className={`fa fa-${faIcon}`} />
  29. </div>
  30. <div className={classnames('wsContentGeneric__header__title mr-auto', `${customClass}__header__title`)}>
  31. {this.state.editTitle
  32. ? <input className='wsContentGeneric__header__title__editiontitle editiontitle' value={this.state.editTitleValue} onChange={this.onChangeTitle} />
  33. : <div>{title}</div>
  34. }
  35. </div>
  36. <div
  37. className={classnames('wsContentGeneric__header__edittitle', `${customClass}__header__changetitle`)}
  38. onClick={this.handleClickChangeTitleBtn}
  39. >
  40. {this.state.editTitle ? <i className='fa fa-check' title='Valider le Titre' /> : <i className='fa fa-pencil' title='Modifier le Titre' />}
  41. </div>
  42. <div
  43. className={classnames('wsContentGeneric__header__close', `${customClass}__header__close`)}
  44. onClick={onClickCloseBtn}
  45. >
  46. <i className='fa fa-times' />
  47. </div>
  48. </div>
  49. )
  50. }
  51. }
  52. export default PopinFixedHeader
  53. PopinFixedHeader.propTypes = {
  54. faIcon: PropTypes.string.isRequired,
  55. onClickCloseBtn: PropTypes.func.isRequired,
  56. customClass: PropTypes.string,
  57. customColor: PropTypes.string,
  58. title: PropTypes.string,
  59. onValidateChangeTitle: PropTypes.func
  60. }
  61. PopinFixedHeader.defaultProps = {
  62. customClass: '',
  63. customColor: '',
  64. title: '',
  65. onChangeTitle: () => {}
  66. }