@guestbell/react-page-plugins
Version:
Plugins we use in GuestBell for working with amazing react-page package
226 lines • 12.9 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
import * as React from 'react';
import Button from '@mui/material/Button';
import Slider from '@mui/material/Slider';
import Typography from '@mui/material/Typography';
import IconButton from '@mui/material/IconButton';
import DeleteIcon from '@mui/icons-material/Delete';
import { ColorPicker } from '@react-page/editor';
var LinearGradientComponent = /*#__PURE__*/function (_React$Component) {
function LinearGradientComponent() {
var _this;
_classCallCheck(this, LinearGradientComponent);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, LinearGradientComponent, [].concat(args));
_this.addGradient = function () {
_this.props.ensureModeOn();
_this.props.onChange({
gradients: (_this.props.data.gradients ? _this.props.data.gradients : []).concat({
deg: 45,
opacity: 1
})
});
};
_this.handleChangeDeg = function (index, value) {
return function () {
_this.props.onChangeGradientDegPreview && _this.props.onChangeGradientDegPreview(undefined, undefined);
_this.props.onChange({
gradients: (_this.props.data.gradients ? _this.props.data.gradients : []).map(function (g, i) {
return i === index ? _objectSpread(_objectSpread({}, g), {}, {
deg: value
}) : g;
})
});
};
};
_this.handleChangeDegPreview = function (index) {
return function (e, value) {
_this.props.onChangeGradientDegPreview && _this.props.onChangeGradientDegPreview(value, index);
};
};
_this.handleChangeOpacity = function (index, value) {
return function () {
_this.props.onChangeGradientOpacityPreview && _this.props.onChangeGradientOpacityPreview(undefined, undefined);
_this.props.onChange({
gradients: (_this.props.data.gradients ? _this.props.data.gradients : []).map(function (g, i) {
return i === index ? _objectSpread(_objectSpread({}, g), {}, {
opacity: value
}) : g;
})
});
};
};
_this.handleChangeOpacityPreview = function (index) {
return function (e, value) {
_this.props.onChangeGradientOpacityPreview && _this.props.onChangeGradientOpacityPreview(value, index);
};
};
_this.handleChangeGradientColor = function (index, cpIndex) {
return function (e) {
_this.props.onChangeGradientColorPreview && _this.props.onChangeGradientColorPreview(undefined, undefined, undefined);
_this.props.onChange({
gradients: [].concat(_this.props.data.gradients ? _this.props.data.gradients : []).map(function (g, i) {
return i === index ? _objectSpread(_objectSpread({}, g), {}, {
colors: (g.colors ? g.colors : []).map(function (c, cpI) {
return cpI === cpIndex ? _objectSpread(_objectSpread({}, c), {}, {
color: e
}) : c;
})
}) : g;
})
});
};
};
_this.handleChangeGradientColorPreview = function (index, cpIndex) {
return function (e) {
_this.props.onChangeGradientColorPreview && _this.props.onChangeGradientColorPreview(e, index, cpIndex);
};
};
_this.addColor = function (index) {
return function () {
_this.props.ensureModeOn();
_this.props.onChange({
gradients: (_this.props.data.gradients ? _this.props.data.gradients : []).map(function (g, i) {
return i === index ? _objectSpread(_objectSpread({}, g), {}, {
colors: (g.colors ? g.colors : []).concat({
color: (g.colors ? g.colors : []).length % 2 === index % 2 ? _this.props.defaultGradientColor : _this.props.defaultGradientSecondaryColor
})
}) : g;
})
});
};
};
_this.removeColor = function (index, cpIndex) {
return function () {
_this.props.onChange({
gradients: [].concat(_this.props.data.gradients ? _this.props.data.gradients : []).map(function (g, i) {
return i === index ? _objectSpread(_objectSpread({}, g), {}, {
colors: (g.colors ? g.colors : []).filter(function (c, cpI) {
return cpI !== cpIndex;
})
}) : g;
})
});
};
};
_this.removeGradient = function (index) {
return function () {
_this.props.onChange({
gradients: [].concat(_this.props.data.gradients ? _this.props.data.gradients : []).filter(function (item, i) {
return i !== index;
})
});
};
};
return _this;
}
_inherits(LinearGradientComponent, _React$Component);
return _createClass(LinearGradientComponent, [{
key: "render",
value: function render() {
var _this2 = this;
var _this$props = this.props,
gradientDegPreview = _this$props.gradientDegPreview,
gradientDegPreviewIndex = _this$props.gradientDegPreviewIndex,
gradientOpacityPreview = _this$props.gradientOpacityPreview,
gradientOpacityPreviewIndex = _this$props.gradientOpacityPreviewIndex,
gradientColorPreview = _this$props.gradientColorPreview,
gradientColorPreviewIndex = _this$props.gradientColorPreviewIndex,
gradientColorPreviewColorIndex = _this$props.gradientColorPreviewColorIndex,
_this$props$data$grad = _this$props.data.gradients,
gradients = _this$props$data$grad === void 0 ? [] : _this$props$data$grad;
return /*#__PURE__*/React.createElement("div", null, gradients.map(function (gradient, i) {
var colors = gradient.colors ? gradient.colors : [];
var deg = i === gradientDegPreviewIndex && gradientDegPreview !== undefined ? gradientDegPreview : gradient.deg;
var opacity = i === gradientOpacityPreviewIndex && gradientOpacityPreview !== undefined ? gradientOpacityPreview : gradient.opacity;
return /*#__PURE__*/React.createElement("div", {
key: i,
style: {
marginBottom: '8px',
borderLeft: '2px',
borderLeftStyle: 'solid',
paddingLeft: '8px'
}
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Typography, {
variant: "body1",
id: "linear-gradient-degree-label"
}, "Gradient rotation (", deg, "deg)"), /*#__PURE__*/React.createElement(Slider, {
"aria-labelledby": "linear-gradient-degree-label",
value: deg,
onChange: _this2.handleChangeDegPreview(i),
onChangeCommitted: _this2.handleChangeDeg(i, deg),
step: 5,
min: 0,
max: 360
})), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Typography, {
variant: "body1",
id: "linear-gradient-opacity-label"
}, "Gradient opacity (", (opacity * 100).toFixed(0), "%)"), /*#__PURE__*/React.createElement(Slider, {
"aria-labelledby": "linear-gradient-opacity-label",
value: opacity,
onChange: _this2.handleChangeOpacityPreview(i),
onChangeCommitted: _this2.handleChangeOpacity(i, opacity),
step: 0.01,
min: 0,
max: 1
})), colors.map(function (c, cpIndex) {
var color = i === gradientColorPreviewIndex && cpIndex === gradientColorPreviewColorIndex && gradientColorPreview !== undefined ? gradientColorPreview : c.color;
return /*#__PURE__*/React.createElement(React.Fragment, {
key: cpIndex
}, /*#__PURE__*/React.createElement(ColorPicker, {
style: {
marginLeft: '8px'
},
color: color,
onChange: _this2.handleChangeGradientColorPreview(i, cpIndex),
onChangeComplete: _this2.handleChangeGradientColor(i, cpIndex)
}), /*#__PURE__*/React.createElement(IconButton, {
"aria-label": "Delete",
onClick: _this2.removeColor(i, cpIndex),
size: "large"
}, /*#__PURE__*/React.createElement(DeleteIcon, null)));
}), /*#__PURE__*/React.createElement(Button, {
variant: "contained",
onClick: _this2.addColor(i),
style: {
marginLeft: '8px'
}
}, "Add color"), /*#__PURE__*/React.createElement(IconButton, {
"aria-label": "Delete",
onClick: _this2.removeGradient(i),
size: "large"
}, /*#__PURE__*/React.createElement(DeleteIcon, null)));
}), /*#__PURE__*/React.createElement("div", {
style: {
display: 'flex'
}
}, /*#__PURE__*/React.createElement(Button, {
style: {
margin: 'auto'
},
variant: "contained",
onClick: this.addGradient,
disabled: gradients.length > 5
}, "Add gradient")));
}
}]);
}(React.Component);
export default LinearGradientComponent;
//# sourceMappingURL=LinearGradient.js.map