DialogPreview.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (C) 2015 - 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 I18n from 'i18n!react_files'
  19. import React from 'react'
  20. import PropTypes from 'prop-types'
  21. import customPropTypes from 'compiled/react_files/modules/customPropTypes'
  22. import Folder from 'compiled/models/Folder'
  23. import filesEnv from 'compiled/react_files/modules/filesEnv'
  24. import FilesystemObjectThumbnail from 'jsx/files/FilesystemObjectThumbnail'
  25. var MAX_THUMBNAILS_TO_SHOW = 5;
  26. // This is used to show a preview inside of a modal dialog.
  27. var DialogPreview = React.createClass({
  28. displayName: 'DialogPreview',
  29. propTypes: {
  30. itemsToShow: PropTypes.arrayOf(customPropTypes.filesystemObject).isRequired
  31. },
  32. renderPreview () {
  33. if (this.props.itemsToShow.length === 1) {
  34. return (
  35. <FilesystemObjectThumbnail
  36. model={this.props.itemsToShow[0]}
  37. className='DialogPreview__thumbnail'
  38. />
  39. );
  40. } else {
  41. return this.props.itemsToShow.slice(0, MAX_THUMBNAILS_TO_SHOW).map((model, index) => {
  42. return (
  43. <i
  44. key={model.cid}
  45. className='media-object ef-big-icon FilesystemObjectThumbnail mimeClass-file DialogPreview__thumbnail'
  46. style={{
  47. left: (10 * index),
  48. top: (-140 * index)
  49. }}
  50. />
  51. );
  52. });
  53. }
  54. },
  55. render () {
  56. return (
  57. <div className='DialogPreview__container'>
  58. {this.renderPreview()}
  59. </div>
  60. );
  61. }
  62. });
  63. export default DialogPreview