@nicertravel/ui 1.2.0 → 1.4.1-beta.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/README.md CHANGED
@@ -57,7 +57,11 @@ Git hooks live in [`.vite-hooks`](.vite-hooks): before a commit, `vp staged` run
57
57
 
58
58
  ## Release
59
59
 
60
- Releases are automatic. Every push to `main` runs the [Release workflow](.github/workflows/release.yml): `vp check`, the build, then [semantic-release](https://semantic-release.gitbook.io), which picks the next version from the [Conventional Commits](https://www.conventionalcommits.org) since the last release, publishes to npm and writes the GitHub release.
60
+ The release workflow checks and packs every push to `dev` and `main`. On `dev`, releasable Conventional Commits publish a prerelease to npm’s `beta` tag and create a GitHub prerelease. On `main`, those commits publish the stable version to `latest`. The frontend’s DEV dependency workflow adopts exact betas after building all four applications.
61
+
62
+ ```sh
63
+ npm install @nicertravel/ui@beta
64
+ ```
61
65
 
62
66
  | Commit | Release |
63
67
  | ------------------------------------------------------------------ | ------- |
package/dist/index.d.ts CHANGED
@@ -77,17 +77,26 @@ 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;
83
85
  label?: string;
86
+ /**
87
+ * An X empties the field as deleting what was typed would: it answers
88
+ * `onInputChange("")`. For a host that follows the typing there.
89
+ */
90
+ clearable?: boolean;
91
+ /** Empties the field, as a text input's X; with `clearable`, after it. */
92
+ onClear?: () => void;
84
93
  onInputChange?: (value: string) => void;
85
94
  onSelectOption?: (value?: T) => void;
86
95
  options: DropdownOption<T>[];
87
96
  required?: boolean;
88
97
  selectedOptions?: T[];
89
98
  }
90
- declare function Autocomplete<T>({ label, options, onInputChange, onSelectOption, selectedOptions, inputValue, required, isLoading, onBlur, onFocus, defaultOptions, icon, ...rest }: AutocompleteProps<T>): import("react").JSX.Element;
99
+ declare function Autocomplete<T>({ label, options, onInputChange, onSelectOption, selectedOptions, inputValue, required, isLoading, onBlur, onFocus, defaultOptions, icon, clearable, onClear, ...rest }: AutocompleteProps<T>): import("react").JSX.Element;
91
100
  export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
92
101
  buttonType: "primary" | "secondary" | "tertiary" | "destructive";
93
102
  dropdown?: boolean;
@@ -170,12 +179,14 @@ interface DateInputProps {
170
179
  }
171
180
  declare function DateInput({ id, defaultDate, disabled, label, name, onChange, required, key, minDate, maxDate }: DateInputProps): import("react").JSX.Element;
172
181
  export interface DateInputV2Props extends InputHTMLAttributes<HTMLInputElement> {
182
+ /** What is wrong with the date, under the field as a text input's. */
183
+ error?: string;
173
184
  label?: string;
174
185
  /**
175
186
  * The latest and earliest days a typed date may be (YYYY-MM-DD), as the
176
187
  * 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.
188
+ * a bubble under the field says which days are while it has the cursor.
189
+ * A host that words its own range error leaves them out.
179
190
  */
180
191
  maxDate?: string;
181
192
  minDate?: string;
@@ -191,7 +202,7 @@ export interface DateInputV2Props extends InputHTMLAttributes<HTMLInputElement>
191
202
  }
192
203
  /** "12-24-2026" → "2026-12-24", or null while it isn't a whole, real day. */
193
204
  export declare const typedDate: (text: string) => string | null;
