logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

column_header.js (5477B)


  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import classNames from 'classnames';
  4. import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
  5. const messages = defineMessages({
  6. show: { id: 'column_header.show_settings', defaultMessage: 'Show settings' },
  7. hide: { id: 'column_header.hide_settings', defaultMessage: 'Hide settings' },
  8. moveLeft: { id: 'column_header.moveLeft_settings', defaultMessage: 'Move column to the left' },
  9. moveRight: { id: 'column_header.moveRight_settings', defaultMessage: 'Move column to the right' },
  10. });
  11. @injectIntl
  12. export default class ColumnHeader extends React.PureComponent {
  13. static contextTypes = {
  14. router: PropTypes.object,
  15. };
  16. static propTypes = {
  17. intl: PropTypes.object.isRequired,
  18. title: PropTypes.node,
  19. icon: PropTypes.string,
  20. active: PropTypes.bool,
  21. multiColumn: PropTypes.bool,
  22. extraButton: PropTypes.node,
  23. showBackButton: PropTypes.bool,
  24. children: PropTypes.node,
  25. pinned: PropTypes.bool,
  26. onPin: PropTypes.func,
  27. onMove: PropTypes.func,
  28. onClick: PropTypes.func,
  29. };
  30. state = {
  31. collapsed: true,
  32. animating: false,
  33. };
  34. handleToggleClick = (e) => {
  35. e.stopPropagation();
  36. this.setState({ collapsed: !this.state.collapsed, animating: true });
  37. }
  38. handleTitleClick = () => {
  39. this.props.onClick();
  40. }
  41. handleMoveLeft = () => {
  42. this.props.onMove(-1);
  43. }
  44. handleMoveRight = () => {
  45. this.props.onMove(1);
  46. }
  47. handleBackClick = () => {
  48. if (window.history && window.history.length === 1) this.context.router.history.push('/');
  49. else this.context.router.history.goBack();
  50. }
  51. handleTransitionEnd = () => {
  52. this.setState({ animating: false });
  53. }
  54. render () {
  55. const { title, icon, active, children, pinned, onPin, multiColumn, extraButton, showBackButton, intl: { formatMessage } } = this.props;
  56. const { collapsed, animating } = this.state;
  57. const wrapperClassName = classNames('column-header__wrapper', {
  58. 'active': active,
  59. });
  60. const buttonClassName = classNames('column-header', {
  61. 'active': active,
  62. });
  63. const collapsibleClassName = classNames('column-header__collapsible', {
  64. 'collapsed': collapsed,
  65. 'animating': animating,
  66. });
  67. const collapsibleButtonClassName = classNames('column-header__button', {
  68. 'active': !collapsed,
  69. });
  70. let extraContent, pinButton, moveButtons, backButton, collapseButton;
  71. if (children) {
  72. extraContent = (
  73. <div key='extra-content' className='column-header__collapsible__extra'>
  74. {children}
  75. </div>
  76. );
  77. }
  78. if (multiColumn && pinned) {
  79. pinButton = <button key='pin-button' className='text-btn column-header__setting-btn' onClick={onPin}><i className='fa fa fa-times' /> <FormattedMessage id='column_header.unpin' defaultMessage='Unpin' /></button>;
  80. moveButtons = (
  81. <div key='move-buttons' className='column-header__setting-arrows'>
  82. <button title={formatMessage(messages.moveLeft)} aria-label={formatMessage(messages.moveLeft)} className='text-btn column-header__setting-btn' onClick={this.handleMoveLeft}><i className='fa fa-chevron-left' /></button>
  83. <button title={formatMessage(messages.moveRight)} aria-label={formatMessage(messages.moveRight)} className='text-btn column-header__setting-btn' onClick={this.handleMoveRight}><i className='fa fa-chevron-right' /></button>
  84. </div>
  85. );
  86. } else if (multiColumn) {
  87. pinButton = <button key='pin-button' className='text-btn column-header__setting-btn' onClick={onPin}><i className='fa fa fa-plus' /> <FormattedMessage id='column_header.pin' defaultMessage='Pin' /></button>;
  88. }
  89. if (!pinned && (multiColumn || showBackButton)) {
  90. backButton = (
  91. <button onClick={this.handleBackClick} className='column-header__back-button'>
  92. <i className='fa fa-fw fa-chevron-left column-back-button__icon' />
  93. <FormattedMessage id='column_back_button.label' defaultMessage='Back' />
  94. </button>
  95. );
  96. }
  97. const collapsedContent = [
  98. extraContent,
  99. ];
  100. if (multiColumn) {
  101. collapsedContent.push(moveButtons);
  102. collapsedContent.push(pinButton);
  103. }
  104. if (children || multiColumn) {
  105. collapseButton = <button className={collapsibleButtonClassName} title={formatMessage(collapsed ? messages.show : messages.hide)} aria-label={formatMessage(collapsed ? messages.show : messages.hide)} aria-pressed={collapsed ? 'false' : 'true'} onClick={this.handleToggleClick}><i className='fa fa-sliders' /></button>;
  106. }
  107. const hasTitle = icon && title;
  108. return (
  109. <div className={wrapperClassName}>
  110. <h1 className={buttonClassName}>
  111. {hasTitle && (
  112. <button onClick={this.handleTitleClick}>
  113. <i className={`fa fa-fw fa-${icon} column-header__icon`} />
  114. {title}
  115. </button>
  116. )}
  117. {!hasTitle && backButton}
  118. <div className='column-header__buttons'>
  119. {hasTitle && backButton}
  120. {extraButton}
  121. {collapseButton}
  122. </div>
  123. </h1>
  124. <div className={collapsibleClassName} tabIndex={collapsed ? -1 : null} onTransitionEnd={this.handleTransitionEnd}>
  125. <div className='column-header__collapsible-inner'>
  126. {(!collapsed || animating) && collapsedContent}
  127. </div>
  128. </div>
  129. </div>
  130. );
  131. }
  132. }