UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

94 lines 3.84 kB
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; function _callSuper(_this, derived, args) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { return !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (e) { return false; } } derived = _getPrototypeOf(derived); return _possibleConstructorReturn(_this, isNativeReflectConstruct() ? Reflect.construct(derived, args || [], _getPrototypeOf(_this).constructor) : derived.apply(_this, args)); } import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { IconDragHandleLine } from '@instructure/ui-icons'; import { IconButton } from '@instructure/ui-buttons'; import { Menu } from '@instructure/ui-menu'; import t from '@instructure/quiz-i18n/es/format-message'; var ReorderChoiceButton = /*#__PURE__*/function (_Component) { function ReorderChoiceButton() { var _this2; _classCallCheck(this, ReorderChoiceButton); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this2 = _callSuper(this, ReorderChoiceButton, [].concat(args)); _defineProperty(_this2, "popover", null); _defineProperty(_this2, "handleMoveUp", function () { _this2.focus(); _this2.props.onMoveChoiceUp(_this2.props.id); }); _defineProperty(_this2, "handleMoveDown", function () { _this2.focus(); _this2.props.onMoveChoiceDown(_this2.props.id); }); _defineProperty(_this2, "handlePopoverRef", function (node) { _this2.popover = node; }); return _this2; } _inherits(ReorderChoiceButton, _Component); return _createClass(ReorderChoiceButton, [{ key: "focus", value: function focus() { this.popover._trigger && this.popover._trigger.focus(); } }, { key: "render", value: function render() { return /*#__PURE__*/React.createElement(Menu, { ref: this.handlePopoverRef, placement: "start", trigger: /*#__PURE__*/React.createElement(IconButton, { as: "div", size: this.props.buttonSize, withBackground: false, withBorder: false, margin: "0 xxx-small", renderIcon: IconDragHandleLine, screenReaderLabel: this.props.screenReaderText }) }, !this.props.isFirstChoice && /*#__PURE__*/React.createElement(Menu.Item, { onSelect: this.handleMoveUp, "data-automation": "sdk-ordering-moveup" }, t('Move Up')), !this.props.isFinalChoice && /*#__PURE__*/React.createElement(Menu.Item, { onSelect: this.handleMoveDown, "data-automation": "sdk-ordering-movedown" }, t('Move Down'))); } }]); }(Component); _defineProperty(ReorderChoiceButton, "propTypes", { buttonSize: PropTypes.oneOf(['small', 'medium', 'large']), id: PropTypes.string.isRequired, screenReaderText: PropTypes.string.isRequired, isFinalChoice: PropTypes.bool, isFirstChoice: PropTypes.bool, onMoveChoiceUp: PropTypes.func.isRequired, onMoveChoiceDown: PropTypes.func.isRequired }); _defineProperty(ReorderChoiceButton, "defaultProps", { buttonSize: 'medium', isFinalChoice: void 0, isFirstChoice: void 0 }); export { ReorderChoiceButton as default };