path-option.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2016 - 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 classNames from 'classnames'
  21. import I18n from 'i18n!choose_mastery_path'
  22. import Assignment from './assignment'
  23. import SelectButton from './select-button'
  24. import assignmentShape from '../shapes/assignment-shape'
  25. const { func, number, arrayOf } = PropTypes
  26. export default class PathOption extends React.Component {
  27. static propTypes = {
  28. assignments: arrayOf(assignmentShape).isRequired,
  29. optionIndex: number.isRequired,
  30. setId: number.isRequired,
  31. selectedOption: number,
  32. selectOption: func.isRequired,
  33. }
  34. constructor () {
  35. super()
  36. this.selectOption = this.selectOption.bind(this)
  37. }
  38. selectOption () {
  39. this.props.selectOption(this.props.setId)
  40. }
  41. render () {
  42. const { selectedOption, setId, optionIndex } = this.props
  43. const disabled = selectedOption !== null && selectedOption !== undefined && selectedOption !== setId
  44. const selected = selectedOption === setId
  45. const optionClasses = classNames({
  46. 'item-group-container': true,
  47. 'cmp-option': true,
  48. 'cmp-option__selected': selected,
  49. 'cmp-option__disabled': disabled,
  50. })
  51. return (
  52. <div className={optionClasses}>
  53. <div className='item-group-condensed context_module'>
  54. <div className='ig-header'>
  55. <span className='name'>
  56. {I18n.t('Option %{index}', { index: optionIndex + 1 })}
  57. </span>
  58. <SelectButton isDisabled={disabled} isSelected={selected} onSelect={this.selectOption} />
  59. </div>
  60. <ul className='ig-list'>
  61. {this.props.assignments.map((assg, i) => (
  62. <Assignment
  63. key={i}
  64. assignment={assg}
  65. isSelected={selected}
  66. />
  67. ))}
  68. </ul>
  69. </div>
  70. </div>
  71. )
  72. }
  73. }