@magicx-eng/ai-autocomplete-react 0.53.1 → 0.53.2
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 +9 -9
- package/REFERENCE.md +10 -4
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +151 -229
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +151 -229
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ To get a key, create your product at https://ai-autocomplete.com/edit/logic (it
|
|
|
47
47
|
- **Product strip:** a row of product cards under the options, from your catalog or from your own search.
|
|
48
48
|
- **Option overrides:** supply a parameter's options yourself, as a fixed list, a computed one, or results from your own endpoint.
|
|
49
49
|
- **Catalog report:** each response says which of the query's constraints the catalog applied, which it dropped, and how many items are left.
|
|
50
|
-
- **Motion:** the picked option presses in, new details shimmer, and
|
|
50
|
+
- **Motion:** the picked option presses in, new details shimmer, and the options fade out while a request is in flight.
|
|
51
51
|
- **Input handling:** keyboard navigation, the ARIA combobox 1.2 pattern, and IME-safe typing.
|
|
52
52
|
- **Auth:** a public key, or short-lived access tokens with automatic refresh and one retry on a 401.
|
|
53
53
|
- **Styling:** light and dark themes, CSS variables and stable `data-aia-*` selector hooks. It uses your page's font unless you set `--aia-font-family`.
|
|
@@ -218,11 +218,11 @@ Skip `<AIAutocompleteDropdown />` and render the suggestions UI yourself. `dropd
|
|
|
218
218
|
|
|
219
219
|
> **Location search in a custom UI.** For a location pill, `dropdownProps.formatType` is `"location"`, `suggestions[0].options` is empty, and `dropdownProps.locationView` holds `{ query, places, status, highlighted }`. Call `onLocationQuery(text)` as the user types (the SDK debounces and cancels the searches), `onLocationMove(±1)` for the arrow keys and `onLocationCommit(index?)` to answer. Call `onLocationFocusChange(true)` *before* moving focus into your field (and `false` when it leaves), so the input's blur doesn't close the panel.
|
|
220
220
|
|
|
221
|
-
> **Option icons.** An option may carry an icon: `icon_svg` is inline SVG markup and `icon` its name. The built-in dropdown draws the SVG before the option's text, in the text color
|
|
221
|
+
> **Option icons.** An option may carry an icon: `icon_svg` is inline SVG markup and `icon` its name. The built-in dropdown draws the SVG before the option's text, in the text color. When rendering options yourself, pass `icon_svg` through the exported `sanitizeOptionIconSvg` before inserting it — it reduces the markup to plain vector drawing and returns `null` for anything else — and use `optionLabel(option)` for the text — it is the option's `text` alone; `icon` is the icon's name and is never shown as text, even when `icon_svg` is missing or fails to draw. A picked option's `icon` / `icon_svg` are copied onto its completed parameter, and the chip in the input draws the glyph before its text. Both surfaces can be switched off: `showOptionIcons: false` renders option rows as text only and `showChipIcons: false` renders chips as text only; either way the icon element is omitted rather than hidden.
|
|
222
222
|
|
|
223
|
-
> **Option pictures and counts.** An option may also carry `image_url` — a picture of the best-matching catalog item offering it — and `item_count`, how many items offer it (each is present only when the server includes it; when it includes counts, the options also arrive ordered by them, most items first; a starting state carries pictures but no counts). The built-in dropdown draws the picture as a square thumbnail before the option's text (in place of its `icon_svg`, so a row never leads with two visuals) and the count as a muted label at the row's trailing edge (`"12 items"`)
|
|
223
|
+
> **Option pictures and counts.** An option may also carry `image_url` — a picture of the best-matching catalog item offering it — and `item_count`, how many items offer it (each is present only when the server includes it; when it includes counts, the options also arrive ordered by them, most items first; a starting state carries pictures but no counts). The built-in dropdown draws the picture as a square thumbnail before the option's text (in place of its `icon_svg`, so a row never leads with two visuals) and the count as a muted label at the row's trailing edge (`"12 items"`). Icons and pictures are all-or-nothing per list: if any tappable option would draw neither, no row draws one, so a list never mixes rows with and without a leading visual (non-tappable rows don't count). A custom dropdown can apply the same rule with the exported `optionsShowLeadingVisuals(options, showIcons, showImages)`. The unit word after the number is a token: set `--aia-option-count-unit: "sneakers"` to name what is being counted, `--aia-option-count-unit-one: "sneaker"` for a count of 1 (it falls back to the plural token), or `--aia-option-count-unit: ""` for the number alone. When rendering options yourself, pass `image_url` through the exported `optionImageSrc` before using it as an `<img src>` — it returns the URL only when it is `http(s)` and `null` otherwise — and `formatOptionCount(option.item_count)` gives the number the built-in rows print (`null` when there is no count); `optionCountLabel(count, unit?)` appends a unit for a dropdown that prints the word itself (`"item"` / `"items"` by default; one word, a `{ one, other }` pair, or `""` for none). Both surfaces can be switched off: `showOptionImages: false` renders rows without pictures (an option's icon then draws instead) and `showOptionCounts: false` hides the counts. A picked option's `image_url` is copied onto its completed parameter too, and the chip in the input draws it as a small rounded tile before its text, in place of the icon; `showChipImages: false` renders chips without pictures (the icon then draws instead). The tile is sized by `--aia-option-image-size` (28px), rounded by `--aia-option-image-radius` (8.4px), spaced by `--aia-option-image-gap` (8.4px) and filled by `--aia-option-image-bg` (default: `--aia-skeleton-bg`) as a placeholder until its picture loads (or if the picture fails); a loaded picture is scaled to fit rather than cropped and sits on the dropdown's background, and one narrower than the tile is rounded on its own corners by `--aia-option-picture-radius` (4.2px); in a grid with pictures, an icon row draws its glyph at `--aia-option-tile-icon-size` (1.5em) so it holds the picture column; the count reads `--aia-option-count-font-size` (8.4px), `--aia-option-count-color` and `--aia-option-count-opacity` (0.6); the chip's tile reads `--aia-chip-image-size` (1.25em of the chip's font), `--aia-chip-image-radius` (4px) and `--aia-chip-image-bg` (default: `--aia-skeleton-bg`), the placeholder fill shown until the picture loads; a loaded picture narrower than the tile narrows it to the picture's own width, so the radius rounds the picture.
|
|
224
224
|
|
|
225
|
-
> **Parameter names under options.** An option that completes the word being typed (the server's `traditional_autocomplete` suggestion) can read the same as an option of another parameter, so the built-in dropdown draws the name of the parameter it answers under its text, muted and smaller (`Flavor`, `Subcategory`); the SDK sets it as `parameterLabel` from the option's `parameter
|
|
225
|
+
> **Parameter names under options.** An option that completes the word being typed (the server's `traditional_autocomplete` suggestion) can read the same as an option of another parameter, so the built-in dropdown draws the name of the parameter it answers under its text, muted and smaller (`Flavor`, `Subcategory`); the SDK sets it as `parameterLabel` from the option's `parameter`. It reads `--aia-option-parameter-font-size` (8.4px), `--aia-option-parameter-color` and `--aia-option-parameter-opacity` (0.6).
|
|
226
226
|
|
|
227
227
|
```tsx
|
|
228
228
|
import { useAIAutocomplete } from "@magicx-eng/ai-autocomplete-react";
|
|
@@ -290,7 +290,7 @@ function App() {
|
|
|
290
290
|
| `prependPlaceholder?` | `boolean` | `true` | Set to `false` to show the starting state's lead-in text as a hint only: a picked option is not written after it. |
|
|
291
291
|
| `showNonTappableOptions?` | `boolean` | `true` | When `true`, non-tappable options are rendered alongside tappable ones in the dropdown. Set to `false` to hide non-tappable options entirely. |
|
|
292
292
|
| `locationSearch?` | `boolean` | `true` | When `true`, a location parameter without options searches places as the user types in its field. Set to `false` to take typed text only. See [Location search](#location-search). |
|
|
293
|
-
| `showSkipButton?` | `boolean` | `true` | When `true`, the dropdown's pill bar ends in a small "skip" button that dismisses the active pill — same action as pressing <kbd>→</kbd> at the end of the input. It
|
|
293
|
+
| `showSkipButton?` | `boolean` | `true` | When `true`, the dropdown's pill bar ends in a small "skip" button that dismisses the active pill — same action as pressing <kbd>→</kbd> at the end of the input. It sits at the header's trailing edge, across from the label, once the input has text. Set to `false` to hide it. |
|
|
294
294
|
| `showOptionIcons?` | `boolean` | `true` | When `true`, an option that carries an `icon_svg` draws its icon before its text in the dropdown. Set to `false` to render option rows as text only. |
|
|
295
295
|
| `showChipIcons?` | `boolean` | `true` | When `true`, a completed chip in the input draws the icon of the option that answered it. Set to `false` to render chips as text only. |
|
|
296
296
|
| `showChipImages?` | `boolean` | `true` | When `true`, a completed chip in the input draws the picture (`image_url`) of the option that answered it, in place of its icon. Set to `false` to render chips without pictures. |
|
|
@@ -406,7 +406,7 @@ The headless hook for Tier 2 and Tier 3. Accepts the same options as `<AIAutocom
|
|
|
406
406
|
| `newParamId` | `string \| null` | ID of the most recently added param (for shimmer animation). |
|
|
407
407
|
| `suggestions` | `Suggestion[]` | All suggestions from server (including placeholder type). |
|
|
408
408
|
| `activeIndex` | `number` | Highlighted option index. `-1` = none. |
|
|
409
|
-
| `isLoading` | `boolean` | True when the dropdown should render its loading
|
|
409
|
+
| `isLoading` | `boolean` | True when the dropdown should render its loading state — a fetch is in flight, no option-selection animation is playing, and the user is not in re-edit mode (where cached options stay visible). |
|
|
410
410
|
| `isReady` | `boolean` | Server indicates query is complete. |
|
|
411
411
|
| `isDropdownOpen` | `boolean` | Whether the dropdown should be visible. Drive your own dropdown's visibility with this in Tier 3. |
|
|
412
412
|
| `placeholderText` | `string` | Suggested placeholder text for the current step. |
|
|
@@ -466,7 +466,7 @@ The dropdown component for Tier 2. Spread `dropdownProps` from the hook (and add
|
|
|
466
466
|
| `onProductSelect?` | `(product: Product) => void` | Called when a card is activated. |
|
|
467
467
|
| `onProductAddToCart?` | `(product: Product) => void \| PromiseLike<unknown>` | When set, every card that isn't sold out draws an add-to-cart button whose press calls this. See [Product strip](#product-strip). |
|
|
468
468
|
| `onProductFocusChange?` | `(focused: boolean) => void` | Called when focus enters/leaves the strip. Wired to `setFocused` by `dropdownProps` so a tabbed-to card doesn't close the panel. |
|
|
469
|
-
| `isLoading?` | `boolean` | When `true`, the dropdown
|
|
469
|
+
| `isLoading?` | `boolean` | When `true`, the dropdown fades its cached pills + options out over 160ms, keeping their space (an empty placeholder holds it when nothing is cached). |
|
|
470
470
|
|
|
471
471
|
### `AutocompleteResult`
|
|
472
472
|
|
|
@@ -569,7 +569,7 @@ For styling beyond the CSS variables, target these stable `data-aia-*` attribute
|
|
|
569
569
|
| `[data-aia-pill]` | Each unfilled-suggestion pill |
|
|
570
570
|
| `[data-aia-pillbar]` | Pill bar container inside the dropdown |
|
|
571
571
|
| `[data-aia-pill-scroll]` | Scrollable pill region inside the bar — carries the horizontal scroll and right-edge fade mask |
|
|
572
|
-
| `[data-aia-skip]` | The pill bar's "skip" button:
|
|
572
|
+
| `[data-aia-skip]` | The pill bar's "skip" button: at the header's trailing edge, or alone at the end of a skip-only row. Tune via `--aia-skip-font-size` / `--aia-skip-color` / `--aia-skip-color-hover` / `--aia-skip-hover-bg` |
|
|
573
573
|
| `[data-aia-option]` | Each suggestion option |
|
|
574
574
|
| `[data-aia-scroll-arrow]` | The "more below" arrow on the dropdown — carries `data-aia-visible` while shown |
|
|
575
575
|
| `[data-aia-dropdown]` | The dropdown root (listbox). Carries `data-aia-has-products` while the product strip has cards, and `data-aia-fit` while it is fitted to a short screen (see [Short screens](#short-screens)). |
|
|
@@ -631,7 +631,7 @@ Submits from Enter and from Tier 1's built-in button are recorded for you. If yo
|
|
|
631
631
|
|
|
632
632
|
## Option Overrides
|
|
633
633
|
|
|
634
|
-
Supply the options for a parameter yourself instead of taking the server's. Each entry is keyed by the suggestion `parameter` and is a function of the phrase the user has typed for that parameter — return an array for a fixed or computed list, or a promise for one that lives behind a request (the dropdown shows its loading
|
|
634
|
+
Supply the options for a parameter yourself instead of taking the server's. Each entry is keyed by the suggestion `parameter` and is a function of the phrase the user has typed for that parameter — return an array for a fixed or computed list, or a promise for one that lives behind a request (the dropdown shows its loading state until it settles):
|
|
635
635
|
|
|
636
636
|
```tsx
|
|
637
637
|
import type { OptionOverrides } from "@magicx-eng/ai-autocomplete-react";
|
package/REFERENCE.md
CHANGED
|
@@ -462,6 +462,10 @@ locations is the server's call: it marks them `type: { kind: "location" }`.
|
|
|
462
462
|
- **Without options**, the dropdown shows a search field instead. Typing in it
|
|
463
463
|
searches places through the MagicX server, which proxies a location provider,
|
|
464
464
|
and lists what it finds; any city, address or landmark can be picked.
|
|
465
|
+
What the user types in the main input is searched there too, cut to its
|
|
466
|
+
place-name end ("going to paris" searches "paris"; "to san fran" searches
|
|
467
|
+
"san fran"). Typing in the field itself takes over until it loses focus, and
|
|
468
|
+
an input that holds no place name never clears the field.
|
|
465
469
|
|
|
466
470
|
Nothing is required to switch it on. The field searches
|
|
467
471
|
`…/locations/autocomplete`, next to your `/suggest` endpoint
|
|
@@ -549,14 +553,15 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
|
|
|
549
553
|
| `--aia-footer-gap` | `12px` | `12px` | Breathing room above the dropdown footer (badge / keyboard hints), additive to the dropdown's 8px section gap. |
|
|
550
554
|
| `--aia-footer-chip-bg` | `--aia-surface` at 65% | `--aia-surface` at 65% | Fill behind the footer's keyboard hint and AI-Autocomplete badge. The option list scrolls under the footer, so this keeps both legible over the row passing behind them. `transparent` on the glass surface. |
|
|
551
555
|
| `--aia-dropdown-bg` | — | — | Optional bg color the dropdown's "glass" rim shadow tints toward. Set this to the page background behind the dropdown so the bottom-corner glow blends seamlessly. |
|
|
552
|
-
| `--aia-scrollbar-
|
|
556
|
+
| `--aia-scrollbar-track` | `rgba(15, 23, 42, 0.05)` | `rgba(255, 255, 255, 0.08)` | The floating options box's thin scrollbar track, shown while a long list overflows. |
|
|
557
|
+
| `--aia-scrollbar-thumb` | `rgba(15, 23, 42, 0.22)` | `rgba(255, 255, 255, 0.28)` | That scrollbar's thumb. |
|
|
553
558
|
| `--aia-streak-rgb` | `99, 102, 241` | `255, 255, 255` | Comma-separated RGB triplet tinting the datepicker's pressed cell, and its selected cell when `--aia-date-selected-bg` is unset. The today ring uses `--aia-date-today-ring`, not this. |
|
|
554
559
|
| `--aia-product-card-width` | `81.2px` | `81.2px` | Width of a product card in the strip. The media tile is square, so this also sets its height. |
|
|
555
560
|
| `--aia-product-gap` | `5.6px` | `5.6px` | Gap between product cards. |
|
|
556
561
|
| `--aia-product-bg` | `transparent` | `transparent` | Product card background. |
|
|
557
562
|
| `--aia-product-bg-active` | `--aia-option-bg` | `--aia-option-bg` | Product card background on hover. |
|
|
558
563
|
| `--aia-product-media-bg` | `--aia-skeleton-bg` | `--aia-skeleton-bg` | Placeholder fill of the product tile: shown until the photo loads, and behind both fallback tiles (placeholder pictogram or title initial) used when an image URL is missing, blank or fails to load. Once a photo loads the tile is transparent. |
|
|
559
|
-
| `--aia-scroll-arrow-color` | `--aia-option-color` | `--aia-option-color` | Chevron color of the arrow (`--aia-scroll-arrow-color-hover` on hover). |
|
|
564
|
+
| `--aia-scroll-arrow-color` | `--aia-option-color` | `--aia-option-color` | Chevron color of the arrow (`--aia-scroll-arrow-color-hover` on hover). `optionsStyle: "classic"` only: the floating box draws a thin scrollbar instead (`--aia-scrollbar-*`). |
|
|
560
565
|
| `--aia-placeholder-fade` | `120ms` | `120ms` | Fade-out of the outgoing placeholder phrase when the starting-state placeholder changes (the incoming one types itself in). |
|
|
561
566
|
| `--aia-product-image-radius` | `5.6px` | `5.6px` | Corner radius of a product photo narrower than its square tile (a tall one), which is scaled to fit rather than cropped. A photo that fills the tile takes the tile's own 5.6px corners. |
|
|
562
567
|
| `--aia-product-placeholder-image` | storefront pictogram | storefront pictogram | The pictogram used by `productImageFallback: "image"` (the default) when an image URL is missing, blank or fails to load. Defaults to a two-tone storefront inlined as a data URI. Set any `url(...)` to swap it; it is centered and contained over `--aia-product-media-bg`. Does not affect `"initial"` tiles. |
|
|
@@ -589,7 +594,8 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
|
|
|
589
594
|
| `--aia-confirm-color` | `#ffffff` | `#000000` | The checkbox's checkmark (and, in dark mode, the Done buttons' text). |
|
|
590
595
|
| `--aia-done-bg` / `--aia-done-bg-hover` / `--aia-done-color` | `#e4e8f0` / `#d8dde8` / `#2a3150` | `--aia-confirm-*` | The Done buttons (multi-select and time wheel). |
|
|
591
596
|
| `--aia-multi-done-bg` / `--aia-multi-done-bg-hover` / `--aia-multi-done-color` | `--aia-done-*` | `--aia-done-*` | Override the multi-select Done button alone. |
|
|
592
|
-
| `--aia-multi-done-width` | as wide as the widest option | same | Width of the multi-select Done button
|
|
597
|
+
| `--aia-multi-done-width` | `100%` (classic: as wide as the widest option) | same | Width of the multi-select Done button. |
|
|
598
|
+
| `--aia-panel-min-width` | `160px` | same | Narrowest the floating options box gets when it hugs its options (desktop). |
|
|
593
599
|
| `--aia-multi-done-min-width` | `120px` | `120px` | Narrowest the multi-select Done button gets. |
|
|
594
600
|
| `--aia-time-done-bg` / `--aia-time-done-bg-hover` / `--aia-time-done-color` | `--aia-done-*` | `--aia-done-*` | Override the time wheel's Done button alone. |
|
|
595
601
|
| `--aia-location-field-bg-idle` | `transparent` | `transparent` | The location search field at rest. |
|
|
@@ -597,6 +603,6 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
|
|
|
597
603
|
| `--aia-location-field-radius` | `10px` | `10px` | Corner radius of the location search field. |
|
|
598
604
|
| `--aia-location-font-size` | `15px` | `15px` | The location field's text and the place names. |
|
|
599
605
|
| `--aia-location-row-bg-highlighted` | `--aia-streak-rgb` at 8% (indigo) | `--aia-streak-rgb` at 8% (white) | The highlighted (or hovered) place. |
|
|
600
|
-
| `--aia-skeleton-bg` | `rgba(189, 189, 189, 0.083)` | `#1a1b1d` | Fill color
|
|
606
|
+
| `--aia-skeleton-bg` | `rgba(189, 189, 189, 0.083)` | `#1a1b1d` | Fill color of the option and chip image tiles while their picture loads (unless `--aia-option-image-bg` / `--aia-chip-image-bg` are set). |
|
|
601
607
|
|
|
602
608
|
Legacy `--aia-color-*` variables are still supported as fallbacks.
|
package/dist/index.d.mts
CHANGED
|
@@ -117,12 +117,12 @@ interface AIAutocompleteProps {
|
|
|
117
117
|
/**
|
|
118
118
|
* When true (default), the dropdown's pill bar ends in a small "skip" button
|
|
119
119
|
* that dismisses the active pill — same action as pressing → at the end of
|
|
120
|
-
* the input. It sits
|
|
121
|
-
*
|
|
120
|
+
* the input. It sits at the header row's trailing edge, across from the
|
|
121
|
+
* parameter label. Set to false to hide it. When pills render elsewhere
|
|
122
122
|
* (`pillPlacement: "inline"` / `"hidden"`) the bar renders as a skip-only
|
|
123
|
-
* row holding just the button, alone at the bar's trailing edge
|
|
124
|
-
*
|
|
125
|
-
*
|
|
123
|
+
* row holding just the button, alone at the bar's trailing edge; it hides
|
|
124
|
+
* during re-edit, on the loading skeleton, and while the input is empty
|
|
125
|
+
* either way.
|
|
126
126
|
*/
|
|
127
127
|
showSkipButton?: boolean;
|
|
128
128
|
/** Focus the input on mount. Default: true. */
|
package/dist/index.d.ts
CHANGED
|
@@ -117,12 +117,12 @@ interface AIAutocompleteProps {
|
|
|
117
117
|
/**
|
|
118
118
|
* When true (default), the dropdown's pill bar ends in a small "skip" button
|
|
119
119
|
* that dismisses the active pill — same action as pressing → at the end of
|
|
120
|
-
* the input. It sits
|
|
121
|
-
*
|
|
120
|
+
* the input. It sits at the header row's trailing edge, across from the
|
|
121
|
+
* parameter label. Set to false to hide it. When pills render elsewhere
|
|
122
122
|
* (`pillPlacement: "inline"` / `"hidden"`) the bar renders as a skip-only
|
|
123
|
-
* row holding just the button, alone at the bar's trailing edge
|
|
124
|
-
*
|
|
125
|
-
*
|
|
123
|
+
* row holding just the button, alone at the bar's trailing edge; it hides
|
|
124
|
+
* during re-edit, on the loading skeleton, and while the input is empty
|
|
125
|
+
* either way.
|
|
126
126
|
*/
|
|
127
127
|
showSkipButton?: boolean;
|
|
128
128
|
/** Focus the input on mount. Default: true. */
|