wix-style-react
Version:
wix-style-react
93 lines (73 loc) • 4.14 kB
JavaScript
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; }; }();
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; }
import React from 'react';
import classNames from 'classnames';
import SortableList from 'wix-style-react/SortableList';
import styles from './IntroductionExample.scss';
/**
* 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 = classNames(styles.card, (_classNames = {}, _defineProperty(_classNames, styles.placeholder, isPlaceholder), _defineProperty(_classNames, styles.preview, isPreview), _classNames));
return React.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 React.createElement(SortableList, {
containerId: 'single-area-1',
dataHook: 'list-single-area',
items: this.state.items,
renderItem: this.renderItem,
onDrop: this.handleDrop
});
}
}]);
return IntroductionExample;
}(React.Component);
export { IntroductionExample as default };