UNPKG

@copilotkit/a2ui-renderer

Version:

A2UI Renderer for CopilotKit - render A2UI surfaces in React applications

1 lines 3.3 kB
{"version":3,"file":"Tabs.mjs","names":[],"sources":["../../../../../../src/react-renderer/a2ui-react/catalog/basic/components/Tabs.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 { useState } from \"react\";\nimport { createReactComponent } from \"../../../adapter\";\nimport { TabsApi } from \"@a2ui/web_core/v0_9/basic_catalog\";\nimport { LEAF_MARGIN } from \"../utils\";\n\n// The type of a tab is deeply nested into the TabsApi schema, and\n// it seems z.infer is not inferring it correctly (?). We use `any` for now.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype _Tab = any;\n\nexport const Tabs = createReactComponent(TabsApi, ({ props, buildChild }) => {\n const [selectedIndex, setSelectedIndex] = useState(0);\n\n const tabs = props.tabs || [];\n const activeTab = tabs[selectedIndex];\n\n return (\n <div\n style={{\n display: \"flex\",\n flexDirection: \"column\",\n width: \"100%\",\n margin: LEAF_MARGIN,\n }}\n >\n <div\n style={{\n display: \"flex\",\n borderBottom: \"1px solid #ccc\",\n marginBottom: \"8px\",\n }}\n >\n {tabs.map((tab: _Tab, i: number) => (\n <button\n key={i}\n onClick={() => setSelectedIndex(i)}\n style={{\n padding: \"8px 16px\",\n border: \"none\",\n background: \"none\",\n borderBottom:\n selectedIndex === i\n ? \"2px solid var(--a2ui-primary-color, #007bff)\"\n : \"none\",\n fontWeight: selectedIndex === i ? \"bold\" : \"normal\",\n cursor: \"pointer\",\n color:\n selectedIndex === i\n ? \"var(--a2ui-primary-color, #007bff)\"\n : \"inherit\",\n }}\n >\n {tab.title}\n </button>\n ))}\n </div>\n <div style={{ flex: 1 }}>\n {activeTab ? buildChild(activeTab.child) : null}\n </div>\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,OAAO,qBAAqB,UAAU,EAAE,OAAO,iBAAiB;CAC3E,MAAM,CAAC,eAAe,oBAAoB,SAAS,EAAE;CAErD,MAAM,OAAO,MAAM,QAAQ,EAAE;CAC7B,MAAM,YAAY,KAAK;AAEvB,QACE,qBAAC;EACC,OAAO;GACL,SAAS;GACT,eAAe;GACf,OAAO;GACP,QAAQ;GACT;aAED,oBAAC;GACC,OAAO;IACL,SAAS;IACT,cAAc;IACd,cAAc;IACf;aAEA,KAAK,KAAK,KAAW,MACpB,oBAAC;IAEC,eAAe,iBAAiB,EAAE;IAClC,OAAO;KACL,SAAS;KACT,QAAQ;KACR,YAAY;KACZ,cACE,kBAAkB,IACd,iDACA;KACN,YAAY,kBAAkB,IAAI,SAAS;KAC3C,QAAQ;KACR,OACE,kBAAkB,IACd,uCACA;KACP;cAEA,IAAI;MAlBA,EAmBE,CACT;IACE,EACN,oBAAC;GAAI,OAAO,EAAE,MAAM,GAAG;aACpB,YAAY,WAAW,UAAU,MAAM,GAAG;IACvC;GACF;EAER"}