UNPKG

wix-style-react

Version:
112 lines (83 loc) 4.74 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _SortableList = require('wix-style-react/SortableList'); var _SortableList2 = _interopRequireDefault(_SortableList); var _IntroductionExample = require('./IntroductionExample.scss'); var _IntroductionExample2 = _interopRequireDefault(_IntroductionExample); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * An example for a simple drag and drop list component. */ var IntroductionExample = function (_React$Component) { _inherits(IntroductionExample, _React$Component); function IntroductionExample() { _classCallCheck(this, IntroductionExample); var _this = _possibleConstructorReturn(this, (IntroductionExample.__proto__ || Object.getPrototypeOf(IntroductionExample)).call(this)); _this.handleDrop = function (_ref) { var removedIndex = _ref.removedIndex, addedIndex = _ref.addedIndex; var nextItems = [].concat(_toConsumableArray(_this.state.items)); nextItems.splice.apply(nextItems, [addedIndex, 0].concat(_toConsumableArray(nextItems.splice(removedIndex, 1)))); _this.setState({ items: nextItems }); }; _this.renderItem = function (_ref2) { var _classNames; var isPlaceholder = _ref2.isPlaceholder, isPreview = _ref2.isPreview, id = _ref2.id, previewStyles = _ref2.previewStyles, item = _ref2.item; var classes = (0, _classnames2.default)(_IntroductionExample2.default.card, (_classNames = {}, _defineProperty(_classNames, _IntroductionExample2.default.placeholder, isPlaceholder), _defineProperty(_classNames, _IntroductionExample2.default.preview, isPreview), _classNames)); return _react2.default.createElement( 'div', { className: classes, style: previewStyles, 'data-hook': 'item-' + id }, item.text ); }; _this.state = { items: [{ id: 'a', text: 'Item 1' }, { id: 'b', text: 'Item 2' }, { id: 'c', text: 'Item 3' }, { id: 'd', text: 'Item 4' }] }; return _this; } _createClass(IntroductionExample, [{ key: 'render', value: function render() { return _react2.default.createElement(_SortableList2.default, { containerId: 'single-area-1', dataHook: 'list-single-area', items: this.state.items, renderItem: this.renderItem, onDrop: this.handleDrop }); } }]); return IntroductionExample; }(_react2.default.Component); exports.default = IntroductionExample;