elbe-ui 0.4.12 → 0.4.15

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.
@@ -1,9 +1,12 @@
1
+ import { VNode } from "preact";
2
+ import { NestedArray } from "preact-iso";
1
3
  import { ElbeChild, HeaderLogos } from "../../..";
2
4
  import { MenuItem } from "./menu";
3
5
  export type AppBaseProps = HeaderLogos & {
4
6
  initial?: string;
5
7
  menu: MenuItem[];
6
8
  globalActions?: ElbeChild[];
9
+ children: NestedArray<VNode>;
7
10
  };
8
11
  /**
9
12
  * app base is a layout component that provides a side menu and a content area.
@@ -11,4 +14,8 @@ export type AppBaseProps = HeaderLogos & {
11
14
  * used to create a consistent layout for pages. You can also pass global actions
12
15
  * that will be displayed in the header of all pages.
13
16
  */
14
- export declare function AppBase(p: AppBaseProps): import("preact/compat").JSX.Element;
17
+ export declare function AppBase(p: AppBaseProps): import("preact").JSX.Element;
18
+ export declare const Redirect: (p: {
19
+ path: string;
20
+ to: string;
21
+ }) => null;
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
- import { useState } from "preact/compat";
2
+ import { Router, useLocation } from "preact-iso";
3
+ import { useEffect, useState } from "preact/compat";
3
4
  import { Box } from "../../..";
4
5
  import { AppBaseContext } from "./ctx_app_base";
5
6
  import { Menu } from "./menu";
@@ -10,19 +11,28 @@ import { Menu } from "./menu";
10
11
  * that will be displayed in the header of all pages.
11
12
  */
12
13
  export function AppBase(p) {
13
- var _a, _b, _c, _d, _e, _f;
14
- const [state, setState] = useState({
15
- menuSelected: (_c = (_a = p.initial) !== null && _a !== void 0 ? _a : (_b = p.menu[0]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : null,
16
- menuOpen: false,
17
- });
18
- return (_jsx(AppBaseContext.Provider, { value: Object.assign(Object.assign({}, state), { icons: {
14
+ var _a, _b;
15
+ const [menuOpen, setMenuOpen] = useState(false);
16
+ return (_jsx(AppBaseContext.Provider, { value: {
17
+ menuOpen: menuOpen,
18
+ icons: {
19
19
  logo: p.logo,
20
20
  logoDark: p.logoDark,
21
21
  endLogo: p.endLogo,
22
22
  endLogoDark: p.endLogoDark,
23
- }, globalActions: (_d = p.globalActions) !== null && _d !== void 0 ? _d : [], setMenuOpen: (b) => setState(Object.assign(Object.assign({}, state), { menuOpen: b })), setMenuSelected: (s) => setState(Object.assign(Object.assign({}, state), { menuSelected: s })) }), children: _jsxs(Box, { scheme: "primary", style: {
23
+ },
24
+ globalActions: (_a = p.globalActions) !== null && _a !== void 0 ? _a : [],
25
+ setMenuOpen: (b) => setMenuOpen(b),
26
+ }, children: _jsxs(Box, { scheme: "primary", style: {
24
27
  display: "flex",
25
28
  width: "100%",
26
29
  minHeight: "100vh",
27
- }, children: [_jsx(Menu, { items: p.menu }), _jsx("div", { style: { flex: 1 }, children: (_f = (_e = p.menu.find((i) => i.id == state.menuSelected)) === null || _e === void 0 ? void 0 : _e.component) !== null && _f !== void 0 ? _f : _jsx("div", {}) })] }) }));
30
+ }, children: [_jsx(Menu, { items: p.menu }), _jsx("div", { style: { flex: 1 }, children: _jsxs(Router, { children: [_jsx(Redirect, { path: "/", to: `/${(_b = p.initial) !== null && _b !== void 0 ? _b : p.menu[0].id}` }), p.children] }) })] }) }));
28
31
  }
32
+ export const Redirect = (p) => {
33
+ const location = useLocation();
34
+ useEffect(() => {
35
+ location.route(p.to, true);
36
+ }, [p.to]);
37
+ return null; // This component doesn't render anything
38
+ };
@@ -1,14 +1,12 @@
1
1
  import { ElbeChild } from "../../util/types";
2
2
  import { HeaderLogos } from "./header";
3
3
  export interface _AppBaseState {
4
- menuSelected: string | null;
5
4
  menuOpen: boolean;
6
5
  icons: HeaderLogos;
7
6
  globalActions: ElbeChild[];
8
7
  }
9
8
  interface _AppBaseControl extends _AppBaseState {
10
9
  setMenuOpen: (open: boolean) => void;
11
- setMenuSelected: (selected: string) => void;
12
10
  }
13
11
  export declare const AppBaseContext: import("preact").Context<_AppBaseControl | null>;
14
12
  export declare function useAppBase(): _AppBaseControl;
@@ -1,11 +1,10 @@
1
- import { ElbeChild } from "../../..";
2
1
  import { IconChild } from "../button/icon_button";
3
2
  export type MenuItem = {
4
3
  id: string;
5
4
  label: string;
6
5
  icon?: IconChild;
7
6
  bottom?: boolean;
8
- component?: ElbeChild;
7
+ disabled?: boolean;
9
8
  };
10
9
  export declare function Menu(p: {
11
10
  items: MenuItem[];
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "preact/jsx-runtime";
2
2
  import { MenuIcon } from "lucide-react";
3
+ import { useLocation } from "preact-iso";
3
4
  import { useLayoutMode, useTheme, useThemeConfig } from "../../..";
4
5
  import { Card, elevatedShadow } from "../base/card";
5
6
  import { Button } from "../button/button";
@@ -52,8 +53,7 @@ export function Menu(p) {
52
53
  } }), _jsx(Column, { flex: 1, scroll: true, noScrollbar: true, children: topBot.top.map((i) => (_jsx(_MenuItemView, { item: i }))) }), topBot.bottom.map((i) => (_jsx(_MenuItemView, { item: i })))] })) })] }));
53
54
  }
54
55
  function _MenuItemView({ item }) {
56
+ const location = useLocation();
55
57
  const appBase = useAppBase();
56
- return (_jsx(Button, { ariaLabel: item.label, contentAlign: "start", manner: item.id === appBase.menuSelected ? "major" : "plain", label: appBase.menuOpen ? item.label : undefined, icon: item.icon, onTap: item.component != null
57
- ? () => appBase.setMenuSelected(item.id)
58
- : undefined }));
58
+ return (_jsx(Button, { ariaLabel: item.label, contentAlign: "start", manner: location.path.startsWith(`/${item.id}`) ? "major" : "plain", label: appBase.menuOpen ? item.label : undefined, icon: item.icon, onTap: item.disabled ? undefined : () => location.route(`/${item.id}`, true) }));
59
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elbe-ui",
3
- "version": "0.4.12",
3
+ "version": "0.4.15",
4
4
  "author": "Robin Naumann",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,6 +38,7 @@
38
38
  "colors-convert": "^1.4.1",
39
39
  "lucide-react": "^0.438.0",
40
40
  "preact": "^10.24.2",
41
+ "preact-iso": "^2.9.1",
41
42
  "preact-router": "^4.1.2",
42
43
  "vite": "^5.4.10"
43
44
  }