@sonardigital/carbon-ui 1.2.9 → 1.2.12
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,15 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
ClickAwayListener,
|
|
3
3
|
IconButton,
|
|
4
|
-
InputAdornment,
|
|
5
4
|
Stack,
|
|
6
5
|
TextField,
|
|
7
6
|
TextFieldProps,
|
|
8
|
-
useFormControl,
|
|
9
7
|
} from '@mui/material';
|
|
10
8
|
import { Controller } from 'react-hook-form';
|
|
11
9
|
import { FormLabel } from '../layout';
|
|
12
10
|
import { FormError } from '../layout/FormError';
|
|
11
|
+
import { useState } from 'react';
|
|
13
12
|
import { RiCloseFill } from 'react-icons/ri';
|
|
14
13
|
|
|
15
14
|
interface FormInputProps extends TextFieldProps<'standard'> {
|
|
@@ -17,52 +16,43 @@ interface FormInputProps extends TextFieldProps<'standard'> {
|
|
|
17
16
|
label: string;
|
|
18
17
|
}
|
|
19
18
|
|
|
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
|
-
|
|
30
19
|
export function FormInput({
|
|
31
20
|
name,
|
|
32
21
|
label,
|
|
33
22
|
...props
|
|
34
23
|
}: FormInputProps): React.ReactElement {
|
|
24
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
35
25
|
return (
|
|
36
26
|
<Controller
|
|
37
27
|
name={name}
|
|
38
28
|
render={({ field, fieldState }) => (
|
|
39
29
|
<FormLabel label={label}>
|
|
40
|
-
<
|
|
41
|
-
<
|
|
30
|
+
<Stack gap={0.8}>
|
|
31
|
+
<ClickAwayListener onClickAway={() => setIsFocused(false)}>
|
|
42
32
|
<TextField
|
|
43
33
|
{...field}
|
|
44
34
|
{...props}
|
|
35
|
+
onFocus={() => setIsFocused(true)}
|
|
45
36
|
InputProps={{
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
</InputAdornment>
|
|
57
|
-
</Adornment>
|
|
37
|
+
endAdornment: isFocused && field.value && (
|
|
38
|
+
<IconButton
|
|
39
|
+
size="medium"
|
|
40
|
+
onClick={() => {
|
|
41
|
+
field.onChange(null);
|
|
42
|
+
setIsFocused(false);
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
<RiCloseFill size={18} />
|
|
46
|
+
</IconButton>
|
|
58
47
|
),
|
|
48
|
+
...props.InputProps,
|
|
59
49
|
}}
|
|
60
50
|
/>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
</
|
|
51
|
+
</ClickAwayListener>
|
|
52
|
+
{fieldState.error && (
|
|
53
|
+
<FormError label={fieldState.error?.message ?? ''} />
|
|
54
|
+
)}
|
|
55
|
+
</Stack>
|
|
66
56
|
</FormLabel>
|
|
67
57
|
)}
|
|
68
58
|
/>
|
|
@@ -40,7 +40,7 @@ export function SelectAutocomplete(
|
|
|
40
40
|
onChange={(_, value) => value?.value && onChange(value.value)}
|
|
41
41
|
getOptionLabel={option => option.label || ''}
|
|
42
42
|
clearIcon={
|
|
43
|
-
<IconButton size="
|
|
43
|
+
<IconButton size="medium" onClick={() => onChange(null)}>
|
|
44
44
|
<RiCloseFill size={18} />
|
|
45
45
|
</IconButton>
|
|
46
46
|
}
|