@nicertravel/ui 1.2.0 → 1.3.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.ts CHANGED
@@ -77,6 +77,8 @@ interface OptionsProps<T> {
77
77
  export declare function Option<T>({ active, checked, index, option, onClick, showCheck }: OptionsProps<T>): import("react").JSX.Element;
78
78
  interface AutocompleteProps<T> extends InputHTMLAttributes<HTMLInputElement> {
79
79
  defaultOptions?: DropdownOption<T>[];
80
+ /** What is wrong with the choice, under the field as a text input's. */
81
+ error?: string;
80
82
  icon?: string;
81
83
  inputValue?: string;
82
84
  isLoading?: boolean;
@@ -170,12 +172,14 @@ interface DateInputProps {
170
172
  }
171
173
  declare function DateInput({ id, defaultDate, disabled, label, name, onChange, required, key, minDate, maxDate }: DateInputProps): import("react").JSX.Element;
172
174
  export interface DateInputV2Props extends InputHTMLAttributes<HTMLInputElement> {
175
+ /** What is wrong with the date, under the field as a text input's. */
176
+ error?: string;
173
177
  label?: string;
174
178
  /**
175
179
  * The latest and earliest days a typed date may be (YYYY-MM-DD), as the
176
180
  * calendar's own bounds: a whole day outside them isn't handed on, and
177
- * the field says which days are. A host that words its own range error
178
- * leaves them out.
181
+ * a bubble under the field says which days are while it has the cursor.
182
+ * A host that words its own range error leaves them out.
179
183
  */
180
184
  maxDate?: string;
181
185
  minDate?: string;
@@ -191,7 +195,7 @@ export interface DateInputV2Props extends InputHTMLAttributes<HTMLInputElement>
191
195
  }
192
196
  /** "12-24-2026" → "2026-12-24", or null while it isn't a whole, real day. */
193
197
  export declare const typedDate: (text: string) => string | null;
194
- export declare const DateInputV2: ({ label, maxDate, minDate, onType, setCalendarVisible, ...rest }: DateInputV2Props) => import("react").JSX.Element;
198
+ export declare const DateInputV2: ({ error, label, maxDate, minDate, onType, placeholder, setCalendarVisible, ...rest }: DateInputV2Props) => import("react").JSX.Element;
195
199
  interface DialogProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "title"> {
196
200
  actions: DialogAction[];
197
201
  children?: React.ReactNode;
@@ -253,6 +257,19 @@ interface Props$2 {
253
257
  * telemetry picks those up from `onerror` / `unhandledrejection`.
254
258
  */
255
259
  declare function ErrorBoundary({ children, message }: Props$2): import("react").JSX.Element;
260
+ interface FieldErrorProps {
261
+ children: ReactNode;
262
+ /** Where a host places it: over a save bar, under a field of its own. */
263
+ className?: string;
264
+ id?: string;
265
+ }
266
+ /**
267
+ * What is wrong with a field, the same everywhere: the alert icon and one
268
+ * short line, in the negative tone. Every field's `error` renders it, and a
269
+ * host that checks a field of its own puts it under that field. The `error`
270
+ * class stays for the hosts that already style a field's error by it.
271
+ */
272
+ export declare function FieldError({ children, className, id }: FieldErrorProps): import("react").JSX.Element;
256
273
  interface FileInputProps extends InputHTMLAttributes<HTMLInputElement> {
257
274
  /** The picker button's words. */
258
275
  browseLabel?: string;
@@ -629,6 +646,8 @@ interface PriceProps {
629
646
  defaultCurrency?: string;
630
647
  defaultValue?: string;
631
648
  disabled?: boolean;
649
+ /** What is wrong with the amount, under the field as a text input's. */
650
+ error?: string;
632
651
  id?: string;
633
652
  max?: number;
634
653
  min?: number;
@@ -641,7 +660,7 @@ interface PriceProps {
641
660
  }[];
642
661
  required?: boolean;
643
662
  }
644
- declare function PriceInput({ "aria-label": ariaLabel, id, options, currencySelector, defaultCurrency, defaultValue, disabled, name, onChange, onCurrencyChange, required, min, max }: PriceProps): import("react").JSX.Element;
663
+ declare function PriceInput({ "aria-label": ariaLabel, id, options, currencySelector, defaultCurrency, defaultValue, disabled, error, name, onChange, onCurrencyChange, required, min, max }: PriceProps): import("react").JSX.Element;
645
664
  interface RadioButtonProps extends InputHTMLAttributes<HTMLInputElement> {}
646
665
  declare function RadioButton({ ...rest }: RadioButtonProps): import("react").JSX.Element;
647
666
  export interface SelectOption {
@@ -657,6 +676,8 @@ export interface SelectOption {
657
676
  }
658
677
  export interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
659
678
  defaultValue?: string;
679
+ /** What is wrong with the choice, under the select as a text input's. */
680
+ error?: string;
660
681
  options?: SelectOption[];
661
682
  placeholder?: string;
662
683
  readOnly?: boolean;
@@ -679,7 +700,7 @@ export interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
679
700
  * own picker. A choice that searches the server or takes free text is an
680
701
  * Autocomplete instead. Several at once stay the native select.
681
702
  */
682
- declare function Select({ searchable, ...props }: SelectProps): import("react").JSX.Element;
703
+ declare function Select({ error, searchable, ...props }: SelectProps): import("react").JSX.Element;
683
704
  interface RangeSliderProps {
684
705
  /** Names each thumb for screen readers: "Minimum price", "Maximum price". */
685
706
  labels?: [string, string];
@@ -742,9 +763,11 @@ interface TextAreaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
742
763
  * a long note reads whole instead of hiding under the box's edge.
743
764
  */
744
765
  autoGrow?: boolean;
766
+ /** What is wrong with the text, under the box as a text input's. */
767
+ error?: string;
745
768
  label?: string;
746
769
  }
747
- declare function TextArea({ autoGrow, label, defaultValue, ...rest }: TextAreaProps): import("react").JSX.Element;
770
+ declare function TextArea({ autoGrow, error, label, defaultValue, ...rest }: TextAreaProps): import("react").JSX.Element;
748
771
  interface TextInputProps extends InputHTMLAttributes<HTMLInputElement> {
749
772
  error?: string;
750
773
  icon?: string;
@@ -898,14 +921,30 @@ interface TooltipProps {
898
921
  /** Usually a line of text; a list when there is more than one thing to say. */
899
922
  label: React.ReactNode;
900
923
  }
924
+ interface TooltipBubbleProps {
925
+ /** What the bubble is about: it opens next to it, its arrow at its middle. */
926
+ anchor: RefObject<HTMLElement | null>;
927
+ className?: string;
928
+ id?: string;
929
+ label: React.ReactNode;
930
+ /** "alert" for a bubble that says something went wrong, read out at once. */
931
+ role?: "alert" | "tooltip";
932
+ }
933
+ /**
934
+ * The bubble alone, open while it is rendered: a Tooltip's, or one a field
935
+ * opens on its own (a typed date out of range). It renders on
936
+ * `document.body` at fixed viewport coordinates, so a scrolling rail or a
937
+ * card with `overflow: hidden` can't clip it. It opens below the anchor,
938
+ * left edges aligned; it moves above when there is no room below and
939
+ * slides left to stay on screen. Its arrow points at the anchor's middle,
940
+ * wherever the bubble slid to. Content that needs its own styles must
941
+ * carry them (a styled element as `label`), since the bubble doesn't sit
942
+ * inside the host's markup.
943
+ */
944
+ export declare function TooltipBubble({ anchor, className, id, label, role }: TooltipBubbleProps): import("react").ReactPortal;
901
945
  /**
902
- * A hover label. The bubble renders on `document.body` at fixed viewport
903
- * coordinates, so a scrolling rail or a card with `overflow: hidden` can't
904
- * clip it. It opens below the anchor, left edges aligned; it moves above
905
- * when there is no room below and slides left to stay on screen. Its arrow
906
- * points at the anchor's middle, wherever the bubble slid to. Content
907
- * that needs its own styles must carry them (a styled element as `label`),
908
- * since the bubble no longer sits inside the host's markup.
946
+ * A hover label: its bubble opens while the pointer or the focus is on what
947
+ * it wraps.
909
948
  */
910
949
  declare function Tag$1({ label, children, className, disabled, ...rest }: TooltipProps): import("react").JSX.Element;
911
950
  export interface StatusProps {
package/dist/index.js CHANGED
@@ -422,14 +422,42 @@ function Spinner({ size }) {
422
422
  }
423
423
  });
424
424
  }
425
+ // src/components/FieldError.tsx
426
+ /**
427
+ * What is wrong with a field, the same everywhere: the alert icon and one
428
+ * short line, in the negative tone. Every field's `error` renders it, and a
429
+ * host that checks a field of its own puts it under that field. The `error`
430
+ * class stays for the hosts that already style a field's error by it.
431
+ */
432
+ function FieldError({ children, className, id }) {
433
+ return /* @__PURE__ */ jsxs("div", {
434
+ className: [
435
+ "ui-field-error",
436
+ "error",
437
+ className
438
+ ].filter(Boolean).join(" "),
439
+ id,
440
+ role: "alert",
441
+ children: [/* @__PURE__ */ jsx(Icon, {
442
+ name: "alert",
443
+ size: 12
444
+ }), /* @__PURE__ */ jsx("p", {
445
+ className: "t-xxs",
446
+ children
447
+ })]
448
+ });
449
+ }
425
450
  // src/components/TextInput.tsx
426
451
  function TextInput({ icon, id, isLoading, label, error, ...rest }) {
427
452
  const generatedId = useId();
428
453
  const inputId = id ?? generatedId;
454
+ const errorId = `${inputId}-error`;
429
455
  return /* @__PURE__ */ jsxs("div", {
430
456
  className: `ui-text-input ${icon ? "icon" : ""}`,
431
457
  children: [
432
458
  /* @__PURE__ */ jsx("input", {
459
+ "aria-describedby": error ? errorId : void 0,
460
+ "aria-invalid": error ? true : void 0,
433
461
  id: inputId,
434
462
  placeholder: " ",
435
463
  type: "text",
@@ -447,16 +475,10 @@ function TextInput({ icon, id, isLoading, label, error, ...rest }) {
447
475
  color: "light",
448
476
  size: 16
449
477
  }),
450
- error && /* @__PURE__ */ jsxs("div", {
451
- className: "error",
452
- children: [/* @__PURE__ */ jsx(Icon, {
453
- name: "alert",
454
- size: 12
455
- }), /* @__PURE__ */ jsx("p", {
456
- className: "t-xxs",
457
- children: error
458
- })]
459
- })
478
+ error ? /* @__PURE__ */ jsx(FieldError, {
479
+ id: errorId,
480
+ children: error
481
+ }) : null
460
482
  ]
461
483
  });
462
484
  }
@@ -1124,7 +1146,109 @@ function DateInput({ id, defaultDate, disabled, label, name, onChange, required,
1124
1146
  const formatDate = (date) => {
1125
1147
  return dayjs(date).format("MM-DD-YYYY");
1126
1148
  };
1149
+ // src/components/Tooltip.tsx
1150
+ const MAX_WIDTH = 300;
1151
+ /** Gap between the anchor and the bubble. */
1152
+ const OFFSET = 8;
1153
+ /** Room kept between the bubble and the viewport edges. */
1154
+ const EDGE = 16;
1155
+ /** The least room between the arrow and the bubble's corners. */
1156
+ const ARROW_INSET = 12;
1157
+ /**
1158
+ * The bubble alone, open while it is rendered: a Tooltip's, or one a field
1159
+ * opens on its own (a typed date out of range). It renders on
1160
+ * `document.body` at fixed viewport coordinates, so a scrolling rail or a
1161
+ * card with `overflow: hidden` can't clip it. It opens below the anchor,
1162
+ * left edges aligned; it moves above when there is no room below and
1163
+ * slides left to stay on screen. Its arrow points at the anchor's middle,
1164
+ * wherever the bubble slid to. Content that needs its own styles must
1165
+ * carry them (a styled element as `label`), since the bubble doesn't sit
1166
+ * inside the host's markup.
1167
+ */
1168
+ function TooltipBubble({ anchor, className, id, label, role = "tooltip" }) {
1169
+ const [position, setPosition] = useState();
1170
+ const bubbleRef = useRef(null);
1171
+ useLayoutEffect(() => {
1172
+ const calculatePosition = () => {
1173
+ if (!(bubbleRef.current && anchor.current)) return;
1174
+ const box = anchor.current.getBoundingClientRect();
1175
+ const { height, width } = bubbleRef.current.getBoundingClientRect();
1176
+ const viewportWidth = window.innerWidth;
1177
+ const viewportHeight = window.innerHeight;
1178
+ let left = box.left;
1179
+ if (left + width > viewportWidth - EDGE) left = box.right - width;
1180
+ left = Math.max(EDGE, Math.min(left, viewportWidth - EDGE - width));
1181
+ let top = box.bottom + OFFSET;
1182
+ let side = "below";
1183
+ const above = box.top - OFFSET - height;
1184
+ if (top + height > viewportHeight - EDGE && above >= EDGE) {
1185
+ top = above;
1186
+ side = "above";
1187
+ }
1188
+ const arrow = Math.min(Math.max(box.left + box.width / 2 - left, ARROW_INSET), width - ARROW_INSET);
1189
+ setPosition({
1190
+ arrow,
1191
+ left,
1192
+ side,
1193
+ top
1194
+ });
1195
+ };
1196
+ calculatePosition();
1197
+ window.addEventListener("resize", calculatePosition);
1198
+ window.addEventListener("scroll", calculatePosition, true);
1199
+ return () => {
1200
+ window.removeEventListener("resize", calculatePosition);
1201
+ window.removeEventListener("scroll", calculatePosition, true);
1202
+ };
1203
+ }, [anchor, label]);
1204
+ return createPortal(/* @__PURE__ */ jsx("div", {
1205
+ className: [
1206
+ "ui-tooltip-bubble",
1207
+ "t-xxs",
1208
+ className
1209
+ ].filter(Boolean).join(" "),
1210
+ "data-side": position?.side,
1211
+ id,
1212
+ ref: bubbleRef,
1213
+ role,
1214
+ style: {
1215
+ "--arrow-x": `${position?.arrow ?? ARROW_INSET}px`,
1216
+ left: position?.left ?? 0,
1217
+ maxWidth: `min(${MAX_WIDTH}px, calc(100vw - 32px))`,
1218
+ top: position?.top ?? 0,
1219
+ visibility: position ? "visible" : "hidden"
1220
+ },
1221
+ children: label
1222
+ }), document.body);
1223
+ }
1224
+ /**
1225
+ * A hover label: its bubble opens while the pointer or the focus is on what
1226
+ * it wraps.
1227
+ */
1228
+ function Tag$1({ label, children, className, disabled = false, ...rest }) {
1229
+ const [visible, setVisible] = useState(false);
1230
+ const containerRef = useRef(null);
1231
+ return /* @__PURE__ */ jsxs("div", {
1232
+ className: [
1233
+ "ui-tooltip",
1234
+ disabled ? "disabled" : "",
1235
+ className
1236
+ ].filter(Boolean).join(" "),
1237
+ ref: containerRef,
1238
+ ...rest,
1239
+ onBlur: () => setVisible(false),
1240
+ onFocus: () => setVisible(true),
1241
+ onMouseEnter: () => setVisible(true),
1242
+ onMouseLeave: () => setVisible(false),
1243
+ children: [visible && !disabled ? /* @__PURE__ */ jsx(TooltipBubble, {
1244
+ anchor: containerRef,
1245
+ label
1246
+ }) : null, children]
1247
+ });
1248
+ }
1127
1249
  // src/components/DateInputV2.tsx
1250
+ /** The format a typed date takes, shown in the field while it has the cursor. */
1251
+ const FORMAT = "MM-DD-YYYY";
1128
1252
  const readable = (date) => dayjs(date).format("MMM D, YYYY");
1129
1253
  /** "Enter a date from Jan 1, 1926 to Dec 23, 2014.", or one bound alone. */
1130
1254
  const rangeError = (minDate, maxDate) => `Enter a date ${[minDate ? `from ${readable(minDate)}` : null, maxDate ? `${minDate ? "to" : "up to"} ${readable(maxDate)}` : null].filter(Boolean).join(" ")}.`;
@@ -1145,24 +1269,46 @@ const typedDate = (text) => {
1145
1269
  const iso = `${match[3]}-${match[1]}-${match[2]}`;
1146
1270
  return dayjs(iso).format("YYYY-MM-DD") === iso ? iso : null;
1147
1271
  };
1148
- const DateInputV2 = ({ label, maxDate, minDate, onType, setCalendarVisible, ...rest }) => {
1272
+ /** Where the format sits: over the field's text, in the field's own type. */
1273
+ const formatBox = (input) => {
1274
+ const style = window.getComputedStyle(input);
1275
+ return {
1276
+ fontFamily: style.fontFamily,
1277
+ fontSize: style.fontSize,
1278
+ fontWeight: style.fontWeight,
1279
+ height: input.offsetHeight,
1280
+ left: input.offsetLeft,
1281
+ letterSpacing: style.letterSpacing,
1282
+ paddingLeft: style.paddingLeft,
1283
+ top: input.offsetTop
1284
+ };
1285
+ };
1286
+ const DateInputV2 = ({ error, label, maxDate, minDate, onType, placeholder = "Select date", setCalendarVisible, ...rest }) => {
1149
1287
  const generatedId = useId();
1150
1288
  const inputId = rest.id ?? generatedId;
1289
+ const errorId = `${inputId}-error`;
1290
+ const inputRef = useRef(null);
1151
1291
  const [typed, setTyped] = useState(null);
1152
1292
  const [outOfRange, setOutOfRange] = useState(false);
1293
+ const [box, setBox] = useState(null);
1153
1294
  const stored = isEmpty(rest.value) ? "" : formatDate(rest.value);
1295
+ const text = typed ?? stored;
1296
+ const remaining = box ? FORMAT.slice(text.length) : "";
1154
1297
  return /* @__PURE__ */ jsxs("div", {
1155
1298
  className: "ui-date-input",
1156
1299
  children: [
1157
1300
  onType ? /* @__PURE__ */ jsx("input", {
1301
+ "aria-describedby": outOfRange || error ? errorId : rest["aria-describedby"],
1302
+ "aria-invalid": outOfRange || Boolean(error) || void 0,
1158
1303
  autoComplete: "off",
1159
1304
  disabled: rest.disabled,
1160
1305
  id: inputId,
1161
1306
  inputMode: "numeric",
1162
- "aria-invalid": outOfRange || void 0,
1163
- onBlur: () => {
1307
+ onBlur: (event) => {
1164
1308
  setTyped(null);
1165
1309
  setOutOfRange(false);
1310
+ setBox(null);
1311
+ rest.onBlur?.(event);
1166
1312
  },
1167
1313
  onChange: (event) => {
1168
1314
  const next = masked(event.target.value);
@@ -1180,11 +1326,18 @@ const DateInputV2 = ({ label, maxDate, minDate, onType, setCalendarVisible, ...r
1180
1326
  }
1181
1327
  onType(day);
1182
1328
  },
1183
- placeholder: "MM-DD-YYYY",
1329
+ onFocus: (event) => {
1330
+ setBox(formatBox(event.currentTarget));
1331
+ rest.onFocus?.(event);
1332
+ },
1333
+ placeholder: box ? "" : placeholder,
1334
+ ref: inputRef,
1184
1335
  required: rest.required,
1185
1336
  type: "text",
1186
- value: typed ?? stored
1337
+ value: text
1187
1338
  }) : /* @__PURE__ */ jsx("input", {
1339
+ "aria-describedby": error ? errorId : rest["aria-describedby"],
1340
+ "aria-invalid": error ? true : void 0,
1188
1341
  id: inputId,
1189
1342
  disabled: rest.disabled,
1190
1343
  readOnly: true,
@@ -1197,11 +1350,17 @@ const DateInputV2 = ({ label, maxDate, minDate, onType, setCalendarVisible, ...r
1197
1350
  setCalendarVisible(true);
1198
1351
  }
1199
1352
  },
1200
- placeholder: "Select date",
1353
+ placeholder,
1201
1354
  required: rest.required,
1202
1355
  type: "text",
1203
1356
  value: stored
1204
1357
  }),
1358
+ box && remaining ? /* @__PURE__ */ jsxs("span", {
1359
+ "aria-hidden": true,
1360
+ className: "format",
1361
+ style: box,
1362
+ children: [/* @__PURE__ */ jsx("span", { children: text }), remaining]
1363
+ }) : null,
1205
1364
  label && /* @__PURE__ */ jsx("label", {
1206
1365
  htmlFor: inputId,
1207
1366
  children: label
@@ -1216,16 +1375,16 @@ const DateInputV2 = ({ label, maxDate, minDate, onType, setCalendarVisible, ...r
1216
1375
  size: 16
1217
1376
  })
1218
1377
  }),
1219
- outOfRange ? /* @__PURE__ */ jsxs("div", {
1378
+ outOfRange && box ? /* @__PURE__ */ jsx(TooltipBubble, {
1379
+ anchor: inputRef,
1220
1380
  className: "error",
1221
- role: "alert",
1222
- children: [/* @__PURE__ */ jsx(Icon, {
1223
- name: "alert",
1224
- size: 12
1225
- }), /* @__PURE__ */ jsx("p", {
1226
- className: "t-xxs",
1381
+ label: /* @__PURE__ */ jsx(FieldError, {
1382
+ id: errorId,
1227
1383
  children: rangeError(minDate, maxDate)
1228
- })]
1384
+ })
1385
+ }) : error ? /* @__PURE__ */ jsx(FieldError, {
1386
+ id: errorId,
1387
+ children: error
1229
1388
  }) : null
1230
1389
  ]
1231
1390
  });
@@ -2048,16 +2207,7 @@ function NumberInput({ id, defaultValue, disabled, error, label, minValue = 0, m
2048
2207
  },
2049
2208
  size: "s"
2050
2209
  }),
2051
- error ? /* @__PURE__ */ jsxs("div", {
2052
- className: "error",
2053
- children: [/* @__PURE__ */ jsx(Icon, {
2054
- name: "alert",
2055
- size: 12
2056
- }), /* @__PURE__ */ jsx("p", {
2057
- className: "t-xxs",
2058
- children: error
2059
- })]
2060
- }) : null
2210
+ error ? /* @__PURE__ */ jsx(FieldError, { children: error }) : null
2061
2211
  ]
2062
2212
  });
2063
2213
  }
@@ -3658,16 +3808,7 @@ function PhoneInput({ id, defaultDialCode, defaultValue, disabled, error, label,
3658
3808
  htmlFor: inputId,
3659
3809
  children: label
3660
3810
  }) : null,
3661
- error ? /* @__PURE__ */ jsxs("div", {
3662
- className: "error",
3663
- children: [/* @__PURE__ */ jsx(Icon, {
3664
- name: "alert",
3665
- size: 12
3666
- }), /* @__PURE__ */ jsx("p", {
3667
- className: "t-xxs",
3668
- children: error
3669
- })]
3670
- }) : null
3811
+ error ? /* @__PURE__ */ jsx(FieldError, { children: error }) : null
3671
3812
  ]
3672
3813
  });
3673
3814
  }
@@ -4269,94 +4410,6 @@ function Grip() {
4269
4410
  }, `r${y}`)])
4270
4411
  });
