UNPKG

react-forminate

Version:

React.js + Typescript package that creates dynamic UI forms based on the JSON schema

2 lines (1 loc) 1.06 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index-BHL74Jf6.cjs"),E=require("./FieldComponents-TtYXly-g.cjs"),r=require("react"),S=d=>{const{eventHandlers:m,processedProps:t,fieldParams:p,fieldValue:x,fieldId:n,dynamicOptions:o,fieldErrors:j,hasDefaultStyling:f}=s.useField(d),i=r.useMemo(()=>{const e=o?.[n]||t.options||[];return typeof e[0]=="string"?e.map(l=>({label:l,value:l})):e},[o?.[n],t.options]),a={...p,...m.htmlHandlers,value:x,hasError:!!j,className:t.className},c=r.useMemo(()=>s.jsxRuntimeExports.jsxs(s.jsxRuntimeExports.Fragment,{children:[s.jsxRuntimeExports.jsx("option",{value:"",disabled:!0,children:t.placeholder||"Select an option"}),i.map((e,l)=>{const u=typeof e=="string"?e:e.value,h=typeof e=="string"?e:e.label;return s.jsxRuntimeExports.jsx("option",{value:u,children:h},`${u}-${l}`)})]}),[i,t.placeholder]);return f?s.jsxRuntimeExports.jsx(E.Select,{...a,children:c}):s.jsxRuntimeExports.jsx("select",{...a,className:t.className,children:c})},g=r.memo(S);exports.default=g;