@sonardigital/carbon-ui 1.2.19 → 1.2.20
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
|
@@ -3,7 +3,7 @@ import { Controller } from 'react-hook-form';
|
|
|
3
3
|
import { FormLabel } from '../layout';
|
|
4
4
|
import { FormError } from '../layout/FormError';
|
|
5
5
|
import { NumberProps } from '../../inputs';
|
|
6
|
-
import {
|
|
6
|
+
import { NumberInput } from '../../inputs/Number';
|
|
7
7
|
|
|
8
8
|
interface FormNumberProps extends NumberProps {
|
|
9
9
|
name: string;
|
|
@@ -21,7 +21,7 @@ export function FormNumber({
|
|
|
21
21
|
render={({ field, fieldState }) => (
|
|
22
22
|
<FormLabel label={label}>
|
|
23
23
|
<Stack gap={0.8}>
|
|
24
|
-
<
|
|
24
|
+
<NumberInput {...field} {...props} />
|
|
25
25
|
{fieldState.error && (
|
|
26
26
|
<FormError label={fieldState.error?.message ?? ''} />
|
|
27
27
|
)}
|
|
@@ -5,6 +5,7 @@ import InputAdornment from '@mui/material/InputAdornment';
|
|
|
5
5
|
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
|
|
6
6
|
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
|
|
7
7
|
import { TextField } from '@mui/material';
|
|
8
|
+
import { BaseUIEvent } from '@base-ui/react/types';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* This component is a placeholder for FormControl to correctly set the shrink label state on SSR.
|
|
@@ -21,12 +22,14 @@ export interface NumberProps extends Omit<
|
|
|
21
22
|
error?: boolean;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export function
|
|
25
|
+
export function NumberInput({
|
|
25
26
|
id: idProp,
|
|
27
|
+
label,
|
|
26
28
|
error,
|
|
27
29
|
...other
|
|
28
30
|
}: BaseNumberField.Root.Props & {
|
|
29
31
|
label?: React.ReactNode;
|
|
32
|
+
onChange: (event: BaseUIEvent<React.ChangeEvent<HTMLInputElement>>) => void;
|
|
30
33
|
error?: boolean;
|
|
31
34
|
}) {
|
|
32
35
|
const size = 'medium';
|
|
@@ -36,18 +39,32 @@ export function Number({
|
|
|
36
39
|
id = idProp;
|
|
37
40
|
}
|
|
38
41
|
return (
|
|
39
|
-
<BaseNumberField.Root
|
|
42
|
+
<BaseNumberField.Root>
|
|
40
43
|
<SSRInitialFilled {...other} />
|
|
41
44
|
<BaseNumberField.Input
|
|
42
45
|
id={id}
|
|
46
|
+
onChange={event =>
|
|
47
|
+
other.onChange(
|
|
48
|
+
event as BaseUIEvent<React.ChangeEvent<HTMLInputElement>>,
|
|
49
|
+
)
|
|
50
|
+
}
|
|
43
51
|
render={(props, state) => (
|
|
44
52
|
<TextField
|
|
45
53
|
aria-describedby={`${id}-helper-text`}
|
|
46
54
|
inputRef={props.ref}
|
|
47
55
|
value={state.inputValue}
|
|
48
56
|
onBlur={props.onBlur}
|
|
49
|
-
onChange={
|
|
50
|
-
|
|
57
|
+
onChange={e => {
|
|
58
|
+
const value = isNaN(Number(e.target.value))
|
|
59
|
+
? 0
|
|
60
|
+
: Number(e.target.value);
|
|
61
|
+
props?.onChange?.({
|
|
62
|
+
...e,
|
|
63
|
+
target: { value },
|
|
64
|
+
} as unknown as BaseUIEvent<
|
|
65
|
+
React.ChangeEvent<HTMLInputElement>
|
|
66
|
+
>);
|
|
67
|
+
}}
|
|
51
68
|
onKeyDown={props.onKeyDown}
|
|
52
69
|
onFocus={props.onFocus}
|
|
53
70
|
InputProps={{
|
|
@@ -74,7 +91,15 @@ export function Number({
|
|
|
74
91
|
}}
|
|
75
92
|
>
|
|
76
93
|
<BaseNumberField.Increment
|
|
77
|
-
render={
|
|
94
|
+
render={
|
|
95
|
+
<IconButton
|
|
96
|
+
aria-label="Increase"
|
|
97
|
+
onClick={() =>
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
props?.onChange?.(state.value ?? 0)
|
|
100
|
+
}
|
|
101
|
+
/>
|
|
102
|
+
}
|
|
78
103
|
>
|
|
79
104
|
<KeyboardArrowUpIcon
|
|
80
105
|
fontSize={size}
|
|
@@ -83,7 +108,15 @@ export function Number({
|
|
|
83
108
|
</BaseNumberField.Increment>
|
|
84
109
|
|
|
85
110
|
<BaseNumberField.Decrement
|
|
86
|
-
render={
|
|
111
|
+
render={
|
|
112
|
+
<IconButton
|
|
113
|
+
aria-label="Decrease"
|
|
114
|
+
onClick={() =>
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
props?.onChange?.(state.value ?? 0)
|
|
117
|
+
}
|
|
118
|
+
/>
|
|
119
|
+
}
|
|
87
120
|
>
|
|
88
121
|
<KeyboardArrowDownIcon
|
|
89
122
|
fontSize={size}
|