@dbcdk/react-components 0.0.210 → 0.0.212

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.
Files changed (61) hide show
  1. package/README.md +6 -1
  2. package/dist/components/button/Button.cjs +2 -1
  3. package/dist/components/button/Button.d.ts +6 -1
  4. package/dist/components/button/Button.js +2 -1
  5. package/dist/components/button/Button.module.css +14 -0
  6. package/dist/components/color-scheme-button/ColorSchemeButton.cjs +2 -2
  7. package/dist/components/color-scheme-button/ColorSchemeButton.js +2 -2
  8. package/dist/components/forms/file-upload/FileUpload.cjs +4 -0
  9. package/dist/components/forms/file-upload/FileUpload.js +4 -0
  10. package/dist/components/forms/form-select/FormSelect.cjs +4 -0
  11. package/dist/components/forms/form-select/FormSelect.d.ts +1 -1
  12. package/dist/components/forms/form-select/FormSelect.js +4 -0
  13. package/dist/components/forms/input/Input.cjs +4 -0
  14. package/dist/components/forms/input/Input.js +4 -0
  15. package/dist/components/forms/radio-buttons/RadioButtonGroup.cjs +6 -5
  16. package/dist/components/forms/radio-buttons/RadioButtonGroup.js +2 -5
  17. package/dist/components/forms/radio-buttons/RadioButtons.module.css +15 -0
  18. package/dist/components/forms/select/Select.cjs +4 -0
  19. package/dist/components/forms/select/Select.d.ts +1 -1
  20. package/dist/components/forms/select/Select.js +4 -0
  21. package/dist/components/forms/text-area/Textarea.cjs +4 -0
  22. package/dist/components/forms/text-area/Textarea.js +4 -0
  23. package/dist/components/forms/typeahead/Typeahead.cjs +109 -42
  24. package/dist/components/forms/typeahead/Typeahead.d.ts +6 -0
  25. package/dist/components/forms/typeahead/Typeahead.js +109 -42
  26. package/dist/components/forms/typeahead/Typeahead.module.css +16 -0
  27. package/dist/components/headline/CollapsibleHeadline.cjs +15 -18
  28. package/dist/components/headline/CollapsibleHeadline.d.ts +2 -2
  29. package/dist/components/headline/CollapsibleHeadline.js +15 -18
  30. package/dist/components/headline/Headline.module.css +22 -0
  31. package/dist/components/nav-bar/NavBar.d.ts +2 -1
  32. package/dist/components/sidebar/Sidebar.cjs +2 -1
  33. package/dist/components/sidebar/Sidebar.js +2 -1
  34. package/dist/components/sidebar/components/SidebarItem.cjs +36 -13
  35. package/dist/components/sidebar/components/SidebarItem.d.ts +5 -2
  36. package/dist/components/sidebar/components/SidebarItem.js +32 -13
  37. package/dist/components/sidebar/components/SidebarItem.module.css +16 -0
  38. package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.cjs +43 -116
  39. package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.d.ts +5 -5
  40. package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.js +44 -117
  41. package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.module.css +17 -25
  42. package/dist/components/sidebar/components/sidebar-container/SidebarContainer.module.css +40 -1
  43. package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.cjs +3 -2
  44. package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.d.ts +2 -2
  45. package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.js +3 -2
  46. package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.module.css +13 -10
  47. package/dist/components/sidebar/components/sidebar-items/SidebarItems.cjs +16 -22
  48. package/dist/components/sidebar/components/sidebar-items/SidebarItems.js +16 -22
  49. package/dist/components/sidebar/components/sidebar-items/SidebarItems.module.css +0 -1
  50. package/dist/components/sidebar/providers/SidebarProvider.cjs +9 -7
  51. package/dist/components/sidebar/providers/SidebarProvider.d.ts +2 -1
  52. package/dist/components/sidebar/providers/SidebarProvider.js +9 -7
  53. package/dist/components/theme-script/ThemeScript.cjs +1 -1
  54. package/dist/components/theme-script/ThemeScript.d.ts +1 -1
  55. package/dist/components/theme-script/ThemeScript.js +1 -1
  56. package/dist/hooks/useColorScheme.cjs +1 -1
  57. package/dist/hooks/useColorScheme.js +1 -1
  58. package/dist/hooks/useGetActiveTheme.cjs +1 -1
  59. package/dist/hooks/useGetActiveTheme.js +1 -1
  60. package/dist/styles/themes/dbc/colors.css +4 -4
  61. package/package.json +1 -1
