@postenbring/hedwig-react 4.1.2 → 4.2.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.
- package/dist/accordion/accordion-content.js.map +1 -1
- package/dist/accordion/accordion-content.mjs +3 -3
- package/dist/accordion/accordion.js.map +1 -1
- package/dist/accordion/accordion.mjs +4 -4
- package/dist/accordion/index.js.map +1 -1
- package/dist/accordion/index.mjs +4 -4
- package/dist/{chunk-77M2ZTP7.mjs → chunk-3V4GFS46.mjs} +11 -1
- package/dist/chunk-3V4GFS46.mjs.map +1 -0
- package/dist/chunk-5M6MEYM7.mjs +1 -0
- package/dist/chunk-62VLFCXX.mjs +64 -0
- package/dist/chunk-62VLFCXX.mjs.map +1 -0
- package/dist/chunk-CD4LCDK3.mjs +27 -0
- package/dist/chunk-CD4LCDK3.mjs.map +1 -0
- package/dist/chunk-CSIXGT7P.mjs +1 -0
- package/dist/chunk-CVE23PMJ.mjs +1 -0
- package/dist/chunk-CVE23PMJ.mjs.map +1 -0
- package/dist/chunk-D2XZT2RA.mjs +17 -0
- package/dist/chunk-D2XZT2RA.mjs.map +1 -0
- package/dist/{chunk-JFTUBOIF.mjs → chunk-DMRQEQQK.mjs} +27 -9
- package/dist/chunk-DMRQEQQK.mjs.map +1 -0
- package/dist/chunk-DNCWDWK2.mjs +113 -0
- package/dist/chunk-DNCWDWK2.mjs.map +1 -0
- package/dist/chunk-F23MNQCK.mjs +28 -0
- package/dist/chunk-F23MNQCK.mjs.map +1 -0
- package/dist/{chunk-5RXT5GLF.mjs → chunk-F6QJWZJX.mjs} +2 -2
- package/dist/{chunk-UYLKAPXD.mjs → chunk-GICUX46A.mjs} +2 -2
- package/dist/{chunk-SF6EDUHP.mjs → chunk-HOLFVKXQ.mjs} +2 -2
- package/dist/chunk-JGQTAIEP.mjs +67 -0
- package/dist/chunk-JGQTAIEP.mjs.map +1 -0
- package/dist/chunk-JKKH77UC.mjs +103 -0
- package/dist/chunk-JKKH77UC.mjs.map +1 -0
- package/dist/{chunk-GYI4NCUY.mjs → chunk-KPNAC2WN.mjs} +2 -2
- package/dist/{chunk-WNYCOHSD.mjs → chunk-NAXSP4VU.mjs} +2 -2
- package/dist/{chunk-R6MQFVHE.mjs → chunk-O55OTMJ5.mjs} +2 -2
- package/dist/chunk-OQD4GKOS.mjs +65 -0
- package/dist/chunk-OQD4GKOS.mjs.map +1 -0
- package/dist/{chunk-B4D2GO6E.mjs → chunk-QDG2QLFV.mjs} +2 -2
- package/dist/{chunk-B6T36QDV.mjs → chunk-QTC4ATZD.mjs} +2 -2
- package/dist/{chunk-Z56XN4AZ.mjs → chunk-RGZSYJFL.mjs} +14 -5
- package/dist/chunk-RGZSYJFL.mjs.map +1 -0
- package/dist/chunk-RJ763KDH.mjs +21 -0
- package/dist/chunk-RJ763KDH.mjs.map +1 -0
- package/dist/{chunk-AGIY7SFP.mjs → chunk-SO7TS4TS.mjs} +2 -2
- package/dist/{chunk-E6OOFTRQ.mjs → chunk-SQNGMF3D.mjs} +14 -8
- package/dist/chunk-SQNGMF3D.mjs.map +1 -0
- package/dist/{chunk-LHIG6RW7.mjs → chunk-VNH7CZJ4.mjs} +5 -13
- package/dist/chunk-VNH7CZJ4.mjs.map +1 -0
- package/dist/{chunk-HEDGKRGC.mjs → chunk-WMSOBRKN.mjs} +6 -32
- package/dist/chunk-WMSOBRKN.mjs.map +1 -0
- package/dist/{chunk-HBGFFKP3.mjs → chunk-WVCJV74B.mjs} +2 -2
- package/dist/{chunk-EDPWJWQO.mjs → chunk-YQT2TN3U.mjs} +2 -2
- package/dist/footer/footer.js.map +1 -1
- package/dist/footer/footer.mjs +5 -5
- package/dist/footer/index.js.map +1 -1
- package/dist/footer/index.mjs +5 -5
- package/dist/form/checkbox/checkbox.d.ts +10 -1
- package/dist/form/checkbox/checkbox.d.ts.map +1 -1
- package/dist/form/checkbox/checkbox.js +170 -71
- package/dist/form/checkbox/checkbox.js.map +1 -1
- package/dist/form/checkbox/checkbox.mjs +11 -4
- package/dist/form/checkbox/index.js +170 -71
- package/dist/form/checkbox/index.js.map +1 -1
- package/dist/form/checkbox/index.mjs +11 -4
- package/dist/form/date-picker/date-picker.d.ts.map +1 -1
- package/dist/form/date-picker/date-picker.js +75 -45
- package/dist/form/date-picker/date-picker.js.map +1 -1
- package/dist/form/date-picker/date-picker.mjs +8 -4
- package/dist/form/date-picker/index.js +75 -45
- package/dist/form/date-picker/index.js.map +1 -1
- package/dist/form/date-picker/index.mjs +8 -4
- package/dist/form/error-message/error-message.d.ts +2 -0
- package/dist/form/error-message/error-message.d.ts.map +1 -1
- package/dist/form/error-message/error-message.js +18 -8
- package/dist/form/error-message/error-message.js.map +1 -1
- package/dist/form/error-message/error-message.mjs +3 -1
- package/dist/form/error-message/index.js +18 -8
- package/dist/form/error-message/index.js.map +1 -1
- package/dist/form/error-message/index.mjs +3 -1
- package/dist/form/error-summary/error-summary.js.map +1 -1
- package/dist/form/error-summary/error-summary.mjs +3 -3
- package/dist/form/error-summary/index.js.map +1 -1
- package/dist/form/error-summary/index.mjs +3 -3
- package/dist/form/fieldset/fieldset-description.d.ts +12 -0
- package/dist/form/fieldset/fieldset-description.d.ts.map +1 -0
- package/dist/form/fieldset/fieldset-description.js +51 -0
- package/dist/form/fieldset/fieldset-description.js.map +1 -0
- package/dist/form/fieldset/fieldset-description.mjs +8 -0
- package/dist/form/fieldset/fieldset-description.mjs.map +1 -0
- package/dist/form/fieldset/fieldset-legend.d.ts +9 -0
- package/dist/form/fieldset/fieldset-legend.d.ts.map +1 -0
- package/dist/form/fieldset/fieldset-legend.js +72 -0
- package/dist/form/fieldset/fieldset-legend.js.map +1 -0
- package/dist/form/fieldset/fieldset-legend.mjs +8 -0
- package/dist/form/fieldset/fieldset-legend.mjs.map +1 -0
- package/dist/form/fieldset/fieldset.d.ts +30 -6
- package/dist/form/fieldset/fieldset.d.ts.map +1 -1
- package/dist/form/fieldset/fieldset.js +110 -35
- package/dist/form/fieldset/fieldset.js.map +1 -1
- package/dist/form/fieldset/fieldset.mjs +9 -2
- package/dist/form/fieldset/index.d.ts +2 -0
- package/dist/form/fieldset/index.d.ts.map +1 -1
- package/dist/form/fieldset/index.js +114 -35
- package/dist/form/fieldset/index.js.map +1 -1
- package/dist/form/fieldset/index.mjs +16 -3
- package/dist/form/index.d.ts +1 -0
- package/dist/form/index.d.ts.map +1 -1
- package/dist/form/index.js +460 -278
- package/dist/form/index.js.map +1 -1
- package/dist/form/index.mjs +41 -28
- package/dist/form/input/index.js +102 -38
- package/dist/form/input/index.js.map +1 -1
- package/dist/form/input/index.mjs +8 -3
- package/dist/form/input/input.d.ts.map +1 -1
- package/dist/form/input/input.js +102 -38
- package/dist/form/input/input.js.map +1 -1
- package/dist/form/input/input.mjs +8 -3
- package/dist/form/input-group/index.js +58 -22
- package/dist/form/input-group/index.js.map +1 -1
- package/dist/form/input-group/index.mjs +7 -2
- package/dist/form/input-group/input-group.d.ts +8 -0
- package/dist/form/input-group/input-group.d.ts.map +1 -1
- package/dist/form/input-group/input-group.js +58 -22
- package/dist/form/input-group/input-group.js.map +1 -1
- package/dist/form/input-group/input-group.mjs +7 -2
- package/dist/form/radio-button/index.js +139 -86
- package/dist/form/radio-button/index.js.map +1 -1
- package/dist/form/radio-button/index.mjs +12 -5
- package/dist/form/radio-button/radio-button.d.ts +2 -10
- package/dist/form/radio-button/radio-button.d.ts.map +1 -1
- package/dist/form/radio-button/radio-button.js +139 -86
- package/dist/form/radio-button/radio-button.js.map +1 -1
- package/dist/form/radio-button/radio-button.mjs +12 -5
- package/dist/form/radio-button/radio-group.d.ts +11 -13
- package/dist/form/radio-button/radio-group.d.ts.map +1 -1
- package/dist/form/radio-button/radio-group.js +123 -48
- package/dist/form/radio-button/radio-group.js.map +1 -1
- package/dist/form/radio-button/radio-group.mjs +11 -4
- package/dist/form/search-wrapper/index.js +6 -17
- package/dist/form/search-wrapper/index.js.map +1 -1
- package/dist/form/search-wrapper/index.mjs +1 -1
- package/dist/form/search-wrapper/search-wrapper.d.ts +2 -5
- package/dist/form/search-wrapper/search-wrapper.d.ts.map +1 -1
- package/dist/form/search-wrapper/search-wrapper.js +6 -17
- package/dist/form/search-wrapper/search-wrapper.js.map +1 -1
- package/dist/form/search-wrapper/search-wrapper.mjs +1 -1
- package/dist/form/select/index.js +104 -37
- package/dist/form/select/index.js.map +1 -1
- package/dist/form/select/index.mjs +8 -3
- package/dist/form/select/select.d.ts.map +1 -1
- package/dist/form/select/select.js +104 -37
- package/dist/form/select/select.js.map +1 -1
- package/dist/form/select/select.mjs +8 -3
- package/dist/form/textarea/index.js +91 -26
- package/dist/form/textarea/index.js.map +1 -1
- package/dist/form/textarea/index.mjs +8 -3
- package/dist/form/textarea/textarea.d.ts.map +1 -1
- package/dist/form/textarea/textarea.js +91 -26
- package/dist/form/textarea/textarea.js.map +1 -1
- package/dist/form/textarea/textarea.mjs +8 -3
- package/dist/form/validation-message/index.d.ts +3 -0
- package/dist/form/validation-message/index.d.ts.map +1 -0
- package/dist/form/validation-message/index.js +75 -0
- package/dist/form/validation-message/index.js.map +1 -0
- package/dist/form/validation-message/index.mjs +9 -0
- package/dist/form/validation-message/index.mjs.map +1 -0
- package/dist/form/validation-message/validation-message.d.ts +6 -0
- package/dist/form/validation-message/validation-message.d.ts.map +1 -0
- package/dist/form/validation-message/validation-message.js +73 -0
- package/dist/form/validation-message/validation-message.js.map +1 -0
- package/dist/form/validation-message/validation-message.mjs +8 -0
- package/dist/form/validation-message/validation-message.mjs.map +1 -0
- package/dist/index.js +669 -485
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -46
- package/dist/modal/index.js.map +1 -1
- package/dist/modal/index.mjs +2 -2
- package/dist/modal/modal.js.map +1 -1
- package/dist/modal/modal.mjs +2 -2
- package/dist/navbar/index.js.map +1 -1
- package/dist/navbar/index.mjs +3 -3
- package/dist/navbar/navbar-expandable-menu.js.map +1 -1
- package/dist/navbar/navbar-expandable-menu.mjs +2 -2
- package/dist/navbar/navbar.js.map +1 -1
- package/dist/navbar/navbar.mjs +3 -3
- package/dist/skeleton/index.js.map +1 -1
- package/dist/skeleton/index.mjs +3 -3
- package/dist/skeleton/skeleton.js.map +1 -1
- package/dist/skeleton/skeleton.mjs +3 -3
- package/dist/tabs/index.js.map +1 -1
- package/dist/tabs/index.mjs +3 -3
- package/dist/tabs/tabs-list.js.map +1 -1
- package/dist/tabs/tabs-list.mjs +2 -2
- package/dist/tabs/tabs.js.map +1 -1
- package/dist/tabs/tabs.mjs +3 -3
- package/dist/utils/auto-animate-height.js.map +1 -1
- package/dist/utils/auto-animate-height.mjs +2 -2
- package/dist/utils/index.js +11 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +4 -2
- package/dist/utils/utils.d.ts +4 -0
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +11 -0
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/utils.mjs +3 -1
- package/package.json +4 -4
- package/src/form/checkbox/checkbox.tsx +32 -11
- package/src/form/date-picker/date-picker.tsx +7 -1
- package/src/form/error-message/error-message.tsx +8 -14
- package/src/form/fieldset/fieldset-description.tsx +17 -0
- package/src/form/fieldset/fieldset-legend.tsx +22 -0
- package/src/form/fieldset/fieldset.stories.tsx +2 -1
- package/src/form/fieldset/fieldset.tsx +95 -26
- package/src/form/fieldset/index.tsx +2 -0
- package/src/form/index.tsx +1 -0
- package/src/form/input/input.tsx +23 -8
- package/src/form/input-group/input-group.tsx +22 -7
- package/src/form/radio-button/radio-button.stories.tsx +0 -1
- package/src/form/radio-button/radio-button.tsx +8 -34
- package/src/form/radio-button/radio-group.tsx +20 -19
- package/src/form/search-wrapper/search-wrapper.tsx +7 -22
- package/src/form/select/select.tsx +25 -8
- package/src/form/textarea/textarea.tsx +19 -2
- package/src/form/validation-message/index.tsx +2 -0
- package/src/form/validation-message/validation-message.stories.tsx +20 -0
- package/src/form/validation-message/validation-message.tsx +18 -0
- package/src/utils/utils.ts +16 -0
- package/dist/chunk-6BDVJ3J2.mjs +0 -37
- package/dist/chunk-6BDVJ3J2.mjs.map +0 -1
- package/dist/chunk-77M2ZTP7.mjs.map +0 -1
- package/dist/chunk-7T2GDVFS.mjs +0 -37
- package/dist/chunk-7T2GDVFS.mjs.map +0 -1
- package/dist/chunk-BO3EWZGA.mjs +0 -78
- package/dist/chunk-BO3EWZGA.mjs.map +0 -1
- package/dist/chunk-BOPY5K4T.mjs +0 -1
- package/dist/chunk-E6OOFTRQ.mjs.map +0 -1
- package/dist/chunk-HEDGKRGC.mjs.map +0 -1
- package/dist/chunk-IZFODQCF.mjs +0 -36
- package/dist/chunk-IZFODQCF.mjs.map +0 -1
- package/dist/chunk-JFTUBOIF.mjs.map +0 -1
- package/dist/chunk-LHIG6RW7.mjs.map +0 -1
- package/dist/chunk-LMF3QGSF.mjs +0 -1
- package/dist/chunk-Z2ZPTZ6F.mjs +0 -69
- package/dist/chunk-Z2ZPTZ6F.mjs.map +0 -1
- package/dist/chunk-Z56XN4AZ.mjs.map +0 -1
- package/dist/chunk-ZIVURWHY.mjs +0 -30
- package/dist/chunk-ZIVURWHY.mjs.map +0 -1
- package/src/form/error-message/error-message.stories.tsx +0 -20
- /package/dist/{chunk-BOPY5K4T.mjs.map → chunk-5M6MEYM7.mjs.map} +0 -0
- /package/dist/{chunk-LMF3QGSF.mjs.map → chunk-CSIXGT7P.mjs.map} +0 -0
- /package/dist/{chunk-5RXT5GLF.mjs.map → chunk-F6QJWZJX.mjs.map} +0 -0
- /package/dist/{chunk-UYLKAPXD.mjs.map → chunk-GICUX46A.mjs.map} +0 -0
- /package/dist/{chunk-SF6EDUHP.mjs.map → chunk-HOLFVKXQ.mjs.map} +0 -0
- /package/dist/{chunk-GYI4NCUY.mjs.map → chunk-KPNAC2WN.mjs.map} +0 -0
- /package/dist/{chunk-WNYCOHSD.mjs.map → chunk-NAXSP4VU.mjs.map} +0 -0
- /package/dist/{chunk-R6MQFVHE.mjs.map → chunk-O55OTMJ5.mjs.map} +0 -0
- /package/dist/{chunk-B4D2GO6E.mjs.map → chunk-QDG2QLFV.mjs.map} +0 -0
- /package/dist/{chunk-B6T36QDV.mjs.map → chunk-QTC4ATZD.mjs.map} +0 -0
- /package/dist/{chunk-AGIY7SFP.mjs.map → chunk-SO7TS4TS.mjs.map} +0 -0
- /package/dist/{chunk-HBGFFKP3.mjs.map → chunk-WVCJV74B.mjs.map} +0 -0
- /package/dist/{chunk-EDPWJWQO.mjs.map → chunk-YQT2TN3U.mjs.map} +0 -0
|
@@ -66,39 +66,69 @@ var import_react4 = require("react");
|
|
|
66
66
|
var import_typed_classname3 = require("@postenbring/hedwig-css/typed-classname");
|
|
67
67
|
|
|
68
68
|
// src/form/input-group/input-group.tsx
|
|
69
|
-
var
|
|
69
|
+
var import_react3 = require("react");
|
|
70
70
|
var import_typed_classname2 = require("@postenbring/hedwig-css/typed-classname");
|
|
71
71
|
|
|
72
|
-
// src/form/
|
|
72
|
+
// src/form/validation-message/validation-message.tsx
|
|
73
73
|
var import_typed_classname = require("@postenbring/hedwig-css/typed-classname");
|
|
74
74
|
var import_react = require("react");
|
|
75
75
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
76
|
-
var
|
|
76
|
+
var ValidationMessage = (0, import_react.forwardRef)(
|
|
77
77
|
(_a, ref) => {
|
|
78
|
-
var _b = _a, {
|
|
78
|
+
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
79
79
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
80
80
|
"div",
|
|
81
|
-
|
|
81
|
+
__spreadValues({
|
|
82
82
|
"aria-live": "polite",
|
|
83
|
-
className: (0, import_typed_classname.clsx)("hds-
|
|
84
|
-
id,
|
|
83
|
+
className: (0, import_typed_classname.clsx)("hds-validation-message", className),
|
|
85
84
|
ref
|
|
86
|
-
}, rest)
|
|
87
|
-
children
|
|
88
|
-
})
|
|
85
|
+
}, rest)
|
|
89
86
|
);
|
|
90
87
|
}
|
|
91
88
|
);
|
|
92
|
-
|
|
89
|
+
ValidationMessage.displayName = "ValidationMessage";
|
|
90
|
+
|
|
91
|
+
// src/utils/utils.ts
|
|
92
|
+
var React = __toESM(require("react"));
|
|
93
|
+
var import_react2 = require("react");
|
|
94
|
+
function useMergeRefs(refs) {
|
|
95
|
+
return React.useMemo(() => {
|
|
96
|
+
if (refs.every((ref) => ref === null)) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return (value) => {
|
|
100
|
+
refs.forEach((ref) => {
|
|
101
|
+
if (typeof ref === "function") {
|
|
102
|
+
ref(value);
|
|
103
|
+
} else if (ref !== null) {
|
|
104
|
+
ref.current = value;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
}, refs);
|
|
109
|
+
}
|
|
110
|
+
function getValidationMessageValue(validationMessage, errorMessage) {
|
|
111
|
+
if (validationMessage) {
|
|
112
|
+
if (typeof validationMessage === "object" && "value" in validationMessage) {
|
|
113
|
+
return validationMessage.value;
|
|
114
|
+
}
|
|
115
|
+
return validationMessage;
|
|
116
|
+
}
|
|
117
|
+
return errorMessage;
|
|
118
|
+
}
|
|
119
|
+
var inertBooleanSupported = Number(import_react2.version.split(".")[0]) >= 19;
|
|
93
120
|
|
|
94
121
|
// src/form/input-group/input-group.tsx
|
|
95
122
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
96
|
-
var InputGroup = (0,
|
|
123
|
+
var InputGroup = (0, import_react3.forwardRef)(function InputGroup2(_a, ref) {
|
|
97
124
|
var _b = _a, {
|
|
98
125
|
id,
|
|
99
126
|
className,
|
|
100
127
|
style,
|
|
128
|
+
"data-color": dataColor = void 0,
|
|
101
129
|
size = "large",
|
|
130
|
+
validationMessage,
|
|
131
|
+
validationMessageProps,
|
|
102
132
|
errorMessage,
|
|
103
133
|
errorMessageProps,
|
|
104
134
|
labelProps: _c = {}
|
|
@@ -111,7 +141,10 @@ var InputGroup = (0, import_react2.forwardRef)(function InputGroup2(_a, ref) {
|
|
|
111
141
|
"id",
|
|
112
142
|
"className",
|
|
113
143
|
"style",
|
|
144
|
+
"data-color",
|
|
114
145
|
"size",
|
|
146
|
+
"validationMessage",
|
|
147
|
+
"validationMessageProps",
|
|
115
148
|
"errorMessage",
|
|
116
149
|
"errorMessageProps",
|
|
117
150
|
"labelProps",
|
|
@@ -120,12 +153,14 @@ var InputGroup = (0, import_react2.forwardRef)(function InputGroup2(_a, ref) {
|
|
|
120
153
|
"readOnly",
|
|
121
154
|
"children"
|
|
122
155
|
]);
|
|
123
|
-
const
|
|
124
|
-
const inputId = (0,
|
|
156
|
+
const validationMessageId = (0, import_react3.useId)();
|
|
157
|
+
const inputId = (0, import_react3.useId)();
|
|
158
|
+
const validationColor = errorMessage ? "error" : dataColor;
|
|
159
|
+
const validationMessageValue = getValidationMessageValue(validationMessage, errorMessage);
|
|
125
160
|
const renderInput = () => {
|
|
126
161
|
var _a2;
|
|
127
162
|
const inputProps = {
|
|
128
|
-
"aria-describedby":
|
|
163
|
+
"aria-describedby": validationMessage ? validationMessageId : void 0,
|
|
129
164
|
"aria-invalid": errorMessage ? true : void 0,
|
|
130
165
|
id: id != null ? id : inputId,
|
|
131
166
|
className: (0, import_typed_classname2.clsx)("hds-input-group__input")
|
|
@@ -133,11 +168,11 @@ var InputGroup = (0, import_react2.forwardRef)(function InputGroup2(_a, ref) {
|
|
|
133
168
|
if (typeof children === "function") {
|
|
134
169
|
return children(inputProps);
|
|
135
170
|
}
|
|
136
|
-
const input =
|
|
137
|
-
if (!(0,
|
|
171
|
+
const input = import_react3.Children.toArray(children)[0];
|
|
172
|
+
if (!(0, import_react3.isValidElement)(input)) {
|
|
138
173
|
return;
|
|
139
174
|
}
|
|
140
|
-
return (0,
|
|
175
|
+
return (0, import_react3.cloneElement)(input, __spreadProps(__spreadValues(__spreadValues({}, inputProps), input.props), {
|
|
141
176
|
className: `${inputProps.className} ${(_a2 = input.props.className) != null ? _a2 : ""}`
|
|
142
177
|
}));
|
|
143
178
|
};
|
|
@@ -147,13 +182,13 @@ var InputGroup = (0, import_react2.forwardRef)(function InputGroup2(_a, ref) {
|
|
|
147
182
|
className: (0, import_typed_classname2.clsx)(
|
|
148
183
|
"hds-input-group",
|
|
149
184
|
{
|
|
150
|
-
[`hds-input-group--${size}`]: size
|
|
151
|
-
"hds-input-group--error": errorMessage
|
|
185
|
+
[`hds-input-group--${size}`]: size
|
|
152
186
|
},
|
|
153
187
|
className
|
|
154
188
|
),
|
|
155
189
|
ref,
|
|
156
|
-
style
|
|
190
|
+
style,
|
|
191
|
+
"data-color": validationColor
|
|
157
192
|
}, rest), {
|
|
158
193
|
children: [
|
|
159
194
|
label !== null && label !== void 0 && label !== false && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
@@ -174,39 +209,27 @@ var InputGroup = (0, import_react2.forwardRef)(function InputGroup2(_a, ref) {
|
|
|
174
209
|
children: renderInput()
|
|
175
210
|
}
|
|
176
211
|
),
|
|
177
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
212
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
213
|
+
ValidationMessage,
|
|
214
|
+
__spreadProps(__spreadValues({
|
|
215
|
+
id: validationMessageId
|
|
216
|
+
}, validationMessageProps != null ? validationMessageProps : errorMessageProps), {
|
|
217
|
+
children: validationMessageValue
|
|
218
|
+
})
|
|
219
|
+
)
|
|
178
220
|
]
|
|
179
221
|
})
|
|
180
222
|
);
|
|
181
223
|
});
|
|
182
224
|
|
|
183
|
-
// src/utils/utils.ts
|
|
184
|
-
var React = __toESM(require("react"));
|
|
185
|
-
var import_react3 = require("react");
|
|
186
|
-
function useMergeRefs(refs) {
|
|
187
|
-
return React.useMemo(() => {
|
|
188
|
-
if (refs.every((ref) => ref === null)) {
|
|
189
|
-
return null;
|
|
190
|
-
}
|
|
191
|
-
return (value) => {
|
|
192
|
-
refs.forEach((ref) => {
|
|
193
|
-
if (typeof ref === "function") {
|
|
194
|
-
ref(value);
|
|
195
|
-
} else if (ref !== null) {
|
|
196
|
-
ref.current = value;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
};
|
|
200
|
-
}, refs);
|
|
201
|
-
}
|
|
202
|
-
var inertBooleanSupported = Number(import_react3.version.split(".")[0]) >= 19;
|
|
203
|
-
|
|
204
225
|
// src/form/date-picker/date-picker.tsx
|
|
205
226
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
206
227
|
var DatePicker = (0, import_react4.forwardRef)(function DatePicker2(_a, ref) {
|
|
207
228
|
var _b = _a, {
|
|
208
229
|
className,
|
|
209
230
|
size,
|
|
231
|
+
validationMessage,
|
|
232
|
+
validationMessageProps,
|
|
210
233
|
errorMessage,
|
|
211
234
|
labelProps,
|
|
212
235
|
label,
|
|
@@ -214,10 +237,13 @@ var DatePicker = (0, import_react4.forwardRef)(function DatePicker2(_a, ref) {
|
|
|
214
237
|
style,
|
|
215
238
|
disabled,
|
|
216
239
|
readOnly,
|
|
240
|
+
"data-color": dataColor,
|
|
217
241
|
calendarButtonTitle = "\xC5pne kalender"
|
|
218
242
|
} = _b, rest = __objRest(_b, [
|
|
219
243
|
"className",
|
|
220
244
|
"size",
|
|
245
|
+
"validationMessage",
|
|
246
|
+
"validationMessageProps",
|
|
221
247
|
"errorMessage",
|
|
222
248
|
"labelProps",
|
|
223
249
|
"label",
|
|
@@ -225,6 +251,7 @@ var DatePicker = (0, import_react4.forwardRef)(function DatePicker2(_a, ref) {
|
|
|
225
251
|
"style",
|
|
226
252
|
"disabled",
|
|
227
253
|
"readOnly",
|
|
254
|
+
"data-color",
|
|
228
255
|
"calendarButtonTitle"
|
|
229
256
|
]);
|
|
230
257
|
const inputRef = (0, import_react4.useRef)(null);
|
|
@@ -234,6 +261,8 @@ var DatePicker = (0, import_react4.forwardRef)(function DatePicker2(_a, ref) {
|
|
|
234
261
|
{
|
|
235
262
|
className: (0, import_typed_classname3.clsx)("hds-date-picker", className),
|
|
236
263
|
disabled,
|
|
264
|
+
validationMessage,
|
|
265
|
+
validationMessageProps,
|
|
237
266
|
errorMessage,
|
|
238
267
|
id,
|
|
239
268
|
label,
|
|
@@ -241,15 +270,16 @@ var DatePicker = (0, import_react4.forwardRef)(function DatePicker2(_a, ref) {
|
|
|
241
270
|
readOnly,
|
|
242
271
|
style,
|
|
243
272
|
size,
|
|
273
|
+
"data-color": dataColor,
|
|
244
274
|
children: (inputProps) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
245
275
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
246
276
|
"input",
|
|
247
|
-
__spreadProps(__spreadValues(
|
|
277
|
+
__spreadValues(__spreadProps(__spreadValues({}, inputProps), {
|
|
248
278
|
disabled,
|
|
249
279
|
readOnly,
|
|
250
280
|
ref: mergedRef,
|
|
251
281
|
type: "date"
|
|
252
|
-
})
|
|
282
|
+
}), rest)
|
|
253
283
|
),
|
|
254
284
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
255
285
|
"button",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/form/date-picker/date-picker.tsx","../../../src/form/input-group/input-group.tsx","../../../src/form/error-message/error-message.tsx","../../../src/utils/utils.ts"],"sourcesContent":["import { forwardRef, useRef, type InputHTMLAttributes } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { InputGroup, type InputGroupProps } from \"../input-group\";\nimport { useMergeRefs } from \"../../utils/utils\";\n\nexport type DatePickerProps = Omit<\n InputGroupProps & Omit<InputHTMLAttributes<HTMLInputElement>, \"size\">,\n \"children\" | \"type\"\n> & {\n /**\n * Accessible title for the calendar button\n *\n * This button currently only shows in Chrome.\n *\n * @defaultValue \"Åpne kalender\"\n */\n calendarButtonTitle?: string;\n};\n\n/**\n * A basic implementation of a date picker\n *\n * This date picker is an implementation of native date picker, as you get\n * with `<input type=\"date\" />`, where the input field is dressed in Hedwig styling.\n *\n * Due to accessibility concerns you will only see the appropriate Hedwig calendar\n * icon in Chrome. Firefox will show built in icon and Safari will show no icon.\n * Not tested in Edge.\n */\nexport const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(function DatePicker(\n {\n className,\n size,\n errorMessage,\n labelProps,\n label,\n id,\n style,\n disabled,\n readOnly,\n calendarButtonTitle = \"Åpne kalender\",\n ...rest\n },\n ref,\n) {\n const inputRef = useRef<HTMLInputElement>(null);\n const mergedRef = useMergeRefs([inputRef, ref]);\n\n return (\n <InputGroup\n className={clsx(\"hds-date-picker\", className as undefined)}\n disabled={disabled}\n errorMessage={errorMessage}\n id={id}\n label={label}\n labelProps={labelProps}\n readOnly={readOnly}\n style={style}\n size={size}\n >\n {(inputProps) => (\n <>\n <input\n {...rest}\n {...inputProps}\n disabled={disabled}\n readOnly={readOnly}\n ref={mergedRef}\n type=\"date\"\n />\n <button\n className={clsx(\"hds-date-picker__calendar-button\")}\n type=\"button\"\n title={calendarButtonTitle}\n onClick={() => {\n inputRef.current?.showPicker();\n }}\n />\n </>\n )}\n </InputGroup>\n );\n});\n\nDatePicker.displayName = \"DatePicker\";\n","import { useId, forwardRef, Children, isValidElement, cloneElement } from \"react\";\nimport type { LabelHTMLAttributes, ReactNode, CSSProperties } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { ErrorMessage, type ErrorMessageProps } from \"../error-message\";\n\ninterface InputProps {\n \"aria-describedby\"?: string;\n \"aria-invalid\"?: boolean;\n id?: string;\n className?: string;\n}\n\nexport interface InputGroupProps {\n id?: string;\n className?: string;\n style?: CSSProperties;\n size?: \"large\" | \"small\";\n errorMessage?: ReactNode;\n errorMessageProps?: Partial<ErrorMessageProps>;\n labelProps?: LabelHTMLAttributes<HTMLLabelElement>;\n label?: ReactNode;\n disabled?: boolean;\n readOnly?: boolean;\n /**\n * `children` must be either a single input element or a render function.\n *\n * If you use a render function, make sure you spread the input props to the appropriate element.\n */\n children: Exclude<ReactNode, Iterable<ReactNode>> | ((inputProps: InputProps) => ReactNode);\n}\n\nexport const InputGroup = forwardRef<HTMLDivElement, InputGroupProps>(function InputGroup(\n {\n id,\n className,\n style,\n size = \"large\",\n errorMessage,\n errorMessageProps,\n labelProps: { className: labelClassName, ...labelProps } = {},\n label,\n disabled,\n readOnly,\n children,\n ...rest\n },\n ref,\n) {\n const errorMessageId = useId();\n const inputId = useId();\n\n const renderInput = () => {\n const inputProps: InputProps = {\n \"aria-describedby\": errorMessage ? errorMessageId : undefined,\n \"aria-invalid\": errorMessage ? true : undefined,\n id: id ?? inputId,\n className: clsx(\"hds-input-group__input\"),\n };\n\n if (typeof children === \"function\") {\n return children(inputProps);\n }\n\n const input: ReactNode = Children.toArray(children)[0];\n\n if (!isValidElement<InputProps>(input)) {\n return;\n }\n\n return cloneElement<InputProps>(input, {\n ...inputProps,\n ...input.props,\n className: `${inputProps.className} ${input.props.className ?? \"\"}`,\n });\n };\n\n return (\n <div\n className={clsx(\n \"hds-input-group\",\n {\n [`hds-input-group--${size}`]: size,\n \"hds-input-group--error\": errorMessage,\n },\n className as undefined,\n )}\n ref={ref}\n style={style}\n {...rest}\n >\n {label !== null && label !== undefined && label !== false && (\n <label\n className={clsx(\"hds-input-group__label\", labelClassName as undefined)}\n {...labelProps}\n htmlFor={id ?? inputId}\n >\n {label}\n </label>\n )}\n <div\n className={clsx(\"hds-input-group__input-wrapper\")}\n data-disabled={disabled}\n data-readonly={readOnly}\n >\n {renderInput()}\n </div>\n <ErrorMessage id={errorMessageId} {...errorMessageProps}>\n {errorMessage}\n </ErrorMessage>\n </div>\n );\n});\n","import { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { forwardRef, type ReactNode } from \"react\";\n\nexport interface ErrorMessageProps extends React.HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n id: string;\n className?: string;\n}\n\nexport const ErrorMessage = forwardRef<HTMLDivElement, ErrorMessageProps>(\n ({ children, id, className, ...rest }, ref) => {\n return (\n <div\n aria-live=\"polite\"\n className={clsx(\"hds-error-message\", className as undefined)}\n id={id}\n ref={ref}\n {...rest}\n >\n {children}\n </div>\n );\n },\n);\nErrorMessage.displayName = \"ErrorMessage\";\n","import * as React from \"react\";\nimport { useCallback, useEffect, useState, version } from \"react\";\n\n/**\n * Merges an array of refs into a single memoized callback ref or `null`.\n * @see https://floating-ui.com/docs/useMergeRefs\n */\nexport function useMergeRefs<Instance>(\n refs: (React.Ref<Instance> | undefined)[],\n): React.RefCallback<Instance> | null {\n return React.useMemo(() => {\n if (refs.every((ref) => ref === null)) {\n return null;\n }\n\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(value);\n } else if (ref !== null) {\n (ref as React.MutableRefObject<Instance | null>).current = value;\n }\n });\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, refs);\n}\n\nexport function useResize<Instance extends HTMLElement>(\n ref: React.RefObject<Instance> | undefined | null,\n): { width: number; height: number } {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n const handleResize = useCallback(() => {\n if (ref?.current !== null) {\n setWidth(ref?.current?.offsetWidth ?? 0);\n setHeight(ref?.current?.offsetHeight ?? 0);\n }\n }, [ref]);\n useEffect(() => {\n window.addEventListener(\"load\", handleResize);\n window.addEventListener(\"resize\", handleResize);\n return () => {\n window.removeEventListener(\"load\", handleResize);\n window.removeEventListener(\"resize\", handleResize);\n };\n }, [ref, handleResize]);\n useEffect(() => {\n handleResize();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, []);\n return { width, height };\n}\n\nfunction subscribe() {\n // eslint-disable-next-line @typescript-eslint/no-empty-function -- It's ok\n return () => {};\n}\n\nexport function useHydrated() {\n return React.useSyncExternalStore(\n subscribe,\n () => true,\n () => false,\n );\n}\n\n/**\n * Trap focus inside an element using the `inert` attribute.\n *\n * Adds `inert` to all siblings of the given element, and all their ancestors up to the body.\n * Returns a cleanup function which removes the `inert` property from the elements, effectively giving focus back to rest of the document.\n *\n * NOTE: Does not support portals, i.e. elements outside the DOM hierarchy of the given element.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert\n * @see https://web.dev/articles/inert\n */\nexport function focusTrap(element: HTMLElement) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function -- NOP on focus trapping the body element\n if (element === document.body) return () => {};\n\n let inertElements: HTMLElement[] = [];\n for (let el: HTMLElement | null = element; el; el = el.parentElement) {\n if (el === document.body) break;\n\n for (const sibling of el.parentElement?.children ?? []) {\n if (sibling === el) continue;\n if (!(sibling instanceof HTMLElement)) continue;\n if (sibling.hasAttribute(\"inert\")) continue;\n\n sibling.setAttribute(\"inert\", \"true\");\n inertElements.push(sibling);\n }\n }\n\n return () => {\n releaseFocusTrap(inertElements);\n inertElements = [];\n };\n}\n\n/**\n * Unset the `inert` attribute on all elements given\n */\nfunction releaseFocusTrap(inertElements: Iterable<HTMLElement>) {\n for (const el of inertElements) {\n el.removeAttribute(\"inert\");\n }\n}\n\n/**\n * React 19 supports inert prop\n * React 18 needs inert to be a string\n */\nconst inertBooleanSupported: boolean = Number(version.split(\".\")[0]) >= 19;\n\n/**\n * Returns the inert prop value based on the React version.\n */\nexport const inertPropValue: (x: boolean) => boolean | \"\" | undefined = inertBooleanSupported\n ? (x: boolean): boolean => x\n : (x: boolean): \"\" | undefined => (x ? \"\" : undefined);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAA6D;AAC7D,IAAAC,0BAAqB;;;ACDrB,IAAAC,gBAA0E;AAE1E,IAAAC,0BAAqB;;;ACFrB,6BAAqB;AACrB,mBAA2C;AAWrC;AAHC,IAAM,mBAAe;AAAA,EAC1B,CAAC,IAAsC,QAAQ;AAA9C,iBAAE,YAAU,IAAI,UAVnB,IAUG,IAA8B,iBAA9B,IAA8B,CAA5B,YAAU,MAAI;AACf,WACE;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;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,sBAAsB;AAAA,EAxC1B,IA8BE,IAWK,iBAXL,IAWK;AAAA,IAVH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAKF,QAAM,eAAW,sBAAyB,IAAI;AAC9C,QAAM,YAAY,aAAa,CAAC,UAAU,GAAG,CAAC;AAE9C,SACE;AAAA,IAAC;AAAA;AAAA,MACC,eAAW,8BAAK,mBAAmB,SAAsB;AAAA,MACzD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEC,WAAC,eACA,8EACE;AAAA;AAAA,UAAC;AAAA,0DACK,OACA,aAFL;AAAA,YAGC;AAAA,YACA;AAAA,YACA,KAAK;AAAA,YACL,MAAK;AAAA;AAAA,QACP;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,eAAW,8BAAK,kCAAkC;AAAA,YAClD,MAAK;AAAA,YACL,OAAO;AAAA,YACP,SAAS,MAAM;AA1E3B,kBAAAC;AA2Ec,eAAAA,MAAA,SAAS,YAAT,gBAAAA,IAAkB;AAAA,YACpB;AAAA;AAAA,QACF;AAAA,SACF;AAAA;AAAA,EAEJ;AAEJ,CAAC;AAED,WAAW,cAAc;","names":["import_react","import_typed_classname","import_react","import_typed_classname","import_jsx_runtime","InputGroup","_a","import_react","import_jsx_runtime","DatePicker","_a"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/form/date-picker/date-picker.tsx","../../../src/form/input-group/input-group.tsx","../../../src/form/validation-message/validation-message.tsx","../../../src/utils/utils.ts"],"sourcesContent":["import { forwardRef, useRef, type InputHTMLAttributes } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { InputGroup, type InputGroupProps } from \"../input-group\";\nimport { useMergeRefs } from \"../../utils/utils\";\n\nexport type DatePickerProps = Omit<\n InputGroupProps & Omit<InputHTMLAttributes<HTMLInputElement>, \"size\">,\n \"children\" | \"type\"\n> & {\n /**\n * Accessible title for the calendar button\n *\n * This button currently only shows in Chrome.\n *\n * @defaultValue \"Åpne kalender\"\n */\n calendarButtonTitle?: string;\n};\n\n/**\n * A basic implementation of a date picker\n *\n * This date picker is an implementation of native date picker, as you get\n * with `<input type=\"date\" />`, where the input field is dressed in Hedwig styling.\n *\n * Due to accessibility concerns you will only see the appropriate Hedwig calendar\n * icon in Chrome. Firefox will show built in icon and Safari will show no icon.\n * Not tested in Edge.\n */\nexport const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(function DatePicker(\n {\n className,\n size,\n validationMessage,\n validationMessageProps,\n errorMessage,\n labelProps,\n label,\n id,\n style,\n disabled,\n readOnly,\n \"data-color\": dataColor,\n calendarButtonTitle = \"Åpne kalender\",\n ...rest\n },\n ref,\n) {\n const inputRef = useRef<HTMLInputElement>(null);\n const mergedRef = useMergeRefs([inputRef, ref]);\n\n return (\n <InputGroup\n className={clsx(\"hds-date-picker\", className as undefined)}\n disabled={disabled}\n validationMessage={validationMessage}\n validationMessageProps={validationMessageProps}\n errorMessage={errorMessage}\n id={id}\n label={label}\n labelProps={labelProps}\n readOnly={readOnly}\n style={style}\n size={size}\n data-color={dataColor}\n >\n {(inputProps) => (\n <>\n <input\n {...inputProps}\n disabled={disabled}\n readOnly={readOnly}\n ref={mergedRef}\n type=\"date\"\n {...rest}\n />\n <button\n className={clsx(\"hds-date-picker__calendar-button\")}\n type=\"button\"\n title={calendarButtonTitle}\n onClick={() => {\n inputRef.current?.showPicker();\n }}\n />\n </>\n )}\n </InputGroup>\n );\n});\n\nDatePicker.displayName = \"DatePicker\";\n","import { useId, forwardRef, Children, isValidElement, cloneElement } from \"react\";\nimport type { LabelHTMLAttributes, ReactNode, CSSProperties } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { ValidationMessage, type ValidationMessageProps } from \"../validation-message\";\nimport { type ErrorMessageProps } from \"../error-message\";\nimport { getValidationMessageValue } from \"../../utils\";\n\ninterface InputProps {\n \"aria-describedby\"?: string;\n \"aria-invalid\"?: boolean;\n id?: string;\n className?: string;\n}\n\nexport interface InputGroupProps {\n id?: string;\n className?: string;\n style?: CSSProperties;\n \"data-color\"?: \"info\" | \"success\" | \"warning\" | \"error\";\n size?: \"large\" | \"small\";\n validationMessage?: ReactNode | { value: ReactNode };\n validationMessageProps?: Partial<ValidationMessageProps>;\n /** @deprecated Use `validationMessage` instead */\n errorMessage?: ReactNode;\n /** @deprecated Use `validationMessageProps` instead */\n errorMessageProps?: Partial<ErrorMessageProps>;\n labelProps?: LabelHTMLAttributes<HTMLLabelElement>;\n label?: ReactNode;\n disabled?: boolean;\n readOnly?: boolean;\n /**\n * `children` must be either a single input element or a render function.\n *\n * If you use a render function, make sure you spread the input props to the appropriate element.\n */\n children: Exclude<ReactNode, Iterable<ReactNode>> | ((inputProps: InputProps) => ReactNode);\n}\n\nexport const InputGroup = forwardRef<HTMLDivElement, InputGroupProps>(function InputGroup(\n {\n id,\n className,\n style,\n \"data-color\": dataColor = undefined,\n size = \"large\",\n validationMessage,\n validationMessageProps,\n errorMessage,\n errorMessageProps,\n labelProps: { className: labelClassName, ...labelProps } = {},\n label,\n disabled,\n readOnly,\n children,\n ...rest\n },\n ref,\n) {\n const validationMessageId = useId();\n const inputId = useId();\n const validationColor = errorMessage ? \"error\" : dataColor;\n const validationMessageValue = getValidationMessageValue(validationMessage, errorMessage);\n\n const renderInput = () => {\n const inputProps: InputProps = {\n \"aria-describedby\": validationMessage ? validationMessageId : undefined,\n \"aria-invalid\": errorMessage ? true : undefined,\n id: id ?? inputId,\n className: clsx(\"hds-input-group__input\"),\n };\n\n if (typeof children === \"function\") {\n return children(inputProps);\n }\n\n const input: ReactNode = Children.toArray(children)[0];\n\n if (!isValidElement<InputProps>(input)) {\n return;\n }\n\n return cloneElement<InputProps>(input, {\n ...inputProps,\n ...input.props,\n className: `${inputProps.className} ${input.props.className ?? \"\"}`,\n });\n };\n\n return (\n <div\n className={clsx(\n \"hds-input-group\",\n {\n [`hds-input-group--${size}`]: size,\n },\n className as undefined,\n )}\n ref={ref}\n style={style}\n data-color={validationColor}\n {...rest}\n >\n {label !== null && label !== undefined && label !== false && (\n <label\n className={clsx(\"hds-input-group__label\", labelClassName as undefined)}\n {...labelProps}\n htmlFor={id ?? inputId}\n >\n {label}\n </label>\n )}\n <div\n className={clsx(\"hds-input-group__input-wrapper\")}\n data-disabled={disabled}\n data-readonly={readOnly}\n >\n {renderInput()}\n </div>\n <ValidationMessage\n id={validationMessageId}\n {...(validationMessageProps ?? errorMessageProps)}\n >\n {validationMessageValue}\n </ValidationMessage>\n </div>\n );\n});\n","import { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { forwardRef, type HTMLAttributes } from \"react\";\n\nexport interface ValidationMessageProps extends HTMLAttributes<HTMLDivElement> {\n className?: string;\n}\n\nexport const ValidationMessage = forwardRef<HTMLDivElement, ValidationMessageProps>(\n ({ className, ...rest }, ref) => (\n <div\n aria-live=\"polite\"\n className={clsx(\"hds-validation-message\", className as undefined)}\n ref={ref}\n {...rest}\n />\n ),\n);\nValidationMessage.displayName = \"ValidationMessage\";\n","import * as React from \"react\";\nimport { useCallback, useEffect, useState, version } from \"react\";\nimport type { ReactNode } from \"react\";\n\n/**\n * Merges an array of refs into a single memoized callback ref or `null`.\n * @see https://floating-ui.com/docs/useMergeRefs\n */\nexport function useMergeRefs<Instance>(\n refs: (React.Ref<Instance> | undefined)[],\n): React.RefCallback<Instance> | null {\n return React.useMemo(() => {\n if (refs.every((ref) => ref === null)) {\n return null;\n }\n\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(value);\n } else if (ref !== null) {\n (ref as React.MutableRefObject<Instance | null>).current = value;\n }\n });\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, refs);\n}\n\nexport function useResize<Instance extends HTMLElement>(\n ref: React.RefObject<Instance> | undefined | null,\n): { width: number; height: number } {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n const handleResize = useCallback(() => {\n if (ref?.current !== null) {\n setWidth(ref?.current?.offsetWidth ?? 0);\n setHeight(ref?.current?.offsetHeight ?? 0);\n }\n }, [ref]);\n useEffect(() => {\n window.addEventListener(\"load\", handleResize);\n window.addEventListener(\"resize\", handleResize);\n return () => {\n window.removeEventListener(\"load\", handleResize);\n window.removeEventListener(\"resize\", handleResize);\n };\n }, [ref, handleResize]);\n useEffect(() => {\n handleResize();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, []);\n return { width, height };\n}\n\nfunction subscribe() {\n // eslint-disable-next-line @typescript-eslint/no-empty-function -- It's ok\n return () => {};\n}\n\nexport function useHydrated() {\n return React.useSyncExternalStore(\n subscribe,\n () => true,\n () => false,\n );\n}\n\nexport function getValidationMessageValue(\n validationMessage?: ReactNode | { value: ReactNode },\n errorMessage?: ReactNode,\n): ReactNode {\n if (validationMessage) {\n if (typeof validationMessage === \"object\" && \"value\" in validationMessage) {\n return validationMessage.value;\n }\n\n return validationMessage;\n }\n\n return errorMessage;\n}\n\n/**\n * Trap focus inside an element using the `inert` attribute.\n *\n * Adds `inert` to all siblings of the given element, and all their ancestors up to the body.\n * Returns a cleanup function which removes the `inert` property from the elements, effectively giving focus back to rest of the document.\n *\n * NOTE: Does not support portals, i.e. elements outside the DOM hierarchy of the given element.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert\n * @see https://web.dev/articles/inert\n */\nexport function focusTrap(element: HTMLElement) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function -- NOP on focus trapping the body element\n if (element === document.body) return () => {};\n\n let inertElements: HTMLElement[] = [];\n for (let el: HTMLElement | null = element; el; el = el.parentElement) {\n if (el === document.body) break;\n\n for (const sibling of el.parentElement?.children ?? []) {\n if (sibling === el) continue;\n if (!(sibling instanceof HTMLElement)) continue;\n if (sibling.hasAttribute(\"inert\")) continue;\n\n sibling.setAttribute(\"inert\", \"true\");\n inertElements.push(sibling);\n }\n }\n\n return () => {\n releaseFocusTrap(inertElements);\n inertElements = [];\n };\n}\n\n/**\n * Unset the `inert` attribute on all elements given\n */\nfunction releaseFocusTrap(inertElements: Iterable<HTMLElement>) {\n for (const el of inertElements) {\n el.removeAttribute(\"inert\");\n }\n}\n\n/**\n * React 19 supports inert prop\n * React 18 needs inert to be a string\n */\nconst inertBooleanSupported: boolean = Number(version.split(\".\")[0]) >= 19;\n\n/**\n * Returns the inert prop value based on the React version.\n */\nexport const inertPropValue: (x: boolean) => boolean | \"\" | undefined = inertBooleanSupported\n ? (x: boolean): boolean => x\n : (x: boolean): \"\" | undefined => (x ? \"\" : undefined);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAA6D;AAC7D,IAAAC,0BAAqB;;;ACDrB,IAAAC,gBAA0E;AAE1E,IAAAC,0BAAqB;;;ACFrB,6BAAqB;AACrB,mBAAgD;AAQ5C;AAFG,IAAM,wBAAoB;AAAA,EAC/B,CAAC,IAAwB,QAAK;AAA7B,iBAAE,YARL,IAQG,IAAgB,iBAAhB,IAAgB,CAAd;AACD;AAAA,MAAC;AAAA;AAAA,QACC,aAAU;AAAA,QACV,eAAW,6BAAK,0BAA0B,SAAsB;AAAA,QAChE;AAAA,SACI;AAAA,IACN;AAAA;AAEJ;AACA,kBAAkB,cAAc;;;ACjBhC,YAAuB;AACvB,IAAAC,gBAA0D;AAOnD,SAAS,aACd,MACoC;AACpC,SAAa,cAAQ,MAAM;AACzB,QAAI,KAAK,MAAM,CAAC,QAAQ,QAAQ,IAAI,GAAG;AACrC,aAAO;AAAA,IACT;AAEA,WAAO,CAAC,UAAU;AACh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A,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,sBAAsB;AAAA,EA3C1B,IA8BE,IAcK,iBAdL,IAcK;AAAA,IAbH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAKF,QAAM,eAAW,sBAAyB,IAAI;AAC9C,QAAM,YAAY,aAAa,CAAC,UAAU,GAAG,CAAC;AAE9C,SACE;AAAA,IAAC;AAAA;AAAA,MACC,eAAW,8BAAK,mBAAmB,SAAsB;AAAA,MACzD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAY;AAAA,MAEX,WAAC,eACA,8EACE;AAAA;AAAA,UAAC;AAAA,0DACK,aADL;AAAA,YAEC;AAAA,YACA;AAAA,YACA,KAAK;AAAA,YACL,MAAK;AAAA,cACD;AAAA,QACN;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,eAAW,8BAAK,kCAAkC;AAAA,YAClD,MAAK;AAAA,YACL,OAAO;AAAA,YACP,SAAS,MAAM;AAhF3B,kBAAAC;AAiFc,eAAAA,MAAA,SAAS,YAAT,gBAAAA,IAAkB;AAAA,YACpB;AAAA;AAAA,QACF;AAAA,SACF;AAAA;AAAA,EAEJ;AAEJ,CAAC;AAED,WAAW,cAAc;","names":["import_react","import_typed_classname","import_react","import_typed_classname","import_react","import_jsx_runtime","InputGroup","_a","import_jsx_runtime","DatePicker","_a"]}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DatePicker
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-RGZSYJFL.mjs";
|
|
4
4
|
import "../../chunk-Y5SUMFYJ.mjs";
|
|
5
|
-
import "../../chunk-
|
|
5
|
+
import "../../chunk-DMRQEQQK.mjs";
|
|
6
6
|
import "../../chunk-NSLSA7F7.mjs";
|
|
7
|
-
import "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
7
|
+
import "../../chunk-VNH7CZJ4.mjs";
|
|
8
|
+
import "../../chunk-5M6MEYM7.mjs";
|
|
9
|
+
import "../../chunk-F23MNQCK.mjs";
|
|
10
|
+
import "../../chunk-CYDWEPFL.mjs";
|
|
11
|
+
import "../../chunk-KPNAC2WN.mjs";
|
|
12
|
+
import "../../chunk-3V4GFS46.mjs";
|
|
9
13
|
import "../../chunk-YOSPWY5K.mjs";
|
|
10
14
|
export {
|
|
11
15
|
DatePicker
|
|
@@ -68,39 +68,69 @@ var import_react4 = require("react");
|
|
|
68
68
|
var import_typed_classname3 = require("@postenbring/hedwig-css/typed-classname");
|
|
69
69
|
|
|
70
70
|
// src/form/input-group/input-group.tsx
|
|
71
|
-
var
|
|
71
|
+
var import_react3 = require("react");
|
|
72
72
|
var import_typed_classname2 = require("@postenbring/hedwig-css/typed-classname");
|
|
73
73
|
|
|
74
|
-
// src/form/
|
|
74
|
+
// src/form/validation-message/validation-message.tsx
|
|
75
75
|
var import_typed_classname = require("@postenbring/hedwig-css/typed-classname");
|
|
76
76
|
var import_react = require("react");
|
|
77
77
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
78
|
-
var
|
|
78
|
+
var ValidationMessage = (0, import_react.forwardRef)(
|
|
79
79
|
(_a, ref) => {
|
|
80
|
-
var _b = _a, {
|
|
80
|
+
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
81
81
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
82
82
|
"div",
|
|
83
|
-
|
|
83
|
+
__spreadValues({
|
|
84
84
|
"aria-live": "polite",
|
|
85
|
-
className: (0, import_typed_classname.clsx)("hds-
|
|
86
|
-
id,
|
|
85
|
+
className: (0, import_typed_classname.clsx)("hds-validation-message", className),
|
|
87
86
|
ref
|
|
88
|
-
}, rest)
|
|
89
|
-
children
|
|
90
|
-
})
|
|
87
|
+
}, rest)
|
|
91
88
|
);
|
|
92
89
|
}
|
|
93
90
|
);
|
|
94
|
-
|
|
91
|
+
ValidationMessage.displayName = "ValidationMessage";
|
|
92
|
+
|
|
93
|
+
// src/utils/utils.ts
|
|
94
|
+
var React = __toESM(require("react"));
|
|
95
|
+
var import_react2 = require("react");
|
|
96
|
+
function useMergeRefs(refs) {
|
|
97
|
+
return React.useMemo(() => {
|
|
98
|
+
if (refs.every((ref) => ref === null)) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return (value) => {
|
|
102
|
+
refs.forEach((ref) => {
|
|
103
|
+
if (typeof ref === "function") {
|
|
104
|
+
ref(value);
|
|
105
|
+
} else if (ref !== null) {
|
|
106
|
+
ref.current = value;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
}, refs);
|
|
111
|
+
}
|
|
112
|
+
function getValidationMessageValue(validationMessage, errorMessage) {
|
|
113
|
+
if (validationMessage) {
|
|
114
|
+
if (typeof validationMessage === "object" && "value" in validationMessage) {
|
|
115
|
+
return validationMessage.value;
|
|
116
|
+
}
|
|
117
|
+
return validationMessage;
|
|
118
|
+
}
|
|
119
|
+
return errorMessage;
|
|
120
|
+
}
|
|
121
|
+
var inertBooleanSupported = Number(import_react2.version.split(".")[0]) >= 19;
|
|
95
122
|
|
|
96
123
|
// src/form/input-group/input-group.tsx
|
|
97
124
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
98
|
-
var InputGroup = (0,
|
|
125
|
+
var InputGroup = (0, import_react3.forwardRef)(function InputGroup2(_a, ref) {
|
|
99
126
|
var _b = _a, {
|
|
100
127
|
id,
|
|
101
128
|
className,
|
|
102
129
|
style,
|
|
130
|
+
"data-color": dataColor = void 0,
|
|
103
131
|
size = "large",
|
|
132
|
+
validationMessage,
|
|
133
|
+
validationMessageProps,
|
|
104
134
|
errorMessage,
|
|
105
135
|
errorMessageProps,
|
|
106
136
|
labelProps: _c = {}
|
|
@@ -113,7 +143,10 @@ var InputGroup = (0, import_react2.forwardRef)(function InputGroup2(_a, ref) {
|
|
|
113
143
|
"id",
|
|
114
144
|
"className",
|
|
115
145
|
"style",
|
|
146
|
+
"data-color",
|
|
116
147
|
"size",
|
|
148
|
+
"validationMessage",
|
|
149
|
+
"validationMessageProps",
|
|
117
150
|
"errorMessage",
|
|
118
151
|
"errorMessageProps",
|
|
119
152
|
"labelProps",
|
|
@@ -122,12 +155,14 @@ var InputGroup = (0, import_react2.forwardRef)(function InputGroup2(_a, ref) {
|
|
|
122
155
|
"readOnly",
|
|
123
156
|
"children"
|
|
124
157
|
]);
|
|
125
|
-
const
|
|
126
|
-
const inputId = (0,
|
|
158
|
+
const validationMessageId = (0, import_react3.useId)();
|
|
159
|
+
const inputId = (0, import_react3.useId)();
|
|
160
|
+
const validationColor = errorMessage ? "error" : dataColor;
|
|
161
|
+
const validationMessageValue = getValidationMessageValue(validationMessage, errorMessage);
|
|
127
162
|
const renderInput = () => {
|
|
128
163
|
var _a2;
|
|
129
164
|
const inputProps = {
|
|
130
|
-
"aria-describedby":
|
|
165
|
+
"aria-describedby": validationMessage ? validationMessageId : void 0,
|
|
131
166
|
"aria-invalid": errorMessage ? true : void 0,
|
|
132
167
|
id: id != null ? id : inputId,
|
|
133
168
|
className: (0, import_typed_classname2.clsx)("hds-input-group__input")
|
|
@@ -135,11 +170,11 @@ var InputGroup = (0, import_react2.forwardRef)(function InputGroup2(_a, ref) {
|
|
|
135
170
|
if (typeof children === "function") {
|
|
136
171
|
return children(inputProps);
|
|
137
172
|
}
|
|
138
|
-
const input =
|
|
139
|
-
if (!(0,
|
|
173
|
+
const input = import_react3.Children.toArray(children)[0];
|
|
174
|
+
if (!(0, import_react3.isValidElement)(input)) {
|
|
140
175
|
return;
|
|
141
176
|
}
|
|
142
|
-
return (0,
|
|
177
|
+
return (0, import_react3.cloneElement)(input, __spreadProps(__spreadValues(__spreadValues({}, inputProps), input.props), {
|
|
143
178
|
className: `${inputProps.className} ${(_a2 = input.props.className) != null ? _a2 : ""}`
|
|
144
179
|
}));
|
|
145
180
|
};
|
|
@@ -149,13 +184,13 @@ var InputGroup = (0, import_react2.forwardRef)(function InputGroup2(_a, ref) {
|
|
|
149
184
|
className: (0, import_typed_classname2.clsx)(
|
|
150
185
|
"hds-input-group",
|
|
151
186
|
{
|
|
152
|
-
[`hds-input-group--${size}`]: size
|
|
153
|
-
"hds-input-group--error": errorMessage
|
|
187
|
+
[`hds-input-group--${size}`]: size
|
|
154
188
|
},
|
|
155
189
|
className
|
|
156
190
|
),
|
|
157
191
|
ref,
|
|
158
|
-
style
|
|
192
|
+
style,
|
|
193
|
+
"data-color": validationColor
|
|
159
194
|
}, rest), {
|
|
160
195
|
children: [
|
|
161
196
|
label !== null && label !== void 0 && label !== false && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
@@ -176,39 +211,27 @@ var InputGroup = (0, import_react2.forwardRef)(function InputGroup2(_a, ref) {
|
|
|
176
211
|
children: renderInput()
|
|
177
212
|
}
|
|
178
213
|
),
|
|
179
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
214
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
215
|
+
ValidationMessage,
|
|
216
|
+
__spreadProps(__spreadValues({
|
|
217
|
+
id: validationMessageId
|
|
218
|
+
}, validationMessageProps != null ? validationMessageProps : errorMessageProps), {
|
|
219
|
+
children: validationMessageValue
|
|
220
|
+
})
|
|
221
|
+
)
|
|
180
222
|
]
|
|
181
223
|
})
|
|
182
224
|
);
|
|
183
225
|
});
|
|
184
226
|
|
|
185
|
-
// src/utils/utils.ts
|
|
186
|
-
var React = __toESM(require("react"));
|
|
187
|
-
var import_react3 = require("react");
|
|
188
|
-
function useMergeRefs(refs) {
|
|
189
|
-
return React.useMemo(() => {
|
|
190
|
-
if (refs.every((ref) => ref === null)) {
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
return (value) => {
|
|
194
|
-
refs.forEach((ref) => {
|
|
195
|
-
if (typeof ref === "function") {
|
|
196
|
-
ref(value);
|
|
197
|
-
} else if (ref !== null) {
|
|
198
|
-
ref.current = value;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
}, refs);
|
|
203
|
-
}
|
|
204
|
-
var inertBooleanSupported = Number(import_react3.version.split(".")[0]) >= 19;
|
|
205
|
-
|
|
206
227
|
// src/form/date-picker/date-picker.tsx
|
|
207
228
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
208
229
|
var DatePicker = (0, import_react4.forwardRef)(function DatePicker2(_a, ref) {
|
|
209
230
|
var _b = _a, {
|
|
210
231
|
className,
|
|
211
232
|
size,
|
|
233
|
+
validationMessage,
|
|
234
|
+
validationMessageProps,
|
|
212
235
|
errorMessage,
|
|
213
236
|
labelProps,
|
|
214
237
|
label,
|
|
@@ -216,10 +239,13 @@ var DatePicker = (0, import_react4.forwardRef)(function DatePicker2(_a, ref) {
|
|
|
216
239
|
style,
|
|
217
240
|
disabled,
|
|
218
241
|
readOnly,
|
|
242
|
+
"data-color": dataColor,
|
|
219
243
|
calendarButtonTitle = "\xC5pne kalender"
|
|
220
244
|
} = _b, rest = __objRest(_b, [
|
|
221
245
|
"className",
|
|
222
246
|
"size",
|
|
247
|
+
"validationMessage",
|
|
248
|
+
"validationMessageProps",
|
|
223
249
|
"errorMessage",
|
|
224
250
|
"labelProps",
|
|
225
251
|
"label",
|
|
@@ -227,6 +253,7 @@ var DatePicker = (0, import_react4.forwardRef)(function DatePicker2(_a, ref) {
|
|
|
227
253
|
"style",
|
|
228
254
|
"disabled",
|
|
229
255
|
"readOnly",
|
|
256
|
+
"data-color",
|
|
230
257
|
"calendarButtonTitle"
|
|
231
258
|
]);
|
|
232
259
|
const inputRef = (0, import_react4.useRef)(null);
|
|
@@ -236,6 +263,8 @@ var DatePicker = (0, import_react4.forwardRef)(function DatePicker2(_a, ref) {
|
|
|
236
263
|
{
|
|
237
264
|
className: (0, import_typed_classname3.clsx)("hds-date-picker", className),
|
|
238
265
|
disabled,
|
|
266
|
+
validationMessage,
|
|
267
|
+
validationMessageProps,
|
|
239
268
|
errorMessage,
|
|
240
269
|
id,
|
|
241
270
|
label,
|
|
@@ -243,15 +272,16 @@ var DatePicker = (0, import_react4.forwardRef)(function DatePicker2(_a, ref) {
|
|
|
243
272
|
readOnly,
|
|
244
273
|
style,
|
|
245
274
|
size,
|
|
275
|
+
"data-color": dataColor,
|
|
246
276
|
children: (inputProps) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
247
277
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
248
278
|
"input",
|
|
249
|
-
__spreadProps(__spreadValues(
|
|
279
|
+
__spreadValues(__spreadProps(__spreadValues({}, inputProps), {
|
|
250
280
|
disabled,
|
|
251
281
|
readOnly,
|
|
252
282
|
ref: mergedRef,
|
|
253
283
|
type: "date"
|
|
254
|
-
})
|
|
284
|
+
}), rest)
|
|
255
285
|
),
|
|
256
286
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
257
287
|
"button",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/form/date-picker/index.tsx","../../../src/form/date-picker/date-picker.tsx","../../../src/form/input-group/input-group.tsx","../../../src/form/error-message/error-message.tsx","../../../src/utils/utils.ts"],"sourcesContent":["export { DatePicker } from \"./date-picker\";\nexport type * from \"./date-picker\";\n","import { forwardRef, useRef, type InputHTMLAttributes } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { InputGroup, type InputGroupProps } from \"../input-group\";\nimport { useMergeRefs } from \"../../utils/utils\";\n\nexport type DatePickerProps = Omit<\n InputGroupProps & Omit<InputHTMLAttributes<HTMLInputElement>, \"size\">,\n \"children\" | \"type\"\n> & {\n /**\n * Accessible title for the calendar button\n *\n * This button currently only shows in Chrome.\n *\n * @defaultValue \"Åpne kalender\"\n */\n calendarButtonTitle?: string;\n};\n\n/**\n * A basic implementation of a date picker\n *\n * This date picker is an implementation of native date picker, as you get\n * with `<input type=\"date\" />`, where the input field is dressed in Hedwig styling.\n *\n * Due to accessibility concerns you will only see the appropriate Hedwig calendar\n * icon in Chrome. Firefox will show built in icon and Safari will show no icon.\n * Not tested in Edge.\n */\nexport const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(function DatePicker(\n {\n className,\n size,\n errorMessage,\n labelProps,\n label,\n id,\n style,\n disabled,\n readOnly,\n calendarButtonTitle = \"Åpne kalender\",\n ...rest\n },\n ref,\n) {\n const inputRef = useRef<HTMLInputElement>(null);\n const mergedRef = useMergeRefs([inputRef, ref]);\n\n return (\n <InputGroup\n className={clsx(\"hds-date-picker\", className as undefined)}\n disabled={disabled}\n errorMessage={errorMessage}\n id={id}\n label={label}\n labelProps={labelProps}\n readOnly={readOnly}\n style={style}\n size={size}\n >\n {(inputProps) => (\n <>\n <input\n {...rest}\n {...inputProps}\n disabled={disabled}\n readOnly={readOnly}\n ref={mergedRef}\n type=\"date\"\n />\n <button\n className={clsx(\"hds-date-picker__calendar-button\")}\n type=\"button\"\n title={calendarButtonTitle}\n onClick={() => {\n inputRef.current?.showPicker();\n }}\n />\n </>\n )}\n </InputGroup>\n );\n});\n\nDatePicker.displayName = \"DatePicker\";\n","import { useId, forwardRef, Children, isValidElement, cloneElement } from \"react\";\nimport type { LabelHTMLAttributes, ReactNode, CSSProperties } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { ErrorMessage, type ErrorMessageProps } from \"../error-message\";\n\ninterface InputProps {\n \"aria-describedby\"?: string;\n \"aria-invalid\"?: boolean;\n id?: string;\n className?: string;\n}\n\nexport interface InputGroupProps {\n id?: string;\n className?: string;\n style?: CSSProperties;\n size?: \"large\" | \"small\";\n errorMessage?: ReactNode;\n errorMessageProps?: Partial<ErrorMessageProps>;\n labelProps?: LabelHTMLAttributes<HTMLLabelElement>;\n label?: ReactNode;\n disabled?: boolean;\n readOnly?: boolean;\n /**\n * `children` must be either a single input element or a render function.\n *\n * If you use a render function, make sure you spread the input props to the appropriate element.\n */\n children: Exclude<ReactNode, Iterable<ReactNode>> | ((inputProps: InputProps) => ReactNode);\n}\n\nexport const InputGroup = forwardRef<HTMLDivElement, InputGroupProps>(function InputGroup(\n {\n id,\n className,\n style,\n size = \"large\",\n errorMessage,\n errorMessageProps,\n labelProps: { className: labelClassName, ...labelProps } = {},\n label,\n disabled,\n readOnly,\n children,\n ...rest\n },\n ref,\n) {\n const errorMessageId = useId();\n const inputId = useId();\n\n const renderInput = () => {\n const inputProps: InputProps = {\n \"aria-describedby\": errorMessage ? errorMessageId : undefined,\n \"aria-invalid\": errorMessage ? true : undefined,\n id: id ?? inputId,\n className: clsx(\"hds-input-group__input\"),\n };\n\n if (typeof children === \"function\") {\n return children(inputProps);\n }\n\n const input: ReactNode = Children.toArray(children)[0];\n\n if (!isValidElement<InputProps>(input)) {\n return;\n }\n\n return cloneElement<InputProps>(input, {\n ...inputProps,\n ...input.props,\n className: `${inputProps.className} ${input.props.className ?? \"\"}`,\n });\n };\n\n return (\n <div\n className={clsx(\n \"hds-input-group\",\n {\n [`hds-input-group--${size}`]: size,\n \"hds-input-group--error\": errorMessage,\n },\n className as undefined,\n )}\n ref={ref}\n style={style}\n {...rest}\n >\n {label !== null && label !== undefined && label !== false && (\n <label\n className={clsx(\"hds-input-group__label\", labelClassName as undefined)}\n {...labelProps}\n htmlFor={id ?? inputId}\n >\n {label}\n </label>\n )}\n <div\n className={clsx(\"hds-input-group__input-wrapper\")}\n data-disabled={disabled}\n data-readonly={readOnly}\n >\n {renderInput()}\n </div>\n <ErrorMessage id={errorMessageId} {...errorMessageProps}>\n {errorMessage}\n </ErrorMessage>\n </div>\n );\n});\n","import { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { forwardRef, type ReactNode } from \"react\";\n\nexport interface ErrorMessageProps extends React.HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n id: string;\n className?: string;\n}\n\nexport const ErrorMessage = forwardRef<HTMLDivElement, ErrorMessageProps>(\n ({ children, id, className, ...rest }, ref) => {\n return (\n <div\n aria-live=\"polite\"\n className={clsx(\"hds-error-message\", className as undefined)}\n id={id}\n ref={ref}\n {...rest}\n >\n {children}\n </div>\n );\n },\n);\nErrorMessage.displayName = \"ErrorMessage\";\n","import * as React from \"react\";\nimport { useCallback, useEffect, useState, version } from \"react\";\n\n/**\n * Merges an array of refs into a single memoized callback ref or `null`.\n * @see https://floating-ui.com/docs/useMergeRefs\n */\nexport function useMergeRefs<Instance>(\n refs: (React.Ref<Instance> | undefined)[],\n): React.RefCallback<Instance> | null {\n return React.useMemo(() => {\n if (refs.every((ref) => ref === null)) {\n return null;\n }\n\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(value);\n } else if (ref !== null) {\n (ref as React.MutableRefObject<Instance | null>).current = value;\n }\n });\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, refs);\n}\n\nexport function useResize<Instance extends HTMLElement>(\n ref: React.RefObject<Instance> | undefined | null,\n): { width: number; height: number } {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n const handleResize = useCallback(() => {\n if (ref?.current !== null) {\n setWidth(ref?.current?.offsetWidth ?? 0);\n setHeight(ref?.current?.offsetHeight ?? 0);\n }\n }, [ref]);\n useEffect(() => {\n window.addEventListener(\"load\", handleResize);\n window.addEventListener(\"resize\", handleResize);\n return () => {\n window.removeEventListener(\"load\", handleResize);\n window.removeEventListener(\"resize\", handleResize);\n };\n }, [ref, handleResize]);\n useEffect(() => {\n handleResize();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, []);\n return { width, height };\n}\n\nfunction subscribe() {\n // eslint-disable-next-line @typescript-eslint/no-empty-function -- It's ok\n return () => {};\n}\n\nexport function useHydrated() {\n return React.useSyncExternalStore(\n subscribe,\n () => true,\n () => false,\n );\n}\n\n/**\n * Trap focus inside an element using the `inert` attribute.\n *\n * Adds `inert` to all siblings of the given element, and all their ancestors up to the body.\n * Returns a cleanup function which removes the `inert` property from the elements, effectively giving focus back to rest of the document.\n *\n * NOTE: Does not support portals, i.e. elements outside the DOM hierarchy of the given element.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert\n * @see https://web.dev/articles/inert\n */\nexport function focusTrap(element: HTMLElement) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function -- NOP on focus trapping the body element\n if (element === document.body) return () => {};\n\n let inertElements: HTMLElement[] = [];\n for (let el: HTMLElement | null = element; el; el = el.parentElement) {\n if (el === document.body) break;\n\n for (const sibling of el.parentElement?.children ?? []) {\n if (sibling === el) continue;\n if (!(sibling instanceof HTMLElement)) continue;\n if (sibling.hasAttribute(\"inert\")) continue;\n\n sibling.setAttribute(\"inert\", \"true\");\n inertElements.push(sibling);\n }\n }\n\n return () => {\n releaseFocusTrap(inertElements);\n inertElements = [];\n };\n}\n\n/**\n * Unset the `inert` attribute on all elements given\n */\nfunction releaseFocusTrap(inertElements: Iterable<HTMLElement>) {\n for (const el of inertElements) {\n el.removeAttribute(\"inert\");\n }\n}\n\n/**\n * React 19 supports inert prop\n * React 18 needs inert to be a string\n */\nconst inertBooleanSupported: boolean = Number(version.split(\".\")[0]) >= 19;\n\n/**\n * Returns the inert prop value based on the React version.\n */\nexport const inertPropValue: (x: boolean) => boolean | \"\" | undefined = inertBooleanSupported\n ? (x: boolean): boolean => x\n : (x: boolean): \"\" | undefined => (x ? \"\" : undefined);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA6D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,UAAC,IAAgD,UAAU;AAAA,QAC7D;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EAEF,GAAG,IAAI;AACT;AAyFA,IAAM,wBAAiC,OAAO,sBAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK;;;AHtDhE,IAAAC,sBAAA;AAhCD,IAAM,iBAAa,0BAA8C,SAASC,YAC/E,IAaA,KACA;AAdA,eACE;AAAA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,sBAAsB;AAAA,EAxC1B,IA8BE,IAWK,iBAXL,IAWK;AAAA,IAVH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAKF,QAAM,eAAW,sBAAyB,IAAI;AAC9C,QAAM,YAAY,aAAa,CAAC,UAAU,GAAG,CAAC;AAE9C,SACE;AAAA,IAAC;AAAA;AAAA,MACC,eAAW,8BAAK,mBAAmB,SAAsB;AAAA,MACzD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEC,WAAC,eACA,8EACE;AAAA;AAAA,UAAC;AAAA,0DACK,OACA,aAFL;AAAA,YAGC;AAAA,YACA;AAAA,YACA,KAAK;AAAA,YACL,MAAK;AAAA;AAAA,QACP;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,eAAW,8BAAK,kCAAkC;AAAA,YAClD,MAAK;AAAA,YACL,OAAO;AAAA,YACP,SAAS,MAAM;AA1E3B,kBAAAC;AA2Ec,eAAAA,MAAA,SAAS,YAAT,gBAAAA,IAAkB;AAAA,YACpB;AAAA;AAAA,QACF;AAAA,SACF;AAAA;AAAA,EAEJ;AAEJ,CAAC;AAED,WAAW,cAAc;","names":["import_react","import_typed_classname","import_react","import_typed_classname","import_jsx_runtime","InputGroup","_a","import_react","import_jsx_runtime","DatePicker","_a"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/form/date-picker/index.tsx","../../../src/form/date-picker/date-picker.tsx","../../../src/form/input-group/input-group.tsx","../../../src/form/validation-message/validation-message.tsx","../../../src/utils/utils.ts"],"sourcesContent":["export { DatePicker } from \"./date-picker\";\nexport type * from \"./date-picker\";\n","import { forwardRef, useRef, type InputHTMLAttributes } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { InputGroup, type InputGroupProps } from \"../input-group\";\nimport { useMergeRefs } from \"../../utils/utils\";\n\nexport type DatePickerProps = Omit<\n InputGroupProps & Omit<InputHTMLAttributes<HTMLInputElement>, \"size\">,\n \"children\" | \"type\"\n> & {\n /**\n * Accessible title for the calendar button\n *\n * This button currently only shows in Chrome.\n *\n * @defaultValue \"Åpne kalender\"\n */\n calendarButtonTitle?: string;\n};\n\n/**\n * A basic implementation of a date picker\n *\n * This date picker is an implementation of native date picker, as you get\n * with `<input type=\"date\" />`, where the input field is dressed in Hedwig styling.\n *\n * Due to accessibility concerns you will only see the appropriate Hedwig calendar\n * icon in Chrome. Firefox will show built in icon and Safari will show no icon.\n * Not tested in Edge.\n */\nexport const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(function DatePicker(\n {\n className,\n size,\n validationMessage,\n validationMessageProps,\n errorMessage,\n labelProps,\n label,\n id,\n style,\n disabled,\n readOnly,\n \"data-color\": dataColor,\n calendarButtonTitle = \"Åpne kalender\",\n ...rest\n },\n ref,\n) {\n const inputRef = useRef<HTMLInputElement>(null);\n const mergedRef = useMergeRefs([inputRef, ref]);\n\n return (\n <InputGroup\n className={clsx(\"hds-date-picker\", className as undefined)}\n disabled={disabled}\n validationMessage={validationMessage}\n validationMessageProps={validationMessageProps}\n errorMessage={errorMessage}\n id={id}\n label={label}\n labelProps={labelProps}\n readOnly={readOnly}\n style={style}\n size={size}\n data-color={dataColor}\n >\n {(inputProps) => (\n <>\n <input\n {...inputProps}\n disabled={disabled}\n readOnly={readOnly}\n ref={mergedRef}\n type=\"date\"\n {...rest}\n />\n <button\n className={clsx(\"hds-date-picker__calendar-button\")}\n type=\"button\"\n title={calendarButtonTitle}\n onClick={() => {\n inputRef.current?.showPicker();\n }}\n />\n </>\n )}\n </InputGroup>\n );\n});\n\nDatePicker.displayName = \"DatePicker\";\n","import { useId, forwardRef, Children, isValidElement, cloneElement } from \"react\";\nimport type { LabelHTMLAttributes, ReactNode, CSSProperties } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { ValidationMessage, type ValidationMessageProps } from \"../validation-message\";\nimport { type ErrorMessageProps } from \"../error-message\";\nimport { getValidationMessageValue } from \"../../utils\";\n\ninterface InputProps {\n \"aria-describedby\"?: string;\n \"aria-invalid\"?: boolean;\n id?: string;\n className?: string;\n}\n\nexport interface InputGroupProps {\n id?: string;\n className?: string;\n style?: CSSProperties;\n \"data-color\"?: \"info\" | \"success\" | \"warning\" | \"error\";\n size?: \"large\" | \"small\";\n validationMessage?: ReactNode | { value: ReactNode };\n validationMessageProps?: Partial<ValidationMessageProps>;\n /** @deprecated Use `validationMessage` instead */\n errorMessage?: ReactNode;\n /** @deprecated Use `validationMessageProps` instead */\n errorMessageProps?: Partial<ErrorMessageProps>;\n labelProps?: LabelHTMLAttributes<HTMLLabelElement>;\n label?: ReactNode;\n disabled?: boolean;\n readOnly?: boolean;\n /**\n * `children` must be either a single input element or a render function.\n *\n * If you use a render function, make sure you spread the input props to the appropriate element.\n */\n children: Exclude<ReactNode, Iterable<ReactNode>> | ((inputProps: InputProps) => ReactNode);\n}\n\nexport const InputGroup = forwardRef<HTMLDivElement, InputGroupProps>(function InputGroup(\n {\n id,\n className,\n style,\n \"data-color\": dataColor = undefined,\n size = \"large\",\n validationMessage,\n validationMessageProps,\n errorMessage,\n errorMessageProps,\n labelProps: { className: labelClassName, ...labelProps } = {},\n label,\n disabled,\n readOnly,\n children,\n ...rest\n },\n ref,\n) {\n const validationMessageId = useId();\n const inputId = useId();\n const validationColor = errorMessage ? \"error\" : dataColor;\n const validationMessageValue = getValidationMessageValue(validationMessage, errorMessage);\n\n const renderInput = () => {\n const inputProps: InputProps = {\n \"aria-describedby\": validationMessage ? validationMessageId : undefined,\n \"aria-invalid\": errorMessage ? true : undefined,\n id: id ?? inputId,\n className: clsx(\"hds-input-group__input\"),\n };\n\n if (typeof children === \"function\") {\n return children(inputProps);\n }\n\n const input: ReactNode = Children.toArray(children)[0];\n\n if (!isValidElement<InputProps>(input)) {\n return;\n }\n\n return cloneElement<InputProps>(input, {\n ...inputProps,\n ...input.props,\n className: `${inputProps.className} ${input.props.className ?? \"\"}`,\n });\n };\n\n return (\n <div\n className={clsx(\n \"hds-input-group\",\n {\n [`hds-input-group--${size}`]: size,\n },\n className as undefined,\n )}\n ref={ref}\n style={style}\n data-color={validationColor}\n {...rest}\n >\n {label !== null && label !== undefined && label !== false && (\n <label\n className={clsx(\"hds-input-group__label\", labelClassName as undefined)}\n {...labelProps}\n htmlFor={id ?? inputId}\n >\n {label}\n </label>\n )}\n <div\n className={clsx(\"hds-input-group__input-wrapper\")}\n data-disabled={disabled}\n data-readonly={readOnly}\n >\n {renderInput()}\n </div>\n <ValidationMessage\n id={validationMessageId}\n {...(validationMessageProps ?? errorMessageProps)}\n >\n {validationMessageValue}\n </ValidationMessage>\n </div>\n );\n});\n","import { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { forwardRef, type HTMLAttributes } from \"react\";\n\nexport interface ValidationMessageProps extends HTMLAttributes<HTMLDivElement> {\n className?: string;\n}\n\nexport const ValidationMessage = forwardRef<HTMLDivElement, ValidationMessageProps>(\n ({ className, ...rest }, ref) => (\n <div\n aria-live=\"polite\"\n className={clsx(\"hds-validation-message\", className as undefined)}\n ref={ref}\n {...rest}\n />\n ),\n);\nValidationMessage.displayName = \"ValidationMessage\";\n","import * as React from \"react\";\nimport { useCallback, useEffect, useState, version } from \"react\";\nimport type { ReactNode } from \"react\";\n\n/**\n * Merges an array of refs into a single memoized callback ref or `null`.\n * @see https://floating-ui.com/docs/useMergeRefs\n */\nexport function useMergeRefs<Instance>(\n refs: (React.Ref<Instance> | undefined)[],\n): React.RefCallback<Instance> | null {\n return React.useMemo(() => {\n if (refs.every((ref) => ref === null)) {\n return null;\n }\n\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(value);\n } else if (ref !== null) {\n (ref as React.MutableRefObject<Instance | null>).current = value;\n }\n });\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, refs);\n}\n\nexport function useResize<Instance extends HTMLElement>(\n ref: React.RefObject<Instance> | undefined | null,\n): { width: number; height: number } {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n const handleResize = useCallback(() => {\n if (ref?.current !== null) {\n setWidth(ref?.current?.offsetWidth ?? 0);\n setHeight(ref?.current?.offsetHeight ?? 0);\n }\n }, [ref]);\n useEffect(() => {\n window.addEventListener(\"load\", handleResize);\n window.addEventListener(\"resize\", handleResize);\n return () => {\n window.removeEventListener(\"load\", handleResize);\n window.removeEventListener(\"resize\", handleResize);\n };\n }, [ref, handleResize]);\n useEffect(() => {\n handleResize();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- It's ok\n }, []);\n return { width, height };\n}\n\nfunction subscribe() {\n // eslint-disable-next-line @typescript-eslint/no-empty-function -- It's ok\n return () => {};\n}\n\nexport function useHydrated() {\n return React.useSyncExternalStore(\n subscribe,\n () => true,\n () => false,\n );\n}\n\nexport function getValidationMessageValue(\n validationMessage?: ReactNode | { value: ReactNode },\n errorMessage?: ReactNode,\n): ReactNode {\n if (validationMessage) {\n if (typeof validationMessage === \"object\" && \"value\" in validationMessage) {\n return validationMessage.value;\n }\n\n return validationMessage;\n }\n\n return errorMessage;\n}\n\n/**\n * Trap focus inside an element using the `inert` attribute.\n *\n * Adds `inert` to all siblings of the given element, and all their ancestors up to the body.\n * Returns a cleanup function which removes the `inert` property from the elements, effectively giving focus back to rest of the document.\n *\n * NOTE: Does not support portals, i.e. elements outside the DOM hierarchy of the given element.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert\n * @see https://web.dev/articles/inert\n */\nexport function focusTrap(element: HTMLElement) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function -- NOP on focus trapping the body element\n if (element === document.body) return () => {};\n\n let inertElements: HTMLElement[] = [];\n for (let el: HTMLElement | null = element; el; el = el.parentElement) {\n if (el === document.body) break;\n\n for (const sibling of el.parentElement?.children ?? []) {\n if (sibling === el) continue;\n if (!(sibling instanceof HTMLElement)) continue;\n if (sibling.hasAttribute(\"inert\")) continue;\n\n sibling.setAttribute(\"inert\", \"true\");\n inertElements.push(sibling);\n }\n }\n\n return () => {\n releaseFocusTrap(inertElements);\n inertElements = [];\n };\n}\n\n/**\n * Unset the `inert` attribute on all elements given\n */\nfunction releaseFocusTrap(inertElements: Iterable<HTMLElement>) {\n for (const el of inertElements) {\n el.removeAttribute(\"inert\");\n }\n}\n\n/**\n * React 19 supports inert prop\n * React 18 needs inert to be a string\n */\nconst inertBooleanSupported: boolean = Number(version.split(\".\")[0]) >= 19;\n\n/**\n * Returns the inert prop value based on the React version.\n */\nexport const inertPropValue: (x: boolean) => boolean | \"\" | undefined = inertBooleanSupported\n ? (x: boolean): boolean => x\n : (x: boolean): \"\" | undefined => (x ? \"\" : undefined);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA6D;AAC7D,IAAAC,0BAAqB;;;ACDrB,IAAAC,gBAA0E;AAE1E,IAAAC,0BAAqB;;;ACFrB,6BAAqB;AACrB,mBAAgD;AAQ5C;AAFG,IAAM,wBAAoB;AAAA,EAC/B,CAAC,IAAwB,QAAK;AAA7B,iBAAE,YARL,IAQG,IAAgB,iBAAhB,IAAgB,CAAd;AACD;AAAA,MAAC;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AAS,YAAT,gBAAAA,IAAkB;AAAA,YACpB;AAAA;AAAA,QACF;AAAA,SACF;AAAA;AAAA,EAEJ;AAEJ,CAAC;AAED,WAAW,cAAc;","names":["import_react","import_typed_classname","import_react","import_typed_classname","import_react","import_jsx_runtime","InputGroup","_a","import_jsx_runtime","DatePicker","_a"]}
|