DashboardCardMovementMenu.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 I18n from 'i18n!dashcards'
  21. import Menu, { MenuItem } from 'instructure-ui/lib/components/Menu'
  22. import Typography from 'instructure-ui/lib/components/Typography'
  23. import IconMoveUpTopSolid from 'instructure-icons/lib/Solid/IconMoveUpTopSolid'
  24. import IconMoveUpSolid from 'instructure-icons/lib/Solid/IconMoveUpSolid'
  25. import IconMoveDownSolid from 'instructure-icons/lib/Solid/IconMoveDownSolid'
  26. import IconMoveDownBottomSolid from 'instructure-icons/lib/Solid/IconMoveDownBottomSolid'
  27. class DashboardCardMovementMenu extends React.Component {
  28. static propTypes = {
  29. assetString: PropTypes.string.isRequired,
  30. handleMove: PropTypes.func.isRequired,
  31. onMenuSelect: PropTypes.func,
  32. menuOptions: PropTypes.shape({
  33. canMoveLeft: PropTypes.bool,
  34. canMoveRight: PropTypes.bool,
  35. canMoveToBeginning: PropTypes.bool,
  36. canMoveToEnd: PropTypes.bool
  37. }).isRequired,
  38. lastPosition: PropTypes.number,
  39. currentPosition: PropTypes.number
  40. };
  41. static defaultProps = {
  42. onMenuSelect: () => {},
  43. lastPosition: 0,
  44. currentPosition: 0
  45. }
  46. handleMoveCard = positionToMoveTo => () => this.props.handleMove(this.props.assetString, positionToMoveTo);
  47. render () {
  48. const {
  49. canMoveLeft,
  50. canMoveRight,
  51. canMoveToBeginning,
  52. canMoveToEnd
  53. } = this.props.menuOptions;
  54. return (
  55. <Menu onSelect={this.props.onMenuSelect}>
  56. {!!canMoveToBeginning && (
  57. <MenuItem
  58. onSelect={this.handleMoveCard(0)}
  59. >
  60. <span className="DashboardCardMenu__MovementItem">
  61. <IconMoveUpTopSolid className="DashboardCardMenu__MovementIcon" />
  62. <Typography weight="bold" size="small">{I18n.t('Top')}</Typography>
  63. </span>
  64. </MenuItem>
  65. )}
  66. {!!canMoveLeft && (
  67. <MenuItem
  68. onSelect={this.handleMoveCard(this.props.currentPosition - 1)}
  69. >
  70. <span className="DashboardCardMenu__MovementItem">
  71. <IconMoveUpSolid className="DashboardCardMenu__MovementIcon" />
  72. <Typography weight="bold" size="small">{I18n.t('Ahead')}</Typography>
  73. </span>
  74. </MenuItem>
  75. )}
  76. {!!canMoveRight && (
  77. <MenuItem
  78. onSelect={this.handleMoveCard(this.props.currentPosition + 1)}
  79. >
  80. <span className="DashboardCardMenu__MovementItem">
  81. <IconMoveDownSolid className="DashboardCardMenu__MovementIcon" />
  82. <Typography weight="bold" size="small">{I18n.t('Behind')}</Typography>
  83. </span>
  84. </MenuItem>
  85. )}
  86. {!!canMoveToEnd && (
  87. <MenuItem
  88. onSelect={this.handleMoveCard(this.props.lastPosition)}
  89. >
  90. <span className="DashboardCardMenu__MovementItem">
  91. <IconMoveDownBottomSolid className="DashboardCardMenu__MovementIcon"/>
  92. <Typography weight="bold" size="small">{I18n.t('Bottom')}</Typography>
  93. </span>
  94. </MenuItem>
  95. )}
  96. </Menu>
  97. );
  98. }
  99. }
  100. export default DashboardCardMovementMenu