NewUserTutorialToggleButton.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2017 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import React from 'react'
  19. import PropTypes from 'prop-types'
  20. import I18n from 'i18n!new_user_tutorial'
  21. import Button from 'instructure-ui/lib/components/Button'
  22. import IconMoveLeftLine from 'instructure-icons/lib/Line/IconMoveLeftLine'
  23. import IconMoveRightLine from 'instructure-icons/lib/Line/IconMoveRightLine'
  24. import plainStoreShape from 'jsx/shared/proptypes/plainStoreShape'
  25. class NewUserTutorialToggleButton extends React.Component {
  26. static propTypes = {
  27. store: PropTypes.shape(plainStoreShape).isRequired
  28. }
  29. constructor (props) {
  30. super(props);
  31. this.state = props.store.getState();
  32. }
  33. componentDidMount () {
  34. this.props.store.addChangeListener(this.handleStoreChange)
  35. }
  36. componentWillUnmount () {
  37. this.props.store.removeChangeListener(this.handleStoreChange)
  38. }
  39. focus () {
  40. this.button.focus();
  41. }
  42. handleStoreChange = () => {
  43. this.setState(this.props.store.getState());
  44. }
  45. handleButtonClick = (event) => {
  46. event.preventDefault();
  47. this.props.store.setState({
  48. isCollapsed: !this.state.isCollapsed
  49. });
  50. }
  51. render () {
  52. return (
  53. <Button
  54. ref={(c) => { this.button = c; }}
  55. variant="icon"
  56. id="new_user_tutorial_toggle"
  57. onClick={this.handleButtonClick}
  58. >
  59. {
  60. (this.state.isCollapsed) ?
  61. (<IconMoveLeftLine title={I18n.t('Expand tutorial tray')} />) :
  62. (<IconMoveRightLine title={I18n.t('Collapse tutorial tray')} />)
  63. }
  64. </Button>
  65. );
  66. }
  67. }
  68. export default NewUserTutorialToggleButton;