UNPKG

@pagamio/frontend-commons-lib

Version:

Pagamio library for Frontend reusable components like the form engine and table container

7 lines (6 loc) 1.12 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Controller } from 'react-hook-form'; import React from 'react'; import { Label, RadioGroup, RadioGroupItem } from '../../../../components'; const RadioInput = React.forwardRef(({ field, error, control }, ref) => (_jsxs("div", { ref: ref, children: [_jsx("label", { htmlFor: field.name, className: "block text-sm font-medium text-gray-700", children: field.label }), _jsx(Controller, { name: field.name, control: control, rules: field.validation, render: ({ field: { onChange, value } }) => (_jsx(RadioGroup, { onValueChange: onChange, value: value, disabled: field.disabled, className: "space-y-2 disabled:bg-gray-50", children: field.options.map((option, index) => (_jsxs("div", { className: "flex items-center space-x-2", children: [_jsx(RadioGroupItem, { value: option, id: `${field.name}-${index}`, disabled: field.disabled }), _jsx(Label, { htmlFor: `${field.name}-${index}`, children: option })] }, index))) })) }), error && _jsx("p", { className: "mt-2 text-sm text-red-500", children: error.message })] }))); export default RadioInput;