wix-style-react
Version:
wix-style-react
157 lines (128 loc) • 6.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
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 _EditableSelector = require('../../src/EditableSelector');
var _EditableSelector2 = _interopRequireDefault(_EditableSelector);
var _Grid = require('../../src/Grid');
var _Card = require('../../src/Card');
var _Card2 = _interopRequireDefault(_Card);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; }
var CardWithEditableSelector = function (_React$Component) {
_inherits(CardWithEditableSelector, _React$Component);
function CardWithEditableSelector(props) {
_classCallCheck(this, CardWithEditableSelector);
var _this = _possibleConstructorReturn(this, (CardWithEditableSelector.__proto__ || Object.getPrototypeOf(CardWithEditableSelector)).call(this, props));
_this.onOptionAdded = function (_ref) {
var newTitle = _ref.newTitle;
_this.setState({
options: [].concat(_toConsumableArray(_this.state.options), [{ title: newTitle }])
});
};
_this.onOptionEdit = function (_ref2) {
var newTitle = _ref2.newTitle,
index = _ref2.index;
_this.setState({
options: _this.state.options.map(function (option, i) {
return index === i ? { title: newTitle } : option;
})
});
};
_this.onOptionToggle = function (index) {
var selectedIndex = _this.state.selectedIndex;
if (index === selectedIndex) {
return;
}
var newOptions = _this.state.options.map(function (opt) {
return Object.assign({}, opt);
});
if (selectedIndex !== null) {
newOptions[selectedIndex].isSelected = false;
}
newOptions[index].isSelected = true;
_this.setState({
options: newOptions,
selectedIndex: index
});
};
_this.onOptionDelete = function (_ref3) {
var index = _ref3.index;
var newSelectedIndex = _this.state.selectedIndex;
if (index === _this.state.selectedIndex) {
newSelectedIndex = null;
} else if (index < _this.state.selectedIndex) {
newSelectedIndex = 1;
}
_this.setState({
options: _this.state.options.filter(function (option, i) {
return index !== i;
}),
selectedIndex: newSelectedIndex
});
};
_this.state = {
options: [{ title: 'Pumpkin Seeds' }, { title: 'Sunflower Seeds' }],
selectedIndex: null
};
return _this;
}
_createClass(CardWithEditableSelector, [{
key: 'render',
value: function render() {
var _this2 = this;
return _react2.default.createElement(
'div',
{ style: { backgroundColor: '#f0f4f7', padding: '20px' } },
_react2.default.createElement(
_Grid.Container,
null,
_react2.default.createElement(
_Grid.Row,
null,
_react2.default.createElement(
_Grid.Col,
{ span: 4 },
_react2.default.createElement(
_Card2.default,
null,
_react2.default.createElement(_Card2.default.Header, { title: 'Editable Selector Inside Card' }),
_react2.default.createElement(
_Card2.default.Content,
null,
_react2.default.createElement(_EditableSelector2.default, {
dataHook: 'story-editable-selector',
onOptionAdded: function onOptionAdded(params) {
return _this2.onOptionAdded(params);
},
onOptionEdit: function onOptionEdit(params) {
return _this2.onOptionEdit(params);
},
onOptionDelete: function onOptionDelete(params) {
return _this2.onOptionDelete(params);
},
onOptionToggle: function onOptionToggle(params) {
return _this2.onOptionToggle(params);
},
toggleType: 'radio',
title: 'Type of Seeds',
options: this.state.options
}),
'\xA0'
)
)
)
)
)
);
}
}]);
return CardWithEditableSelector;
}(_react2.default.Component);
exports.default = CardWithEditableSelector;