UNPKG

infinity-forge

Version:
78 lines 4.36 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.InputRadioComponent = InputRadioComponent; exports.InputRadio = InputRadio; var jsx_runtime_1 = require("react/jsx-runtime"); var formik_1 = require("formik"); var S = __importStar(require("./styles.js")); var input_control_1 = require("../input-control/index.js"); function InputRadioComponent(props) { var _a = (0, formik_1.useField)({ name: props.name }), field = _a[0], state = _a[1], helpers = _a[2]; var isActive = field.value === props.value; var handleChange = function (value, checked) { var _a; helpers.setValue(value); (_a = props === null || props === void 0 ? void 0 : props.onChangeInput) === null || _a === void 0 ? void 0 : _a.call(props, value, undefined, { state: state, utils: helpers }, undefined); }; return ((0, jsx_runtime_1.jsxs)("label", { htmlFor: props.name + props.label, children: [(0, jsx_runtime_1.jsx)("input", __assign({ id: props.name + props.label }, field, { checked: isActive, type: 'radio', readOnly: props.readOnly, value: props.value, onChange: function (e) { return handleChange(String(props.value), e.target.checked); }, style: { display: props.CustomOption ? 'none' : 'block' } })), props.CustomOption ? (0, jsx_runtime_1.jsx)(props.CustomOption, __assign({}, props, { isActive: isActive })) : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: props.label && props.label })] })); } function InputRadio(_a) { var name = _a.name, options = _a.options, props = __rest(_a, ["name", "options"]); return ((0, jsx_runtime_1.jsx)(input_control_1.InputControl, __assign({}, props, { name: name, i18n: { disabled: true }, children: (0, jsx_runtime_1.jsx)(S.InputRadio, { children: (0, jsx_runtime_1.jsx)("div", { className: 'list-radios', children: options.map(function (option) { return ((0, jsx_runtime_1.jsx)(InputRadioComponent, __assign({ onChangeInput: props === null || props === void 0 ? void 0 : props.onChangeInput, readOnly: props.readOnly }, option, { name: name }), option.value)); }) }) }) }))); } //# sourceMappingURL=index.js.map