UploadArea.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 I18n from 'i18n!course_images'
  20. import classnames from 'classnames'
  21. import htmlEscape from 'str/htmlEscape'
  22. class UploadArea extends React.Component {
  23. constructor (props) {
  24. super(props);
  25. this.handleFileChange = this.handleFileChange.bind(this);
  26. this.uploadFile = this.uploadFile.bind(this);
  27. }
  28. handleFileChange (e) {
  29. this.props.handleFileUpload(e, this.props.courseId);
  30. e.preventDefault();
  31. e.stopPropagation();
  32. }
  33. uploadFile () {
  34. this.refs.courseImagefileUpload.click();
  35. }
  36. render () {
  37. return (
  38. <div className="UploadArea">
  39. <div className="UploadArea__Content">
  40. <div className="UploadArea__Icon">
  41. <i className="icon-upload" />
  42. </div>
  43. <div className="UploadArea__Instructions">
  44. <strong>
  45. {I18n.t('Drag and drop your image here or ')}
  46. <a tabIndex="0" role="button" href="#" onClick={this.uploadFile}>
  47. <span className="screenreader-only">{I18n.t('Browse your computer for a course image')}</span>
  48. <span aria-hidden="true">{I18n.t('browse your computer')}</span>
  49. </a>
  50. </strong>
  51. <input
  52. type="file"
  53. ref="courseImagefileUpload"
  54. name="fileUpload"
  55. className="FileUpload__Input"
  56. accept=".jpg, .jpeg, .gif, .png, image/png, image/jpeg, image/gif"
  57. aria-hidden="true"
  58. onChange={this.handleFileChange}
  59. />
  60. </div>
  61. <div className="UploadArea__FileTypes">
  62. {I18n.t('For best results crop image to 262px wide by 146px tall. JPG, PNG or GIF file types accepted')}
  63. </div>
  64. </div>
  65. </div>
  66. );
  67. }
  68. }
  69. export default UploadArea