UNPKG

@focuson/form_components

Version:

Components that can be used by @focuson/forms

24 lines (23 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommandButton = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const state_1 = require("@focuson/state"); const common_1 = require("./common"); const rest_1 = require("@focuson/rest"); const focuson_1 = require("@focuson/focuson"); const pages_1 = require("@focuson/pages"); function CommandButton({ id, state, label, commands, buttonType, enabledBy, validate }) { function onClick() { const errorPrefix = `CommandButton ${id}`; const s = state.optJson(); const config = (0, focuson_1.makeInputProcessorsConfig)(state.main, state.context); const processor = (0, rest_1.commandButtonCommandProcessors)(config)(state.main); const txs = (0, rest_1.processChangeCommandProcessor)(errorPrefix, processor, commands); if (txs.length === 0) return; state.massTransform((0, state_1.reasonFor)('CommandButton', 'onClick', id))(...txs); } return (0, pages_1.wrapWithErrors)(id, enabledBy, [], (errorProps, error, errorRef, allErrors) => (0, jsx_runtime_1.jsx)("button", Object.assign({ ref: (0, pages_1.getRefForValidateLogicToButton)(state)(id, false, validate, allErrors, errorRef), id: id }, errorProps, { disabled: error, onClick: onClick, className: (0, common_1.getButtonClassName)(buttonType) }, { children: label }))); } exports.CommandButton = CommandButton;