@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.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +117 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -859,6 +859,18 @@ interface BookingFormClassNames {
|
|
|
859
859
|
errorText?: string;
|
|
860
860
|
/** Submit button */
|
|
861
861
|
button?: string;
|
|
862
|
+
/** Date field <fieldset> wrapper */
|
|
863
|
+
dateFieldset?: string;
|
|
864
|
+
/** Date field <legend> */
|
|
865
|
+
dateLegend?: string;
|
|
866
|
+
/** Flex row containing day/month/year items */
|
|
867
|
+
dateInputGroup?: string;
|
|
868
|
+
/** Each day/month/year wrapper */
|
|
869
|
+
dateInputItem?: string;
|
|
870
|
+
/** Small "Day"/"Month"/"Year" label */
|
|
871
|
+
dateInputLabel?: string;
|
|
872
|
+
/** Date sub-input element (falls back to `input` / `inputError`) */
|
|
873
|
+
dateInput?: string;
|
|
862
874
|
}
|
|
863
875
|
interface BookingFormProps {
|
|
864
876
|
questions: Question[];
|
package/dist/index.d.ts
CHANGED
|
@@ -859,6 +859,18 @@ interface BookingFormClassNames {
|
|
|
859
859
|
errorText?: string;
|
|
860
860
|
/** Submit button */
|
|
861
861
|
button?: string;
|
|
862
|
+
/** Date field <fieldset> wrapper */
|
|
863
|
+
dateFieldset?: string;
|
|
864
|
+
/** Date field <legend> */
|
|
865
|
+
dateLegend?: string;
|
|
866
|
+
/** Flex row containing day/month/year items */
|
|
867
|
+
dateInputGroup?: string;
|
|
868
|
+
/** Each day/month/year wrapper */
|
|
869
|
+
dateInputItem?: string;
|
|
870
|
+
/** Small "Day"/"Month"/"Year" label */
|
|
871
|
+
dateInputLabel?: string;
|
|
872
|
+
/** Date sub-input element (falls back to `input` / `inputError`) */
|
|
873
|
+
dateInput?: string;
|
|
862
874
|
}
|
|
863
875
|
interface BookingFormProps {
|
|
864
876
|
questions: Question[];
|
package/dist/index.js
CHANGED
|
@@ -56,7 +56,10 @@ function FormField({
|
|
|
56
56
|
};
|
|
57
57
|
switch (question.detail_type) {
|
|
58
58
|
case "heading":
|
|
59
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
59
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classNames?.fieldWrapper ?? defaultFieldWrapper, children: [
|
|
60
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: classNames?.heading ?? defaultHeading, children: question.name }),
|
|
61
|
+
renderHelpText()
|
|
62
|
+
] });
|
|
60
63
|
case "text_field":
|
|
61
64
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classNames?.fieldWrapper ?? defaultFieldWrapper, children: [
|
|
62
65
|
renderLabel(),
|
|
@@ -146,25 +149,120 @@ function FormField({
|
|
|
146
149
|
renderHelpText(),
|
|
147
150
|
renderError()
|
|
148
151
|
] });
|
|
149
|
-
case "date":
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
152
|
+
case "date": {
|
|
153
|
+
const raw = typeof value === "string" ? value : "";
|
|
154
|
+
const match2 = raw.match(/^(\d{0,4})-?(\d{0,2})-?(\d{0,2})$/);
|
|
155
|
+
const yearPart = match2?.[1] ?? "";
|
|
156
|
+
const monthPart = match2?.[2] ? String(Number(match2[2])) : "";
|
|
157
|
+
const dayPart = match2?.[3] ? String(Number(match2[3])) : "";
|
|
158
|
+
const dayId = `${inputId}-day`;
|
|
159
|
+
const monthId = `${inputId}-month`;
|
|
160
|
+
const yearId = `${inputId}-year`;
|
|
161
|
+
const buildValue = (d, m, y) => {
|
|
162
|
+
const dt = d.trim();
|
|
163
|
+
const mt = m.trim();
|
|
164
|
+
const yt = y.trim();
|
|
165
|
+
if (!dt && !mt && !yt) return "";
|
|
166
|
+
if (/^\d{1,2}$/.test(dt) && /^\d{1,2}$/.test(mt) && /^\d{4}$/.test(yt)) {
|
|
167
|
+
const dn = Number(dt);
|
|
168
|
+
const mn = Number(mt);
|
|
169
|
+
const yn = Number(yt);
|
|
170
|
+
const date = new Date(yn, mn - 1, dn);
|
|
171
|
+
if (date.getFullYear() === yn && date.getMonth() === mn - 1 && date.getDate() === dn) {
|
|
172
|
+
return `${String(yn).padStart(4, "0")}-${String(mn).padStart(2, "0")}-${String(dn).padStart(2, "0")}`;
|
|
163
173
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
174
|
+
}
|
|
175
|
+
return "";
|
|
176
|
+
};
|
|
177
|
+
const dateInputBase = classNames?.dateInput ?? classNames?.input ?? defaultInput;
|
|
178
|
+
const dateInputCls = hasError ? cx(dateInputBase, classNames?.inputError ?? defaultInputError) : dateInputBase;
|
|
179
|
+
const sublabelCls = classNames?.dateInputLabel ?? "block text-xs font-medium mb-1 text-gray-700";
|
|
180
|
+
const itemCls = classNames?.dateInputItem ?? "flex flex-col";
|
|
181
|
+
const groupCls = classNames?.dateInputGroup ?? "flex flex-row gap-3 items-end";
|
|
182
|
+
const legendCls = classNames?.dateLegend ?? labelClasses;
|
|
183
|
+
const fieldsetCls = classNames?.dateFieldset ?? (classNames?.fieldWrapper ?? defaultFieldWrapper);
|
|
184
|
+
const handleSubChange = (part, v) => {
|
|
185
|
+
const sanitized = v.replace(/[^\d]/g, "");
|
|
186
|
+
const next = {
|
|
187
|
+
day: part === "day" ? sanitized : dayPart,
|
|
188
|
+
month: part === "month" ? sanitized : monthPart,
|
|
189
|
+
year: part === "year" ? sanitized : yearPart
|
|
190
|
+
};
|
|
191
|
+
const combined = buildValue(next.day, next.month, next.year);
|
|
192
|
+
onChange(combined);
|
|
193
|
+
};
|
|
194
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
195
|
+
"fieldset",
|
|
196
|
+
{
|
|
197
|
+
className: fieldsetCls,
|
|
198
|
+
"aria-describedby": hasError ? errorId : void 0,
|
|
199
|
+
children: [
|
|
200
|
+
/* @__PURE__ */ jsxRuntime.jsxs("legend", { className: legendCls, children: [
|
|
201
|
+
question.name,
|
|
202
|
+
question.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-red-500 ml-1", "aria-hidden": "true", children: "*" })
|
|
203
|
+
] }),
|
|
204
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: groupCls, role: "group", "aria-labelledby": void 0, children: [
|
|
205
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: itemCls, children: [
|
|
206
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: dayId, className: sublabelCls, children: "Day" }),
|
|
207
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
208
|
+
"input",
|
|
209
|
+
{
|
|
210
|
+
id: dayId,
|
|
211
|
+
type: "text",
|
|
212
|
+
inputMode: "numeric",
|
|
213
|
+
pattern: "[0-9]*",
|
|
214
|
+
maxLength: 2,
|
|
215
|
+
value: dayPart,
|
|
216
|
+
onChange: (e) => handleSubChange("day", e.target.value),
|
|
217
|
+
className: cx(dateInputCls, "w-16"),
|
|
218
|
+
"aria-invalid": hasError ? true : void 0,
|
|
219
|
+
"aria-required": question.required || void 0
|
|
220
|
+
}
|
|
221
|
+
)
|
|
222
|
+
] }),
|
|
223
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: itemCls, children: [
|
|
224
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: monthId, className: sublabelCls, children: "Month" }),
|
|
225
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
226
|
+
"input",
|
|
227
|
+
{
|
|
228
|
+
id: monthId,
|
|
229
|
+
type: "text",
|
|
230
|
+
inputMode: "numeric",
|
|
231
|
+
pattern: "[0-9]*",
|
|
232
|
+
maxLength: 2,
|
|
233
|
+
value: monthPart,
|
|
234
|
+
onChange: (e) => handleSubChange("month", e.target.value),
|
|
235
|
+
className: cx(dateInputCls, "w-16"),
|
|
236
|
+
"aria-invalid": hasError ? true : void 0,
|
|
237
|
+
"aria-required": question.required || void 0
|
|
238
|
+
}
|
|
239
|
+
)
|
|
240
|
+
] }),
|
|
241
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: itemCls, children: [
|
|
242
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: yearId, className: sublabelCls, children: "Year" }),
|
|
243
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
244
|
+
"input",
|
|
245
|
+
{
|
|
246
|
+
id: yearId,
|
|
247
|
+
type: "text",
|
|
248
|
+
inputMode: "numeric",
|
|
249
|
+
pattern: "[0-9]*",
|
|
250
|
+
maxLength: 4,
|
|
251
|
+
value: yearPart,
|
|
252
|
+
onChange: (e) => handleSubChange("year", e.target.value),
|
|
253
|
+
className: cx(dateInputCls, "w-24"),
|
|
254
|
+
"aria-invalid": hasError ? true : void 0,
|
|
255
|
+
"aria-required": question.required || void 0
|
|
256
|
+
}
|
|
257
|
+
)
|
|
258
|
+
] })
|
|
259
|
+
] }),
|
|
260
|
+
renderHelpText(),
|
|
261
|
+
renderError()
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
);
|
|
265
|
+
}
|
|
168
266
|
case "number":
|
|
169
267
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classNames?.fieldWrapper ?? defaultFieldWrapper, children: [
|
|
170
268
|
renderLabel(),
|