UNPKG

@vectara/vectara-ui

Version:

Vectara's design system, codified as a React and Sass component library

35 lines (34 loc) 1.63 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { jsx as _jsx } from "react/jsx-runtime"; import { createContext, useContext } from "react"; const VuiContext = createContext(undefined); export const VuiContextProvider = ({ children, linkProvider, pathProvider, drawerTitle = "h2" }) => { const createLink = (linkConfig) => { if (linkProvider) return linkProvider(linkConfig); const { className, href, onClick, children } = linkConfig, rest = __rest(linkConfig, ["className", "href", "onClick", "children"]); return (_jsx("a", Object.assign({ className: className, href: href, onClick: onClick }, rest, { children: children }))); }; const getPath = () => { return pathProvider ? pathProvider() : window.location.pathname; }; const DrawerTitle = drawerTitle; return _jsx(VuiContext.Provider, Object.assign({ value: { createLink, getPath, DrawerTitle } }, { children: children })); }; export const useVuiContext = () => { const context = useContext(VuiContext); if (context === undefined) { throw new Error("useVuiContext must be used within a VuiContextProvider"); } return context; };