@altinn/altinn-components 0.60.1 → 0.61.0

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,89 +1,90 @@
1
- import { jsxs as l, Fragment as I, jsx as s } from "react/jsx-runtime";
2
- import { useMemo as L, useState as N, createElement as O } from "react";
3
- import { Button as w } from "../Button/Button.js";
1
+ import { jsxs as l, Fragment as L, jsx as i } from "react/jsx-runtime";
2
+ import { useMemo as N, useState as O, createElement as y } from "react";
3
+ import { Button as E } from "../Button/Button.js";
4
4
  import "../../index-p1eeF8LQ.js";
5
- import { s as y } from "../../ToolbarSearch-56Sm2j7P.js";
5
+ import { s as X } from "../../ToolbarSearch-56Sm2j7P.js";
6
6
  import "../Typography/Link.js";
7
7
  import "react-dom";
8
8
  import "../Snackbar/useSnackbar.js";
9
- import { ToolbarFilterMenu as E } from "./ToolbarFilterMenu.js";
10
- import { useFilter as X } from "./useFilter.js";
11
- import { ToolbarControls as q } from "./ToolbarControls.js";
12
- import { ToolbarFilterAddMenu as z } from "./ToolbarFilterAddMenu.js";
13
- const _ = ({
9
+ import { ToolbarFilterMenu as q } from "./ToolbarFilterMenu.js";
10
+ import { useFilter as w } from "./useFilter.js";
11
+ import { ToolbarControls as z } from "./ToolbarControls.js";
12
+ import { ToolbarFilterAddMenu as D } from "./ToolbarFilterAddMenu.js";
13
+ const $ = ({
14
14
  disabled: n,
15
15
  filters: r,
16
16
  filterState: e = {},
17
17
  onFilterStateChange: t,
18
- addLabel: v = "Legg til filter",
19
- addNextLabel: F = "Legg til",
20
- resetLabel: b = "Nullstill",
21
- removeLabel: T = "Fjern filter",
22
- submitLabel: j,
23
- getFilterLabel: M,
24
- virtualized: R,
25
- controls: k
18
+ addLabel: b = "Legg til filter",
19
+ addNextLabel: T = "Legg til",
20
+ resetLabel: j = "Nullstill",
21
+ removeLabel: M = "Fjern filter",
22
+ submitLabel: k,
23
+ getFilterLabel: x,
24
+ virtualized: A,
25
+ showResetButton: R = !0,
26
+ controls: s
26
27
  }) => {
27
- const { visibleFilters: i, hiddenFilters: a, onFilterAdd: x, onFilterChange: A, onFilterRemove: d } = X({
28
+ const { visibleFilters: a, hiddenFilters: d, onFilterAdd: f, onFilterChange: B, onFilterRemove: p } = w({
28
29
  filters: r,
29
30
  filterState: e,
30
31
  onFilterStateChange: t
31
- }), p = L(
32
+ }), c = N(
32
33
  () => r?.filter((o) => o.removable)?.map((o) => o.name) ?? [],
33
34
  [r]
34
- ), f = p.length > 0 && Object.values(e)?.some((o) => o && o?.length > 0), [c, g] = N(void 0), h = (o) => {
35
- g((m) => m === o ? void 0 : o);
36
- }, u = () => {
37
- g(void 0);
38
- }, B = () => {
39
- for (const o of p)
40
- d(o);
35
+ ), g = R && c.length > 0 && Object.values(e)?.some((o) => o && o?.length > 0), [u, h] = O(void 0), v = (o) => {
36
+ h((m) => m === o ? void 0 : o);
37
+ }, F = () => {
38
+ h(void 0);
39
+ }, C = () => {
40
+ for (const o of c)
41
+ p(o);
41
42
  t?.({});
42
43
  };
43
- return /* @__PURE__ */ l(I, { children: [
44
- i?.map((o, m) => {
45
- const C = M?.(o?.name, e?.[o?.id]) ?? o?.label;
46
- return /* @__PURE__ */ O(
47
- E,
44
+ return /* @__PURE__ */ l(L, { children: [
45
+ a?.map((o, m) => {
46
+ const I = x?.(o?.name, e?.[o?.id]) ?? o?.label;
47
+ return /* @__PURE__ */ y(
48
+ q,
48
49
  {
49
50
  ...o,
50
51
  disabled: n,
51
- submitLabel: j,
52
+ submitLabel: k,
52
53
  key: m,
53
- onToggle: () => h(o.name),
54
- onClose: u,
55
- open: c === o.name,
56
- label: C,
57
- onRemove: () => d(o.name),
58
- removeLabel: T,
59
- onFilterChange: A,
54
+ onToggle: () => v(o.name),
55
+ onClose: F,
56
+ open: u === o.name,
57
+ label: I,
58
+ onRemove: () => p(o.name),
59
+ removeLabel: M,
60
+ onFilterChange: B,
60
61
  onFilterStateChange: t,
61
62
  filterState: e
62
63
  }
63
64
  );
64
65
  }),
65
- !n && a?.length > 0 && /* @__PURE__ */ s(
66
- z,
66
+ !n && d?.length > 0 && /* @__PURE__ */ i(
67
+ D,
67
68
  {
68
69
  name: "add",
69
- onToggle: () => h("add"),
70
- onClose: u,
71
- open: c === "add",
72
- items: a,
73
- onAdd: x,
74
- label: i?.length > 0 ? F : v,
75
- virtualized: R
70
+ onToggle: () => v("add"),
71
+ onClose: F,
72
+ open: u === "add",
73
+ items: d,
74
+ onAdd: f,
75
+ label: a?.length > 0 ? T : b,
76
+ virtualized: A
76
77
  }
77
78
  ),
78
- /* @__PURE__ */ l(q, { children: [
79
- !n && f && /* @__PURE__ */ l(w, { onClick: B, variant: "ghost", children: [
80
- /* @__PURE__ */ s(y, { "aria-hidden": "true" }),
81
- /* @__PURE__ */ s("span", { children: b })
79
+ (g || s) && /* @__PURE__ */ l(z, { children: [
80
+ !n && g && /* @__PURE__ */ l(E, { onClick: C, variant: "ghost", children: [
81
+ /* @__PURE__ */ i(X, { "aria-hidden": "true" }),
82
+ /* @__PURE__ */ i("span", { children: j })
82
83
  ] }),
83
- k
84
+ s
84
85
  ] })
85
86
  ] });
86
87
  };
87
88
  export {
88
- _ as ToolbarFilter
89
+ $ as ToolbarFilter
89
90
  };
@@ -1,39 +1,42 @@
1
1
  "use client";
2
- import { useState as g, useMemo as f, useEffect as h } from "react";
3
- const m = (l, c) => c || `toolbar-filter-${l}`, N = ({ filters: l = [], filterState: c, onFilterStateChange: u }) => {
4
- const i = c || {}, d = typeof u == "function" ? u : () => {
5
- }, [r, o] = g(
6
- () => l.filter((e) => !e.removable || typeof i[e.name] < "u").map((e) => e.name)
2
+ import { useState as h, useMemo as f, useEffect as p } from "react";
3
+ const m = (n, o) => o || `toolbar-filter-${n}`, x = ({ filters: n = [], filterState: o, onFilterStateChange: u }) => {
4
+ const i = o || {}, c = typeof u == "function" ? u : () => {
5
+ }, [d, a] = h(
6
+ () => n.filter((e) => !e.removable || typeof i[e.name] < "u").map((e) => e.name)
7
7
  ), F = f(
8
- () => r.map((e) => l.find((t) => t.name === e)).filter((e) => typeof e < "u"),
9
- [l, r]
8
+ () => d.map((e) => n.find((t) => t.name === e)).filter((e) => typeof e < "u"),
9
+ [n, d]
10
10
  ), b = f(
11
- () => l.filter((e) => !r.includes(e.name)),
12
- [l, r]
11
+ () => n.filter((e) => !d.includes(e.name)),
12
+ [n, d]
13
13
  );
14
- h(() => {
15
- const e = l.filter((t) => !t.removable || typeof i[t.name] < "u").map((t) => t.name);
16
- o((t) => {
17
- const s = e.filter((n) => !t.includes(n));
18
- return s.length === 0 ? t : [...t, ...s];
14
+ p(() => {
15
+ const e = n.filter((t) => !t.removable || typeof i[t.name] < "u").map((t) => t.name);
16
+ a((t) => {
17
+ const s = [
18
+ ...t.filter((l) => e.includes(l)),
19
+ ...e.filter((l) => !t.includes(l))
20
+ ];
21
+ return s.length === t.length && s.every((l, r) => l === t[r]) ? t : s;
19
22
  });
20
- }, [l, i]);
23
+ }, [n, i]);
21
24
  const v = (e, t, s) => {
22
- const n = [s];
23
- d(e === "radio" ? {
25
+ const l = [s];
26
+ c(e === "radio" ? {
24
27
  ...i,
25
- [t]: n
28
+ [t]: l
26
29
  } : {
27
30
  ...i,
28
- [t]: i[t] ? i[t].some((a) => n.includes(String(a))) ? i[t].filter((a) => !(n || []).includes(String(a))) : [...i[t], ...n || []] : n
31
+ [t]: i[t] ? i[t].some((r) => l.includes(String(r))) ? i[t].filter((r) => !(l || []).includes(String(r))) : [...i[t], ...l || []] : l
29
32
  });
30
- }, p = (e) => {
31
- o((t) => t.filter((s) => s !== e)), d({
33
+ }, y = (e) => {
34
+ a((t) => t.filter((s) => s !== e)), c({
32
35
  ...i,
33
36
  [e]: void 0
34
37
  });
35
- }, y = (e) => {
36
- r.includes(e) || o((t) => [...t, e]), d({
38
+ }, g = (e) => {
39
+ d.includes(e) || a((t) => [...t, e]), c({
37
40
  ...i,
38
41
  [e]: i[e] ?? []
39
42
  }), requestAnimationFrame(() => {
@@ -55,10 +58,10 @@ const m = (l, c) => c || `toolbar-filter-${l}`, N = ({ filters: l = [], filterSt
55
58
  id: m(e.name, e.id)
56
59
  })),
57
60
  onFilterChange: v,
58
- onFilterRemove: p,
59
- onFilterAdd: y
61
+ onFilterRemove: y,
62
+ onFilterAdd: g
60
63
  };
61
64
  };
62
65
  export {
63
- N as useFilter
66
+ x as useFilter
64
67
  };
@@ -13,5 +13,6 @@ export interface ToolbarFilterProps {
13
13
  onFilterStateChange?: (state: FilterState) => void;
14
14
  virtualized?: boolean;
15
15
  controls?: ReactNode;
16
+ showResetButton?: boolean;
16
17
  }
17
- export declare const ToolbarFilter: ({ disabled, filters, filterState, onFilterStateChange, addLabel, addNextLabel, resetLabel, removeLabel, submitLabel, getFilterLabel, virtualized, controls, }: ToolbarFilterProps) => import("react/jsx-runtime").JSX.Element;
18
+ export declare const ToolbarFilter: ({ disabled, filters, filterState, onFilterStateChange, addLabel, addNextLabel, resetLabel, removeLabel, submitLabel, getFilterLabel, virtualized, showResetButton, controls, }: ToolbarFilterProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,7 +1,7 @@
1
1
  import { ToolbarFilterProps } from './ToolbarFilter';
2
2
  declare const meta: {
3
3
  title: string;
4
- component: ({ disabled, filters, filterState, onFilterStateChange, addLabel, addNextLabel, resetLabel, removeLabel, submitLabel, getFilterLabel, virtualized, controls, }: ToolbarFilterProps) => import("react/jsx-runtime").JSX.Element;
4
+ component: ({ disabled, filters, filterState, onFilterStateChange, addLabel, addNextLabel, resetLabel, removeLabel, submitLabel, getFilterLabel, virtualized, showResetButton, controls, }: ToolbarFilterProps) => import("react/jsx-runtime").JSX.Element;
5
5
  parameters: {};
6
6
  args: {};
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altinn/altinn-components",
3
- "version": "0.60.1",
3
+ "version": "0.61.0",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/",