UNPKG

@focuson/form_components

Version:

Components that can be used by @focuson/forms

24 lines (23 loc) 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ListPrevButton = exports.ListNextButton = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const state_1 = require("@focuson/state"); const utils_1 = require("@focuson/utils"); const common_1 = require("./common"); const pages_1 = require("@focuson/pages"); function ListNextButton({ id, title, value, list, enabledBy, buttonType }) { const index = value.optJson(); const i = index ? index : 0; const listSize = (0, utils_1.safeArray)(list.optJson()).length; const noNextItemCondition = [index === undefined || index >= listSize - 1, 'There is no next item']; return (0, pages_1.wrapWithErrors)(id, enabledBy, [noNextItemCondition], (errorProps, error) => (0, jsx_runtime_1.jsxs)("button", Object.assign({ id: id }, errorProps, { disabled: error, onClick: () => value.setJson(i + 1, (0, state_1.reasonFor)('ListNextButton', 'onClick', id)), className: (0, common_1.getButtonClassName)(buttonType) }, { children: [title, " "] }))); } exports.ListNextButton = ListNextButton; function ListPrevButton({ id, title, value, enabledBy, buttonType }) { const index = value.optJson(); const i = index ? index : 0; const noPrevItemCondition = [index === undefined || index <= 0, 'There is no previous item']; return (0, pages_1.wrapWithErrors)(id, enabledBy, [noPrevItemCondition], (errorProps, error) => (0, jsx_runtime_1.jsx)("button", Object.assign({ id: id }, errorProps, { disabled: error, onClick: () => value.setJson(i - 1, (0, state_1.reasonFor)('ListPrevButton', 'onClick', id)), className: (0, common_1.getButtonClassName)(buttonType) }, { children: title }))); } exports.ListPrevButton = ListPrevButton;