FilesUsage.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 React from 'react'
  19. import I18n from 'i18n!react_files'
  20. import FilesUsage from 'compiled/react_files/components/FilesUsage'
  21. import friendlyBytes from 'compiled/util/friendlyBytes'
  22. FilesUsage.render = function () {
  23. if (this.state) {
  24. const percentUsed = Math.round(this.state.quota_used / this.state.quota * 100);
  25. const label = I18n.t('%{percentUsed} of %{bytesAvailable} used', {
  26. percentUsed: I18n.n(percentUsed, { percentage: true }),
  27. bytesAvailable: friendlyBytes(this.state.quota)
  28. });
  29. const srLabel = I18n.t('Files Quota: %{percentUsed} of %{bytesAvailable} used', {
  30. percentUsed: I18n.n(percentUsed, { percentage: true }),
  31. bytesAvailable: friendlyBytes(this.state.quota)
  32. });
  33. return (
  34. <div className='grid-row ef-quota-usage'>
  35. <div className='col-xs-5'>
  36. <div ref='container' className='progress-bar__bar-container' aria-hidden={true}>
  37. <div
  38. ref='bar'
  39. className='progress-bar__bar'
  40. style={{
  41. width: Math.min(percentUsed, 100) + '%'
  42. }}
  43. />
  44. </div>
  45. </div>
  46. <div className='col-xs-7' style={{paddingLeft: '0px'}} aria-hidden={true}>
  47. {label}
  48. </div>
  49. <div className='screenreader-only'>{srLabel}</div>
  50. </div>
  51. );
  52. } else {
  53. return <div />;
  54. }
  55. };
  56. export default React.createClass(FilesUsage)