@altinn/altinn-components 0.25.0 → 0.25.1

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,82 +1,87 @@
1
1
  "use client";
2
- import { jsxs as v, jsx as i } from "react/jsx-runtime";
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}`, Q = ({
2
+ import { jsxs as E, jsx as m } from "react/jsx-runtime";
3
+ import { useState as v, useEffect as M, useMemo as T } from "react";
4
+ import { useRootContext as V } from "../RootProvider/RootProvider.js";
5
+ import { ToolbarAccountMenu as $ } from "./ToolbarAccountMenu.js";
6
+ import { ToolbarAdd as q } from "./ToolbarAdd.js";
7
+ import { ToolbarBase as w } from "./ToolbarBase.js";
8
+ import { ToolbarFilter as z } from "./ToolbarFilter.js";
9
+ import { ToolbarSearch as D } from "./ToolbarSearch.js";
10
+ const g = (n, r) => r || `toolbar-filter-${n}`, X = ({
11
11
  filters: n = [],
12
- filterState: l,
13
- onFilterStateChange: s,
14
- search: m,
15
- accountMenu: b,
16
- getFilterLabel: y,
17
- children: x,
18
- showResultsLabel: A,
19
- removeButtonAltText: S,
12
+ filterState: r,
13
+ onFilterStateChange: b,
14
+ search: u,
15
+ accountMenu: f,
16
+ getFilterLabel: S,
17
+ children: y,
18
+ showResultsLabel: x,
19
+ removeButtonAltText: A,
20
20
  addFilterButtonLabel: h
21
21
  }) => {
22
- const { openId: C, closeAll: I } = B(), [N, R] = F(
23
- l ?? {}
24
- ), p = typeof s == "function" ? s : R, t = l || N, [c, u] = F(
22
+ const { openId: C, closeAll: I } = V(), [N, R] = v(r || {}), p = typeof b == "function" ? b : R, t = r || N, [c, d] = v(
25
23
  (n == null ? void 0 : n.filter((o) => !(o.removable && typeof t[o.name] > "u")).map((o) => o.name)) ?? []
26
- ), f = n == null ? void 0 : n.filter((o) => !c.includes(o.name)), j = T(
24
+ );
25
+ M(() => {
26
+ d(
27
+ (n == null ? void 0 : n.filter((o) => !(o.removable && typeof t[o.name] > "u")).map((o) => o.name)) ?? []
28
+ );
29
+ }, [t]);
30
+ const F = n == null ? void 0 : n.filter((o) => !c.includes(o.name)), j = T(
27
31
  () => c.map((o) => n.find((e) => e.name === o)).filter((o) => typeof o < "u"),
28
32
  [n, c]
29
- ), a = T(
30
- () => n.filter((o) => f.includes(o)),
31
- [n, f]
32
- ), G = (o, e, r) => {
33
- r === "radio" ? (I(), p({
33
+ ), i = T(
34
+ () => n.filter((o) => F.includes(o)),
35
+ [n, F]
36
+ ), G = (o) => {
37
+ const { name: e, value: l, type: B } = o.target, a = [l];
38
+ B === "radio" ? (I(), p({
34
39
  ...t,
35
- [o]: e
40
+ [e]: a
36
41
  })) : p({
37
42
  ...t,
38
- [o]: t[o] ? t[o].some((d) => e == null ? void 0 : e.includes(d)) ? t[o].filter((d) => !e.includes(d)) : [...t[o], ...e] : e
43
+ [e]: t[e] ? t[e].some((s) => a == null ? void 0 : a.includes(String(s))) ? t[e].filter((s) => !a.includes(String(s))) : [...t[e], ...a] : a
39
44
  });
40
45
  }, L = (o) => {
41
- u((e) => e.filter((r) => r !== o)), p({
46
+ d((e) => e.filter((l) => l !== o)), p({
42
47
  ...t,
43
48
  [o]: void 0
44
49
  });
45
50
  }, k = (o, e) => {
46
- u((r) => [...r, o]), C(e);
51
+ d((l) => [...l, o]), C(e);
47
52
  };
48
- return /* @__PURE__ */ v($, { children: [
49
- b && /* @__PURE__ */ i(M, { ...b }),
50
- m && /* @__PURE__ */ i(w, { ...m }),
51
- j.map((o) => /* @__PURE__ */ i(
52
- q,
53
+ return /* @__PURE__ */ E(w, { children: [
54
+ f && /* @__PURE__ */ m($, { ...f }),
55
+ u && /* @__PURE__ */ m(D, { ...u }),
56
+ j.map((o) => /* @__PURE__ */ m(
57
+ z,
53
58
  {
54
59
  id: g(o.name, o.id),
55
- showResultsLabel: A,
60
+ showResultsLabel: x,
56
61
  onRemove: () => {
57
62
  L(o.name);
58
63
  },
59
64
  onChange: (e) => {
60
- G(o.name, [e.target.value], o.optionType);
65
+ G(e);
61
66
  },
62
67
  name: o.name,
63
68
  options: o.options,
64
69
  label: o.label,
65
- value: t[o.name],
66
70
  optionType: o.optionType,
67
71
  removable: o.removable,
68
- getSelectedLabel: y,
69
- buttonAltText: S,
70
- optionGroups: o.optionGroups
72
+ getSelectedLabel: S,
73
+ buttonAltText: A,
74
+ optionGroups: o.optionGroups,
75
+ filterState: t
71
76
  },
72
77
  o.name
73
78
  )),
74
- (a == null ? void 0 : a.length) > 0 && /* @__PURE__ */ i(
75
- V,
79
+ (i == null ? void 0 : i.length) > 0 && /* @__PURE__ */ m(
80
+ q,
76
81
  {
77
82
  id: "toolbar-filter-add",
78
83
  label: h,
79
- items: a.map((o) => {
84
+ items: i.map((o) => {
80
85
  const e = g(o.name, o.id);
81
86
  return {
82
87
  id: e,
@@ -89,9 +94,9 @@ const g = (n, l) => l || `toolbar-filter-${n}`, Q = ({
89
94
  })
90
95
  }
91
96
  ),
92
- x
97
+ y
93
98
  ] });
94
99
  };
95
100
  export {
96
- Q as Toolbar
101
+ X as Toolbar
97
102
  };
@@ -1,62 +1,64 @@
1
- import { jsxs as j, jsx as s } from "react/jsx-runtime";
1
+ import { jsxs as B, jsx as u } from "react/jsx-runtime";
2
2
  import "../../index-L8X2o7IH.js";
3
3
  import "react";
4
- import { useRootContext as B } from "../RootProvider/RootProvider.js";
5
- import { DrawerOrDropdown as C } from "../Dropdown/DrawerOrDropdown.js";
4
+ import { useRootContext as C } from "../RootProvider/RootProvider.js";
5
+ import { DrawerOrDropdown as O } from "../Dropdown/DrawerOrDropdown.js";
6
6
  import "../Search/AutocompleteBase.js";
7
7
  import "../Snackbar/useSnackbar.js";
8
- import { ToolbarButton as O } from "./ToolbarButton.js";
9
- import { ToolbarFilterBase as k } from "./ToolbarFilterBase.js";
10
- import { ToolbarOptions as D } from "./ToolbarOptions.js";
11
- const F = (p, o) => Array.isArray(o) ? o.join(", ") : o, J = ({
12
- removable: p,
13
- label: o,
14
- name: t,
15
- value: r,
16
- options: m,
17
- optionGroups: f,
18
- onChange: a,
19
- onRemove: d,
20
- buttonAltText: y = "Remove button",
21
- getSelectedLabel: n,
22
- showResultsLabel: A = "Show results",
23
- optionType: h,
24
- id: e = `toolbar-filter-${t}`
8
+ import { ToolbarButton as k } from "./ToolbarButton.js";
9
+ import { ToolbarFilterBase as D } from "./ToolbarFilterBase.js";
10
+ import { ToolbarOptions as F } from "./ToolbarOptions.js";
11
+ const I = (l, r) => Array.isArray(r) ? r.join(", ") : r, K = ({
12
+ removable: l,
13
+ label: r,
14
+ name: o,
15
+ filterState: n,
16
+ options: a,
17
+ optionGroups: y,
18
+ onChange: A,
19
+ onRemove: e,
20
+ buttonAltText: h = "Remove button",
21
+ getSelectedLabel: i,
22
+ showResultsLabel: T = "Show results",
23
+ optionType: b,
24
+ id: t = `toolbar-filter-${o}`
25
25
  }) => {
26
- const { currentId: u, toggleId: T, closeAll: b } = B(), w = (m ?? []).map(
27
- (i) => ({
28
- ...i,
29
- name: t,
30
- checked: Array.isArray(r) ? r.includes(i.value) : i.value === r
31
- })
32
- ), x = (n == null ? void 0 : n(t, r)) ?? F(t, r), c = () => T(e), l = u === e;
33
- return /* @__PURE__ */ j(k, { expanded: l, children: [
34
- /* @__PURE__ */ s(
35
- O,
26
+ const { currentId: v, toggleId: w, closeAll: x } = C(), f = (a ?? []).map((p) => {
27
+ const c = n == null ? void 0 : n[p.name || o];
28
+ return {
29
+ name: o,
30
+ ...p,
31
+ checked: Array.isArray(c) ? c.includes(p.value) : p.value === c
32
+ };
33
+ }), s = n == null ? void 0 : n[o], j = (i == null ? void 0 : i(o, s)) ?? I(o, s), d = () => w(t), m = v === t;
34
+ return /* @__PURE__ */ B(D, { expanded: m, children: [
35
+ /* @__PURE__ */ u(
36
+ k,
36
37
  {
37
38
  type: "select",
38
- removable: p,
39
- active: Array.isArray(r) ? r.length > 0 : typeof r < "u",
40
- onToggle: c,
41
- ariaLabel: y,
42
- onRemove: d,
43
- children: x || o
39
+ removable: l,
40
+ active: Array.isArray(s) ? s.length > 0 : typeof s < "u",
41
+ onToggle: d,
42
+ ariaLabel: h,
43
+ onRemove: e,
44
+ children: j || r
44
45
  }
45
46
  ),
46
- /* @__PURE__ */ s(
47
- C,
47
+ /* @__PURE__ */ u(
48
+ O,
48
49
  {
49
- open: l,
50
- drawerTitle: o,
51
- onClose: b,
52
- drawerButton: { onClick: c, label: A },
53
- children: /* @__PURE__ */ s(
54
- D,
50
+ open: m,
51
+ drawerTitle: r,
52
+ onClose: x,
53
+ drawerButton: { onClick: d, label: T },
54
+ children: /* @__PURE__ */ u(
55
+ F,
55
56
  {
56
- options: w,
57
- optionGroups: f,
58
- onChange: a,
59
- optionType: h
57
+ name: o,
58
+ options: f,
59
+ optionGroups: y,
60
+ onChange: A,
61
+ optionType: b
60
62
  }
61
63
  )
62
64
  }
@@ -64,5 +66,5 @@ const F = (p, o) => Array.isArray(o) ? o.join(", ") : o, J = ({
64
66
  ] });
65
67
  };
66
68
  export {
67
- J as ToolbarFilter
69
+ K as ToolbarFilter
68
70
  };
@@ -1,48 +1,56 @@
1
- import { jsxs as c, jsx as r } from "react/jsx-runtime";
2
- import { Fragment as M } from "react";
1
+ import { jsxs as c, jsx as t } from "react/jsx-runtime";
2
+ import { Fragment as v } from "react";
3
3
  import "../../index-L8X2o7IH.js";
4
4
  import "../RootProvider/RootProvider.js";
5
5
  import "../Search/AutocompleteBase.js";
6
6
  import "../Snackbar/useSnackbar.js";
7
- import { MenuOption as v } from "../Menu/MenuOption.js";
8
- import { MenuSearch as j } from "../Menu/MenuSearch.js";
9
- import { MenuHeader as x } from "../Menu/MenuHeader.js";
10
- import { MenuBase as O, MenuList as I, MenuListItem as m } from "../Menu/MenuBase.js";
11
- const w = ({ search: d, optionGroups: o = {}, options: h, onChange: f, optionType: b }) => {
7
+ import { MenuOption as j } from "../Menu/MenuOption.js";
8
+ import { MenuSearch as x } from "../Menu/MenuSearch.js";
9
+ import { MenuHeader as O } from "../Menu/MenuHeader.js";
10
+ import { MenuBase as I, MenuList as L, MenuListItem as l } from "../Menu/MenuBase.js";
11
+ const z = ({
12
+ name: h,
13
+ search: a,
14
+ optionGroups: o = {},
15
+ options: f,
16
+ onChange: b,
17
+ optionType: g
18
+ }) => {
12
19
  var u;
13
- const p = h.reduce(
14
- (e, l) => {
15
- const n = l.groupId || "";
16
- return e[n] = e[n] || [], e[n].push(l), e;
20
+ const d = f.reduce(
21
+ (e, m) => {
22
+ const n = m.groupId || "";
23
+ return e[n] = e[n] || [], e[n].push(m), e;
17
24
  },
18
25
  {}
19
26
  );
20
- return /* @__PURE__ */ c(O, { theme: "default", children: [
21
- d && /* @__PURE__ */ r(j, { ...d }),
22
- /* @__PURE__ */ r(I, { children: (u = Object.keys(p)) == null ? void 0 : u.map((e, l) => {
27
+ return /* @__PURE__ */ c(I, { theme: "default", children: [
28
+ a && /* @__PURE__ */ t(x, { ...a }),
29
+ /* @__PURE__ */ t(L, { children: (u = Object.keys(d)) == null ? void 0 : u.map((e, m) => {
23
30
  var i;
24
- const n = o[e] || {}, { title: a, divider: g = !0 } = n;
25
- return /* @__PURE__ */ c(M, { children: [
26
- l && g ? /* @__PURE__ */ r(m, { role: "separator" }) : "",
27
- a && /* @__PURE__ */ r(m, { children: /* @__PURE__ */ r(x, { title: a }) }),
28
- (i = p[e]) == null ? void 0 : i.map((t) => {
31
+ const n = o[e] || {}, { title: p, divider: M = !0 } = n;
32
+ return /* @__PURE__ */ c(v, { children: [
33
+ m && M ? /* @__PURE__ */ t(l, { role: "separator" }) : "",
34
+ p && /* @__PURE__ */ t(l, { children: /* @__PURE__ */ t(O, { title: p }) }),
35
+ (i = d[e]) == null ? void 0 : i.map((r) => {
29
36
  var s;
30
- return /* @__PURE__ */ r(m, { children: /* @__PURE__ */ r(
31
- v,
37
+ return /* @__PURE__ */ t(l, { children: /* @__PURE__ */ t(
38
+ j,
32
39
  {
33
- onChange: f,
34
- label: t.label,
35
- badge: t.badge,
36
- type: t.type || ((s = o == null ? void 0 : o[e]) == null ? void 0 : s.optionType) || b,
37
- value: t.value,
38
- checked: t.checked
40
+ onChange: b,
41
+ label: r.label,
42
+ badge: r.badge,
43
+ name: r.name || h,
44
+ type: r.type || ((s = o == null ? void 0 : o[e]) == null ? void 0 : s.optionType) || g,
45
+ value: r.value,
46
+ checked: r.checked
39
47
  }
40
- ) }, t.value);
48
+ ) }, r.value);
41
49
  })
42
50
  ] }, e);
43
51
  }) })
44
52
  ] });
45
53
  };
46
54
  export {
47
- w as ToolbarOptions
55
+ z as ToolbarOptions
48
56
  };
@@ -2,13 +2,13 @@ import { ReactNode } from 'react';
2
2
  import { ToolbarAccountMenuProps } from './ToolbarAccountMenu.tsx';
3
3
  import { ToolbarFilterProps } from './ToolbarFilter.tsx';
4
4
  import { ToolbarSearchProps } from './ToolbarSearch.tsx';
5
- export type FilterState = Record<string, ToolbarFilterProps['value']>;
5
+ export type FilterState = Record<string, (string | number)[] | undefined>;
6
6
  export interface ToolbarProps {
7
7
  accountMenu?: ToolbarAccountMenuProps;
8
8
  filters?: ToolbarFilterProps[];
9
9
  search?: ToolbarSearchProps;
10
10
  filterState?: FilterState;
11
- getFilterLabel?: (name: string, value: ToolbarFilterProps['value']) => string;
11
+ getFilterLabel?: (name: string, value: (string | number)[] | undefined) => string;
12
12
  onFilterStateChange?: (state: FilterState) => void;
13
13
  showResultsLabel?: string;
14
14
  addFilterButtonLabel?: string;
@@ -21,3 +21,4 @@ export declare const WithSearch: Story;
21
21
  export declare const LongListAccounts: Story;
22
22
  export declare const ControlledStateFilters: (args: typeof Toolbar) => import("react/jsx-runtime").JSX.Element;
23
23
  export declare const ControlledStateAccount: () => import("react/jsx-runtime").JSX.Element;
24
+ export declare const CombinedRadioCheckboxFilter: () => import("react/jsx-runtime").JSX.Element;
@@ -1,12 +1,11 @@
1
1
  import { StoryObj } from '@storybook/react';
2
2
  declare const meta: {
3
3
  title: string;
4
- component: ({ removable, label, name, value, options, optionGroups, onChange, onRemove, buttonAltText, getSelectedLabel, showResultsLabel, optionType, id, }: import('./ToolbarFilter').ToolbarFilterProps) => import("react/jsx-runtime").JSX.Element;
4
+ component: ({ removable, label, name, filterState, options, optionGroups, onChange, onRemove, buttonAltText, getSelectedLabel, showResultsLabel, optionType, id, }: import('./ToolbarFilter').ToolbarFilterProps) => import("react/jsx-runtime").JSX.Element;
5
5
  tags: string[];
6
6
  parameters: {};
7
7
  args: {
8
8
  label: string;
9
- value: string[];
10
9
  optionType: "radio";
11
10
  options: ({
12
11
  groupId: string;
@@ -1,4 +1,5 @@
1
1
  import { ChangeEventHandler, MouseEventHandler } from 'react';
2
+ import { FilterState } from '../';
2
3
  import { MenuOptionProps } from '../Menu';
3
4
  import { OptionGroup } from './ToolbarOptions';
4
5
  type ToolbarFilterValue = (string | number)[];
@@ -10,7 +11,7 @@ export interface ToolbarFilterProps {
10
11
  };
11
12
  label: string;
12
13
  id?: string;
13
- value?: ToolbarFilterValue;
14
+ filterState?: FilterState;
14
15
  optionType: 'checkbox' | 'radio';
15
16
  removable?: boolean;
16
17
  getSelectedLabel?: (name: string, value?: ToolbarFilterValue) => string;
@@ -20,5 +21,5 @@ export interface ToolbarFilterProps {
20
21
  onRemove?: MouseEventHandler;
21
22
  showResultsLabel?: string;
22
23
  }
23
- export declare const ToolbarFilter: ({ removable, label, name, value, options, optionGroups, onChange, onRemove, buttonAltText, getSelectedLabel, showResultsLabel, optionType, id, }: ToolbarFilterProps) => import("react/jsx-runtime").JSX.Element;
24
+ export declare const ToolbarFilter: ({ removable, label, name, filterState, options, optionGroups, onChange, onRemove, buttonAltText, getSelectedLabel, showResultsLabel, optionType, id, }: ToolbarFilterProps) => import("react/jsx-runtime").JSX.Element;
24
25
  export {};
@@ -1,7 +1,7 @@
1
1
  import { StoryObj } from '@storybook/react';
2
2
  declare const meta: {
3
3
  title: string;
4
- component: ({ removable, label, name, value, options, optionGroups, onChange, onRemove, buttonAltText, getSelectedLabel, showResultsLabel, optionType, id, }: import('./ToolbarFilter').ToolbarFilterProps) => import("react/jsx-runtime").JSX.Element;
4
+ component: ({ removable, label, name, filterState, options, optionGroups, onChange, onRemove, buttonAltText, getSelectedLabel, showResultsLabel, optionType, id, }: import('./ToolbarFilter').ToolbarFilterProps) => import("react/jsx-runtime").JSX.Element;
5
5
  tags: string[];
6
6
  parameters: {};
7
7
  args: {
@@ -7,6 +7,7 @@ export interface OptionGroup {
7
7
  optionType?: ToolbarOptionType;
8
8
  }
9
9
  export interface ToolbarOptionsProps {
10
+ name: string;
10
11
  options: MenuOptionProps[];
11
12
  onChange?: ChangeEventHandler;
12
13
  search?: MenuSearchProps;
@@ -15,4 +16,4 @@ export interface ToolbarOptionsProps {
15
16
  [key: string]: OptionGroup;
16
17
  };
17
18
  }
18
- export declare const ToolbarOptions: ({ search, optionGroups, options, onChange, optionType }: ToolbarOptionsProps) => import("react/jsx-runtime").JSX.Element;
19
+ export declare const ToolbarOptions: ({ name, search, optionGroups, options, onChange, optionType, }: ToolbarOptionsProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,7 +1,7 @@
1
1
  import { StoryObj } from '@storybook/react';
2
2
  declare const meta: {
3
3
  title: string;
4
- component: ({ search, optionGroups, options, onChange, optionType }: import('./ToolbarOptions').ToolbarOptionsProps) => import("react/jsx-runtime").JSX.Element;
4
+ component: ({ name, search, optionGroups, options, onChange, optionType, }: import('./ToolbarOptions').ToolbarOptionsProps) => import("react/jsx-runtime").JSX.Element;
5
5
  tags: string[];
6
6
  parameters: {};
7
7
  args: {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altinn/altinn-components",
3
- "version": "0.25.0",
3
+ "version": "0.25.1",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/",