4271
4412
  }
4272
- // src/components/Tooltip.tsx
4273
- const MAX_WIDTH = 300;
4274
- /** Gap between the anchor and the bubble. */
4275
- const OFFSET = 8;
4276
- /** Room kept between the bubble and the viewport edges. */
4277
- const EDGE = 16;
4278
- /** The least room between the arrow and the bubble's corners. */
4279
- const ARROW_INSET = 12;
4280
- /**
4281
- * A hover label. The bubble renders on `document.body` at fixed viewport
4282
- * coordinates, so a scrolling rail or a card with `overflow: hidden` can't
4283
- * clip it. It opens below the anchor, left edges aligned; it moves above
4284
- * when there is no room below and slides left to stay on screen. Its arrow
4285
- * points at the anchor's middle, wherever the bubble slid to. Content
4286
- * that needs its own styles must carry them (a styled element as `label`),
4287
- * since the bubble no longer sits inside the host's markup.
4288
- */
4289
- function Tag$1({ label, children, className, disabled = false, ...rest }) {
4290
- const [visible, setVisible] = useState(false);
4291
- const [position, setPosition] = useState();
4292
- const tooltipRef = useRef(null);
4293
- const containerRef = useRef(null);
4294
- const calculatePosition = () => {
4295
- if (!(tooltipRef.current && containerRef.current)) return;
4296
- const anchor = containerRef.current.getBoundingClientRect();
4297
- const { height, width } = tooltipRef.current.getBoundingClientRect();
4298
- const viewportWidth = window.innerWidth;
4299
- const viewportHeight = window.innerHeight;
4300
- let left = anchor.left;
4301
- if (left + width > viewportWidth - EDGE) left = anchor.right - width;
4302
- left = Math.max(EDGE, Math.min(left, viewportWidth - EDGE - width));
4303
- let top = anchor.bottom + OFFSET;
4304
- let side = "below";
4305
- const above = anchor.top - OFFSET - height;
4306
- if (top + height > viewportHeight - EDGE && above >= EDGE) {
4307
- top = above;
4308
- side = "above";
4309
- }
4310
- const arrow = Math.min(Math.max(anchor.left + anchor.width / 2 - left, ARROW_INSET), width - ARROW_INSET);
4311
- setPosition({
4312
- arrow,
4313
- left,
4314
- side,
4315
- top
4316
- });
4317
- };
4318
- useLayoutEffect(() => {
4319
- if (visible) calculatePosition();
4320
- else setPosition(void 0);
4321
- }, [visible, label]);
4322
- useEffect(() => {
4323
- if (!visible) return;
4324
- const handle = () => calculatePosition();
4325
- window.addEventListener("resize", handle);
4326
- window.addEventListener("scroll", handle, true);
4327
- return () => {
4328
- window.removeEventListener("resize", handle);
4329
- window.removeEventListener("scroll", handle, true);
4330
- };
4331
- }, [visible]);
4332
- return /* @__PURE__ */ jsxs("div", {
4333
- className: [
4334
- "ui-tooltip",
4335
- disabled ? "disabled" : "",
4336
- className
4337
- ].filter(Boolean).join(" "),
4338
- ref: containerRef,
4339
- ...rest,
4340
- onBlur: () => setVisible(false),
4341
- onFocus: () => setVisible(true),
4342
- onMouseEnter: () => setVisible(true),
4343
- onMouseLeave: () => setVisible(false),
4344
- children: [visible && !disabled ? createPortal(/* @__PURE__ */ jsx("div", {
4345
- className: "ui-tooltip-bubble t-xxs",
4346
- "data-side": position?.side,
4347
- ref: tooltipRef,
4348
- role: "tooltip",
4349
- style: {
4350
- "--arrow-x": `${position?.arrow ?? ARROW_INSET}px`,
4351
- left: position?.left ?? 0,
4352
- maxWidth: `min(${MAX_WIDTH}px, calc(100vw - 32px))`,
4353
- top: position?.top ?? 0,
4354
- visibility: position ? "visible" : "hidden"
4355
- },
4356
- children: label
4357
- }), document.body) : null, children]
4358
- });
4359
- }
4360
4413
  // src/components/SideNav.tsx
