@altinn/altinn-components 0.18.2 → 0.18.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.
@@ -1,44 +1,46 @@
1
1
  import { jsx as m } from "react/jsx-runtime";
2
- import { useRef as v, createElement as x } from "react";
2
+ import { useRef as v, createElement as A } from "react";
3
3
  import "../../index-L8X2o7IH.js";
4
- import { useMenu as A } from "../../hooks/useMenu.js";
4
+ import { useMenu as I } from "../../hooks/useMenu.js";
5
5
  import "../RootProvider/RootProvider.js";
6
- import { AutocompleteBase as I } from "./AutocompleteBase.js";
7
- import { AutocompleteGroup as l } from "./AutocompleteGroup.js";
6
+ import { AutocompleteBase as l } from "./AutocompleteBase.js";
7
+ import { AutocompleteGroup as x } from "./AutocompleteGroup.js";
8
8
  import { AutocompleteItem as h } from "./AutocompleteItem.js";
9
9
  import "../Snackbar/useSnackbar.js";
10
10
  import { useEnterKey as k } from "../../hooks/useEnterKey.js";
11
- const C = ({ className: u, items: s, groups: i = {}, expanded: n, onSelect: r }) => {
11
+ const C = ({ className: s, items: i, groups: n = {}, expanded: u, onSelect: r }) => {
12
12
  const p = v(null);
13
13
  k(() => {
14
- var e;
15
- const t = (e = p.current) == null ? void 0 : e.querySelector('[data-active="true"]');
16
- t == null || t.dispatchEvent(new MouseEvent("click", { bubbles: !0 })), r == null || r();
14
+ var t;
15
+ if (u) {
16
+ const e = (t = p.current) == null ? void 0 : t.querySelector('[data-active="true"]');
17
+ e == null || e.dispatchEvent(new MouseEvent("click", { bubbles: !0 })), r == null || r();
18
+ }
17
19
  });
18
- const { menu: a, setActiveIndex: c } = A({
19
- items: s,
20
- groups: i,
20
+ const { menu: c, setActiveIndex: f } = I({
21
+ items: i,
22
+ groups: n,
21
23
  groupByKey: "groupId",
22
24
  keyboardEvents: !0
23
25
  });
24
- return /* @__PURE__ */ m(I, { className: u, expanded: n, ref: p, children: a.map((t, e) => /* @__PURE__ */ x(l, { ...t.props, key: e }, /* @__PURE__ */ m("ul", { children: t.items.map((d, f) => {
26
+ return /* @__PURE__ */ m(l, { className: s, expanded: u, ref: p, children: c.map((t, e) => /* @__PURE__ */ A(x, { ...t.props, key: e }, /* @__PURE__ */ m("ul", { children: t.items.map((a, d) => {
25
27
  const {
26
28
  active: y,
27
29
  menuIndex: E,
28
30
  props: { groupId: M, onClick: o, ...b }
29
- } = d;
31
+ } = a;
30
32
  return /* @__PURE__ */ m(
31
33
  h,
32
34
  {
33
35
  tabIndex: -1,
34
- onMouseEnter: () => c(E),
36
+ onMouseEnter: () => f(E),
35
37
  ...b,
36
38
  onClick: () => {
37
39
  o == null || o(), r == null || r();
38
40
  },
39
41
  active: y
40
42
  },
41
- f
43
+ d
42
44
  );
43
45
  }) }))) });
44
46
  };
@@ -1,13 +1,13 @@
1
1
  "use client";
2
- import { jsxs as v, jsx as i } from "react/jsx-runtime";
2
+ import { jsxs as B, jsx as i } from "react/jsx-runtime";
3
3
  import { useState as F, useMemo as T } from "react";
4
- import { useRootContext as B } from "../RootProvider/RootProvider.js";
5
- import { ToolbarAccountMenu as M } from "./ToolbarAccountMenu.js";
6
- import { ToolbarAdd as V } from "./ToolbarAdd.js";
7
- import { ToolbarBase as $ } from "./ToolbarBase.js";
8
- import { ToolbarFilter as q } from "./ToolbarFilter.js";
9
- import { ToolbarSearch as w } from "./ToolbarSearch.js";
10
- const g = (n, l) => l || `toolbar-filter-${n}`, P = ({
4
+ import { useRootContext as M } from "../RootProvider/RootProvider.js";
5
+ import { ToolbarAccountMenu as V } from "./ToolbarAccountMenu.js";
6
+ import { ToolbarAdd as $ } from "./ToolbarAdd.js";
7
+ import { ToolbarBase as q } from "./ToolbarBase.js";
8
+ import { ToolbarFilter as w } from "./ToolbarFilter.js";
9
+ import { ToolbarSearch as z } from "./ToolbarSearch.js";
10
+ const g = (n, l) => l || `toolbar-filter-${n}`, Q = ({
11
11
  filters: n = [],
12
12
  filterState: l,
13
13
  onFilterStateChange: s,
@@ -16,47 +16,48 @@ const g = (n, l) => l || `toolbar-filter-${n}`, P = ({
16
16
  getFilterLabel: y,
17
17
  children: x,
18
18
  showResultsLabel: A,
19
- removeButtonAltText: S
19
+ removeButtonAltText: S,
20
+ addFilterButtonLabel: h
20
21
  }) => {
21
- const { openId: h, closeAll: C } = B(), [I, N] = F(
22
+ const { openId: C, closeAll: I } = M(), [N, R] = F(
22
23
  l ?? {}
23
- ), c = typeof s == "function" ? s : N, t = l || I, [d, f] = F(
24
+ ), c = typeof s == "function" ? s : R, t = l || N, [d, f] = F(
24
25
  (n == null ? void 0 : n.filter((o) => !(o.removable && typeof t[o.name] > "u")).map((o) => o.name)) ?? []
25
- ), u = n == null ? void 0 : n.filter((o) => !d.includes(o.name)), R = T(
26
+ ), u = n == null ? void 0 : n.filter((o) => !d.includes(o.name)), j = T(
26
27
  () => d.map((o) => n.find((e) => e.name === o)).filter((o) => typeof o < "u"),
27
28
  [n, d]
28
29
  ), a = T(
29
30
  () => n.filter((o) => u.includes(o)),
30
31
  [n, u]
31
- ), j = (o, e, r) => {
32
- r === "radio" ? (C(), c({
32
+ ), L = (o, e, r) => {
33
+ r === "radio" ? (I(), c({
33
34
  ...t,
34
35
  [o]: e
35
36
  })) : c({
36
37
  ...t,
37
38
  [o]: t[o] ? t[o].some((p) => e == null ? void 0 : e.includes(p)) ? t[o].filter((p) => !e.includes(p)) : [...t[o], ...e] : e
38
39
  });
39
- }, L = (o) => {
40
+ }, k = (o) => {
40
41
  f((e) => e.filter((r) => r !== o)), c({
41
42
  ...t,
42
43
  [o]: void 0
43
44
  });
44
- }, k = (o, e) => {
45
- f((r) => [...r, o]), h(e);
45
+ }, v = (o, e) => {
46
+ f((r) => [...r, o]), C(e);
46
47
  };
47
- return /* @__PURE__ */ v($, { children: [
48
- b && /* @__PURE__ */ i(M, { ...b }),
49
- m && /* @__PURE__ */ i(w, { ...m }),
50
- R.map((o) => /* @__PURE__ */ i(
51
- q,
48
+ return /* @__PURE__ */ B(q, { children: [
49
+ b && /* @__PURE__ */ i(V, { ...b }),
50
+ m && /* @__PURE__ */ i(z, { ...m }),
51
+ j.map((o) => /* @__PURE__ */ i(
52
+ w,
52
53
  {
53
54
  id: g(o.name, o.id),
54
55
  showResultsLabel: A,
55
56
  onRemove: () => {
56
- L(o.name);
57
+ k(o.name);
57
58
  },
58
59
  onChange: (e) => {
59
- j(o.name, [e.target.value], o.optionType);
60
+ L(o.name, [e.target.value], o.optionType);
60
61
  },
61
62
  name: o.name,
62
63
  options: o.options,
@@ -70,9 +71,10 @@ const g = (n, l) => l || `toolbar-filter-${n}`, P = ({
70
71
  o.name
71
72
  )),
72
73
  (a == null ? void 0 : a.length) > 0 && /* @__PURE__ */ i(
73
- V,
74
+ $,
74
75
  {
75
76
  id: "toolbar-filter-add",
77
+ label: h,
76
78
  items: a.map((o) => {
77
79
  const e = g(o.name, o.id);
78
80
  return {
@@ -80,7 +82,7 @@ const g = (n, l) => l || `toolbar-filter-${n}`, P = ({
80
82
  title: o.label,
81
83
  name: o.name,
82
84
  onClick: () => {
83
- k(o.name, e);
85
+ v(o.name, e);
84
86
  }
85
87
  };
86
88
  })
@@ -90,5 +92,5 @@ const g = (n, l) => l || `toolbar-filter-${n}`, P = ({
90
92
  ] });
91
93
  };
92
94
  export {
93
- P as Toolbar
95
+ Q as Toolbar
94
96
  };
@@ -1,20 +1,34 @@
1
- import { jsxs as n, jsx as r } from "react/jsx-runtime";
1
+ import { jsxs as f, jsx as m } from "react/jsx-runtime";
2
2
  import "../../index-L8X2o7IH.js";
3
3
  import "react";
4
- import { useRootContext as a } from "../RootProvider/RootProvider.js";
5
- import { ToolbarButton as d } from "./ToolbarButton.js";
6
- import { ToolbarFilterBase as f } from "./ToolbarFilterBase.js";
7
- import { DrawerOrDropdown as x } from "../Dropdown/DrawerOrDropdown.js";
8
- import { AccountMenu as T } from "../GlobalMenu/AccountMenu.js";
4
+ import { useRootContext as n } from "../RootProvider/RootProvider.js";
5
+ import { ToolbarButton as x } from "./ToolbarButton.js";
6
+ import { ToolbarFilterBase as T } from "./ToolbarFilterBase.js";
7
+ import { DrawerOrDropdown as b } from "../Dropdown/DrawerOrDropdown.js";
8
+ import { AccountMenu as g } from "../GlobalMenu/AccountMenu.js";
9
9
  import "../Search/AutocompleteBase.js";
10
10
  import "../Snackbar/useSnackbar.js";
11
- const k = ({ currentAccount: o, id: t = "toolbar-accounts", ...m }) => {
12
- const { currentId: i, toggleId: l, closeAll: p } = a(), s = () => l(t), e = i === t;
13
- return /* @__PURE__ */ n(f, { expanded: e, children: [
14
- /* @__PURE__ */ r(d, { type: "switch", onToggle: s, active: !!o, children: o == null ? void 0 : o.name }),
15
- /* @__PURE__ */ r(x, { open: e, drawerTitle: "Endre konto", onClose: p, children: /* @__PURE__ */ r(T, { ...m, currentAccount: o }) })
11
+ const y = ({
12
+ currentAccount: o,
13
+ id: i = "toolbar-accounts",
14
+ onSelectAccount: r,
15
+ ...e
16
+ }) => {
17
+ const { currentId: s, toggleId: l, closeAll: p } = n(), a = () => l(i), t = s === i;
18
+ return /* @__PURE__ */ f(T, { expanded: t, children: [
19
+ /* @__PURE__ */ m(x, { type: "switch", onToggle: a, active: !!o, children: o == null ? void 0 : o.name }),
20
+ /* @__PURE__ */ m(b, { open: t, drawerTitle: "Endre konto", onClose: p, children: /* @__PURE__ */ m(
21
+ g,
22
+ {
23
+ ...e,
24
+ onSelectAccount: (d) => {
25
+ r == null || r(d), p();
26
+ },
27
+ currentAccount: o
28
+ }
29
+ ) })
16
30
  ] });
17
31
  };
18
32
  export {
19
- k as ToolbarAccountMenu
33
+ y as ToolbarAccountMenu
20
34
  };
@@ -11,7 +11,8 @@ export interface ToolbarProps {
11
11
  getFilterLabel?: (name: string, value: ToolbarFilterProps['value']) => string;
12
12
  onFilterStateChange?: (state: FilterState) => void;
13
13
  showResultsLabel?: string;
14
+ addFilterButtonLabel?: string;
14
15
  removeButtonAltText?: string;
15
16
  children?: ReactNode;
16
17
  }
17
- export declare const Toolbar: ({ filters, filterState, onFilterStateChange, search, accountMenu, getFilterLabel, children, showResultsLabel, removeButtonAltText, }: ToolbarProps) => import("react/jsx-runtime").JSX.Element;
18
+ export declare const Toolbar: ({ filters, filterState, onFilterStateChange, search, accountMenu, getFilterLabel, children, showResultsLabel, removeButtonAltText, addFilterButtonLabel, }: ToolbarProps) => import("react/jsx-runtime").JSX.Element;
@@ -2,7 +2,7 @@ import { StoryObj } from '@storybook/react';
2
2
  import { Toolbar } from './Toolbar';
3
3
  declare const meta: {
4
4
  title: string;
5
- component: ({ filters, filterState, onFilterStateChange, search, accountMenu, getFilterLabel, children, showResultsLabel, removeButtonAltText, }: import('./Toolbar').ToolbarProps) => import("react/jsx-runtime").JSX.Element;
5
+ component: ({ filters, filterState, onFilterStateChange, search, accountMenu, getFilterLabel, children, showResultsLabel, removeButtonAltText, addFilterButtonLabel, }: import('./Toolbar').ToolbarProps) => import("react/jsx-runtime").JSX.Element;
6
6
  tags: string[];
7
7
  parameters: {};
8
8
  args: {
@@ -19,3 +19,4 @@ export declare const HiddenFilters: Story;
19
19
  export declare const WithAccountMenu: Story;
20
20
  export declare const WithSearch: Story;
21
21
  export declare const ControlledStateFilters: (args: typeof Toolbar) => import("react/jsx-runtime").JSX.Element;
22
+ export declare const ControlledStateAccount: () => import("react/jsx-runtime").JSX.Element;
@@ -2,4 +2,4 @@ import { AccountMenuProps } from '../';
2
2
  export interface ToolbarAccountMenuProps extends AccountMenuProps {
3
3
  id?: string;
4
4
  }
5
- export declare const ToolbarAccountMenu: ({ currentAccount, id, ...rest }: ToolbarAccountMenuProps) => import("react/jsx-runtime").JSX.Element;
5
+ export declare const ToolbarAccountMenu: ({ currentAccount, id, onSelectAccount, ...rest }: ToolbarAccountMenuProps) => import("react/jsx-runtime").JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altinn/altinn-components",
3
- "version": "0.18.2",
3
+ "version": "0.18.4",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/",