@capitaltg/vero 1.9.0 → 1.10.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.
@@ -58,31 +58,109 @@ declare type AlertSize = 'sm' | 'default';
58
58
 
59
59
  declare type AlertVariant = 'success' | 'warning' | 'danger' | 'info';
60
60
 
61
- export declare const Autocomplete: default_2.ForwardRefExoticComponent<AutocompleteProps & default_2.RefAttributes<HTMLButtonElement>>;
61
+ export declare const Autocomplete: <T, K extends keyof T, L extends keyof T>(props: AutocompleteProps<T, K, L> & {
62
+ ref?: default_2.ForwardedRef<HTMLButtonElement>;
63
+ }) => default_2.ReactElement;
62
64
 
63
65
  declare type AutocompleteFormAttributes = Pick<React.SelectHTMLAttributes<HTMLSelectElement>, 'name' | 'required' | 'autoFocus'>;
64
66
 
65
- export declare interface AutocompleteOption {
66
- value: string;
67
- label: string;
68
- }
69
-
70
- export declare interface AutocompleteProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onChange' | 'disabled'>, AutocompleteFormAttributes {
71
- loadOptions?: (inputValue: string) => Promise<AutocompleteOption[]>;
72
- options?: AutocompleteOption[];
73
- value: string;
74
- onChange: (value: string) => void;
67
+ export declare interface AutocompleteProps<T, K extends keyof T, L extends keyof T> extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onChange' | 'disabled' | 'value'>, AutocompleteFormAttributes {
68
+ /**
69
+ * Async function to fetch options based on user input.
70
+ * Receives the current input value and returns a promise that resolves to an array of options.
71
+ * If provided, the component will use async loading instead of static options.
72
+ */
73
+ loadOptions?: (inputValue: string) => Promise<T[]>;
74
+ /**
75
+ * Static array of options to display.
76
+ * Used when loadOptions is not provided. The component will filter these options based on user input.
77
+ */
78
+ options?: T[];
79
+ /**
80
+ * The currently selected value. Must match the value of one of the options using the valueKey.
81
+ * Use an empty string ('') to represent no selection.
82
+ */
83
+ value: T[K] | '';
84
+ /**
85
+ * The key to use for the value property in option objects.
86
+ * Must be a key of T.
87
+ */
88
+ valueKey: K;
89
+ /**
90
+ * The key to use for the label property in option objects.
91
+ * Must be a key of T.
92
+ */
93
+ labelKey: L;
94
+ /**
95
+ * Callback function invoked when the selected value changes.
96
+ * @param value - The selected value from the option object.
97
+ * @param item - The full option object, or undefined when clearing the selection.
98
+ */
99
+ onChange: (value: T[K], item?: T) => void;
100
+ /**
101
+ * Placeholder text displayed when no option is selected.
102
+ * @default 'Select an option...'
103
+ */
75
104
  placeholder?: string;
105
+ /**
106
+ * Message displayed when no options match the search input.
107
+ * @default 'No results found'
108
+ */
76
109
  emptyMessage?: string;
110
+ /**
111
+ * Additional CSS classes to apply to the trigger button.
112
+ */
77
113
  className?: string;
114
+ /**
115
+ * Additional CSS classes to apply to the options list container.
116
+ */
78
117
  listClassName?: string;
118
+ /**
119
+ * Maximum number of suggestions to display in the dropdown.
120
+ * @default 10
121
+ */
79
122
  maxSuggestions?: number;
123
+ /**
124
+ * Debounce delay for async searches in milliseconds.
125
+ * Prevents excessive API calls by waiting for the user to stop typing.
126
+ * @default 300
127
+ */
80
128
  debounceMs?: number;
129
+ /**
130
+ * Minimum number of characters required before triggering an async search.
131
+ * @default 2
132
+ */
81
133
  minSearch?: number;
134
+ /**
135
+ * Message displayed while loading options asynchronously.
136
+ * @default 'Loading...'
137
+ */
82
138
  loadingMessage?: string;
139
+ /**
140
+ * Message displayed when an async fetch fails.
141
+ * @default 'Failed to load options'
142
+ */
83
143
  errorMessage?: string;
144
+ /**
145
+ * Z-index value for the popover dropdown.
146
+ * If not provided, uses the default z-index from the theme.
147
+ */
84
148
  zIndex?: number;
149
+ /**
150
+ * Whether the component is disabled.
151
+ * When true, the autocomplete cannot be interacted with.
152
+ * @default false
153
+ */
85
154
  isDisabled?: boolean;
155
+ /**
156
+ * Custom render function for each option in the dropdown.
157
+ * Receives the option object and whether it's currently selected.
158
+ * If not provided, defaults to rendering a Check icon and the option label.
159
+ * @param option - The option object of type T.
160
+ * @param isSelected - Whether this option is currently selected.
161
+ * @returns A React node to render for this option.
162
+ */
163
+ renderOption?: (option: T, isSelected: boolean) => React.ReactNode;
86
164
  /**
87
165
  * The name attribute for form submission.
88
166
  * This is required for the autocomplete value to be included in form data.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capitaltg/vero",
3
- "version": "1.9.0",
3
+ "version": "1.10.2",
4
4
  "description": "Accessible, modern, open source React component library inspired by USWDS built with Radix UI",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",