@mbao01/common 0.5.2 → 0.5.3

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.
@@ -1,2 +1,2 @@
1
1
  import { ComboboxProps, Item } from './types';
2
- export declare const Combobox: <T extends Item>({ label, items, classes, emptyText, placeholder, getItemValue, getItemLabel, }: ComboboxProps<T>) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const Combobox: <T extends Item>({ label, items, classes, emptyText, placeholder, getItemValue, getItemLabel, onSelectItem, }: ComboboxProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -6,6 +6,7 @@ export type ComboboxProps<T extends Item> = {
6
6
  emptyText?: string;
7
7
  getItemValue?: (item: T) => string;
8
8
  getItemLabel?: (item: T) => string;
9
+ onSelectItem?: (item: T) => void;
9
10
  classes?: Partial<{
10
11
  root: string;
11
12
  trigger: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mbao01/common",
3
3
  "private": false,
4
- "version": "0.5.2",
4
+ "version": "0.5.3",
5
5
  "type": "module",
6
6
  "author": "Ayomide Bakare",
7
7
  "license": "MIT",
@@ -168,5 +168,5 @@
168
168
  "recharts": "2",
169
169
  "typescript": "5"
170
170
  },
171
- "gitHead": "30eba9ab76ef0ae78f5acbfb4b309204ca39971d"
171
+ "gitHead": "4e3cbd9b5e2ce16d8c80137c28cb977f833c968e"
172
172
  }
@@ -16,11 +16,10 @@ export const Combobox = <T extends Item>({
16
16
  placeholder,
17
17
  getItemValue = (item: T) => item.value as string,
18
18
  getItemLabel = (item: T) => item.label as string,
19
+ onSelectItem,
19
20
  }: ComboboxProps<T>) => {
20
21
  const [open, setOpen] = React.useState(false);
21
22
  const [value, setValue] = React.useState<string | number | null>(null);
22
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
23
- const [_, setItem] = React.useState<T | null>(null);
24
23
 
25
24
  const currentItem = items?.find((item) => getItemValue(item) === value);
26
25
 
@@ -49,8 +48,8 @@ export const Combobox = <T extends Item>({
49
48
  value={getItemValue(item)}
50
49
  onSelect={(currentValue) => {
51
50
  setValue(currentValue === value ? null : currentValue);
52
- setItem(item);
53
51
  setOpen(false);
52
+ onSelectItem?.(item);
54
53
  }}
55
54
  className={cn(
56
55
  {
@@ -8,6 +8,7 @@ export type ComboboxProps<T extends Item> = {
8
8
  emptyText?: string;
9
9
  getItemValue?: (item: T) => string;
10
10
  getItemLabel?: (item: T) => string;
11
+ onSelectItem?: (item: T) => void;
11
12
  classes?: Partial<{
12
13
  root: string;
13
14
  trigger: string;