@ponti-studios/ui 0.4.4 → 0.7.0

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,79 +0,0 @@
1
- import { useId } from "react";
2
-
3
- import { Label } from "../primitives/label";
4
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select";
5
-
6
- export interface EntitySelectOption {
7
- id: string;
8
- name: string;
9
- }
10
-
11
- export interface EntitySelectProps {
12
- value: string;
13
- onValueChange: (value: string) => void;
14
- options: EntitySelectOption[];
15
- isLoading?: boolean;
16
- placeholder?: string;
17
- label?: string;
18
- showLabel?: boolean;
19
- allOptionLabel?: string;
20
- emptyLabel?: string;
21
- className?: string;
22
- }
23
-
24
- /** Labeled `Select` over an `{ id, name }[]` list, with loading/empty states and an "all" option. */
25
- export function EntitySelect({
26
- value,
27
- onValueChange,
28
- options,
29
- isLoading = false,
30
- placeholder = "All",
31
- label = "Filter",
32
- showLabel = false,
33
- allOptionLabel = "All",
34
- emptyLabel = "No options available",
35
- className,
36
- }: EntitySelectProps) {
37
- const id = useId();
38
-
39
- const selectElement = (
40
- <Select
41
- name={label}
42
- value={value}
43
- onValueChange={(v: string | null) => v != null && onValueChange(v)}
44
- >
45
- <SelectTrigger id={id} className={className}>
46
- <SelectValue placeholder={placeholder} />
47
- </SelectTrigger>
48
- <SelectContent className="max-h-[250px] overflow-y-auto">
49
- <SelectItem value="all">{allOptionLabel}</SelectItem>
50
- {isLoading ? (
51
- <SelectItem value="loading" disabled>
52
- Loading...
53
- </SelectItem>
54
- ) : options.length === 0 ? (
55
- <SelectItem value="empty" disabled>
56
- {emptyLabel}
57
- </SelectItem>
58
- ) : (
59
- options.map((option) => (
60
- <SelectItem key={option.id} value={option.id}>
61
- {option.name}
62
- </SelectItem>
63
- ))
64
- )}
65
- </SelectContent>
66
- </Select>
67
- );
68
-
69
- if (showLabel) {
70
- return (
71
- <div className="space-y-2">
72
- <Label htmlFor={id}>{label}</Label>
73
- {selectElement}
74
- </div>
75
- );
76
- }
77
-
78
- return selectElement;
79
- }