@sonardigital/carbon-ui 1.2.8 → 1.2.9

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": "@sonardigital/carbon-ui",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -1,13 +1,32 @@
1
- import { Stack, TextField, TextFieldProps } from '@mui/material';
1
+ import {
2
+ FormControl,
3
+ IconButton,
4
+ InputAdornment,
5
+ Stack,
6
+ TextField,
7
+ TextFieldProps,
8
+ useFormControl,
9
+ } from '@mui/material';
2
10
  import { Controller } from 'react-hook-form';
3
11
  import { FormLabel } from '../layout';
4
12
  import { FormError } from '../layout/FormError';
13
+ import { RiCloseFill } from 'react-icons/ri';
5
14
 
6
15
  interface FormInputProps extends TextFieldProps<'standard'> {
7
16
  name: string;
8
17
  label: string;
9
18
  }
10
19
 
20
+ function Adornment({
21
+ children,
22
+ }: {
23
+ children: React.ReactNode;
24
+ }): React.ReactNode {
25
+ const { focused = false } = useFormControl() as { focused: boolean };
26
+
27
+ return focused ? children : <></>;
28
+ }
29
+
11
30
  export function FormInput({
12
31
  name,
13
32
  label,
@@ -18,12 +37,32 @@ export function FormInput({
18
37
  name={name}
19
38
  render={({ field, fieldState }) => (
20
39
  <FormLabel label={label}>
21
- <Stack gap={0.8}>
22
- <TextField {...field} {...props} />
23
- {fieldState.error && (
24
- <FormError label={fieldState.error?.message ?? ''} />
25
- )}
26
- </Stack>
40
+ <FormControl>
41
+ <Stack gap={0.8}>
42
+ <TextField
43
+ {...field}
44
+ {...props}
45
+ InputProps={{
46
+ ...props.InputProps,
47
+ endAdornment: (
48
+ <Adornment>
49
+ <InputAdornment position="end">
50
+ <IconButton
51
+ size="small"
52
+ onClick={() => field.onChange(null)}
53
+ >
54
+ <RiCloseFill size={18} />
55
+ </IconButton>
56
+ </InputAdornment>
57
+ </Adornment>
58
+ ),
59
+ }}
60
+ />
61
+ {fieldState.error && (
62
+ <FormError label={fieldState.error?.message ?? ''} />
63
+ )}
64
+ </Stack>
65
+ </FormControl>
27
66
  </FormLabel>
28
67
  )}
29
68
  />