muffin-admin 9.1.2 → 9.2.2

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": "muffin-admin",
3
- "version": "9.1.2",
3
+ "version": "9.2.2",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
package/src/buildRA.tsx CHANGED
@@ -27,6 +27,7 @@ import {
27
27
  ReferenceManyField,
28
28
  required,
29
29
  RichTextField,
30
+ SearchInput,
30
31
  SelectArrayInput,
31
32
  SelectField,
32
33
  SelectInput,
@@ -36,7 +37,7 @@ import {
36
37
  } from "react-admin"
37
38
 
38
39
  import { AvatarField, CopyField, EditableBooleanField, FKField, JsonField } from "./fields"
39
- import { DateRangeFilter, Filter } from "./filters"
40
+ import { DateRangeFilter, Filter, SearchFilter } from "./filters"
40
41
  import { FKInput, JsonInput, TimestampInput } from "./inputs"
41
42
 
42
43
  const UI: Record<string, JSX.ElementType> = {
@@ -84,10 +85,12 @@ const UI: Record<string, JSX.ElementType> = {
84
85
  SelectInput,
85
86
  TextInput,
86
87
  TimestampInput,
88
+ SearchInput,
87
89
 
88
90
  // Filters
89
91
  Filter,
90
92
  DateRangeFilter,
93
+ SearchFilter,
91
94
  }
92
95
 
93
96
  export function buildRAComponent(name: string, props: any) {
@@ -0,0 +1,40 @@
1
+ import SearchIcon from "@mui/icons-material/Search"
2
+ import { InputAdornment } from "@mui/material"
3
+ import clsx from "clsx"
4
+ import debounce from "lodash/debounce"
5
+ import { useTranslate } from "ra-core"
6
+ import { useState } from "react"
7
+ import { ResettableTextField, SearchInputProps, useInput, useResourceContext } from "react-admin"
8
+
9
+ export function SearchFilter({ source, className, ...props }: SearchInputProps) {
10
+ const translate = useTranslate()
11
+ const { field } = useInput({ source, ...props })
12
+ const [searchValue, setSearchValue] = useState(field.value || "")
13
+ const resource = useResourceContext()
14
+
15
+ const onBlur = () => field.onChange(searchValue)
16
+ const label = translate(`resources.${resource}.fields.${source}`)
17
+
18
+ return (
19
+ <ResettableTextField
20
+ resettable
21
+ ref={field.ref}
22
+ value={searchValue}
23
+ onBlur={debounce(onBlur, 500)}
24
+ onChange={(e) => setSearchValue(e.target?.value ?? e)}
25
+ onKeyUp={(e) => {
26
+ if (e.key === "Enter") field.onChange(searchValue)
27
+ }}
28
+ placeholder={label}
29
+ {...props}
30
+ className={clsx("ra-input", `ra-input-${source}`, className)}
31
+ InputProps={{
32
+ endAdornment: (
33
+ <InputAdornment position="end">
34
+ <SearchIcon color="disabled" />
35
+ </InputAdornment>
36
+ ),
37
+ }}
38
+ />
39
+ )
40
+ }
@@ -1,2 +1,3 @@
1
1
  export * from "./DateRangeFilter"
2
2
  export * from "./Filter"
3
+ export * from "./SearchFilter"
package/src/index.tsx CHANGED
@@ -36,4 +36,4 @@ export async function initAdmin(prefix = "", containerId: string = "root") {
36
36
  )
37
37
  }
38
38
 
39
- export const VERSION = "9.1.2"
39
+ export const VERSION = "9.2.2"