@jinaan/uikit 0.1.52 → 0.1.55

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": "@jinaan/uikit",
3
- "version": "0.1.52",
3
+ "version": "0.1.55",
4
4
  "description": "Reusable React and Tailwind UI components for Jinaan projects.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -77,11 +77,14 @@ export interface DataTableFilterOption {
77
77
  export interface DataTableFilter<T> {
78
78
  id: string;
79
79
  label: string;
80
- options: DataTableFilterOption[];
80
+ options?: DataTableFilterOption[];
81
81
  value: string[];
82
82
  onChange: (value: string[]) => void;
83
83
  /** Return true when the row matches the selected filter values. */
84
84
  match: (row: T, values: string[]) => boolean;
85
+ /** Use text input instead of checkbox options. */
86
+ type?: "text" | "select";
87
+ placeholder?: string;
85
88
  }
86
89
 
87
90
  export interface BulkAction<T> {
@@ -684,39 +687,64 @@ export function DataTable<T>({
684
687
  <FunnelSimple />
685
688
  <span className="font-medium">{filter.label}</span>
686
689
  <span className="h-4 w-px bg-line" aria-hidden />
687
- <span className="text-muted">
690
+ <span className="text-muted max-w-28 truncate">
688
691
  {filter.value.length > 0
689
- ? `${filter.value.length} selected`
692
+ ? filter.type === "text"
693
+ ? filter.value[0]
694
+ : `${filter.value.length} selected`
690
695
  : "Enter value"}
691
696
  </span>
692
697
  <CaretDown className="text-muted" />
693
698
  </Button>
694
699
  </DropdownMenuTrigger>
695
- <DropdownMenuContent align="start" className="w-56">
700
+ <DropdownMenuContent align="start" className={filter.type === "text" ? "w-72" : "w-56"}>
696
701
  <DropdownMenuLabel className="text-[13px]">
697
702
  Filter by {filter.label}
698
703
  </DropdownMenuLabel>
699
- {filter.options.map((option) => {
700
- const checked = filter.value.includes(option.value);
701
- return (
702
- <DropdownMenuCheckboxItem
703
- key={option.value}
704
- checked={checked}
705
- onCheckedChange={() =>
706
- filter.onChange(
707
- checked
708
- ? filter.value.filter((value) => value !== option.value)
709
- : [...filter.value, option.value],
710
- )
711
- }
712
- onSelect={(e) => e.preventDefault()}
713
- >
714
- {option.label}
715
- </DropdownMenuCheckboxItem>
716
- );
717
- })}
718
- <DropdownMenuSeparator />
719
- <DropdownMenuItem onSelect={clear}>Clear filter</DropdownMenuItem>
704
+ {filter.type === "text" ? (
705
+ <div className="px-1 pb-1">
706
+ <Input
707
+ value={filter.value[0] ?? ""}
708
+ onChange={(e) => filter.onChange(e.target.value ? [e.target.value] : [])}
709
+ onClear={filter.value[0] ? () => filter.onChange([]) : undefined}
710
+ placeholder={filter.placeholder ?? `Search ${filter.label.toLowerCase()}...`}
711
+ aria-label={filter.placeholder ?? `Search ${filter.label.toLowerCase()}...`}
712
+ leadingIcon={<MagnifyingGlass className="size-3.5" />}
713
+ size="sm"
714
+ className="h-(--control-h-xs) border-0 bg-(--combobox-search-bg) focus-visible:border-muted focus-visible:ring-0"
715
+ />
716
+ </div>
717
+ ) : (
718
+ <>
719
+ {(filter.options ?? []).map((option) => {
720
+ const checked = filter.value.includes(option.value);
721
+ return (
722
+ <DropdownMenuCheckboxItem
723
+ key={option.value}
724
+ checked={checked}
725
+ onCheckedChange={() =>
726
+ filter.onChange(
727
+ checked
728
+ ? filter.value.filter((value) => value !== option.value)
729
+ : [...filter.value, option.value],
730
+ )
731
+ }
732
+ onSelect={(e) => e.preventDefault()}
733
+ >
734
+ {option.label}
735
+ </DropdownMenuCheckboxItem>
736
+ );
737
+ })}
738
+ <DropdownMenuSeparator />
739
+ <DropdownMenuItem onSelect={clear}>Clear filter</DropdownMenuItem>
740
+ </>
741
+ )}
742
+ {filter.type === "text" ? (
743
+ <>
744
+ <DropdownMenuSeparator />
745
+ <DropdownMenuItem onSelect={clear}>Clear filter</DropdownMenuItem>
746
+ </>
747
+ ) : null}
720
748
  </DropdownMenuContent>
721
749
  </DropdownMenu>
722
750
  </div>
package/styles.css CHANGED
@@ -100,7 +100,7 @@
100
100
  --input-border-hover: #c7c7cf;
101
101
  --input-border-focus: var(--primary);
102
102
  --input-bg-disabled: #f6f6f7;
103
- --combobox-search-bg: rgb(32, 32, 35);
103
+ --combobox-search-bg: rgb(245, 245, 246);
104
104
 
105
105
  /* Button surfaces. */
106
106
  --button-primary-bg: var(--primary);