@snapdragonsnursery/react-components 1.17.1 → 1.17.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapdragonsnursery/react-components",
3
- "version": "1.17.1",
3
+ "version": "1.17.3",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -34,7 +34,7 @@
34
34
  // - maxHeight?: string // max height for dropdown (default: '160px')
35
35
 
36
36
  import React from "react";
37
- import { Users } from "lucide-react";
37
+ import { Users, Search } from "lucide-react";
38
38
  import { cn } from "../lib/utils";
39
39
 
40
40
  import {
@@ -43,7 +43,7 @@ import {
43
43
  SelectItem,
44
44
  SelectTrigger,
45
45
  SelectValue,
46
- } from "./ui/select";
46
+ } from "./ui/radix-select";
47
47
 
48
48
  export const EmployeeSelect = ({
49
49
  value,
@@ -62,6 +62,8 @@ export const EmployeeSelect = ({
62
62
  allLabel = "All employees",
63
63
  maxHeight = "160px",
64
64
  }) => {
65
+ const [searchTerm, setSearchTerm] = React.useState("");
66
+ const [isOpen, setIsOpen] = React.useState(false);
65
67
  // Helper function to generate initials from full name
66
68
  const getInitials = (name) => {
67
69
  if (!name) return "??";
@@ -108,8 +110,21 @@ export const EmployeeSelect = ({
108
110
  }))
109
111
  .filter((e) => e.entraId); // Remove items without entra_id
110
112
 
113
+ // Apply search filter
114
+ const searchFiltered = mapped.filter((e) => {
115
+ if (!searchTerm) return true;
116
+ const searchLower = searchTerm.toLowerCase();
117
+ return (
118
+ e.fullName.toLowerCase().includes(searchLower) ||
119
+ e.siteName.toLowerCase().includes(searchLower) ||
120
+ e.roleName.toLowerCase().includes(searchLower) ||
121
+ e.employeeId.toLowerCase().includes(searchLower) ||
122
+ e.email.toLowerCase().includes(searchLower)
123
+ );
124
+ });
125
+
111
126
  // Sort based on grouping
112
- mapped.sort((a, b) => {
127
+ searchFiltered.sort((a, b) => {
113
128
  if (groupBy === "site") {
114
129
  const siteCompare = a.siteName.localeCompare(b.siteName);
115
130
  if (siteCompare !== 0) return siteCompare;
@@ -123,8 +138,8 @@ export const EmployeeSelect = ({
123
138
  return a.fullName.localeCompare(b.fullName);
124
139
  });
125
140
 
126
- return mapped;
127
- }, [items, filter, groupBy]);
141
+ return searchFiltered;
142
+ }, [items, filter, groupBy, searchTerm]);
128
143
 
129
144
  const selectedEmployee = processedItems.find((e) => e.entraId === value);
130
145
 
@@ -170,8 +185,12 @@ export const EmployeeSelect = ({
170
185
  } else {
171
186
  onChange?.(val);
172
187
  }
188
+ setSearchTerm(""); // Clear search when selection is made
189
+ setIsOpen(false);
173
190
  }}
174
191
  disabled={disabled}
192
+ open={isOpen}
193
+ onOpenChange={setIsOpen}
175
194
  >
176
195
  <SelectTrigger className={cn("w-full", className)}>
177
196
  <div className="flex items-center gap-2">
@@ -192,6 +211,20 @@ export const EmployeeSelect = ({
192
211
  className="[&_[data-radix-select-viewport]]:max-h-[var(--select-max-height)] [&_[data-radix-select-viewport]]:overflow-y-auto [&>button[data-radix-select-scroll-up-button]]:hidden [&>button[data-radix-select-scroll-down-button]]:hidden"
193
212
  style={{ "--select-max-height": maxHeight }}
194
213
  >
214
+ {/* Search input */}
215
+ <div className="p-2 border-b">
216
+ <div className="relative">
217
+ <Search className="absolute left-2 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
218
+ <input
219
+ type="text"
220
+ placeholder="Search employees..."
221
+ value={searchTerm}
222
+ onChange={(e) => setSearchTerm(e.target.value)}
223
+ 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"
224
+ onClick={(e) => e.stopPropagation()}
225
+ />
226
+ </div>
227
+ </div>
195
228
  {allowAll && <SelectItem value="__all__">{allLabel}</SelectItem>}
196
229
  {groupBy === "site"
197
230
  ? // Group by site
@@ -0,0 +1,156 @@
1
+ //
2
+ // radix-select.jsx
3
+ // -----------
4
+ // shadcn/ui Select component wrappers using @radix-ui/react-select.
5
+ // Import and use in forms for consistent dropdown styling with advanced features.
6
+ //
7
+ // Example:
8
+ // <Select value={value} onValueChange={setValue}>
9
+ // <SelectTrigger className="w-full"><SelectValue placeholder="Select..." /></SelectTrigger>
10
+ // <SelectContent>
11
+ // <SelectItem value="site">Nursery site</SelectItem>
12
+ // <SelectItem value="custom">Custom address</SelectItem>
13
+ // </SelectContent>
14
+ // </Select>
15
+
16
+ import * as React from "react";
17
+ import * as SelectPrimitive from "@radix-ui/react-select";
18
+ import { Check, ChevronDown, ChevronUp } from "lucide-react";
19
+ import { cn } from "../../lib/utils";
20
+
21
+ const Select = SelectPrimitive.Root;
22
+
23
+ const SelectGroup = SelectPrimitive.Group;
24
+
25
+ const SelectValue = SelectPrimitive.Value;
26
+
27
+ const SelectTrigger = React.forwardRef(({ className, children, ...props }, ref) => (
28
+ <SelectPrimitive.Trigger
29
+ ref={ref}
30
+ className={cn(
31
+ "flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background",
32
+ "placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
33
+ "disabled:cursor-not-allowed disabled:opacity-50",
34
+ "[&>span]:line-clamp-1",
35
+ className
36
+ )}
37
+ {...props}
38
+ >
39
+ {children}
40
+ <SelectPrimitive.Icon asChild>
41
+ <ChevronDown className="h-4 w-4 opacity-50" />
42
+ </SelectPrimitive.Icon>
43
+ </SelectPrimitive.Trigger>
44
+ ));
45
+ SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
46
+
47
+ const SelectScrollUpButton = React.forwardRef(({ className, ...props }, ref) => (
48
+ <SelectPrimitive.ScrollUpButton
49
+ ref={ref}
50
+ className={cn(
51
+ "flex cursor-default items-center justify-center py-1",
52
+ className
53
+ )}
54
+ {...props}
55
+ >
56
+ <ChevronUp className="h-4 w-4" />
57
+ </SelectPrimitive.ScrollUpButton>
58
+ ));
59
+ SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
60
+
61
+ const SelectScrollDownButton = React.forwardRef(({ className, ...props }, ref) => (
62
+ <SelectPrimitive.ScrollDownButton
63
+ ref={ref}
64
+ className={cn(
65
+ "flex cursor-default items-center justify-center py-1",
66
+ className
67
+ )}
68
+ {...props}
69
+ >
70
+ <ChevronDown className="h-4 w-4" />
71
+ </SelectPrimitive.ScrollDownButton>
72
+ ));
73
+ SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;
74
+
75
+ const SelectContent = React.forwardRef(({ className, children, position = "popper", ...props }, ref) => (
76
+ <SelectPrimitive.Portal>
77
+ <SelectPrimitive.Content
78
+ ref={ref}
79
+ className={cn(
80
+ "relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md",
81
+ "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
82
+ "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
83
+ position === "popper" &&
84
+ "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
85
+ className
86
+ )}
87
+ position={position}
88
+ {...props}
89
+ >
90
+ <SelectScrollUpButton />
91
+ <SelectPrimitive.Viewport
92
+ className={cn(
93
+ "p-1",
94
+ position === "popper" &&
95
+ "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
96
+ )}
97
+ >
98
+ {children}
99
+ </SelectPrimitive.Viewport>
100
+ <SelectScrollDownButton />
101
+ </SelectPrimitive.Content>
102
+ </SelectPrimitive.Portal>
103
+ ));
104
+ SelectContent.displayName = SelectPrimitive.Content.displayName;
105
+
106
+ const SelectLabel = React.forwardRef(({ className, ...props }, ref) => (
107
+ <SelectPrimitive.Label
108
+ ref={ref}
109
+ className={cn("px-2 py-1.5 text-sm font-semibold", className)}
110
+ {...props}
111
+ />
112
+ ));
113
+ SelectLabel.displayName = SelectPrimitive.Label.displayName;
114
+
115
+ const SelectItem = React.forwardRef(({ className, children, ...props }, ref) => (
116
+ <SelectPrimitive.Item
117
+ ref={ref}
118
+ className={cn(
119
+ "relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none",
120
+ "focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
121
+ className
122
+ )}
123
+ {...props}
124
+ >
125
+ <span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
126
+ <SelectPrimitive.ItemIndicator>
127
+ <Check className="h-4 w-4" />
128
+ </SelectPrimitive.ItemIndicator>
129
+ </span>
130
+ <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
131
+ </SelectPrimitive.Item>
132
+ ));
133
+ SelectItem.displayName = SelectPrimitive.Item.displayName;
134
+
135
+ const SelectSeparator = React.forwardRef(({ className, ...props }, ref) => (
136
+ <SelectPrimitive.Separator
137
+ ref={ref}
138
+ className={cn("-mx-1 my-1 h-px bg-muted", className)}
139
+ {...props}
140
+ />
141
+ ));
142
+ SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
143
+
144
+ export {
145
+ Select,
146
+ SelectGroup,
147
+ SelectValue,
148
+ SelectTrigger,
149
+ SelectScrollUpButton,
150
+ SelectScrollDownButton,
151
+ SelectContent,
152
+ SelectLabel,
153
+ SelectItem,
154
+ SelectSeparator,
155
+ };
156
+
@@ -1,155 +1,35 @@
1
- //
2
- // select.jsx
3
- // -----------
4
- // shadcn/ui Select component wrappers using @radix-ui/react-select.
5
- // Import and use in forms for consistent dropdown styling.
6
- //
7
- // Example:
8
- // <Select value={value} onValueChange={setValue}>
9
- // <SelectTrigger className="w-full"><SelectValue placeholder="Select..." /></SelectTrigger>
10
- // <SelectContent>
11
- // <SelectItem value="site">Nursery site</SelectItem>
12
- // <SelectItem value="custom">Custom address</SelectItem>
13
- // </SelectContent>
14
- // </Select>
1
+ // shadcn-style Select component
2
+ // Provides consistent select styling across the application
3
+ // This is a simple HTML select wrapper, for advanced select features use radix-select.jsx
15
4
 
16
5
  import * as React from "react";
17
- import * as SelectPrimitive from "@radix-ui/react-select";
18
- import { Check, ChevronDown, ChevronUp } from "lucide-react";
19
6
  import { cn } from "../../lib/utils";
20
7
 
21
- const Select = SelectPrimitive.Root;
22
-
23
- const SelectGroup = SelectPrimitive.Group;
24
-
25
- const SelectValue = SelectPrimitive.Value;
26
-
27
- const SelectTrigger = React.forwardRef(({ className, children, ...props }, ref) => (
28
- <SelectPrimitive.Trigger
29
- ref={ref}
30
- className={cn(
31
- "flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background",
32
- "placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
33
- "disabled:cursor-not-allowed disabled:opacity-50",
34
- "[&>span]:line-clamp-1",
35
- className
36
- )}
37
- {...props}
38
- >
39
- {children}
40
- <SelectPrimitive.Icon asChild>
41
- <ChevronDown className="h-4 w-4 opacity-50" />
42
- </SelectPrimitive.Icon>
43
- </SelectPrimitive.Trigger>
44
- ));
45
- SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
46
-
47
- const SelectScrollUpButton = React.forwardRef(({ className, ...props }, ref) => (
48
- <SelectPrimitive.ScrollUpButton
49
- ref={ref}
50
- className={cn(
51
- "flex cursor-default items-center justify-center py-1",
52
- className
53
- )}
54
- {...props}
55
- >
56
- <ChevronUp className="h-4 w-4" />
57
- </SelectPrimitive.ScrollUpButton>
58
- ));
59
- SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
60
-
61
- const SelectScrollDownButton = React.forwardRef(({ className, ...props }, ref) => (
62
- <SelectPrimitive.ScrollDownButton
63
- ref={ref}
64
- className={cn(
65
- "flex cursor-default items-center justify-center py-1",
66
- className
67
- )}
68
- {...props}
69
- >
70
- <ChevronDown className="h-4 w-4" />
71
- </SelectPrimitive.ScrollDownButton>
72
- ));
73
- SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;
74
-
75
- const SelectContent = React.forwardRef(({ className, children, position = "popper", ...props }, ref) => (
76
- <SelectPrimitive.Portal>
77
- <SelectPrimitive.Content
78
- ref={ref}
8
+ const Select = React.forwardRef(({ className, children, ...props }, ref) => {
9
+ return (
10
+ <select
79
11
  className={cn(
80
- "relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md",
81
- "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
82
- "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
83
- position === "popper" &&
84
- "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
12
+ "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
85
13
  className
86
14
  )}
87
- position={position}
15
+ ref={ref}
88
16
  {...props}
89
17
  >
90
- <SelectScrollUpButton />
91
- <SelectPrimitive.Viewport
92
- className={cn(
93
- "p-1",
94
- position === "popper" &&
95
- "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
96
- )}
97
- >
18
+ {children}
19
+ </select>
20
+ );
21
+ });
22
+ Select.displayName = "Select";
23
+
24
+ const SelectOption = React.forwardRef(
25
+ ({ className, children, ...props }, ref) => {
26
+ return (
27
+ <option className={cn("", className)} ref={ref} {...props}>
98
28
  {children}
99
- </SelectPrimitive.Viewport>
100
- <SelectScrollDownButton />
101
- </SelectPrimitive.Content>
102
- </SelectPrimitive.Portal>
103
- ));
104
- SelectContent.displayName = SelectPrimitive.Content.displayName;
105
-
106
- const SelectLabel = React.forwardRef(({ className, ...props }, ref) => (
107
- <SelectPrimitive.Label
108
- ref={ref}
109
- className={cn("px-2 py-1.5 text-sm font-semibold", className)}
110
- {...props}
111
- />
112
- ));
113
- SelectLabel.displayName = SelectPrimitive.Label.displayName;
114
-
115
- const SelectItem = React.forwardRef(({ className, children, ...props }, ref) => (
116
- <SelectPrimitive.Item
117
- ref={ref}
118
- className={cn(
119
- "relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none",
120
- "focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
121
- className
122
- )}
123
- {...props}
124
- >
125
- <span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
126
- <SelectPrimitive.ItemIndicator>
127
- <Check className="h-4 w-4" />
128
- </SelectPrimitive.ItemIndicator>
129
- </span>
130
- <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
131
- </SelectPrimitive.Item>
132
- ));
133
- SelectItem.displayName = SelectPrimitive.Item.displayName;
134
-
135
- const SelectSeparator = React.forwardRef(({ className, ...props }, ref) => (
136
- <SelectPrimitive.Separator
137
- ref={ref}
138
- className={cn("-mx-1 my-1 h-px bg-muted", className)}
139
- {...props}
140
- />
141
- ));
142
- SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
29
+ </option>
30
+ );
31
+ }
32
+ );
33
+ SelectOption.displayName = "SelectOption";
143
34
 
144
- export {
145
- Select,
146
- SelectGroup,
147
- SelectValue,
148
- SelectTrigger,
149
- SelectScrollUpButton,
150
- SelectScrollDownButton,
151
- SelectContent,
152
- SelectLabel,
153
- SelectItem,
154
- SelectSeparator,
155
- };
35
+ export { Select, SelectOption };