194
- export declare const DateInputV2: ({ label, maxDate, minDate, onType, setCalendarVisible, ...rest }: DateInputV2Props) => import("react").JSX.Element;
205
+ export declare const DateInputV2: ({ error, label, maxDate, minDate, onType, placeholder, setCalendarVisible, ...rest }: DateInputV2Props) => import("react").JSX.Element;
195
206
  interface DialogProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "title"> {
196
207
  actions: DialogAction[];
197
208
  children?: React.ReactNode;
@@ -253,6 +264,19 @@ interface Props$2 {
253
264
  * telemetry picks those up from `onerror` / `unhandledrejection`.
254
265
  */
255
266
  declare function ErrorBoundary({ children, message }: Props$2): import("react").JSX.Element;
267
+ interface FieldErrorProps {
268
+ children: ReactNode;
269
+ /** Where a host places it: over a save bar, under a field of its own. */
270
+ className?: string;
271
+ id?: string;
272
+ }
273
+ /**
274
+ * What is wrong with a field, the same everywhere: the alert icon and one
275
+ * short line, in the negative tone. Every field's `error` renders it, and a
276
+ * host that checks a field of its own puts it under that field. The `error`
277
+ * class stays for the hosts that already style a field's error by it.
278
+ */
279
+ export declare function FieldError({ children, className, id }: FieldErrorProps): import("react").JSX.Element;
256
280
  interface FileInputProps extends InputHTMLAttributes<HTMLInputElement> {
257
281
  /** The picker button's words. */
258
282
  browseLabel?: string;
@@ -629,6 +653,8 @@ interface PriceProps {
629
653
  defaultCurrency?: string;
630
654
  defaultValue?: string;
631
655
  disabled?: boolean;
656
+ /** What is wrong with the amount, under the field as a text input's. */
657
+ error?: string;
632
658
  id?: string;
633
659
  max?: number;
634
660
  min?: number;
@@ -641,7 +667,7 @@ interface PriceProps {
641
667
  }[];
642
668
  required?: boolean;
643
669
  }
644
- declare function PriceInput({ "aria-label": ariaLabel, id, options, currencySelector, defaultCurrency, defaultValue, disabled, name, onChange, onCurrencyChange, required, min, max }: PriceProps): import("react").JSX.Element;
670
+ 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
671
  interface RadioButtonProps extends InputHTMLAttributes<HTMLInputElement> {}
646
672
  declare function RadioButton({ ...rest }: RadioButtonProps): import("react").JSX.Element;
647
673
  export interface SelectOption {
@@ -657,6 +683,8 @@ export interface SelectOption {
657
683
  }
658
684
  export interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
659
685
  defaultValue?: string;
686
+ /** What is wrong with the choice, under the select as a text input's. */
687
+ error?: string;
660
688
  options?: SelectOption[];
661
689
  placeholder?: string;
662
690
  readOnly?: boolean;
@@ -679,7 +707,7 @@ export interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
679
707
  * own picker. A choice that searches the server or takes free text is an
680
708
  * Autocomplete instead. Several at once stay the native select.
681
709
  */
682
- declare function Select({ searchable, ...props }: SelectProps): import("react").JSX.Element;
710
+ declare function Select({ error, searchable, ...props }: SelectProps): import("react").JSX.Element;
683
711
  interface RangeSliderProps {
684
712
  /** Names each thumb for screen readers: "Minimum price", "Maximum price". */
685
713
  labels?: [string, string];
@@ -742,16 +770,23 @@ interface TextAreaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
742
770
  * a long note reads whole instead of hiding under the box's edge.
743
771
  */
744
772
  autoGrow?: boolean;
773
+ /** What is wrong with the text, under the box as a text input's. */
774
+ error?: string;
745
775
  label?: string;
746
776
  }
747
- declare function TextArea({ autoGrow, label, defaultValue, ...rest }: TextAreaProps): import("react").JSX.Element;
777
+ declare function TextArea({ autoGrow, error, label, defaultValue, ...rest }: TextAreaProps): import("react").JSX.Element;
748
778
  interface TextInputProps extends InputHTMLAttributes<HTMLInputElement> {
749
779
  error?: string;
750
780
  icon?: string;
751
781
  isLoading?: boolean;
752
782
  label?: string;
783
+ /**
784
+ * Empties the field: with it, an X shows at the field's right while it
785
+ * holds text, and puts the cursor back in it. The host clears its value.
786
+ */
787
+ onClear?: () => void;
753
788
  }
754
- declare function TextInput({ icon, id, isLoading, label, error, ...rest }: TextInputProps): import("react").JSX.Element;
789
+ declare function TextInput({ icon, id, isLoading, label, error, onClear, ...rest }: TextInputProps): import("react").JSX.Element;
755
790
  export type ThemeName = "dark" | "light";
756
791
  /**
757
792
  * Shows `theme` and saves it as the visitor's choice. With `persist: false`
@@ -898,14 +933,30 @@ interface TooltipProps {
898
933
  /** Usually a line of text; a list when there is more than one thing to say. */
899
934
  label: React.ReactNode;
900
935
  }
936
+ interface TooltipBubbleProps {
937
+ /** What the bubble is about: it opens next to it, its arrow at its middle. */
938
+ anchor: RefObject<HTMLElement | null>;
939
+ className?: string;
940
+ id?: string;
941
+ label: React.ReactNode;
942
+ /** "alert" for a bubble that says something went wrong, read out at once. */
943
+ role?: "alert" | "tooltip";
944
+ }
945
+ /**
946
+ * The bubble alone, open while it is rendered: a Tooltip's, or one a field
947
+ * opens on its own (a typed date out of range). It renders on
948
+ * `document.body` at fixed viewport coordinates, so a scrolling rail or a
949
+ * card with `overflow: hidden` can't clip it. It opens below the anchor,
950
+ * left edges aligned; it moves above when there is no room below and
951
+ * slides left to stay on screen. Its arrow points at the anchor's middle,
952
+ * wherever the bubble slid to. Content that needs its own styles must
953
+ * carry them (a styled element as `label`), since the bubble doesn't sit
954
+ * inside the host's markup.
955
+ */
956
+ export declare function TooltipBubble({ anchor, className, id, label, role }: TooltipBubbleProps): import("react").ReactPortal;
901
957
  /**
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.
958
+ * A hover label: its bubble opens while the pointer or the focus is on what
959
+ * it wraps.
909
960
  */
910
961
  declare function Tag$1({ label, children, className, disabled, ...rest }: TooltipProps): import("react").JSX.Element;
911
962
  export interface StatusProps {
package/dist/index.js CHANGED
@@ -422,14 +422,49 @@ 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
- function TextInput({ icon, id, isLoading, label, error, ...rest }) {
451
+ function TextInput({ icon, id, isLoading, label, error, onClear, ...rest }) {
452
+ const wrapperRef = useRef(null);
453
+ const clearable = onClear !== void 0 && !isLoading && String(rest.value ?? "") !== "";
427
454
  const generatedId = useId();
428
455
  const inputId = id ?? generatedId;
456
+ const errorId = `${inputId}-error`;
429
457
  return /* @__PURE__ */ jsxs("div", {
430
- className: `ui-text-input ${icon ? "icon" : ""}`,
458
+ className: [
459
+ "ui-text-input",
460
+ icon ? "icon" : "",
461
+ clearable ? "clearable" : ""
462
+ ].filter(Boolean).join(" "),
463
+ ref: wrapperRef,
431
464
  children: [
432
465
  /* @__PURE__ */ jsx("input", {
466
+ "aria-describedby": error ? errorId : void 0,
467
+ "aria-invalid": error ? true : void 0,
433
468
  id: inputId,
434
469
  placeholder: " ",
435
470
  type: "text",
@@ -447,21 +482,37 @@ function TextInput({ icon, id, isLoading, label, error, ...rest }) {
447
482
  color: "light",
448
483
  size: 16
449
484
  }),
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
- })
485
+ clearable ? /* @__PURE__ */ jsx("button", {
486
+ "aria-label": "Clear",
487
+ className: "clear",
488
+ onClick: () => {
489
+ const input = wrapperRef.current?.querySelector("input");
490
+ onClear();
491
+ if (input) {
492
+ input.value = "";
493
+ input.focus();
494
+ }
495
+ },
496
+ onMouseDown: (event) => event.preventDefault(),
497
+ type: "button",
498
+ children: /* @__PURE__ */ jsx(Icon, {
499
+ misc: true,
500
+ name: "misc-cancel"
501
+ })
502
+ }) : null,
503
+ error ? /* @__PURE__ */ jsx(FieldError, {
504
+ id: errorId,
505
+ children: error
506
+ }) : null
460
507
  ]
461
508
  });
462
509
  }
463
510
  // src/components/Autocomplete.tsx
464
- function Autocomplete({ label, options, onInputChange, onSelectOption, selectedOptions, inputValue, required, isLoading, onBlur, onFocus, defaultOptions, icon, ...rest }) {
511
+ function Autocomplete({ label, options, onInputChange, onSelectOption, selectedOptions, inputValue, required, isLoading, onBlur, onFocus, defaultOptions, icon, clearable, onClear, ...rest }) {
512
+ const clear = clearable || onClear ? () => {
513
+ if (clearable) onInputChange?.("");
514
+ onClear?.();
515
+ } : void 0;
465
516
  const [dropdownShown, setDropdownShown] = useState(false);
466
517
  const [defaultOptionsDropdownShown, setDefaultOptionsDropdownShown] = useState(false);
467
518
  const wrapperRef = useRef(null);
@@ -489,6 +540,7 @@ function Autocomplete({ label, options, onInputChange, onSelectOption, selectedO
489
540
  value: inputValue,
490
541
  ...rest,
491
542
  icon,
543
+ onClear: isLoading ? void 0 : clear,
492
544
  onBlur,
493
545
  onFocus: (e) => {
494
546
  if (!inputValue) setDefaultOptionsDropdownShown(true);
@@ -1124,7 +1176,109 @@ function DateInput({ id, defaultDate, disabled, label, name, onChange, required,
1124
1176
  const formatDate = (date) => {
1125
1177
  return dayjs(date).format("MM-DD-YYYY");
1126
1178
  };
1179
+ // src/components/Tooltip.tsx
1180
+ const MAX_WIDTH = 300;
1181
+ /** Gap between the anchor and the bubble. */
1182
+ const OFFSET = 8;
1183
+ /** Room kept between the bubble and the viewport edges. */
1184
+ const EDGE = 16;
1185
+ /** The least room between the arrow and the bubble's corners. */
1186
+ const ARROW_INSET = 12;
1187
+ /**
1188
+ * The bubble alone, open while it is rendered: a Tooltip's, or one a field
1189
+ * opens on its own (a typed date out of range). It renders on
1190
+ * `document.body` at fixed viewport coordinates, so a scrolling rail or a
1191
+ * card with `overflow: hidden` can't clip it. It opens below the anchor,
1192
+ * left edges aligned; it moves above when there is no room below and
1193
+ * slides left to stay on screen. Its arrow points at the anchor's middle,
1194
+ * wherever the bubble slid to. Content that needs its own styles must
1195
+ * carry them (a styled element as `label`), since the bubble doesn't sit
1196
+ * inside the host's markup.
1197
+ */
1198
+ function TooltipBubble({ anchor, className, id, label, role = "tooltip" }) {
1199
+ const [position, setPosition] = useState();
1200
+ const bubbleRef = useRef(null);
1201
+ useLayoutEffect(() => {
1202
+ const calculatePosition = () => {
1203
+ if (!(bubbleRef.current && anchor.current)) return;
1204
+ const box = anchor.current.getBoundingClientRect();
1205
+ const { height, width } = bubbleRef.current.getBoundingClientRect();
1206
+ const viewportWidth = window.innerWidth;
1207
+ const viewportHeight = window.innerHeight;
1208
+ let left = box.left;
1209
+ if (left + width > viewportWidth - EDGE) left = box.right - width;
1210
+ left = Math.max(EDGE, Math.min(left, viewportWidth - EDGE - width));
1211
+ let top = box.bottom + OFFSET;
1212
+ let side = "below";
1213
+ const above = box.top - OFFSET - height;
1214
+ if (top + height > viewportHeight - EDGE && above >= EDGE) {
1215
+ top = above;
1216
+ side = "above";
1217
+ }
1218
+ const arrow = Math.min(Math.max(box.left + box.width / 2 - left, ARROW_INSET), width - ARROW_INSET);
1219
+ setPosition({
1220
+ arrow,
1221
+ left,
1222
+ side,
1223
+ top
1224
+ });
1225
+ };
1226
+ calculatePosition();
1227
+ window.addEventListener("resize", calculatePosition);
1228
+ window.addEventListener("scroll", calculatePosition, true);
1229
+ return () => {
1230
+ window.removeEventListener("resize", calculatePosition);
1231
+ window.removeEventListener("scroll", calculatePosition, true);
1232
+ };
1233
+ }, [anchor, label]);
1234
+ return createPortal(/* @__PURE__ */ jsx("div", {
1235
+ className: [
1236
+ "ui-tooltip-bubble",
1237
+ "t-xxs",
1238
+ className
1239
+ ].filter(Boolean).join(" "),
1240
+ "data-side": position?.side,
1241
+ id,
1242
+ ref: bubbleRef,
1243
+ role,
1244
+ style: {
1245
+ "--arrow-x": `${position?.arrow ?? ARROW_INSET}px`,
1246
+ left: position?.left ?? 0,
1247
+ maxWidth: `min(${MAX_WIDTH}px, calc(100vw - 32px))`,
1248
+ top: position?.top ?? 0,
1249
+ visibility: position ? "visible" : "hidden"
1250
+ },
1251
+ children: label
1252
+ }), document.body);
1253
+ }
1254
+ /**
1255
+ * A hover label: its bubble opens while the pointer or the focus is on what
1256
+ * it wraps.
1257
+ */
1258
+ function Tag$1({ label, children, className, disabled = false, ...rest }) {
1259
+ const [visible, setVisible] = useState(false);
1260
+ const containerRef = useRef(null);
1261
+ return /* @__PURE__ */ jsxs("div", {
1262
+ className: [
1263
+ "ui-tooltip",
1264
+ disabled ? "disabled" : "",
1265
+ className
1266
+ ].filter(Boolean).join(" "),
1267
+ ref: containerRef,
1268
+ ...rest,
1269
+ onBlur: () => setVisible(false),
1270
+ onFocus: () => setVisible(true),
1271
+ onMouseEnter: () => setVisible(true),
1272
+ onMouseLeave: () => setVisible(false),
1273
+ children: [visible && !disabled ? /* @__PURE__ */ jsx(TooltipBubble, {
1274
+ anchor: containerRef,
1275
+ label
1276
+ }) : null, children]
1277
+ });
1278
+ }
1127
1279
  // src/components/DateInputV2.tsx
1280
+ /** The format a typed date takes, shown in the field while it has the cursor. */
1281
+ const FORMAT = "MM-DD-YYYY";
1128
1282
  const readable = (date) => dayjs(date).format("MMM D, YYYY");
1129
1283
  /** "Enter a date from Jan 1, 1926 to Dec 23, 2014.", or one bound alone. */
1130
1284
  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 +1299,46 @@ const typedDate = (text) => {
1145
1299
  const iso = `${match[3]}-${match[1]}-${match[2]}`;
1146
1300
  return dayjs(iso).format("YYYY-MM-DD") === iso ? iso : null;
1147
1301
  };
1148
- const DateInputV2 = ({ label, maxDate, minDate, onType, setCalendarVisible, ...rest }) => {
1302
+ /** Where the format sits: over the field's text, in the field's own type. */
1303
+ const formatBox = (input) => {
1304
+ const style = window.getComputedStyle(input);
1305
+ return {
1306
+ fontFamily: style.fontFamily,
1307
+ fontSize: style.fontSize,
1308
+ fontWeight: style.fontWeight,
1309
+ height: input.offsetHeight,
1310
+ left: input.offsetLeft,
1311
+ letterSpacing: style.letterSpacing,
1312
+ paddingLeft: style.paddingLeft,
1313
+ top: input.offsetTop
1314
+ };
1315
+ };
1316
+ const DateInputV2 = ({ error, label, maxDate, minDate, onType, placeholder = "Select date", setCalendarVisible, ...rest }) => {
1149
1317
  const generatedId = useId();
1150
1318
  const inputId = rest.id ?? generatedId;
1319
+ const errorId = `${inputId}-error`;
1320
+ const inputRef = useRef(null);
1151
1321
  const [typed, setTyped] = useState(null);
1152
1322
  const [outOfRange, setOutOfRange] = useState(false);
1323
+ const [box, setBox] = useState(null);
1153
1324
  const stored = isEmpty(rest.value) ? "" : formatDate(rest.value);
1325
+ const text = typed ?? stored;
1326
+ const remaining = box ? FORMAT.slice(text.length) : "";
1154
1327
  return /* @__PURE__ */ jsxs("div", {
1155
1328
  className: "ui-date-input",
1156
1329
  children: [
1157
1330
  onType ? /* @__PURE__ */ jsx("input", {
1331
+ "aria-describedby": outOfRange || error ? errorId : rest["aria-describedby"],
1332
+ "aria-invalid": outOfRange || Boolean(error) || void 0,
1158
1333
  autoComplete: "off",
1159
1334
  disabled: rest.disabled,
1160
1335
  id: inputId,
1161
1336
  inputMode: "numeric",
1162
- "aria-invalid": outOfRange || void 0,
1163
- onBlur: () => {
1337
+ onBlur: (event) => {
1164
1338
  setTyped(null);
1165
1339
  setOutOfRange(false);
1340
+ setBox(null);
1341
+ rest.onBlur?.(event);
1166
1342
  },
1167
1343
  onChange: (event) => {
1168
1344
  const next = masked(event.target.value);
@@ -1180,11 +1356,18 @@ const DateInputV2 = ({ label, maxDate, minDate, onType, setCalendarVisible, ...r
1180
1356
  }
1181
1357
  onType(day);
1182
1358
  },
1183
- placeholder: "MM-DD-YYYY",
1359
+ onFocus: (event) => {
1360
+ setBox(formatBox(event.currentTarget));
1361
+ rest.onFocus?.(event);
1362
+ },
1363
+ placeholder: box ? "" : placeholder,
1364
+ ref: inputRef,
1184
1365
  required: rest.required,
1185
1366
  type: "text",
1186
- value: typed ?? stored
1367
+ value: text
1187
1368
  }) : /* @__PURE__ */ jsx("input", {
1369
+ "aria-describedby": error ? errorId : rest["aria-describedby"],
1370
+ "aria-invalid": error ? true : void 0,
1188
1371
  id: inputId,
1189
1372
  disabled: rest.disabled,
1190
1373
  readOnly: true,
@@ -1197,11 +1380,17 @@ const DateInputV2 = ({ label, maxDate, minDate, onType, setCalendarVisible, ...r
1197
1380
  setCalendarVisible(true);
1198
1381
  }
1199
1382
  },
1200
- placeholder: "Select date",
1383
+ placeholder,
1201
1384
  required: rest.required,
1202
1385
  type: "text",
1203
1386
  value: stored
1204
1387
  }),
1388
+ box && remaining ? /* @__PURE__ */ jsxs("span", {
1389
+ "aria-hidden": true,
1390
+ className: "format",
1391
+ style: box,
1392
+ children: [/* @__PURE__ */ jsx("span", { children: text }), remaining]
1393
+ }) : null,
1205
1394
  label && /* @__PURE__ */ jsx("label", {
1206
1395
  htmlFor: inputId,
1207
1396
  children: label
@@ -1216,16 +1405,16 @@ const DateInputV2 = ({ label, maxDate, minDate, onType, setCalendarVisible, ...r
1216
1405
  size: 16
1217
1406
  })
1218
1407
  }),
1219
- outOfRange ? /* @__PURE__ */ jsxs("div", {
1408
+ outOfRange && box ? /* @__PURE__ */ jsx(TooltipBubble, {
1409
+ anchor: inputRef,
1220
1410
  className: "error",
1221
- role: "alert",
1222
- children: [/* @__PURE__ */ jsx(Icon, {
1223
- name: "alert",
1224
- size: 12
1225
- }), /* @__PURE__ */ jsx("p", {
1226
- className: "t-xxs",
1411
+ label: /* @__PURE__ */ jsx(FieldError, {
1412
+ id: errorId,
1227
1413
  children: rangeError(minDate, maxDate)
1228
- })]
1414
+ })
1415
+ }) : error ? /* @__PURE__ */ jsx(FieldError, {
1416
+ id: errorId,
1417
+ children: error
1229
1418
  }) : null
1230
1419
  ]
1231
1420
  });
@@ -2048,16 +2237,7 @@ function NumberInput({ id, defaultValue, disabled, error, label, minValue = 0, m
2048
2237
  },
2049
2238
  size: "s"
2050
2239
  }),
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
2240
+ error ? /* @__PURE__ */ jsx(FieldError, { children: error }) : null
2061
2241
  ]
2062
2242
  });
2063
2243
  }
@@ -3658,16 +3838,7 @@ function PhoneInput({ id, defaultDialCode, defaultValue, disabled, error, label,
3658
3838
  htmlFor: inputId,
3659
3839
  children: label
3660
3840
  }) : 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
3841
+ error ? /* @__PURE__ */ jsx(FieldError, { children: error }) : null
3671
3842
  ]
3672
3843
  });
3673
3844
  }
@@ -4269,94 +4440,6 @@ function Grip() {
4269
4440
  }, `r${y}`)])
4270
4441
  });
4271
4442
  }
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
4443
  // src/components/SideNav.tsx
4361
4444
  /**
4362
4445
  * The room a page in hand takes above and below its row while the menu is
@@ -4578,13 +4661,13 @@ const touchScreen = () => {
4578
4661
  * own picker. A choice that searches the server or takes free text is an
4579
4662
  * Autocomplete instead. Several at once stay the native select.
4580
4663
  */
4581
- function Select({ searchable, ...props }) {
4664
+ function Select({ error, searchable, ...props }) {
4582
4665
  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, {
4666
+ const field = props.multiple || !searchable && count < TOUCH_SEARCH_FROM && touchScreen() ? /* @__PURE__ */ jsx(NativeSelect, { ...props }) : /* @__PURE__ */ jsx(ListSelect, {
4585
4667
  ...props,
4586
4668
  search: Boolean(searchable) || count >= SEARCH_FROM
4587
4669
  });
4670
+ return error ? /* @__PURE__ */ jsxs(Fragment$1, { children: [field, /* @__PURE__ */ jsx(FieldError, { children: error })] }) : field;
4588
4671
  }
4589
4672
  function NativeSelect({ className, options, placeholder, variant, defaultValue = "", readOnly, style, ...rest }) {
4590
4673
  return /* @__PURE__ */ jsxs("select", {
@@ -4705,7 +4788,7 @@ function ListSelect({ "aria-describedby": describedBy, "aria-label": ariaLabel,
4705
4788
  ] });
4706
4789
  }
4707
4790
  // src/components/PriceInput.tsx
4708
- function PriceInput({ "aria-label": ariaLabel, id, options, currencySelector, defaultCurrency = "USD", defaultValue = "", disabled, name, onChange, onCurrencyChange, required, min, max }) {
4791
+ function PriceInput({ "aria-label": ariaLabel, id, options, currencySelector, defaultCurrency = "USD", defaultValue = "", disabled, error, name, onChange, onCurrencyChange, required, min, max }) {
4709
4792
  const inputRef = useRef(null);
4710
4793
  const [value, setValue] = useState(defaultValue?.toString());
4711
4794
  useEffect(() => {
@@ -4737,22 +4820,27 @@ function PriceInput({ "aria-label": ariaLabel, id, options, currencySelector, de
4737
4820
  return /* @__PURE__ */ jsxs("div", {
4738
4821
  className: "ui-price-input",
4739
4822
  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: "$" })]
4823
+ children: [
4824
+ /* @__PURE__ */ jsx("input", {
4825
+ "aria-invalid": error ? true : void 0,
4826
+ "aria-label": ariaLabel,
4827
+ disabled,
4828
+ name,
4829
+ onChange: handleChange,
4830
+ placeholder: "0.00",
4831
+ ref: inputRef,
4832
+ required,
4833
+ type: "text",
4834
+ value: value && format(value)
4835
+ }),
4836
+ currencySelector ? /* @__PURE__ */ jsx(Select, {
4837
+ "aria-label": "Currency",
4838
+ defaultValue: defaultCurrency,
4839
+ onChange: (e) => onCurrencyChange?.(e.currentTarget.value),
4840
+ options: dropdownOptions
4841
+ }) : /* @__PURE__ */ jsx("b", { children: "$" }),
4842
+ error ? /* @__PURE__ */ jsx(FieldError, { children: error }) : null
4843
+ ]
4756
4844
  });
4757
4845
  }
4758
4846
  // src/components/RadioButton.tsx
@@ -4970,7 +5058,7 @@ function Tag({ disabled: _disabled, label, type = "default", onRemove, ...rest }
4970
5058
  });
4971
5059
  }
4972
5060
  // src/components/TextArea.tsx
4973
- function TextArea({ autoGrow = false, label, defaultValue, ...rest }) {
5061
+ function TextArea({ autoGrow = false, error, label, defaultValue, ...rest }) {
4974
5062
  const [text, setText] = useState("");
4975
5063
  const areaRef = useRef(null);
4976
5064
  useEffect(() => {
@@ -4990,13 +5078,18 @@ function TextArea({ autoGrow = false, label, defaultValue, ...rest }) {
4990
5078
  }
4991
5079
  return /* @__PURE__ */ jsxs("div", {
4992
5080
  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 })]
5081
+ children: [
5082
+ /* @__PURE__ */ jsx("textarea", {
5083
+ "aria-invalid": error ? true : void 0,
5084
+ className: text.length > 0 ? "filled" : void 0,
5085
+ placeholder: " ",
5086
+ ref: areaRef,
5087
+ ...rest,
5088
+ onChange: handleChange
5089
+ }),
5090
+ label && /* @__PURE__ */ jsx("label", { children: label }),
5091
+ error ? /* @__PURE__ */ jsx(FieldError, { children: error }) : null
5092
+ ]
5000
5093
  });
5001
5094
  }
5002
5095
  // src/contexts/ThemeContext.ts
@@ -6038,4 +6131,4 @@ const readInlineJson = (id) => {
6038
6131
  return;
6039
6132
  }
6040
6133
  };
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 };
6134
+ 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.4.1-beta.1",
4
4
  "description": "Nicer's design system: React primitives, tokens and styles.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -75,7 +75,12 @@
75
75
  },
76
76
  "release": {
77
77
  "branches": [
78
- "main"
78
+ "main",
79
+ {
80
+ "name": "dev",
81
+ "channel": "beta",
82
+ "prerelease": "beta"
83
+ }
79
84
  ],
80
85
  "plugins": [
81
86
  "@semantic-release/commit-analyzer",
@@ -1748,15 +1748,49 @@ 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
1751
+ // Its X while it holds text (onClear), over the field's right end; after
1752
+ // the icon's rule, so the X's icon stays in its button.
1753
+ &.clearable input
1754
+ padding-right: 40px
1756
1755
 
1757
- .ui-icon,
1758
- p
1759
- color: var(--textNegative)
1756
+ > .clear
1757
+ width: 24px
1758
+ height: 24px
1759
+ border-radius: 50%
1760
+ display: grid
1761
+ place-items: center
1762
+ position: absolute
1763
+ top: 8px
1764
+ right: 8px
1765
+ color: var(--textSoft)
1766
+ cursor: pointer
1767
+ transition: background 150ms, color 150ms
1768
+
1769
+ .ui-icon
1770
+ opacity: 1
1771
+ position: static
1772
+
1773
+ &:hover,
1774
+ &:focus-visible
1775
+ background: var(--bgSoft)
1776
+ color: var(--highlight)
1777
+
1778
+
1779
+ // Field error: what is wrong with a field, the same under every field and
1780
+ // in a field's bubble. The icon sits on the first line when the words wrap.
1781
+ .ui-field-error
1782
+ display: flex
1783
+ align-items: flex-start
1784
+ gap: 4px
1785
+ padding: 8px
1786
+
1787
+ .ui-icon
1788
+ flex: none
1789
+ margin-top: 4px
1790
+
1791
+ .ui-icon,
1792
+ p
1793
+ color: var(--textNegative)
1760
1794
 
1761
1795
  // Phone input
1762
1796
  .ui-phone-input
@@ -1839,6 +1873,21 @@ img.ui-image-reveal
1839
1873
  left: 50%
1840
1874
  transform: translate(-50%, -50%)
1841
1875
 
1876
+ // The format while the field has the cursor, in its placeholder's tone:
1877
+ // what is typed covers it from the left (12-DD-YYYY). The component
1878
+ // places it over the text, in the field's own type.
1879
+ > .format
1880
+ display: flex
1881
+ align-items: center
1882
+ color: var(--highlight)
1883
+ opacity: .5
1884
+ white-space: pre
1885
+ position: absolute
1886
+ pointer-events: none
1887
+
1888
+ > span
1889
+ color: transparent
1890
+
1842
1891
  // Time input
1843
1892
  .ui-time-input
1844
1893
  @extend .ui-text-input
@@ -2888,6 +2937,22 @@ img.ui-image-reveal
2888
2937
  overflow-wrap: break-word
2889
2938
  white-space: normal
2890
2939
  pointer-events: none
2940
+ // In from the anchor's side.
2941
+ --enter-y: -4px
2942
+ animation: ui-tooltip-in 200ms var(--easeOutExpo)
2943
+
2944
+ @media (prefers-reduced-motion: reduce)
2945
+ animation: none
2946
+
2947
+ &[data-side="above"]
2948
+ --enter-y: 4px
2949
+
2950
+ // A field's error: the field error's own line, a little roomier.
2951
+ &.error
2952
+ padding: 4px 8px
2953
+
2954
+ .ui-field-error
2955
+ padding: 0
2891
2956
 
2892
2957
  // Its arrow, pointing at what it is about: a square turned on its corner,
2893
2958
  // in the bubble's own fill and border, across the gap to the anchor.
@@ -2910,6 +2975,11 @@ img.ui-image-reveal
2910
2975
  bottom: -5px
2911
2976
  border-width: 0 1px 1px 0
2912
2977
 
2978
+ @keyframes ui-tooltip-in
2979
+ from
2980
+ opacity: 0
2981
+ translate: 0 var(--enter-y)
2982
+
2913
2983
  // Dark
2914
2984
  .dark
2915
2985
  .ui-tooltip-bubble