elbe-ui 2.0.1 → 2.0.3

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.
@@ -20,52 +20,63 @@ function _initialLocation() {
20
20
  return (window.location.pathname + window.location.search + window.location.hash);
21
21
  }
22
22
  function _App(p) {
23
+ var _a;
24
+ const theme = p.themeContext.useTheme();
25
+ const themeSelected = theme.useWith((_a = p.themeSelector) !== null && _a !== void 0 ? _a : (() => ({})), [
26
+ p.config,
27
+ p.themeSelector,
28
+ ]);
29
+ useMemo(() => {
30
+ if (p.config.noGlobalStyles)
31
+ return;
32
+ // apply global background of html and body elements
33
+ const bg = themeSelected.theme.color.currentColor.back.asCss();
34
+ document.documentElement.style.backgroundColor = bg;
35
+ document.body.style.backgroundColor = bg;
36
+ }, [themeSelected, p.config.noGlobalStyles]);
23
37
  const menuItems = useMemo(() => {
24
38
  return _extractMenuItems(p.children);
25
39
  }, [p.children]);
26
40
  const [location, navigate] = Wouter.useLocation();
27
41
  const [history, setHistory] = useState([_initialLocation()]);
28
42
  const [menuOpen, setMenuOpen] = useState(false);
29
- /*const themeSelected = p.themeContext
30
- .useTheme()
31
- .useWith(p.themeSelector ?? (() => ({})), [p.config, p.themeSelector]);*/
32
- return (_jsx(AppContext.Provider, { value: {
33
- appConfig: p.config,
34
- _appThemeContext: p.themeContext,
35
- router: {
36
- goBack: (steps = 1) => {
37
- if (history.length === 0)
38
- return;
39
- const targetIndex = Math.max(0, history.length - 1 - steps);
40
- const target = history[targetIndex];
41
- setHistory((h) => h.slice(0, targetIndex + 1));
42
- navigate(target, { replace: true });
43
- },
44
- go: (p, replace) => {
45
- setHistory((h) => {
46
- if (replace === "all")
47
- return [p];
48
- const repl = Math.max(0, replace !== null && replace !== void 0 ? replace : 0);
49
- if (repl === 0)
50
- return [...h, p];
51
- return [...h.slice(0, -repl), p];
52
- });
53
- navigate(p, { replace: (replace !== null && replace !== void 0 ? replace : 0) !== 0 });
54
- },
55
- history: history,
56
- location: location,
57
- },
58
- menu: menuItems.length === 0
59
- ? undefined
60
- : {
61
- isOpen: menuOpen,
62
- setOpen: (s) => setMenuOpen(s),
43
+ return (_jsx(p.themeContext.WithTheme, { theme: themeSelected, children: _jsx(AppContext.Provider, { value: {
44
+ appConfig: p.config,
45
+ _appThemeContext: p.themeContext,
46
+ router: {
47
+ goBack: (steps = 1) => {
48
+ if (history.length === 0)
49
+ return;
50
+ const targetIndex = Math.max(0, history.length - 1 - steps);
51
+ const target = history[targetIndex];
52
+ setHistory((h) => h.slice(0, targetIndex + 1));
53
+ navigate(target, { replace: true });
54
+ },
55
+ go: (p, replace) => {
56
+ setHistory((h) => {
57
+ if (replace === "all")
58
+ return [p];
59
+ const repl = Math.max(0, replace !== null && replace !== void 0 ? replace : 0);
60
+ if (repl === 0)
61
+ return [...h, p];
62
+ return [...h.slice(0, -repl), p];
63
+ });
64
+ navigate(p, { replace: (replace !== null && replace !== void 0 ? replace : 0) !== 0 });
65
+ },
66
+ history: history,
67
+ location: location,
63
68
  },
64
- }, children: _jsx(ToastProvider, { children: _jsx(DialogsProvider, { children: _jsxs(Box, { typeLabel: "app_base", scheme: "primary", style: {
65
- display: "flex",
66
- width: "100%",
67
- minHeight: "100vh",
68
- }, children: [menuItems.length > 0 && _jsx(Menu, { items: menuItems }), _jsx("div", { style: { flex: 1, width: "0px" }, children: _jsx(Wouter.Switch, { children: p.children }) })] }) }) }) }));
69
+ menu: menuItems.length === 0
70
+ ? undefined
71
+ : {
72
+ isOpen: menuOpen,
73
+ setOpen: (s) => setMenuOpen(s),
74
+ },
75
+ }, children: _jsx(ToastProvider, { children: _jsx(DialogsProvider, { children: _jsxs(Box, { typeLabel: "app_base", scheme: "primary", style: {
76
+ display: "flex",
77
+ width: "100%",
78
+ minHeight: "100vh",
79
+ }, children: [menuItems.length > 0 && _jsx(Menu, { items: menuItems }), _jsx("div", { style: { flex: 1, width: "0px" }, children: _jsx(Wouter.Switch, { children: p.children }) })] }) }) }) }) }));
69
80
  }
70
81
  function _extractMenuItems(children) {
71
82
  if (!children)
@@ -9,6 +9,8 @@ export type AppConfig = {
9
9
  routerConfig?: {
10
10
  basePath?: string;
11
11
  };
12
+ /** If true, global styles will not be applied. This can be useful for embedding Elbe in an existing app with its own styles. */
13
+ noGlobalStyles?: boolean;
12
14
  };
13
15
  type _MenuState = {
14
16
  isOpen: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elbe-ui",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "author": "Robin Naumann",
5
5
  "license": "MIT",
6
6
  "repository": {