@quillforms/blocklib-multiple-choice-block
Version:
Multiple choice block for quillforms
58 lines (54 loc) • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _adminComponents = require("@quillforms/admin-components");
var _react = require("react");
var _emotion = require("emotion");
var _jsxRuntime = require("react/jsx-runtime");
/**
* QuillForms Dependencies
*/
/**
* WordPress Dependencies
*/
/**
* External Dependencies
*/
const DropdownLogicControl = ({
attributes,
value,
setValue,
removeCondition
}) => {
const {
choices
} = attributes;
(0, _react.useEffect)(() => {
if (!value) {
setValue(choices[0].value);
} else if (!choices.some(choice => choice.value === value)) {
removeCondition();
}
}, []);
const options = choices.map((choice, index) => {
return {
key: choice.value,
name: choice.label ? choice.label : `Choice ${index + 1}`
};
});
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_adminComponents.SelectControl, {
className: (0, _emotion.css)`
margin-top: 10px;
margin-bottom: 10px;
`,
value: options.find(option => option.key === value),
onChange: selectedChoice => {
setValue(selectedChoice.selectedItem.key);
},
options: options
});
};
var _default = exports.default = DropdownLogicControl;
//# sourceMappingURL=logic-control.js.map