rk-designsystem 1.4.0 → 1.4.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,101 +1,99 @@
1
1
  "use client";
2
- import { jsxs as L, jsx as g } from "react/jsx-runtime";
3
- import pe, { forwardRef as be, useEffect as M, useRef as S, useCallback as k, useState as me, useId as ve } from "react";
4
- import { parse as ge, isValid as xe } from "date-fns";
2
+ import { jsxs as L, jsx as v } from "react/jsx-runtime";
3
+ import be, { forwardRef as me, useEffect as M, useRef as S, useCallback as B, useState as ve, useId as ge } from "react";
4
+ import { parse as xe, isValid as he } from "date-fns";
5
5
  import o from "./styles.module.css.js";
6
- import { useLanguageOptional as he } from "../../context/LanguageContext.js";
7
- const x = (e) => {
8
- const a = e.slice(0, 2), h = e.slice(2, 4), s = e.slice(4, 8);
9
- return e.length > 4 ? `${a}.${h}.${s}` : e.length > 2 ? `${a}.${h}` : e.length > 0 ? a : "";
10
- }, N = (e) => (e || "").replace(/\D/g, "").slice(0, 8), O = (e) => {
6
+ import { useLanguageOptional as ye } from "../../context/LanguageContext.js";
7
+ const g = (e) => {
8
+ const a = e.slice(0, 2), x = e.slice(2, 4), s = e.slice(4, 8);
9
+ return e.length > 4 ? `${a}.${x}.${s}` : e.length > 2 ? `${a}.${x}` : e.length > 0 ? a : "";
10
+ }, D = (e) => (e || "").replace(/\D/g, "").slice(0, 8), P = (e) => {
11
11
  if (e.length < 8) return null;
12
- const a = ge(x(e), "dd.MM.yyyy", /* @__PURE__ */ new Date());
13
- return xe(a);
14
- }, ye = be(
12
+ const a = xe(g(e), "dd.MM.yyyy", /* @__PURE__ */ new Date());
13
+ return he(a);
14
+ }, Ie = me(
15
15
  (e, a) => {
16
- const { t: h } = he();
16
+ const { t: x } = ye();
17
17
  M(() => {
18
18
  const r = "rk-dateinput-inline-styles";
19
19
  if (typeof document > "u" || document.getElementById(r)) return;
20
- const t = Ie(o), m = document.createElement("style");
21
- m.id = r, m.textContent = t, document.head.prepend(m);
20
+ const t = $e(o), b = document.createElement("style");
21
+ b.id = r, b.textContent = t, document.head.prepend(b);
22
22
  }, []);
23
23
  const {
24
24
  label: s,
25
- suffixIcon: V,
26
- onSuffixClick: u,
27
- className: P,
25
+ suffixIcon: N,
26
+ onSuffixClick: d,
27
+ className: O,
28
28
  inputWrapperClassName: q,
29
29
  inputClassName: H,
30
- value: y,
30
+ value: h,
31
31
  defaultValue: A,
32
- onChange: I,
33
- onValidationChange: $,
32
+ onChange: y,
33
+ onValidationChange: I,
34
34
  readOnly: G,
35
35
  placeholder: J = "dd.mm.åååå",
36
36
  id: K,
37
37
  name: Q,
38
38
  required: T,
39
- disabled: w,
39
+ disabled: $,
40
40
  onClick: U,
41
41
  onFocus: X,
42
- onBlur: z,
42
+ onBlur: w,
43
43
  autoComplete: Y = "off",
44
44
  "aria-label": Z,
45
45
  "aria-labelledby": _,
46
46
  description: C,
47
- error: c,
47
+ error: u,
48
48
  "data-color": ee,
49
49
  "data-size": re,
50
50
  ...te
51
- } = e, B = y !== void 0, f = S(null);
52
- pe.useImperativeHandle(
51
+ } = e, z = h !== void 0, c = S(null);
52
+ be.useImperativeHandle(
53
53
  a,
54
- () => f.current
54
+ () => c.current
55
55
  );
56
- const j = S(null), l = k(
56
+ const V = S(null), n = B(
57
57
  (r, t) => {
58
- r !== j.current && (j.current = r, $ == null || $(r, t));
58
+ r !== V.current && (V.current = r, I == null || I(r, t));
59
59
  },
60
- [$]
61
- ), D = k(
62
- (r) => x(N(r)),
60
+ [I]
61
+ ), k = B(
62
+ (r) => g(D(r)),
63
63
  []
64
- ), [p, W] = me(
65
- () => D(y ?? A)
64
+ ), [f, j] = ve(
65
+ () => k(h ?? A)
66
66
  );
67
67
  M(() => {
68
- if (B) {
69
- const r = D(y);
70
- r !== p && (W(r), f.current && f.current.value !== r && (f.current.value = r));
68
+ if (z) {
69
+ const r = k(h);
70
+ r !== f && (j(r), c.current && c.current.value !== r && (c.current.value = r));
71
71
  }
72
- }, [y, B, p, D]);
73
- const oe = k(
72
+ }, [h, z, f, k]);
73
+ const oe = B(
74
74
  (r) => {
75
- const t = r.target, m = p, i = N(t.value), d = x(i);
76
- let n = 0;
77
- const v = i.length;
78
- v <= 2 ? n = v : v <= 4 ? n = v + 1 : n = v + 2, n = Math.min(n, d.length), W(d), t.value = d, t.setSelectionRange(n, n), (d !== m || B) && (I == null || I(r, d));
79
- const fe = O(i);
80
- (i.length === 0 || i.length === 8) && l(i.length === 0 ? null : fe, d);
75
+ const t = r.target, b = f, l = D(t.value), i = g(l), m = l.length, fe = m <= 2 ? m : m <= 4 ? m + 1 : m + 2, F = Math.min(fe, i.length);
76
+ j(i), t.value = i, t.setSelectionRange(F, F), (i !== b || z) && (y == null || y(r, i));
77
+ const pe = P(l);
78
+ (l.length === 0 || l.length === 8) && n(l.length === 0 ? null : pe, i);
81
79
  },
82
- [p, B, I, l]
83
- ), ae = k(
80
+ [f, z, y, n]
81
+ ), ae = B(
84
82
  (r) => {
85
- const t = N(r.target.value);
86
- t.length === 0 ? l(null, "") : t.length < 8 ? l(!1, x(t)) : l(O(t), x(t)), z == null || z(r);
83
+ const t = D(r.target.value);
84
+ t.length === 0 ? n(null, "") : t.length < 8 ? n(!1, g(t)) : n(P(t), g(t)), w == null || w(r);
87
85
  },
88
- [z, l]
89
- ), ne = [o.fieldset, P].filter(Boolean).join(" "), le = [
86
+ [w, n]
87
+ ), ne = [o.fieldset, O].filter(Boolean).join(" "), le = [
90
88
  o.inputWrapper,
91
89
  q,
92
- c ? o.inputWrapperError : ""
90
+ u ? o.inputWrapperError : ""
93
91
  ].filter(Boolean).join(" "), ie = [
94
92
  H
95
- ].filter(Boolean).join(" "), de = [
93
+ ].filter(Boolean).join(" "), se = [
96
94
  o.suffixButton,
97
- u ? o.suffixButtonInteractive : ""
98
- ].filter(Boolean).join(" "), se = ve(), b = K ?? `dateinput${se}`, R = s ? `${b}-label` : void 0, E = C ? `${b}-desc` : void 0, F = c ? `${b}-err` : void 0, ue = [E, F].filter(Boolean).join(" ") || void 0, ce = _ ?? R;
95
+ d ? o.suffixButtonInteractive : ""
96
+ ].filter(Boolean).join(" "), de = ge(), p = K ?? `dateinput${de}`, W = s ? `${p}-label` : void 0, R = C ? `${p}-desc` : void 0, E = u ? `${p}-err` : void 0, ue = [R, E].filter(Boolean).join(" ") || void 0, ce = _ ?? W;
99
97
  return (
100
98
  // --- Bruk data-color og data-size på den ytre wrapperen ---
101
99
  /* @__PURE__ */ L(
@@ -105,24 +103,24 @@ const x = (e) => {
105
103
  "data-color": ee,
106
104
  "data-size": re,
107
105
  children: [
108
- s ? /* @__PURE__ */ g("label", { id: R, htmlFor: b, children: s }) : null,
109
- C && /* @__PURE__ */ g("p", { id: E, className: o.description, children: C }),
106
+ s ? /* @__PURE__ */ v("label", { id: W, htmlFor: p, children: s }) : null,
107
+ C && /* @__PURE__ */ v("p", { id: R, className: o.description, children: C }),
110
108
  /* @__PURE__ */ L("div", { className: le, children: [
111
- /* @__PURE__ */ g(
109
+ /* @__PURE__ */ v(
112
110
  "input",
113
111
  {
114
- ref: f,
112
+ ref: c,
115
113
  type: "text",
116
114
  inputMode: "numeric",
117
115
  pattern: "\\d{2}\\.\\d{2}\\.\\d{4}",
118
116
  maxLength: 10,
119
- value: p,
117
+ value: f,
120
118
  readOnly: G,
121
119
  placeholder: J,
122
- id: b,
120
+ id: p,
123
121
  name: Q,
124
122
  required: T,
125
- disabled: w,
123
+ disabled: $,
126
124
  onClick: U,
127
125
  onChange: oe,
128
126
  onFocus: X,
@@ -131,34 +129,34 @@ const x = (e) => {
131
129
  "aria-label": Z,
132
130
  "aria-labelledby": ce,
133
131
  "aria-describedby": ue,
134
- "aria-invalid": !!c,
132
+ "aria-invalid": !!u,
135
133
  className: ie,
136
134
  ...te
137
135
  }
138
136
  ),
139
- V && /* @__PURE__ */ g(
137
+ N && /* @__PURE__ */ v(
140
138
  "button",
141
139
  {
142
140
  type: "button",
143
- className: de,
144
- onClick: w ? void 0 : u,
145
- tabIndex: u && !w ? 0 : -1,
146
- "aria-hidden": !u,
147
- disabled: w,
148
- "aria-label": u ? h("dateInput.openDatePicker") : void 0,
149
- children: V
141
+ className: se,
142
+ onClick: $ ? void 0 : d,
143
+ tabIndex: d && !$ ? 0 : -1,
144
+ "aria-hidden": !d,
145
+ disabled: $,
146
+ "aria-label": d ? x("dateInput.openDatePicker") : void 0,
147
+ children: N
150
148
  }
151
149
  )
152
150
  ] }),
153
- c && /* @__PURE__ */ g("p", { id: F, className: o.error, role: "alert", children: c })
151
+ u && /* @__PURE__ */ v("p", { id: E, className: o.error, role: "alert", children: u })
154
152
  ]
155
153
  }
156
154
  )
157
155
  );
158
156
  }
159
157
  );
160
- ye.displayName = "DateInput";
161
- function Ie(e) {
158
+ Ie.displayName = "DateInput";
159
+ function $e(e) {
162
160
  return `
163
161
  .${e.fieldset} {
164
162
  margin-bottom: var(--ds-size-4, 16px);
@@ -252,5 +250,5 @@ function Ie(e) {
252
250
  `;
253
251
  }
254
252
  export {
255
- ye as DateInput
253
+ Ie as DateInput
256
254
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rk-designsystem",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "A React component library built on top of Digdir Design System",
5
5
  "author": "daniel@tunetek.no",
6
6
  "license": "MIT",