@applica-software-guru/react-admin 1.5.303 → 1.5.304

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
@@ -107,5 +107,5 @@
107
107
  "type": "module",
108
108
  "types": "dist/index.d.ts",
109
109
  "typings": "dist/index.d.ts",
110
- "version": "1.5.303"
110
+ "version": "1.5.304"
111
111
  }
@@ -16,7 +16,7 @@ function LabeledInput({
16
16
  }: LabeledInputProps): JSX.Element {
17
17
  const theme = useTheme();
18
18
  const { getCurrentDialog } = useAppConfig();
19
- const { source, resource, isRequired } = props;
19
+ const { source, resource, isRequired, chip } = props;
20
20
  const {
21
21
  fieldState: { invalid }
22
22
  } = useInput(props);
@@ -60,6 +60,7 @@ function LabeledInput({
60
60
  // @ts-ignore
61
61
  ...children.props,
62
62
  ...props,
63
+ chip: chip && typeof chip === 'function' ? React.createElement(chip) : chip,
63
64
  label: display === 'legend' ? label : false
64
65
  })
65
66
  : children}
@@ -90,6 +91,7 @@ type LabeledInputProps = InputProps & {
90
91
  display?: 'legend' | 'label';
91
92
  helperText?: string | boolean | React.ReactElement | null;
92
93
  divider?: boolean;
94
+ chip?: any;
93
95
  };
94
96
 
95
97
  export { LabeledInput };
@@ -75,7 +75,7 @@ function Chips(): ReactElement {
75
75
  flexDirection={'row'}
76
76
  flexWrap={isMobile ? 'nowrap' : 'wrap'}
77
77
  gap={2}
78
- pb={0.5}
78
+ py={0.5}
79
79
  overflow={'auto'}
80
80
  width={isMobile ? window.innerWidth - (24 + 34) : 'auto'}
81
81
  >
@@ -27,7 +27,7 @@ function FiltersInput(props: FiltersInputProps): ReactElement {
27
27
  ? (Array.isArray(filters) ? filters : [filters]).map((filter: ReactElement, i) => {
28
28
  const props = { ...filter.props, display: 'label' };
29
29
  return React.isValidElement(filter) ? (
30
- <Box key={i} sx={{ mb: 1 }}>
30
+ <Box key={i} mb={1}>
31
31
  {React.cloneElement(filter, { ...props, resource })}
32
32
  </Box>
33
33
  ) : null;
@@ -1,5 +1,6 @@
1
1
  import React, { createContext, useContext, useMemo } from 'react';
2
2
  import { FilterContext, useResourceContext } from 'react-admin';
3
+ import { isFunction } from 'lodash';
3
4
 
4
5
  interface FiltersContextType {
5
6
  hasFilterSidebar?: boolean;
@@ -30,24 +31,26 @@ function useGetChipValue({ source, value }: ChipItemProps): JSX.Element | null {
30
31
  [currentSourceFilter]
31
32
  );
32
33
 
33
- const ChipComponent = React.isValidElement(currentSourceFilter) ? currentSourceFilter.props?.chip : null;
34
-
35
- if (!ChipComponent) {
34
+ if (!currentSourceFilterProps?.chip) {
36
35
  throw new Error(
37
36
  `No chip component found for filter source "${source}". Ensure your filter components define a 'chip' prop.`
38
37
  );
39
38
  }
40
39
 
41
- const label = useMemo(() => {
42
- return React.cloneElement(ChipComponent as React.ReactElement<any>, {
43
- ...currentSourceFilterProps,
44
- record: { [source]: value },
45
- value,
46
- resource
47
- });
48
- }, [value, ChipComponent, source, resource, currentSourceFilterProps]);
40
+ const chipProps = {
41
+ ...currentSourceFilterProps,
42
+ record: { [source]: value },
43
+ value,
44
+ resource
45
+ };
46
+
47
+ const Chip = React.isValidElement(currentSourceFilterProps.chip)
48
+ ? React.cloneElement(currentSourceFilterProps.chip, chipProps)
49
+ : isFunction(currentSourceFilterProps.chip)
50
+ ? React.createElement(currentSourceFilterProps.chip, chipProps)
51
+ : null;
49
52
 
50
- return label;
53
+ return Chip;
51
54
  }
52
55
 
53
56
  export { FilterSidebarContext, useGetChipValue, useIsEnabledSidebarFilter };