@@ -17,36 +17,27 @@ function SidebarItems({ activeLink }) {
17
17
  react.useEffect(() => {
18
18
  setActiveLink(activeLink != null ? activeLink : "");
19
19
  }, [activeLink, setActiveLink]);
20
- const renderItem = (item, key) => {
20
+ const renderItem = (item, key, depth = 0) => {
21
21
  var _a, _b;
22
22
  if (item.type === "group") {
23
- return isSidebarCollapsed ? (_a = item.children) == null ? void 0 : _a.map((child, idx) => renderItem(child, `${key}-c${idx}`)) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles__default.default.group, children: [
23
+ return isSidebarCollapsed ? (_a = item.children) == null ? void 0 : _a.map((child, idx) => renderItem(child, `${key}-c${idx}`, depth)) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles__default.default.group, children: [
24
24
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.groupLabel, children: item.label }),
25
- (_b = item.children) == null ? void 0 : _b.map((child, idx) => renderItem(child, `${key}-c${idx}`))
25
+ (_b = item.children) == null ? void 0 : _b.map((child, idx) => renderItem(child, `${key}-c${idx}`, depth))
26
26
  ] }, key);
27
27
  }
28
28
  if (item.type === "expandable") {
29
- const {
30
- component: Component2,
31
- label: label2,
32
- icon: icon2,
33
- badge: badge2,
34
- children,
35
- href: href2,
36
- iconWidth: iconWidth2,
37
- truncateLabel: truncateLabel2
38
- } = item;
39
29
  return /* @__PURE__ */ jsxRuntime.jsx(
40
30
  ExpandableSidebarItem.ExpandableSidebarItem,
41
31
  {
42
- items: children,
43
- label: label2,
44
- icon: icon2,
45
- badge: badge2,
46
- href: href2,
47
- iconWidth: iconWidth2,
48
- truncateLabel: truncateLabel2,
49
- component: Component2
32
+ label: item.label,
33
+ icon: item.icon,
34
+ badge: item.badge,
35
+ href: item.href,
36
+ iconWidth: item.iconWidth,
37
+ truncateLabel: item.truncateLabel,
38
+ enabled: item.enabled,
39
+ depth,
40
+ children: item.children.map((child, idx) => renderItem(child, `${key}-c${idx}`, depth + 1))
50
41
  },
51
42
  key
52
43
  );
@@ -61,7 +52,10 @@ function SidebarItems({ activeLink }) {
61
52
  badge,
62
53
  href,
63
54
  iconWidth,
64
- truncateLabel
55
+ truncateLabel,
56
+ enabled: item.enabled,
57
+ depth,
58
+ external: item.external
65
59
  },
66
60
  key
67
61
  );
