@sonardigital/carbon-ui 1.2.18 → 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonardigital/carbon-ui",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
]
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
+
"@base-ui/react": "^1.6.0",
|
|
55
56
|
"@emotion/react": "^11.14.0",
|
|
56
57
|
"@emotion/styled": "^11.14.1",
|
|
57
58
|
"@mui/icons-material": "^7.3.2",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Stack } from '@mui/material';
|
|
2
|
+
import { Controller } from 'react-hook-form';
|
|
3
|
+
import { FormLabel } from '../layout';
|
|
4
|
+
import { FormError } from '../layout/FormError';
|
|
5
|
+
import { NumberProps } from '../../inputs';
|
|
6
|
+
import { NumberInput } from '../../inputs/Number';
|
|
7
|
+
|
|
8
|
+
interface FormNumberProps extends NumberProps {
|
|
9
|
+
name: string;
|
|
10
|
+
label: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function FormNumber({
|
|
14
|
+
name,
|
|
15
|
+
label,
|
|
16
|
+
...props
|
|
17
|
+
}: FormNumberProps): React.ReactElement {
|
|
18
|
+
return (
|
|
19
|
+
<Controller
|
|
20
|
+
name={name}
|
|
21
|
+
render={({ field, fieldState }) => (
|
|
22
|
+
<FormLabel label={label}>
|
|
23
|
+
<Stack gap={0.8}>
|
|
24
|
+
<NumberInput {...field} {...props} />
|
|
25
|
+
{fieldState.error && (
|
|
26
|
+
<FormError label={fieldState.error?.message ?? ''} />
|
|
27
|
+
)}
|
|
28
|
+
</Stack>
|
|
29
|
+
</FormLabel>
|
|
30
|
+
)}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { NumberField as BaseNumberField } from '@base-ui/react/number-field';
|
|
3
|
+
import IconButton from '@mui/material/IconButton';
|
|
4
|
+
import InputAdornment from '@mui/material/InputAdornment';
|
|
5
|
+
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
|
|
6
|
+
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
|
|
7
|
+
import { TextField } from '@mui/material';
|
|
8
|
+
import { BaseUIEvent } from '@base-ui/react/types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This component is a placeholder for FormControl to correctly set the shrink label state on SSR.
|
|
12
|
+
*/
|
|
13
|
+
function SSRInitialFilled(_: BaseNumberField.Root.Props) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
SSRInitialFilled.muiName = 'Input';
|
|
17
|
+
|
|
18
|
+
export interface NumberProps extends Omit<
|
|
19
|
+
BaseNumberField.Root.Props,
|
|
20
|
+
'render' | 'label' | 'size'
|
|
21
|
+
> {
|
|
22
|
+
error?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function NumberInput({
|
|
26
|
+
id: idProp,
|
|
27
|
+
label,
|
|
28
|
+
error,
|
|
29
|
+
...other
|
|
30
|
+
}: BaseNumberField.Root.Props & {
|
|
31
|
+
label?: React.ReactNode;
|
|
32
|
+
onChange: (event: BaseUIEvent<React.ChangeEvent<HTMLInputElement>>) => void;
|
|
33
|
+
error?: boolean;
|
|
34
|
+
}) {
|
|
35
|
+
const size = 'medium';
|
|
36
|
+
|
|
37
|
+
let id = React.useId();
|
|
38
|
+
if (idProp) {
|
|
39
|
+
id = idProp;
|
|
40
|
+
}
|
|
41
|
+
return (
|
|
42
|
+
<BaseNumberField.Root>
|
|
43
|
+
<SSRInitialFilled {...other} />
|
|
44
|
+
<BaseNumberField.Input
|
|
45
|
+
id={id}
|
|
46
|
+
onChange={event =>
|
|
47
|
+
other.onChange(
|
|
48
|
+
event as BaseUIEvent<React.ChangeEvent<HTMLInputElement>>,
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
render={(props, state) => (
|
|
52
|
+
<TextField
|
|
53
|
+
aria-describedby={`${id}-helper-text`}
|
|
54
|
+
inputRef={props.ref}
|
|
55
|
+
value={state.inputValue}
|
|
56
|
+
onBlur={props.onBlur}
|
|
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
|
+
}}
|
|
68
|
+
onKeyDown={props.onKeyDown}
|
|
69
|
+
onFocus={props.onFocus}
|
|
70
|
+
InputProps={{
|
|
71
|
+
inputProps: {
|
|
72
|
+
sx: {
|
|
73
|
+
height: 19,
|
|
74
|
+
fontWeight: 400,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
endAdornment: (
|
|
78
|
+
<InputAdornment
|
|
79
|
+
position="end"
|
|
80
|
+
sx={{
|
|
81
|
+
flexDirection: 'column',
|
|
82
|
+
maxHeight: 'unset',
|
|
83
|
+
alignSelf: 'stretch',
|
|
84
|
+
borderLeft: '1px solid',
|
|
85
|
+
borderColor: 'divider',
|
|
86
|
+
'& button': {
|
|
87
|
+
py: 0,
|
|
88
|
+
flex: 1,
|
|
89
|
+
borderRadius: 0.5,
|
|
90
|
+
},
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
<BaseNumberField.Increment
|
|
94
|
+
render={
|
|
95
|
+
<IconButton
|
|
96
|
+
aria-label="Increase"
|
|
97
|
+
onClick={() =>
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
props?.onChange?.(state.value ?? 0)
|
|
100
|
+
}
|
|
101
|
+
/>
|
|
102
|
+
}
|
|
103
|
+
>
|
|
104
|
+
<KeyboardArrowUpIcon
|
|
105
|
+
fontSize={size}
|
|
106
|
+
sx={{ transform: 'translateY(2px)' }}
|
|
107
|
+
/>
|
|
108
|
+
</BaseNumberField.Increment>
|
|
109
|
+
|
|
110
|
+
<BaseNumberField.Decrement
|
|
111
|
+
render={
|
|
112
|
+
<IconButton
|
|
113
|
+
aria-label="Decrease"
|
|
114
|
+
onClick={() =>
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
props?.onChange?.(state.value ?? 0)
|
|
117
|
+
}
|
|
118
|
+
/>
|
|
119
|
+
}
|
|
120
|
+
>
|
|
121
|
+
<KeyboardArrowDownIcon
|
|
122
|
+
fontSize={size}
|
|
123
|
+
sx={{ transform: 'translateY(-2px)' }}
|
|
124
|
+
/>
|
|
125
|
+
</BaseNumberField.Decrement>
|
|
126
|
+
</InputAdornment>
|
|
127
|
+
),
|
|
128
|
+
}}
|
|
129
|
+
sx={{ width: '100%' }}
|
|
130
|
+
/>
|
|
131
|
+
)}
|
|
132
|
+
/>
|
|
133
|
+
</BaseNumberField.Root>
|
|
134
|
+
);
|
|
135
|
+
}
|