UNPKG

@copilotkit/a2ui-renderer

Version:

A2UI Renderer for CopilotKit - render A2UI surfaces in React applications

1 lines 3.73 kB
{"version":3,"file":"TextField.cjs","names":["z","CommonSchemas","createReactComponent"],"sources":["../../../../../../src/react-renderer/a2ui-react/catalog/minimal/components/TextField.tsx"],"sourcesContent":["/**\n * Copyright 2026 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nimport { createReactComponent } from \"../../../adapter\";\nimport { z } from \"zod\";\nimport { CommonSchemas } from \"@a2ui/web_core/v0_9\";\n\nexport const TextFieldSchema = z.object({\n label: CommonSchemas.DynamicString,\n value: CommonSchemas.DynamicString,\n variant: z.enum([\"longText\", \"number\", \"shortText\", \"obscured\"]).optional(),\n validationRegexp: z.string().optional(),\n});\n\nexport const TextFieldApiDef = {\n name: \"TextField\",\n schema: TextFieldSchema,\n};\n\nexport const TextField = createReactComponent(\n TextFieldApiDef,\n ({ props, context }) => {\n const onChange = (\n e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,\n ) => {\n if (props.setValue) {\n props.setValue(e.target.value);\n }\n };\n\n const isLong = props.variant === \"longText\";\n const type =\n props.variant === \"number\"\n ? \"number\"\n : props.variant === \"obscured\"\n ? \"password\"\n : \"text\";\n\n const style: React.CSSProperties = {\n padding: \"8px\",\n width: \"100%\",\n border: \"1px solid #ccc\",\n borderRadius: \"4px\",\n boxSizing: \"border-box\",\n };\n\n const id = `textfield-${context.componentModel.id}`;\n\n return (\n <div\n style={{\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"4px\",\n width: \"100%\",\n }}\n >\n {props.label && (\n <label htmlFor={id} style={{ fontSize: \"14px\", fontWeight: \"bold\" }}>\n {props.label}\n </label>\n )}\n {isLong ? (\n <textarea\n id={id}\n style={style}\n value={props.value || \"\"}\n onChange={onChange}\n />\n ) : (\n <input\n id={id}\n type={type}\n style={style}\n value={props.value || \"\"}\n onChange={onChange}\n />\n )}\n </div>\n );\n },\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,kBAAkBA,MAAE,OAAO;CACtC,OAAOC,kCAAc;CACrB,OAAOA,kCAAc;CACrB,SAASD,MAAE,KAAK;EAAC;EAAY;EAAU;EAAa;EAAW,CAAC,CAAC,UAAU;CAC3E,kBAAkBA,MAAE,QAAQ,CAAC,UAAU;CACxC,CAAC;AAEF,MAAa,kBAAkB;CAC7B,MAAM;CACN,QAAQ;CACT;AAED,MAAa,YAAYE,qCACvB,kBACC,EAAE,OAAO,cAAc;CACtB,MAAM,YACJ,MACG;AACH,MAAI,MAAM,SACR,OAAM,SAAS,EAAE,OAAO,MAAM;;CAIlC,MAAM,SAAS,MAAM,YAAY;CACjC,MAAM,OACJ,MAAM,YAAY,WACd,WACA,MAAM,YAAY,aAChB,aACA;CAER,MAAM,QAA6B;EACjC,SAAS;EACT,OAAO;EACP,QAAQ;EACR,cAAc;EACd,WAAW;EACZ;CAED,MAAM,KAAK,aAAa,QAAQ,eAAe;AAE/C,QACE,4CAAC;EACC,OAAO;GACL,SAAS;GACT,eAAe;GACf,KAAK;GACL,OAAO;GACR;aAEA,MAAM,SACL,2CAAC;GAAM,SAAS;GAAI,OAAO;IAAE,UAAU;IAAQ,YAAY;IAAQ;aAChE,MAAM;IACD,EAET,SACC,2CAAC;GACK;GACG;GACP,OAAO,MAAM,SAAS;GACZ;IACV,GAEF,2CAAC;GACK;GACE;GACC;GACP,OAAO,MAAM,SAAS;GACZ;IACV;GAEA;EAGX"}