@robosystems/core 0.9.2 → 0.9.4
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.
package/package.json
CHANGED
|
@@ -4,6 +4,12 @@ export interface CoreNavbarProps {
|
|
|
4
4
|
currentApp: 'roboledger' | 'roboinvestor' | 'robosystems';
|
|
5
5
|
apiUrl?: string;
|
|
6
6
|
homeHref?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Where the user menu's Documentation item points. Defaults to this app's own
|
|
9
|
+
* `/docs`; an app without docs of its own passes an absolute URL. `null` drops
|
|
10
|
+
* the item.
|
|
11
|
+
*/
|
|
12
|
+
docsHref?: string | null;
|
|
7
13
|
logoAltText?: string;
|
|
8
14
|
additionalComponents?: React.ReactNode;
|
|
9
15
|
className?: string;
|
|
@@ -11,4 +17,4 @@ export interface CoreNavbarProps {
|
|
|
11
17
|
useCustomThemeToggle?: boolean;
|
|
12
18
|
showAppSwitcherFirst?: boolean;
|
|
13
19
|
}
|
|
14
|
-
export declare function CoreNavbar({ appName, currentApp, apiUrl, homeHref, logoAltText, additionalComponents, className, borderColorClass, useCustomThemeToggle, showAppSwitcherFirst, }: CoreNavbarProps): React.JSX.Element;
|
|
20
|
+
export declare function CoreNavbar({ appName, currentApp, apiUrl, homeHref, docsHref, logoAltText, additionalComponents, className, borderColorClass, useCustomThemeToggle, showAppSwitcherFirst, }: CoreNavbarProps): React.JSX.Element;
|
|
@@ -12,7 +12,7 @@ import { LogoBadge } from '../Logo';
|
|
|
12
12
|
import { useAccountSettingsLink } from './account-settings';
|
|
13
13
|
import { ThemeToggle } from './ThemeToggle';
|
|
14
14
|
export function CoreNavbar({ appName, currentApp, apiUrl = process.env.NEXT_PUBLIC_ROBOSYSTEMS_API_URL ||
|
|
15
|
-
'http://localhost:8000', homeHref = '/home', logoAltText, additionalComponents, className = '', borderColorClass = 'dark:border-gray-700', useCustomThemeToggle = true, showAppSwitcherFirst = false, }) {
|
|
15
|
+
'http://localhost:8000', homeHref = '/home', docsHref = '/docs', logoAltText, additionalComponents, className = '', borderColorClass = 'dark:border-gray-700', useCustomThemeToggle = true, showAppSwitcherFirst = false, }) {
|
|
16
16
|
const sidebar = useSidebarContext();
|
|
17
17
|
const isDesktop = useMediaQuery('(min-width: 1024px)');
|
|
18
18
|
const { user } = useUser();
|
|
@@ -44,13 +44,18 @@ export function CoreNavbar({ appName, currentApp, apiUrl = process.env.NEXT_PUBL
|
|
|
44
44
|
return (_jsxs(_Fragment, { children: [_jsx("div", { className: "hidden dark:block", children: _jsx(Tooltip, { content: "Toggle light mode", theme: customTheme.tooltip, children: _jsx(DarkThemeToggle, {}) }) }), _jsx("div", { className: "dark:hidden", children: _jsx(Tooltip, { content: "Toggle dark mode", theme: customTheme.tooltip, children: _jsx(DarkThemeToggle, {}) }) })] }));
|
|
45
45
|
};
|
|
46
46
|
const renderAppSwitcher = () => (_jsx(Tooltip, { content: "Switch apps", theme: customTheme.tooltip, children: _jsx(AppSwitcher, { apiUrl: apiUrl, currentApp: currentApp }) }));
|
|
47
|
-
return (_jsx(FlowbiteNavbar, { fluid: true, theme: customTheme.navbar, className: `fixed top-0 z-30 w-full border-b border-gray-200 p-0 ${borderColorClass} bg-white sm:p-0 dark:bg-black ${className}`, children: _jsx("div", { className: "w-full p-3 pr-4", children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center", children: [_jsxs("button", { onClick: handleToggleSidebar, className: "mr-3 cursor-pointer rounded-sm p-2 text-gray-600 hover:bg-zinc-100 hover:text-gray-900 dark:text-gray-400 dark:hover:bg-zinc-700 dark:hover:text-white", children: [_jsx("span", { className: "sr-only", children: "Toggle sidebar" }), _jsx("div", { className: "lg:hidden", children: sidebar.mobile.isOpen ? (_jsx(HiX, { className: "h-6 w-6" })) : (_jsx(HiMenuAlt1, { className: "h-6 w-6" })) }), _jsx("div", { className: "hidden lg:block", children: _jsx(HiMenuAlt1, { className: "h-6 w-6" }) })] }), _jsxs(NavbarBrand, { as: Link, href: homeHref, className: "mr-14", children: [_jsx(LogoBadge, { app: currentApp, animate: "once", className: "mr-2 h-10 w-10" }), _jsx("span", { className: "font-heading mt-2 ml-1 self-center text-2xl font-semibold whitespace-nowrap text-gray-900 dark:text-white", children: appName })] })] }), _jsx("div", { className: "flex items-center lg:gap-3", children: _jsxs("div", { className: "flex items-center", children: [additionalComponents && (_jsx("div", { className: "mr-2 hidden md:block", children: additionalComponents })), _jsxs("div", { className: "flex items-center space-x-2", children: [showAppSwitcherFirst && renderAppSwitcher(), renderThemeToggle(), !showAppSwitcherFirst && renderAppSwitcher(), _jsx(UserDropdown, { user: user, apiUrl: apiUrl, onLogout: handleLogout })] })] }) })] }) }) }));
|
|
47
|
+
return (_jsx(FlowbiteNavbar, { fluid: true, theme: customTheme.navbar, className: `fixed top-0 z-30 w-full border-b border-gray-200 p-0 ${borderColorClass} bg-white sm:p-0 dark:bg-black ${className}`, children: _jsx("div", { className: "w-full p-3 pr-4", children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center", children: [_jsxs("button", { onClick: handleToggleSidebar, className: "mr-3 cursor-pointer rounded-sm p-2 text-gray-600 hover:bg-zinc-100 hover:text-gray-900 dark:text-gray-400 dark:hover:bg-zinc-700 dark:hover:text-white", children: [_jsx("span", { className: "sr-only", children: "Toggle sidebar" }), _jsx("div", { className: "lg:hidden", children: sidebar.mobile.isOpen ? (_jsx(HiX, { className: "h-6 w-6" })) : (_jsx(HiMenuAlt1, { className: "h-6 w-6" })) }), _jsx("div", { className: "hidden lg:block", children: _jsx(HiMenuAlt1, { className: "h-6 w-6" }) })] }), _jsxs(NavbarBrand, { as: Link, href: homeHref, className: "mr-14", children: [_jsx(LogoBadge, { app: currentApp, animate: "once", className: "mr-2 h-10 w-10" }), _jsx("span", { className: "font-heading mt-2 ml-1 self-center text-2xl font-semibold whitespace-nowrap text-gray-900 dark:text-white", children: appName })] })] }), _jsx("div", { className: "flex items-center lg:gap-3", children: _jsxs("div", { className: "flex items-center", children: [additionalComponents && (_jsx("div", { className: "mr-2 hidden md:block", children: additionalComponents })), _jsxs("div", { className: "flex items-center space-x-2", children: [showAppSwitcherFirst && renderAppSwitcher(), renderThemeToggle(), !showAppSwitcherFirst && renderAppSwitcher(), _jsx(UserDropdown, { user: user, apiUrl: apiUrl, docsHref: docsHref, onLogout: handleLogout })] })] }) })] }) }) }));
|
|
48
48
|
}
|
|
49
|
-
function UserDropdown({ user, apiUrl, onLogout }) {
|
|
49
|
+
function UserDropdown({ user, apiUrl, docsHref, onLogout }) {
|
|
50
50
|
const settings = useAccountSettingsLink(apiUrl);
|
|
51
51
|
return (_jsx("div", { className: "relative", children: _jsxs(Dropdown, { theme: Object.assign(Object.assign({}, customTheme.dropdown), { floating: Object.assign(Object.assign({}, customTheme.dropdown.floating), { base: `${customTheme.dropdown.floating.base} z-50! w-64` }) }), arrowIcon: false, inline: true, label: _jsxs("span", { className: "inline-flex h-10 w-10 items-center justify-center rounded-lg text-sm text-gray-500 hover:bg-zinc-100 focus:ring-2 focus:ring-gray-200 focus:outline-hidden dark:text-gray-400 dark:hover:bg-zinc-700 dark:focus:ring-gray-600", children: [_jsx("span", { className: "sr-only", children: "User menu" }), _jsx(HiUserCircle, { className: "h-6 w-6" })] }), children: [_jsxs(DropdownHeader, { theme: { header: customTheme.dropdown.floating.header }, className: "px-4 py-3", children: [_jsx("div", { className: "block text-sm font-medium text-gray-900 dark:text-white", children: (user === null || user === void 0 ? void 0 : user.name) || 'User' }), (user === null || user === void 0 ? void 0 : user.email) && (_jsx("div", { className: "block truncate text-sm text-gray-500 dark:text-gray-400", children: user.email }))] }), settings.isCrossApp ? (_jsxs(DropdownItem, { theme: customTheme.dropdown.floating.item, onClick: () => {
|
|
52
52
|
void settings.open();
|
|
53
|
-
}, title: settings.description, className: "flex w-full items-center justify-between p-3", children: [_jsx("span", { children: "User Settings" }), _jsx(HiExternalLink, { "aria-hidden": "true", className: "ml-3 h-4 w-4 shrink-0 text-gray-400 dark:text-gray-500" }), _jsx("span", { className: "sr-only", children: ` (opens ${settings.hostAppName} in a new tab)` })] })) : (_jsx(DropdownItem, { theme: customTheme.dropdown.floating.item, as: Link, href: settings.href, className: "flex w-full items-center space-x-3 p-3", children: "User Settings" })),
|
|
53
|
+
}, title: settings.description, className: "flex w-full items-center justify-between p-3", children: [_jsx("span", { children: "User Settings" }), _jsx(HiExternalLink, { "aria-hidden": "true", className: "ml-3 h-4 w-4 shrink-0 text-gray-400 dark:text-gray-500" }), _jsx("span", { className: "sr-only", children: ` (opens ${settings.hostAppName} in a new tab)` })] })) : (_jsx(DropdownItem, { theme: customTheme.dropdown.floating.item, as: Link, href: settings.href, className: "flex w-full items-center space-x-3 p-3", children: "User Settings" })), docsHref && (
|
|
54
|
+
// The docs wear the public site's chrome, so they open in a new tab and
|
|
55
|
+
// the app keeps its place. This is the app's only global route to them:
|
|
56
|
+
// a signed-in visitor to / is sent to /home and never sees the public
|
|
57
|
+
// header's links.
|
|
58
|
+
_jsxs(DropdownItem, { theme: customTheme.dropdown.floating.item, as: Link, href: docsHref, target: "_blank", rel: "noopener noreferrer", className: "flex w-full items-center justify-between p-3", children: [_jsx("span", { children: "Documentation" }), _jsx(HiExternalLink, { "aria-hidden": "true", className: "ml-3 h-4 w-4 shrink-0 text-gray-400 dark:text-gray-500" }), _jsx("span", { className: "sr-only", children: " (opens in a new tab)" })] })), _jsx(DropdownDivider, { theme: { divider: customTheme.dropdown.floating.divider } }), _jsx(DropdownItem, { theme: customTheme.dropdown.floating.item, onClick: () => {
|
|
54
59
|
onLogout();
|
|
55
60
|
}, className: "flex w-full items-center space-x-3 p-3", children: "Sign out" })] }) }));
|
|
56
61
|
}
|
|
@@ -23,13 +23,25 @@ function MobileSidebar({ navigationItems, features, bottomMenuActions, additiona
|
|
|
23
23
|
return null;
|
|
24
24
|
return (_jsxs(_Fragment, { children: [_jsx(Sidebar, { "aria-label": "Sidebar with multi-level dropdown example", theme: customTheme.sidebar, className: twMerge(`fixed inset-y-0 left-0 z-20 hidden h-full shrink-0 flex-col border-r border-gray-200 pt-16 ${borderColorClass} lg:flex`, isOpen && 'flex'), id: "sidebar", children: _jsxs("div", { className: "flex h-full flex-col justify-between", children: [_jsxs("div", { className: "py-2", children: [additionalMobileComponents && (_jsx("div", { className: "hidden pb-2 max-md:block", children: additionalMobileComponents })), _jsxs(SidebarItems, { children: [_jsx(OrgSection, { isCollapsed: false, showOrgSection: features.showOrgSection }), _jsx(SidebarItemGroup, { className: "mt-0 border-t-0 pt-2 pb-1", children: navigationItems.map((item) => (_jsx(CustomSidebarItem, Object.assign({}, item, { pathname: pathname }), item.label))) })] })] }), _jsx(BottomMenu, { isCollapsed: false, features: features, bottomMenuActions: bottomMenuActions })] }) }), _jsx("div", { onClick: close, "aria-hidden": "true", className: "fixed inset-0 z-10 h-full w-full bg-zinc-900/50 pt-16 dark:bg-zinc-900/90" })] }));
|
|
25
25
|
}
|
|
26
|
+
// SidebarItem renders an <a> for an href and forwards these, but its props are typed
|
|
27
|
+
// as a div's, so they are spread rather than written as attributes. A link that opens a
|
|
28
|
+
// new tab gets noopener and noreferrer, so the page it opens can't reach back into the
|
|
29
|
+
// app's window through window.opener.
|
|
30
|
+
function newTabProps(target) {
|
|
31
|
+
return target
|
|
32
|
+
? {
|
|
33
|
+
target,
|
|
34
|
+
rel: target === '_blank' ? 'noopener noreferrer' : undefined,
|
|
35
|
+
}
|
|
36
|
+
: {};
|
|
37
|
+
}
|
|
26
38
|
function CustomSidebarItem({ href, target, icon: Icon, label, items, badge, pathname, }) {
|
|
27
39
|
if (!(items === null || items === void 0 ? void 0 : items.length)) {
|
|
28
40
|
const isExternal = target === '_blank' || (href === null || href === void 0 ? void 0 : href.startsWith('http'));
|
|
29
41
|
if (isExternal) {
|
|
30
|
-
return (_jsx(SidebarItem, { href: href || '#', icon: Icon, active: pathname === href, theme: customTheme.sidebar.item, className: pathname === href
|
|
42
|
+
return (_jsx(SidebarItem, Object.assign({ href: href || '#' }, newTabProps(target), { icon: Icon, active: pathname === href, theme: customTheme.sidebar.item, className: pathname === href
|
|
31
43
|
? 'bg-primary-50 text-primary-700 dark:bg-primary-200 dark:text-primary-800'
|
|
32
|
-
: '', children: label }));
|
|
44
|
+
: '', children: label })));
|
|
33
45
|
}
|
|
34
46
|
return (_jsx(SidebarItem, { as: Link, href: href || '#', icon: Icon, active: pathname === href, theme: customTheme.sidebar.item, className: pathname === href
|
|
35
47
|
? 'bg-zinc-100 text-gray-900 dark:bg-zinc-800 dark:text-gray-200'
|
|
@@ -39,9 +51,9 @@ function CustomSidebarItem({ href, target, icon: Icon, label, items, badge, path
|
|
|
39
51
|
var _a;
|
|
40
52
|
const isExternal = item.target === '_blank' || ((_a = item.href) === null || _a === void 0 ? void 0 : _a.startsWith('http'));
|
|
41
53
|
if (isExternal) {
|
|
42
|
-
return (_jsx(SidebarItem, { href: item.href || '#', active: pathname === item.href, theme: customTheme.sidebar.item, className: pathname === item.href
|
|
54
|
+
return (_jsx(SidebarItem, Object.assign({ href: item.href || '#' }, newTabProps(item.target), { active: pathname === item.href, theme: customTheme.sidebar.item, className: pathname === item.href
|
|
43
55
|
? 'bg-primary-50 text-primary-700 dark:bg-primary-200 dark:text-primary-800'
|
|
44
|
-
: '', children: item.label }, item.label));
|
|
56
|
+
: '', children: item.label }), item.label));
|
|
45
57
|
}
|
|
46
58
|
return (_jsx(SidebarItem, { as: Link, href: item.href || '#', active: pathname === item.href, theme: customTheme.sidebar.item, className: pathname === item.href
|
|
47
59
|
? 'bg-primary-50 text-primary-700 dark:bg-primary-200 dark:text-primary-800'
|