@@ -11,36 +11,27 @@ function SidebarItems({ activeLink }) {
11
11
  useEffect(() => {
12
12
  setActiveLink(activeLink != null ? activeLink : "");
13
13
  }, [activeLink, setActiveLink]);
14
- const renderItem = (item, key) => {
14
+ const renderItem = (item, key, depth = 0) => {
15
15
  var _a, _b;
16
16
  if (item.type === "group") {
17
- return isSidebarCollapsed ? (_a = item.children) == null ? void 0 : _a.map((child, idx) => renderItem(child, `${key}-c${idx}`)) : /* @__PURE__ */ jsxs("div", { className: styles.group, children: [
17
+ return isSidebarCollapsed ? (_a = item.children) == null ? void 0 : _a.map((child, idx) => renderItem(child, `${key}-c${idx}`, depth)) : /* @__PURE__ */ jsxs("div", { className: styles.group, children: [
18
18
  /* @__PURE__ */ jsx("div", { className: styles.groupLabel, children: item.label }),
19
- (_b = item.children) == null ? void 0 : _b.map((child, idx) => renderItem(child, `${key}-c${idx}`))
19
+ (_b = item.children) == null ? void 0 : _b.map((child, idx) => renderItem(child, `${key}-c${idx}`, depth))
20
20
  ] }, key);
21
21
  }
22
22
  if (item.type === "expandable") {
23
- const {
24
- component: Component2,
25
- label: label2,
26
- icon: icon2,
27
- badge: badge2,
28
- children,
29
- href: href2,
30
- iconWidth: iconWidth2,
31
- truncateLabel: truncateLabel2
32
- } = item;
33
23
  return /* @__PURE__ */ jsx(
34
24
  ExpandableSidebarItem,
35
25
  {
36
- items: children,
37
- label: label2,
38
- icon: icon2,
39
- badge: badge2,
40
- href: href2,
41
- iconWidth: iconWidth2,
42
- truncateLabel: truncateLabel2,
43
- component: Component2
26
+ label: item.label,
27
+ icon: item.icon,
28
+ badge: item.badge,
29
+ href: item.href,
30
+ iconWidth: item.iconWidth,
31
+ truncateLabel: item.truncateLabel,
32
+ enabled: item.enabled,
33
+ depth,
34
+ children: item.children.map((child, idx) => renderItem(child, `${key}-c${idx}`, depth + 1))
44
35
  },
45
36
  key
46
37
  );
@@ -55,7 +46,10 @@ function SidebarItems({ activeLink }) {
55
46
  badge,
56
47
  href,
57
48
  iconWidth,
58
- truncateLabel
49
+ truncateLabel,
50
+ enabled: item.enabled,
51
+ depth,
52
+ external: item.external
59
53
  },
60
54
  key
61
55
  );
@@ -1,7 +1,6 @@
1
1
  .group {
2
2
  display: flex;
3
3
  flex-direction: column;
4
- gap: var(--spacing-xxs);
5
4
  margin-top: var(--spacing-xs);
6
5
  }
7
6
 
@@ -17,10 +17,10 @@ const findExpandableParentChain = (targetHref, items) => {
17
17
  const dfs = (nodes, parentExpandables) => {
18
18
  for (const node of nodes) {
19
19
  const nodeHref = hasHref(node) ? normalizeHref(node.href) : null;
20
- const isExpandableParent = hasChildren(node) && hasHref(node);
20
+ const isExpandableParent = node.type === "expandable";
21
21
  const nextParents = isExpandableParent && nodeHref ? [...parentExpandables, nodeHref] : parentExpandables;
22
- if (nodeHref === target) {
23
- return isExpandableParent ? nextParents : parentExpandables;
22
+ if (node.type !== "expandable" && nodeHref === target) {
23
+ return parentExpandables;
24
24
  }
25
25
  if (hasChildren(node)) {
26
26
  const found = dfs(node.children, nextParents);
@@ -66,6 +66,7 @@ function SidebarProvider({
66
66
  children,
67
67
  items,
68
68
  initialQuery,
69
+ initialActiveLink = "",
69
70
  initialCollapsed = false,
70
71
  initialSidebarCollapsed
71
72
  }) {
@@ -73,8 +74,10 @@ function SidebarProvider({
73
74
  const [activeQuery, setActiveQuery] = react.useState(initialQuery != null ? initialQuery : "");
74
75
  const [wrapItemText, setWrapItemText] = react.useState(false);
75
76
  const [areItemsCollapsed, setItemsCollapsed] = react.useState(initialCollapsed);
76
- const [activeHref, setActiveHref] = react.useState("");
77
- const [expandedItems, setExpandedItems] = react.useState(/* @__PURE__ */ new Set());
77
+ const [activeHref, setActiveHref] = react.useState(initialActiveLink);
78
+ const [expandedItems, setExpandedItems] = react.useState(
79
+ () => new Set(findExpandableParentChain(initialActiveLink, items))
80
+ );
78
81
  const itemsRef = react.useRef(items);
79
82
  react.useEffect(() => {
80
83
  itemsRef.current = items;
@@ -121,8 +124,7 @@ function SidebarProvider({
121
124
  );
122
125
  react.useEffect(() => {
123
126
  if (!activeHref) return;
124
- const currentItems = itemsRef.current;
125
- const parents = findExpandableParentChain(activeHref, currentItems);
127
+ const parents = findExpandableParentChain(activeHref, itemsRef.current);
126
128
  if (parents.length === 0) return;
127
129
  setExpandedItems((prev) => {
128
130
  let changed = false;
@@ -24,11 +24,12 @@ export type SidebarContextValue = {
24
24
  type SidebarProviderProps = {
25
25
  children: React.ReactNode;
26
26
  items: NavBarItem[];
27
+ initialActiveLink?: string;
27
28
  initialQuery?: string | null;
28
29
  initialCollapsed?: boolean;
29
30
  initialCollapseChildren?: boolean;
30
31
  initialSidebarCollapsed?: boolean;
31
32
  };
32
- export declare function SidebarProvider({ children, items, initialQuery, initialCollapsed, initialSidebarCollapsed, }: SidebarProviderProps): JSX.Element;
33
+ export declare function SidebarProvider({ children, items, initialQuery, initialActiveLink, initialCollapsed, initialSidebarCollapsed, }: SidebarProviderProps): JSX.Element;
33
34
  export declare function useSidebar(): SidebarContextValue;
34
35
  export {};
@@ -15,10 +15,10 @@ const findExpandableParentChain = (targetHref, items) => {
15
15
  const dfs = (nodes, parentExpandables) => {
16
16
  for (const node of nodes) {
17
17
  const nodeHref = hasHref(node) ? normalizeHref(node.href) : null;
18
- const isExpandableParent = hasChildren(node) && hasHref(node);
18
+ const isExpandableParent = node.type === "expandable";
19
19
  const nextParents = isExpandableParent && nodeHref ? [...parentExpandables, nodeHref] : parentExpandables;
20
- if (nodeHref === target) {
21
- return isExpandableParent ? nextParents : parentExpandables;
20
+ if (node.type !== "expandable" && nodeHref === target) {
21
+ return parentExpandables;
22
22
  }
23
23
  if (hasChildren(node)) {
24
24
  const found = dfs(node.children, nextParents);
@@ -64,6 +64,7 @@ function SidebarProvider({
64
64
  children,
65
65
  items,
66
66
  initialQuery,
67
+ initialActiveLink = "",
67
68
  initialCollapsed = false,
68
69
  initialSidebarCollapsed
69
70
  }) {
@@ -71,8 +72,10 @@ function SidebarProvider({
71
72
  const [activeQuery, setActiveQuery] = useState(initialQuery != null ? initialQuery : "");
72
73
  const [wrapItemText, setWrapItemText] = useState(false);
73
74
  const [areItemsCollapsed, setItemsCollapsed] = useState(initialCollapsed);
74
- const [activeHref, setActiveHref] = useState("");
75
- const [expandedItems, setExpandedItems] = useState(/* @__PURE__ */ new Set());
75
+ const [activeHref, setActiveHref] = useState(initialActiveLink);
76
+ const [expandedItems, setExpandedItems] = useState(
77
+ () => new Set(findExpandableParentChain(initialActiveLink, items))
78
+ );
76
79
  const itemsRef = useRef(items);
77
80
  useEffect(() => {
78
81
  itemsRef.current = items;
@@ -119,8 +122,7 @@ function SidebarProvider({
119
122
  );
120
123
  useEffect(() => {
121
124
  if (!activeHref) return;
122
- const currentItems = itemsRef.current;
123
- const parents = findExpandableParentChain(activeHref, currentItems);
125
+ const parents = findExpandableParentChain(activeHref, itemsRef.current);
124
126
  if (parents.length === 0) return;
125
127
  setExpandedItems((prev) => {
126
128
  let changed = false;
@@ -50,7 +50,7 @@ function buildInitScript(defaultColorScheme, defaultTheme, storageKey, colorSche
50
50
  })();`;
51
51
  }
52
52
  function ThemeScript({
53
- defaultColorScheme = "system",
53
+ defaultColorScheme = "light",
54
54
  defaultTheme,
55
55
  storageKey = theme_constants.THEME_STORAGE_KEY,
56
56
  colorSchemeStorageKey = colorScheme_constants.COLOR_SCHEME_STORAGE_KEY
@@ -1,7 +1,7 @@
1
1
  import type { ThemeId } from '../../styles/themes/types';
2
2
  import type { ColorScheme } from '../../utils/color-scheme.constants';
3
3
  export interface ThemeScriptProps {
4
- /** Color scheme applied when nothing is stored yet. Defaults to 'system'. */
4
+ /** Color scheme applied when nothing is stored yet. Defaults to 'light'. */
5
5
  defaultColorScheme?: ColorScheme;
6
6
  /**
7
7
  * The product theme the app already loads via a normal static import. Omit
@@ -48,7 +48,7 @@ function buildInitScript(defaultColorScheme, defaultTheme, storageKey, colorSche
48
48
  })();`;
49
49
  }
50
50
  function ThemeScript({
51
- defaultColorScheme = "system",
51
+ defaultColorScheme = "light",
52
52
  defaultTheme,
53
53
  storageKey = THEME_STORAGE_KEY,
54
54
  colorSchemeStorageKey = COLOR_SCHEME_STORAGE_KEY
@@ -63,7 +63,7 @@ function switchColorSchemeInternal(storageKey, id, persistence) {
63
63
  notify();
64
64
  return id;
65
65
  }
66
- function useColorScheme(initialColorScheme = "system", options = {}) {
66
+ function useColorScheme(initialColorScheme = "light", options = {}) {
67
67
  const { storageKey = colorScheme_constants.COLOR_SCHEME_STORAGE_KEY, persistence = "both" } = options;
68
68
  react.useEffect(() => {
69
69
  ensureResolved(initialColorScheme, storageKey, persistence);
@@ -61,7 +61,7 @@ function switchColorSchemeInternal(storageKey, id, persistence) {
61
61
  notify();
62
62
  return id;
63
63
  }
64
- function useColorScheme(initialColorScheme = "system", options = {}) {
64
+ function useColorScheme(initialColorScheme = "light", options = {}) {
65
65
  const { storageKey = COLOR_SCHEME_STORAGE_KEY, persistence = "both" } = options;
66
66
  useEffect(() => {
67
67
  ensureResolved(initialColorScheme, storageKey, persistence);
@@ -7,7 +7,7 @@ var useTheme = require('./useTheme');
7
7
  function useGetActiveTheme(options = {}) {
8
8
  const { storageKey, colorSchemeStorageKey } = options;
9
9
  const { theme } = useTheme.useTheme({ storageKey });
10
- const { colorScheme } = useColorScheme.useColorScheme("system", { storageKey: colorSchemeStorageKey });
10
+ const { colorScheme } = useColorScheme.useColorScheme(void 0, { storageKey: colorSchemeStorageKey });
11
11
  const themeKey = theme && colorScheme ? `${theme}-${colorScheme}` : null;
12
12
  return { theme, colorScheme, themeKey };
13
13
  }
@@ -5,7 +5,7 @@ import { useTheme } from './useTheme';
5
5
  function useGetActiveTheme(options = {}) {
6
6
  const { storageKey, colorSchemeStorageKey } = options;
7
7
  const { theme } = useTheme({ storageKey });
8
- const { colorScheme } = useColorScheme("system", { storageKey: colorSchemeStorageKey });
8
+ const { colorScheme } = useColorScheme(void 0, { storageKey: colorSchemeStorageKey });
9
9
  const themeKey = theme && colorScheme ? `${theme}-${colorScheme}` : null;
10
10
  return { theme, colorScheme, themeKey };
11
11
  }
@@ -3,11 +3,11 @@ html {
3
3
  * PRIMITIVES (THEME-DEPENDENT)
4
4
  * ======================================================================= */
5
5
 
6
- color-scheme: light dark;
6
+ color-scheme: light;
7
7
 
8
- /*@media (prefers-color-scheme: dark) {*/
9
- /* color-scheme: dark;*/
10
- /*}*/
8
+ &[data-theme='system'] {
9
+ color-scheme: light dark;
10
+ }
11
11
 
12
12
  &[data-theme='dark'] {
13
13
  color-scheme: dark;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcdk/react-components",
3
- "version": "0.0.210",
3
+ "version": "0.0.212",
4
4
  "description": "Reusable React components for DBC projects",
5
5
  "license": "ISC",
6
6
  "author": "",