@snapdragonsnursery/react-components 1.17.8 → 1.17.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapdragonsnursery/react-components",
3
- "version": "1.17.8",
3
+ "version": "1.17.10",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -26,12 +26,18 @@
26
26
  // - showSiteName?: boolean // show site below name (default: true)
27
27
  // - showEmployeeId?: boolean // show employee ID below name (default: false)
28
28
  // - showEmail?: boolean // show email below name (default: false)
29
- // - placeholder?: string
29
+ // - placeholder?: string // select trigger placeholder (default: 'Select employee…')
30
+ // - searchPlaceholder?: string // search input placeholder (default: 'Search employees...')
30
31
  // - disabled?: boolean
31
32
  // - className?: string
32
33
  // - allowAll?: boolean // include "All employees" option
33
34
  // - allLabel?: string // custom label for all option
34
35
  // - maxHeight?: string // max height for dropdown (default: '160px')
36
+ // - enableServerSearch?: boolean // enable server-side search (default: false)
37
+ // - onSearchChange?: (query: string) => void // callback for search query changes
38
+ // - searchResults?: Array<employee> // search results from server
39
+ // - isSearching?: boolean // loading state for server search
40
+ // - requireSearch?: boolean // hide results until user types (default: false)
35
41
 
36
42
  import React from "react";
37
43
  import { Users, Search } from "lucide-react";
@@ -56,6 +62,7 @@ export const EmployeeSelect = ({
56
62
  showEmployeeId = false,
57
63
  showEmail = false,
58
64
  placeholder = "Select employee…",
65
+ searchPlaceholder = "Search employees...",
59
66
  disabled = false,
60
67
  className,
61
68
  allowAll = false,
@@ -66,6 +73,7 @@ export const EmployeeSelect = ({
66
73
  onSearchChange = null,
67
74
  searchResults = [],
68
75
  isSearching = false,
76
+ requireSearch = false,
69
77
  }) => {
70
78
  const [searchTerm, setSearchTerm] = React.useState("");
71
79
  const [isOpen, setIsOpen] = React.useState(false);
@@ -172,8 +180,14 @@ export const EmployeeSelect = ({
172
180
  return a.fullName.localeCompare(b.fullName);
173
181
  });
174
182
 
183
+ // If requireSearch is true and no search term, show only selected item (if any)
184
+ if (requireSearch && !searchTerm) {
185
+ // Return only the currently selected item, or empty array if nothing selected
186
+ return searchFiltered.filter((e) => e.entraId === value);
187
+ }
188
+
175
189
  return searchFiltered;
176
- }, [items, filter, groupBy, searchTerm, enableServerSearch, searchResults]);
190
+ }, [items, filter, groupBy, searchTerm, enableServerSearch, searchResults, requireSearch, value]);
177
191
 
178
192
  const selectedEmployee = processedItems.find((e) => e.entraId === value);
179
193
 
@@ -252,7 +266,7 @@ export const EmployeeSelect = ({
252
266
  <input
253
267
  ref={searchInputRef}
254
268
  type="text"
255
- placeholder={enableServerSearch ? "Search employees..." : "Search employees..."}
269
+ placeholder={searchPlaceholder}
256
270
  value={searchTerm}
257
271
  onChange={(e) => setSearchTerm(e.target.value)}
258
272
  className="w-full pl-8 pr-3 py-2 text-sm border rounded-md focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 bg-background"
@@ -266,7 +280,13 @@ export const EmployeeSelect = ({
266
280
  </div>
267
281
  </div>
268
282
  {allowAll && <SelectItem value="__all__">{allLabel}</SelectItem>}
269
- {groupBy === "site"
283
+ {requireSearch && !searchTerm && processedItems.length === 0 && (
284
+ <div className="px-2 py-6 text-center text-sm text-muted-foreground">
285
+ Start typing to search for employees...
286
+ </div>
287
+ )}
288
+ {(!requireSearch || searchTerm || processedItems.length > 0) && (
289
+ groupBy === "site"
270
290
  ? // Group by site
271
291
  Object.entries(
272
292
  processedItems.reduce((groups, employee) => {
@@ -322,7 +342,8 @@ export const EmployeeSelect = ({
322
342
  {renderEmployeeItem(employee, isSelected)}
323
343
  </SelectItem>
324
344
  );
325
- })}
345
+ })
346
+ )}
326
347
  </SelectContent>
327
348
  </Select>
328
349
  );