@guestbell/react-page-plugins
Version:
Plugins we use in GuestBell for working with amazing react-page package
78 lines • 3.81 kB
JavaScript
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
import classNames from 'classnames';
import * as React from 'react';
import { Resizable } from 'react-resizable';
import { defaultSpacerState } from './../default/state';
var SpacerDefaultControls = function SpacerDefaultControls(props) {
var _ref;
var isPreviewMode = props.isPreviewMode,
onChange = props.onChange,
_props$data = props.data,
_props$data2 = _props$data === void 0 ? defaultSpacerState : _props$data,
height = _props$data2.height;
var _React$useState = React.useState(height),
_React$useState2 = _slicedToArray(_React$useState, 2),
heightPreview = _React$useState2[0],
setHeightPreview = _React$useState2[1];
var changeHeightPreview = React.useCallback(function (h) {
if (!h || h < 24) {
h = 24;
}
setHeightPreview(h);
}, []);
var commitHeight = React.useCallback(function (h) {
if (!h || h < 24) {
h = 24;
}
setHeightPreview(h);
onChange({
height: h
});
}, [onChange]);
React.useEffect(function () {
if (heightPreview !== height) {
setHeightPreview(height);
onChange({
height: height
});
}
}, [height, commitHeight]);
var finalHeight = (_ref = heightPreview !== null && heightPreview !== void 0 ? heightPreview : height) !== null && _ref !== void 0 ? _ref : 0;
return /*#__PURE__*/React.createElement("div", {
className: classNames('ory-plugins-content-spacer', {
'ory-plugins-content-spacer-read-only': isPreviewMode
})
}, /*#__PURE__*/React.createElement(Resizable, {
onResize: function onResize(e, data) {
return changeHeightPreview(data.size.height);
},
onResizeStop: function onResizeStop(e, data) {
return commitHeight(data.size.height);
},
height: finalHeight,
width: 0
}, /*#__PURE__*/React.createElement("div", {
style: {
height: finalHeight,
position: 'relative'
}
}, /*#__PURE__*/React.createElement("div", {
className: "ory-plugins-content-spacer__handle"
}, /*#__PURE__*/React.createElement("svg", {
viewBox: "0 0 24 24",
style: {
color: 'white',
width: 24,
height: 24
}
}, /*#__PURE__*/React.createElement("path", {
d: "M20 9H4v2h16V9zM4 15h16v-2H4v2z"
}))))));
};
export default SpacerDefaultControls;
//# sourceMappingURL=SpacerResizable.js.map