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
|
|
3
|
-
import
|
|
4
|
-
import { parse as
|
|
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
|
|
7
|
-
const
|
|
8
|
-
const a = e.slice(0, 2),
|
|
9
|
-
return e.length > 4 ? `${a}.${
|
|
10
|
-
},
|
|
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 =
|
|
13
|
-
return
|
|
14
|
-
},
|
|
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:
|
|
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 =
|
|
21
|
-
|
|
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:
|
|
26
|
-
onSuffixClick:
|
|
27
|
-
className:
|
|
25
|
+
suffixIcon: N,
|
|
26
|
+
onSuffixClick: d,
|
|
27
|
+
className: O,
|
|
28
28
|
inputWrapperClassName: q,
|
|
29
29
|
inputClassName: H,
|
|
30
|
-
value:
|
|
30
|
+
value: h,
|
|
31
31
|
defaultValue: A,
|
|
32
|
-
onChange:
|
|
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:
|
|
39
|
+
disabled: $,
|
|
40
40
|
onClick: U,
|
|
41
41
|
onFocus: X,
|
|
42
|
-
onBlur:
|
|
42
|
+
onBlur: w,
|
|
43
43
|
autoComplete: Y = "off",
|
|
44
44
|
"aria-label": Z,
|
|
45
45
|
"aria-labelledby": _,
|
|
46
46
|
description: C,
|
|
47
|
-
error:
|
|
47
|
+
error: u,
|
|
48
48
|
"data-color": ee,
|
|
49
49
|
"data-size": re,
|
|
50
50
|
...te
|
|
51
|
-
} = e,
|
|
52
|
-
|
|
51
|
+
} = e, z = h !== void 0, c = S(null);
|
|
52
|
+
be.useImperativeHandle(
|
|
53
53
|
a,
|
|
54
|
-
() =>
|
|
54
|
+
() => c.current
|
|
55
55
|
);
|
|
56
|
-
const
|
|
56
|
+
const V = S(null), n = B(
|
|
57
57
|
(r, t) => {
|
|
58
|
-
r !==
|
|
58
|
+
r !== V.current && (V.current = r, I == null || I(r, t));
|
|
59
59
|
},
|
|
60
|
-
[
|
|
61
|
-
),
|
|
62
|
-
(r) =>
|
|
60
|
+
[I]
|
|
61
|
+
), k = B(
|
|
62
|
+
(r) => g(D(r)),
|
|
63
63
|
[]
|
|
64
|
-
), [
|
|
65
|
-
() =>
|
|
64
|
+
), [f, j] = ve(
|
|
65
|
+
() => k(h ?? A)
|
|
66
66
|
);
|
|
67
67
|
M(() => {
|
|
68
|
-
if (
|
|
69
|
-
const r =
|
|
70
|
-
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
|
-
}, [
|
|
73
|
-
const oe =
|
|
72
|
+
}, [h, z, f, k]);
|
|
73
|
+
const oe = B(
|
|
74
74
|
(r) => {
|
|
75
|
-
const t = r.target,
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
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
|
-
[
|
|
83
|
-
), ae =
|
|
80
|
+
[f, z, y, n]
|
|
81
|
+
), ae = B(
|
|
84
82
|
(r) => {
|
|
85
|
-
const t =
|
|
86
|
-
t.length === 0 ?
|
|
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
|
-
[
|
|
89
|
-
), ne = [o.fieldset,
|
|
86
|
+
[w, n]
|
|
87
|
+
), ne = [o.fieldset, O].filter(Boolean).join(" "), le = [
|
|
90
88
|
o.inputWrapper,
|
|
91
89
|
q,
|
|
92
|
-
|
|
90
|
+
u ? o.inputWrapperError : ""
|
|
93
91
|
].filter(Boolean).join(" "), ie = [
|
|
94
92
|
H
|
|
95
|
-
].filter(Boolean).join(" "),
|
|
93
|
+
].filter(Boolean).join(" "), se = [
|
|
96
94
|
o.suffixButton,
|
|
97
|
-
|
|
98
|
-
].filter(Boolean).join(" "),
|
|
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__ */
|
|
109
|
-
C && /* @__PURE__ */
|
|
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__ */
|
|
109
|
+
/* @__PURE__ */ v(
|
|
112
110
|
"input",
|
|
113
111
|
{
|
|
114
|
-
ref:
|
|
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:
|
|
117
|
+
value: f,
|
|
120
118
|
readOnly: G,
|
|
121
119
|
placeholder: J,
|
|
122
|
-
id:
|
|
120
|
+
id: p,
|
|
123
121
|
name: Q,
|
|
124
122
|
required: T,
|
|
125
|
-
disabled:
|
|
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": !!
|
|
132
|
+
"aria-invalid": !!u,
|
|
135
133
|
className: ie,
|
|
136
134
|
...te
|
|
137
135
|
}
|
|
138
136
|
),
|
|
139
|
-
|
|
137
|
+
N && /* @__PURE__ */ v(
|
|
140
138
|
"button",
|
|
141
139
|
{
|
|
142
140
|
type: "button",
|
|
143
|
-
className:
|
|
144
|
-
onClick:
|
|
145
|
-
tabIndex:
|
|
146
|
-
"aria-hidden": !
|
|
147
|
-
disabled:
|
|
148
|
-
"aria-label":
|
|
149
|
-
children:
|
|
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
|
-
|
|
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
|
-
|
|
161
|
-
function
|
|
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
|
-
|
|
253
|
+
Ie as DateInput
|
|
256
254
|
};
|