@vectara/vectara-ui 16.0.1 → 16.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,9 +10,17 @@ export const VuiTabsNavigator = ({ routes, popover }) => {
10
10
  var _a;
11
11
  const { getPath } = useVuiContext();
12
12
  const [isOpen, setIsOpen] = useState(false);
13
- const activeRoute = routes.find((route) => route.isActive || getPath().includes(route.href));
14
- return (_jsx(VuiPopover, Object.assign({}, popover, { isOpen: isOpen, setIsOpen: () => setIsOpen(!isOpen), button: _jsx("button", Object.assign({ className: "vuiTabsNavigatorButton" }, { children: _jsxs("div", Object.assign({ className: "vuiTabsNavigatorButton__inner" }, { children: [_jsx(VuiIcon, Object.assign({ size: "xs" }, { children: _jsx(BiDotsVertical, {}) })), _jsx("div", { children: (_a = activeRoute === null || activeRoute === void 0 ? void 0 : activeRoute.title) !== null && _a !== void 0 ? _a : "No selection" })] })) })), padding: "none" }, { children: _jsx(VuiTabs, Object.assign({ size: "s", tabStyle: "enclosed", vertical: true }, { children: routes.map(({ href, title, render, testId, isActive }, index) => {
15
- const tabLink = (_jsx(VuiTab, Object.assign({ href: href, isActive: isActive !== null && isActive !== void 0 ? isActive : getPath().includes(href), "data-testid": testId, onClick: () => setIsOpen(false) }, { children: title }), index));
13
+ const isRouteActive = (route) => {
14
+ var _a;
15
+ return (_a = route.isActive) !== null && _a !== void 0 ? _a : (route.href ? getPath().includes(route.href) : false);
16
+ };
17
+ const activeRoute = routes.find((route) => isRouteActive(route));
18
+ return (_jsx(VuiPopover, Object.assign({}, popover, { isOpen: isOpen, setIsOpen: () => setIsOpen(!isOpen), button: _jsx("button", Object.assign({ className: "vuiTabsNavigatorButton" }, { children: _jsxs("div", Object.assign({ className: "vuiTabsNavigatorButton__inner" }, { children: [_jsx(VuiIcon, Object.assign({ size: "xs" }, { children: _jsx(BiDotsVertical, {}) })), _jsx("div", { children: (_a = activeRoute === null || activeRoute === void 0 ? void 0 : activeRoute.title) !== null && _a !== void 0 ? _a : "No selection" })] })) })), padding: "none" }, { children: _jsx(VuiTabs, Object.assign({ size: "s", tabStyle: "enclosed", vertical: true }, { children: routes.map((route, index) => {
19
+ const { href, onClick, title, render, testId } = route;
20
+ const tabLink = (_jsx(VuiTab, Object.assign({ href: href, isActive: isRouteActive(route), "data-testid": testId, onClick: () => {
21
+ onClick === null || onClick === void 0 ? void 0 : onClick();
22
+ setIsOpen(false);
23
+ } }, { children: title }), index));
16
24
  if (render)
17
25
  return render(tabLink);
18
26
  return tabLink;
@@ -6,7 +6,7 @@ import { useVuiContext } from "../context/Context";
6
6
  export const VuiTabbedRoutes = ({ tabs, size, sideContent, children }) => {
7
7
  const { getPath } = useVuiContext();
8
8
  return (_jsxs(_Fragment, { children: [_jsx(VuiTabs, Object.assign({ append: sideContent, size: size }, { children: tabs.map(({ href, title, render, testId, isActive }, index) => {
9
- const tabLink = (_jsx(VuiTab, Object.assign({ href: href, isActive: isActive !== null && isActive !== void 0 ? isActive : getPath().includes(href), "data-testid": testId }, { children: title }), index));
9
+ const tabLink = (_jsx(VuiTab, Object.assign({ href: href, isActive: isActive !== null && isActive !== void 0 ? isActive : (href ? getPath().includes(href) : false), "data-testid": testId }, { children: title }), index));
10
10
  if (render)
11
11
  return render(tabLink);
12
12
  return tabLink;
@@ -1,7 +1,8 @@
1
1
  export declare const TAB_SIZE: readonly ["s", "m"];
2
2
  export type TabSize = (typeof TAB_SIZE)[number];
3
3
  export type TabRoute = {
4
- href: string;
4
+ href?: string;
5
+ onClick?: () => void;
5
6
  title: React.ReactNode;
6
7
  render?: (tabLink: React.ReactNode) => React.ReactNode;
7
8
  testId?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectara/vectara-ui",
3
- "version": "16.0.1",
3
+ "version": "16.1.0",
4
4
  "homepage": "./",
5
5
  "description": "Vectara's design system, codified as a React and Sass component library",
6
6
  "author": "Vectara",
@@ -9,19 +9,22 @@ export const TabsNavigator = () => {
9
9
  href: "#home",
10
10
  title: "Home",
11
11
  testId: "home-tab",
12
- isActive: hash.endsWith("#home")
12
+ isActive: hash.endsWith("#home"),
13
+ onClick: () => console.log("Home tab clicked")
13
14
  },
14
15
  {
15
16
  href: "#profile",
16
17
  title: "Profile",
17
18
  testId: "profile-tab",
18
- isActive: hash.endsWith("#profile")
19
+ isActive: hash.endsWith("#profile"),
20
+ onClick: () => console.log("Profile tab clicked")
19
21
  },
20
22
  {
21
23
  href: "#settings",
22
24
  title: "Settings",
23
25
  testId: "settings-tab",
24
- isActive: hash.endsWith("#settings")
26
+ isActive: hash.endsWith("#settings"),
27
+ onClick: () => console.log("Settings tab clicked")
25
28
  }
26
29
  ];
27
30