4361
4414
  /**
4362
4415
  * The room a page in hand takes above and below its row while the menu is
@@ -4578,13 +4631,13 @@ const touchScreen = () => {
4578
4631
  * own picker. A choice that searches the server or takes free text is an
4579
4632
  * Autocomplete instead. Several at once stay the native select.
4580
4633
  */
4581
- function Select({ searchable, ...props }) {
4634
+ function Select({ error, searchable, ...props }) {
4582
4635
  const count = props.options?.length ?? 0;
4583
- if (props.multiple || !searchable && count < TOUCH_SEARCH_FROM && touchScreen()) return /* @__PURE__ */ jsx(NativeSelect, { ...props });
4584
- return /* @__PURE__ */ jsx(ListSelect, {
4636
+ const field = props.multiple || !searchable && count < TOUCH_SEARCH_FROM && touchScreen() ? /* @__PURE__ */ jsx(NativeSelect, { ...props }) : /* @__PURE__ */ jsx(ListSelect, {
4585
4637
  ...props,
4586
4638
  search: Boolean(searchable) || count >= SEARCH_FROM
4587
4639
  });
4640
+ return error ? /* @__PURE__ */ jsxs(Fragment$1, { children: [field, /* @__PURE__ */ jsx(FieldError, { children: error })] }) : field;
4588
4641
  }
4589
4642
  function NativeSelect({ className, options, placeholder, variant, defaultValue = "", readOnly, style, ...rest }) {
4590
4643
  return /* @__PURE__ */ jsxs("select", {
@@ -4705,7 +4758,7 @@ function ListSelect({ "aria-describedby": describedBy, "aria-label": ariaLabel,
4705
4758
  ] });
4706
4759
  }
4707
4760
  // src/components/PriceInput.tsx
4708
- function PriceInput({ "aria-label": ariaLabel, id, options, currencySelector, defaultCurrency = "USD", defaultValue = "", disabled, name, onChange, onCurrencyChange, required, min, max }) {
4761
+ function PriceInput({ "aria-label": ariaLabel, id, options, currencySelector, defaultCurrency = "USD", defaultValue = "", disabled, error, name, onChange, onCurrencyChange, required, min, max }) {
4709
4762
  const inputRef = useRef(null);
4710
4763
  const [value, setValue] = useState(defaultValue?.toString());
4711
4764
  useEffect(() => {
@@ -4737,22 +4790,27 @@ function PriceInput({ "aria-label": ariaLabel, id, options, currencySelector, de
4737
4790
  return /* @__PURE__ */ jsxs("div", {
4738
4791
  className: "ui-price-input",
4739
4792
  id,
4740
- children: [/* @__PURE__ */ jsx("input", {
4741
- "aria-label": ariaLabel,
4742
- disabled,
4743
- name,
4744
- onChange: handleChange,
4745
- placeholder: "0.00",
4746
- ref: inputRef,
4747
- required,
4748
- type: "text",
4749
- value: value && format(value)
4750
- }), currencySelector ? /* @__PURE__ */ jsx(Select, {
4751
- "aria-label": "Currency",
4752
- defaultValue: defaultCurrency,
4753
- onChange: (e) => onCurrencyChange?.(e.currentTarget.value),
4754
- options: dropdownOptions
4755
- }) : /* @__PURE__ */ jsx("b", { children: "$" })]
4793
+ children: [
4794
+ /* @__PURE__ */ jsx("input", {
4795
+ "aria-invalid": error ? true : void 0,
4796
+ "aria-label": ariaLabel,
4797
+ disabled,
4798
+ name,
4799
+ onChange: handleChange,
4800
+ placeholder: "0.00",
4801
+ ref: inputRef,
4802
+ required,
4803
+ type: "text",
4804
+ value: value && format(value)
4805
+ }),
4806
+ currencySelector ? /* @__PURE__ */ jsx(Select, {
4807
+ "aria-label": "Currency",
4808
+ defaultValue: defaultCurrency,
4809
+ onChange: (e) => onCurrencyChange?.(e.currentTarget.value),
4810
+ options: dropdownOptions
4811
+ }) : /* @__PURE__ */ jsx("b", { children: "$" }),
4812
+ error ? /* @__PURE__ */ jsx(FieldError, { children: error }) : null
4813
+ ]
4756
4814
  });
4757
4815
  }
4758
4816
  // src/components/RadioButton.tsx
@@ -4970,7 +5028,7 @@ function Tag({ disabled: _disabled, label, type = "default", onRemove, ...rest }
4970
5028
  });
4971
5029
  }
4972
5030
  // src/components/TextArea.tsx
4973
- function TextArea({ autoGrow = false, label, defaultValue, ...rest }) {
5031
+ function TextArea({ autoGrow = false, error, label, defaultValue, ...rest }) {
4974
5032
  const [text, setText] = useState("");
4975
5033
  const areaRef = useRef(null);
4976
5034
  useEffect(() => {
@@ -4990,13 +5048,18 @@ function TextArea({ autoGrow = false, label, defaultValue, ...rest }) {
4990
5048
  }
4991
5049
  return /* @__PURE__ */ jsxs("div", {
4992
5050
  className: autoGrow ? "ui-text-area auto-grow" : "ui-text-area",
4993
- children: [/* @__PURE__ */ jsx("textarea", {
4994
- className: text.length > 0 ? "filled" : void 0,
4995
- placeholder: " ",
4996
- ref: areaRef,
4997
- ...rest,
4998
- onChange: handleChange
4999
- }), label && /* @__PURE__ */ jsx("label", { children: label })]
5051
+ children: [
5052
+ /* @__PURE__ */ jsx("textarea", {
5053
+ "aria-invalid": error ? true : void 0,
5054
+ className: text.length > 0 ? "filled" : void 0,
5055
+ placeholder: " ",
5056
+ ref: areaRef,
5057
+ ...rest,
5058
+ onChange: handleChange
5059
+ }),
5060
+ label && /* @__PURE__ */ jsx("label", { children: label }),
5061
+ error ? /* @__PURE__ */ jsx(FieldError, { children: error }) : null
5062
+ ]
5000
5063
  });
5001
5064
  }
5002
5065
  // src/contexts/ThemeContext.ts
@@ -6038,4 +6101,4 @@ const readInlineJson = (id) => {
6038
6101
  return;
6039
6102
  }
6040
6103
  };
6041
- export { Actions, AgencyMark, Autocomplete, Button, Calendar, CalendarV2, CardInput, Check, DateInput, DateInputV2, DetailDrawer, Dialog, Dropdown, EmptyState, ErrorBoundary, FileInput, Grip, Icon, IconButton, MaintenanceGate, Modal, NavButton, NumberInput, Option, Overlay, Paginator, PhoneInput, PriceInput, RadioButton, RangeSlider, SIGN_IN_CODE_LENGTH, Select, Separator, SideNav, SignInCard, Spinner, StatusContext, StatusManager, Switch, Tabs, Tag, TextArea, TextInput, ThemeContext, ThemeProvider, ThemeSwitch, TimeInput, Toast, Toggle, Tag$1 as Tooltip, Tour, applyCssVars, arrangementFrom, cards, defaultArrangement, haptic, initRum, installImageFallbacks, isDefaultArrangement, isPlaceholderPixel, liftRow, loadArrangement, readInlineJson, recordError, recoverStaleAssets, saveArrangement, savedTheme, setFavicon, setFontStylesheet, setMetaContent, showsImageFallback, snapshot, tagSession, typedDate, useDragOrder, useFlip, useLoadedImage, withShownOrder };
6104
+ export { Actions, AgencyMark, Autocomplete, Button, Calendar, CalendarV2, CardInput, Check, DateInput, DateInputV2, DetailDrawer, Dialog, Dropdown, EmptyState, ErrorBoundary, FieldError, FileInput, Grip, Icon, IconButton, MaintenanceGate, Modal, NavButton, NumberInput, Option, Overlay, Paginator, PhoneInput, PriceInput, RadioButton, RangeSlider, SIGN_IN_CODE_LENGTH, Select, Separator, SideNav, SignInCard, Spinner, StatusContext, StatusManager, Switch, Tabs, Tag, TextArea, TextInput, ThemeContext, ThemeProvider, ThemeSwitch, TimeInput, Toast, Toggle, Tag$1 as Tooltip, TooltipBubble, Tour, applyCssVars, arrangementFrom, cards, defaultArrangement, haptic, initRum, installImageFallbacks, isDefaultArrangement, isPlaceholderPixel, liftRow, loadArrangement, readInlineJson, recordError, recoverStaleAssets, saveArrangement, savedTheme, setFavicon, setFontStylesheet, setMetaContent, showsImageFallback, snapshot, tagSession, typedDate, useDragOrder, useFlip, useLoadedImage, withShownOrder };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nicertravel/ui",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Nicer's design system: React primitives, tokens and styles.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -1748,15 +1748,22 @@ img.ui-image-reveal
1748
1748
  left: 12px
1749
1749
  pointer-events: none
1750
1750
 
1751
- > .error
1752
- padding-top: 8px
1753
- display: flex
1754
- align-items: center
1755
- padding: 8px
1756
1751
 
1757
- .ui-icon,
1758
- p
1759
- color: var(--textNegative)
1752
+ // Field error: what is wrong with a field, the same under every field and
1753
+ // in a field's bubble. The icon sits on the first line when the words wrap.
1754
+ .ui-field-error
1755
+ display: flex
1756
+ align-items: flex-start
1757
+ gap: 4px
1758
+ padding: 8px
1759
+
1760
+ .ui-icon
1761
+ flex: none
1762
+ margin-top: 4px
1763
+
1764
+ .ui-icon,
1765
+ p
1766
+ color: var(--textNegative)
1760
1767
 
1761
1768
  // Phone input
1762
1769
  .ui-phone-input
@@ -1839,6 +1846,21 @@ img.ui-image-reveal
1839
1846
  left: 50%
1840
1847
  transform: translate(-50%, -50%)
1841
1848
 
1849
+ // The format while the field has the cursor, in its placeholder's tone:
1850
+ // what is typed covers it from the left (12-DD-YYYY). The component
1851
+ // places it over the text, in the field's own type.
1852
+ > .format
1853
+ display: flex
1854
+ align-items: center
1855
+ color: var(--highlight)
1856
+ opacity: .5
1857
+ white-space: pre
1858
+ position: absolute
1859
+ pointer-events: none
1860
+
1861
+ > span
1862
+ color: transparent
1863
+
1842
1864
  // Time input
1843
1865
  .ui-time-input
1844
1866
  @extend .ui-text-input
@@ -2888,6 +2910,22 @@ img.ui-image-reveal
2888
2910
  overflow-wrap: break-word
2889
2911
  white-space: normal
2890
2912
  pointer-events: none
2913
+ // In from the anchor's side.
2914
+ --enter-y: -4px
2915
+ animation: ui-tooltip-in 200ms var(--easeOutExpo)
2916
+
2917
+ @media (prefers-reduced-motion: reduce)
2918
+ animation: none
2919
+
2920
+ &[data-side="above"]
2921
+ --enter-y: 4px
2922
+
2923
+ // A field's error: the field error's own line, a little roomier.
2924
+ &.error
2925
+ padding: 4px 8px
2926
+
2927
+ .ui-field-error
2928
+ padding: 0
2891
2929
 
2892
2930
  // Its arrow, pointing at what it is about: a square turned on its corner,
2893
2931
  // in the bubble's own fill and border, across the gap to the anchor.
@@ -2910,6 +2948,11 @@ img.ui-image-reveal
2910
2948
  bottom: -5px
2911
2949
  border-width: 0 1px 1px 0
2912
2950
 
2951
+ @keyframes ui-tooltip-in
2952
+ from
2953
+ opacity: 0
2954
+ translate: 0 var(--enter-y)
2955
+
2913
2956
  // Dark
2914
2957
  .dark
2915
2958
  .ui-tooltip-bubble