@appcorp/shadcn 1.1.92 → 1.1.93

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.
@@ -48,6 +48,8 @@ interface EnhancedComboboxProps {
48
48
  info?: string;
49
49
  /** Optional error text displayed below the component (error state). */
50
50
  error?: string;
51
+ /** Optional key used for lookup within the original options object (defaults to 'id'). */
52
+ lookupKey?: string;
51
53
  /** `data-testid` for the trigger button (e.g. `my-combobox-trigger`). */
52
54
  testIdTrigger?: string;
53
55
  /** `data-testid` for the search input inside the popover. */
@@ -69,7 +71,7 @@ interface EnhancedComboboxProps {
69
71
  /** `data-testid` for the scroll-down button (when scroll indicators enabled). */
70
72
  testIdScrollDown?: string;
71
73
  }
72
- export declare function EnhancedCombobox({ className, disabled, emptyText, error, id, info, label, loading, maxHeight, onSearchChange, onValueChange, options, placeholder, required, searchPlaceholder, showScrollIndicators, value, virtualizeThreshold, testIdTrigger, testIdSearchInput, testIdPopoverContent, testIdEmpty, testIdList, testIdOptionPrefix, testIdScrollUp, testIdScrollDown, }: EnhancedComboboxProps): React.JSX.Element;
74
+ export declare function EnhancedCombobox({ className, disabled, emptyText, error, id, info, label, loading, lookupKey, maxHeight, onSearchChange, onValueChange, options, placeholder, required, searchPlaceholder, showScrollIndicators, value, virtualizeThreshold, testIdTrigger, testIdSearchInput, testIdPopoverContent, testIdEmpty, testIdList, testIdOptionPrefix, testIdScrollUp, testIdScrollDown, }: EnhancedComboboxProps): React.JSX.Element;
73
75
  interface CompanyComboboxProps {
74
76
  companies: Array<{
75
77
  id?: string;
@@ -129,13 +129,16 @@ function VirtualizedList(_a) {
129
129
  bottomSpacer > 0 && react_1.default.createElement("div", { style: { height: bottomSpacer } })));
130
130
  }
131
131
  function EnhancedCombobox(_a) {
132
- var className = _a.className, _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.emptyText, emptyText = _c === void 0 ? "No options found." : _c, error = _a.error, id = _a.id, info = _a.info, label = _a.label, _d = _a.loading, loading = _d === void 0 ? false : _d, _e = _a.maxHeight, maxHeight = _e === void 0 ? 256 : _e, onSearchChange = _a.onSearchChange, onValueChange = _a.onValueChange, _f = _a.options, options = _f === void 0 ? [] : _f, _g = _a.placeholder, placeholder = _g === void 0 ? "Select option..." : _g, _h = _a.required, required = _h === void 0 ? false : _h, _j = _a.searchPlaceholder, searchPlaceholder = _j === void 0 ? "Search..." : _j, _k = _a.showScrollIndicators, showScrollIndicators = _k === void 0 ? true : _k, value = _a.value, _l = _a.virtualizeThreshold, virtualizeThreshold = _l === void 0 ? 50 : _l, testIdTrigger = _a.testIdTrigger, testIdSearchInput = _a.testIdSearchInput, testIdPopoverContent = _a.testIdPopoverContent, testIdEmpty = _a.testIdEmpty, testIdList = _a.testIdList, testIdOptionPrefix = _a.testIdOptionPrefix, testIdScrollUp = _a.testIdScrollUp, testIdScrollDown = _a.testIdScrollDown;
132
+ var className = _a.className, _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.emptyText, emptyText = _c === void 0 ? "No options found." : _c, error = _a.error, id = _a.id, info = _a.info, label = _a.label, _d = _a.loading, loading = _d === void 0 ? false : _d, lookupKey = _a.lookupKey, _e = _a.maxHeight, maxHeight = _e === void 0 ? 256 : _e, onSearchChange = _a.onSearchChange, onValueChange = _a.onValueChange, _f = _a.options, options = _f === void 0 ? [] : _f, _g = _a.placeholder, placeholder = _g === void 0 ? "Select option..." : _g, _h = _a.required, required = _h === void 0 ? false : _h, _j = _a.searchPlaceholder, searchPlaceholder = _j === void 0 ? "Search..." : _j, _k = _a.showScrollIndicators, showScrollIndicators = _k === void 0 ? true : _k, value = _a.value, _l = _a.virtualizeThreshold, virtualizeThreshold = _l === void 0 ? 50 : _l, testIdTrigger = _a.testIdTrigger, testIdSearchInput = _a.testIdSearchInput, testIdPopoverContent = _a.testIdPopoverContent, testIdEmpty = _a.testIdEmpty, testIdList = _a.testIdList, testIdOptionPrefix = _a.testIdOptionPrefix, testIdScrollUp = _a.testIdScrollUp, testIdScrollDown = _a.testIdScrollDown;
133
133
  var _m = (0, react_1.useState)(false), open = _m[0], setOpen = _m[1];
134
134
  var _o = (0, react_1.useState)(""), searchValue = _o[0], setSearchValue = _o[1];
135
135
  var _p = (0, react_1.useState)(false), canScrollUp = _p[0], setCanScrollUp = _p[1];
136
136
  var _q = (0, react_1.useState)(false), canScrollDown = _q[0], setCanScrollDown = _q[1];
137
137
  var scrollContainerRef = (0, react_1.useRef)(null);
138
- var selectedOption = options.find(function (option) { return option.value === value; });
138
+ var selectedOption = options.find(function (option) {
139
+ return option.value === value ||
140
+ option[lookupKey] === value;
141
+ });
139
142
  var shouldVirtualize = options.length > virtualizeThreshold;
140
143
  // Filter options based on search - always handle filtering at this level for virtualization
141
144
  var filteredOptions = react_1.default.useMemo(function () {
@@ -4,9 +4,11 @@ interface UseEnhancedComboboxProps<T extends {
4
4
  name: string;
5
5
  }> {
6
6
  emptyText?: string;
7
+ error?: string;
7
8
  id: string;
8
9
  info: string;
9
10
  label: string;
11
+ lookupKey?: keyof T;
10
12
  onValueChange: (value: string) => void;
11
13
  options: T[];
12
14
  placeholder: string;
@@ -18,7 +20,7 @@ interface UseEnhancedComboboxProps<T extends {
18
20
  export declare const useEnhancedCombobox: <T extends {
19
21
  id: string;
20
22
  name: string;
21
- }>({ emptyText, id, info, label, onValueChange, options, placeholder, required, searchEndpoint, searchPlaceholder, value, }: UseEnhancedComboboxProps<T>) => {
23
+ }>({ emptyText, error, id, info, label, lookupKey, onValueChange, options, placeholder, required, searchEndpoint, searchPlaceholder, value, }: UseEnhancedComboboxProps<T>) => {
22
24
  enhancedComboboxElement: React.JSX.Element;
23
25
  };
24
26
  export {};
@@ -76,10 +76,10 @@ var api_methods_1 = require("@react-pakistan/util-functions/constants/api-method
76
76
  var use_debounce_1 = require("@react-pakistan/util-functions/hooks/use-debounce");
77
77
  var enhanced_combobox_1 = require("../components/enhanced-combobox");
78
78
  var useEnhancedCombobox = function (_a) {
79
- var emptyText = _a.emptyText, id = _a.id, info = _a.info, label = _a.label, onValueChange = _a.onValueChange, options = _a.options, placeholder = _a.placeholder, required = _a.required, searchEndpoint = _a.searchEndpoint, searchPlaceholder = _a.searchPlaceholder, value = _a.value;
80
- var _b = (0, react_1.useState)(""), searchQuery = _b[0], setSearchQuery = _b[1];
81
- var _c = (0, react_1.useState)([]), searchOptions = _c[0], setSearchOptions = _c[1];
82
- var _d = (0, react_1.useState)(false), loading = _d[0], setLoading = _d[1];
79
+ var emptyText = _a.emptyText, error = _a.error, id = _a.id, info = _a.info, label = _a.label, _b = _a.lookupKey, lookupKey = _b === void 0 ? "id" : _b, onValueChange = _a.onValueChange, options = _a.options, placeholder = _a.placeholder, required = _a.required, searchEndpoint = _a.searchEndpoint, searchPlaceholder = _a.searchPlaceholder, value = _a.value;
80
+ var _c = (0, react_1.useState)(""), searchQuery = _c[0], setSearchQuery = _c[1];
81
+ var _d = (0, react_1.useState)([]), searchOptions = _d[0], setSearchOptions = _d[1];
82
+ var _e = (0, react_1.useState)(false), loading = _e[0], setLoading = _e[1];
83
83
  var debouncedSearchQuery = (0, use_debounce_1.useDebounce)(searchQuery, 800);
84
84
  (0, react_1.useEffect)(function () {
85
85
  if (!debouncedSearchQuery) {
@@ -120,19 +120,21 @@ var useEnhancedCombobox = function (_a) {
120
120
  var opts = searchOptions.length > 0 ? searchOptions : options;
121
121
  return ((opts === null || opts === void 0 ? void 0 : opts.map(function (category) { return ({
122
122
  label: category.name,
123
- value: category.id,
123
+ value: String(category[lookupKey]),
124
124
  }); })) || []);
125
- }, [searchOptions, options]);
125
+ }, [searchOptions, options, lookupKey]);
126
126
  var handleSearchChange = (0, react_1.useCallback)(function (query) {
127
127
  setSearchQuery(query);
128
128
  }, []);
129
- var enhancedComboboxElement = (0, react_1.useMemo)(function () { return (react_1.default.createElement(enhanced_combobox_1.EnhancedCombobox, { emptyText: emptyText, id: id, info: info, label: label, loading: loading, onSearchChange: handleSearchChange, onValueChange: onValueChange, options: mappedOptions, placeholder: placeholder, required: required, searchPlaceholder: searchPlaceholder, value: value })); }, [
129
+ var enhancedComboboxElement = (0, react_1.useMemo)(function () { return (react_1.default.createElement(enhanced_combobox_1.EnhancedCombobox, { emptyText: emptyText, error: error, id: id, info: info, label: label, loading: loading, lookupKey: lookupKey, onSearchChange: handleSearchChange, onValueChange: onValueChange, options: mappedOptions, placeholder: placeholder, required: required, searchPlaceholder: searchPlaceholder, value: value })); }, [
130
130
  emptyText,
131
+ error,
131
132
  handleSearchChange,
132
133
  id,
133
134
  info,
134
135
  label,
135
136
  loading,
137
+ lookupKey,
136
138
  mappedOptions,
137
139
  onValueChange,
138
140
  placeholder,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/shadcn",
3
- "version": "1.1.92",
3
+ "version": "1.1.93",
4
4
  "scripts": {
5
5
  "build:next": "next build",
6
6
  "build:storybook": "mv ../.pnp.cjs ../.pnp.cjs.bak 2>/dev/null || true && storybook build -c .storybook -o .out && mv ../.pnp.cjs.bak ../.pnp.cjs 2>/dev/null || true",