@bookinglab/booking-ui-react 1.11.1 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -54,7 +54,10 @@ function FormField({
54
54
  };
55
55
  switch (question.detail_type) {
56
56
  case "heading":
57
- return /* @__PURE__ */ jsx("h3", { className: classNames?.heading ?? defaultHeading, children: question.name });
57
+ return /* @__PURE__ */ jsxs("div", { className: classNames?.fieldWrapper ?? defaultFieldWrapper, children: [
58
+ /* @__PURE__ */ jsx("h3", { className: classNames?.heading ?? defaultHeading, children: question.name }),
59
+ renderHelpText()
60
+ ] });
58
61
  case "text_field":
59
62
  return /* @__PURE__ */ jsxs("div", { className: classNames?.fieldWrapper ?? defaultFieldWrapper, children: [
60
63
  renderLabel(),
@@ -144,25 +147,120 @@ function FormField({
144
147
  renderHelpText(),
145
148
  renderError()
146
149
  ] });
147
- case "date":
148
- return /* @__PURE__ */ jsxs("div", { className: classNames?.fieldWrapper ?? defaultFieldWrapper, children: [
149
- renderLabel(),
150
- /* @__PURE__ */ jsx(
151
- "input",
152
- {
153
- id: inputId,
154
- type: "date",
155
- value: value || "",
156
- onChange: (e) => onChange(e.target.value),
157
- min: question.settings?.min?.toString(),
158
- max: question.settings?.max?.toString(),
159
- className: inputClasses,
160
- ...ariaProps
150
+ case "date": {
151
+ const raw = typeof value === "string" ? value : "";
152
+ const match2 = raw.match(/^(\d{0,4})-?(\d{0,2})-?(\d{0,2})$/);
153
+ const yearPart = match2?.[1] ?? "";
154
+ const monthPart = match2?.[2] ? String(Number(match2[2])) : "";
155
+ const dayPart = match2?.[3] ? String(Number(match2[3])) : "";
156
+ const dayId = `${inputId}-day`;
157
+ const monthId = `${inputId}-month`;
158
+ const yearId = `${inputId}-year`;
159
+ const buildValue = (d, m, y) => {
160
+ const dt = d.trim();
161
+ const mt = m.trim();
162
+ const yt = y.trim();
163
+ if (!dt && !mt && !yt) return "";
164
+ if (/^\d{1,2}$/.test(dt) && /^\d{1,2}$/.test(mt) && /^\d{4}$/.test(yt)) {
165
+ const dn = Number(dt);
166
+ const mn = Number(mt);
167
+ const yn = Number(yt);
168
+ const date = new Date(yn, mn - 1, dn);
169
+ if (date.getFullYear() === yn && date.getMonth() === mn - 1 && date.getDate() === dn) {
170
+ return `${String(yn).padStart(4, "0")}-${String(mn).padStart(2, "0")}-${String(dn).padStart(2, "0")}`;
161
171
  }
162
- ),
163
- renderHelpText(),
164
- renderError()
165
- ] });
172
+ }
173
+ return "";
174
+ };
175
+ const dateInputBase = classNames?.dateInput ?? classNames?.input ?? defaultInput;
176
+ const dateInputCls = hasError ? cx(dateInputBase, classNames?.inputError ?? defaultInputError) : dateInputBase;
177
+ const sublabelCls = classNames?.dateInputLabel ?? "block text-xs font-medium mb-1 text-gray-700";
178
+ const itemCls = classNames?.dateInputItem ?? "flex flex-col";
179
+ const groupCls = classNames?.dateInputGroup ?? "flex flex-row gap-3 items-end";
180
+ const legendCls = classNames?.dateLegend ?? labelClasses;
181
+ const fieldsetCls = classNames?.dateFieldset ?? (classNames?.fieldWrapper ?? defaultFieldWrapper);
182
+ const handleSubChange = (part, v) => {
183
+ const sanitized = v.replace(/[^\d]/g, "");
184
+ const next = {
185
+ day: part === "day" ? sanitized : dayPart,
186
+ month: part === "month" ? sanitized : monthPart,
187
+ year: part === "year" ? sanitized : yearPart
188
+ };
189
+ const combined = buildValue(next.day, next.month, next.year);
190
+ onChange(combined);
191
+ };
192
+ return /* @__PURE__ */ jsxs(
193
+ "fieldset",
194
+ {
195
+ className: fieldsetCls,
196
+ "aria-describedby": hasError ? errorId : void 0,
197
+ children: [
198
+ /* @__PURE__ */ jsxs("legend", { className: legendCls, children: [
199
+ question.name,
200
+ question.required && /* @__PURE__ */ jsx("span", { className: "text-red-500 ml-1", "aria-hidden": "true", children: "*" })
201
+ ] }),
202
+ /* @__PURE__ */ jsxs("div", { className: groupCls, role: "group", "aria-labelledby": void 0, children: [
203
+ /* @__PURE__ */ jsxs("div", { className: itemCls, children: [
204
+ /* @__PURE__ */ jsx("label", { htmlFor: dayId, className: sublabelCls, children: "Day" }),
205
+ /* @__PURE__ */ jsx(
206
+ "input",
207
+ {
208
+ id: dayId,
209
+ type: "text",
210
+ inputMode: "numeric",
211
+ pattern: "[0-9]*",
212
+ maxLength: 2,
213
+ value: dayPart,
214
+ onChange: (e) => handleSubChange("day", e.target.value),
215
+ className: cx(dateInputCls, "w-16"),
216
+ "aria-invalid": hasError ? true : void 0,
217
+ "aria-required": question.required || void 0
218
+ }
219
+ )
220
+ ] }),
221
+ /* @__PURE__ */ jsxs("div", { className: itemCls, children: [
222
+ /* @__PURE__ */ jsx("label", { htmlFor: monthId, className: sublabelCls, children: "Month" }),
223
+ /* @__PURE__ */ jsx(
224
+ "input",
225
+ {
226
+ id: monthId,
227
+ type: "text",
228
+ inputMode: "numeric",
229
+ pattern: "[0-9]*",
230
+ maxLength: 2,
231
+ value: monthPart,
232
+ onChange: (e) => handleSubChange("month", e.target.value),
233
+ className: cx(dateInputCls, "w-16"),
234
+ "aria-invalid": hasError ? true : void 0,
235
+ "aria-required": question.required || void 0
236
+ }
237
+ )
238
+ ] }),
239
+ /* @__PURE__ */ jsxs("div", { className: itemCls, children: [
240
+ /* @__PURE__ */ jsx("label", { htmlFor: yearId, className: sublabelCls, children: "Year" }),
241
+ /* @__PURE__ */ jsx(
242
+ "input",
243
+ {
244
+ id: yearId,
245
+ type: "text",
246
+ inputMode: "numeric",
247
+ pattern: "[0-9]*",
248
+ maxLength: 4,
249
+ value: yearPart,
250
+ onChange: (e) => handleSubChange("year", e.target.value),
251
+ className: cx(dateInputCls, "w-24"),
252
+ "aria-invalid": hasError ? true : void 0,
253
+ "aria-required": question.required || void 0
254
+ }
255
+ )
256
+ ] })
257
+ ] }),
258
+ renderHelpText(),
259
+ renderError()
260
+ ]
261
+ }
262
+ );
263
+ }
166
264
  case "number":
167
265
  return /* @__PURE__ */ jsxs("div", { className: classNames?.fieldWrapper ?? defaultFieldWrapper, children: [
168
266
  renderLabel(),