@etsoo/materialui 1.6.27 → 1.6.28
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/lib/cjs/NumberField.d.ts +7 -0
- package/lib/cjs/NumberField.js +78 -0
- package/lib/cjs/NumberSpinner.d.ts +7 -0
- package/lib/cjs/NumberSpinner.js +96 -0
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +2 -0
- package/lib/mjs/NumberField.d.ts +7 -0
- package/lib/mjs/NumberField.js +39 -0
- package/lib/mjs/NumberSpinner.d.ts +7 -0
- package/lib/mjs/NumberSpinner.js +57 -0
- package/lib/mjs/index.d.ts +2 -0
- package/lib/mjs/index.js +2 -0
- package/package.json +2 -1
- package/src/NumberField.tsx +113 -0
- package/src/NumberSpinner.tsx +154 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { NumberField as BaseNumberField } from "@base-ui/react/number-field";
|
|
3
|
+
export default function NumberField({ id: idProp, label, error, size, ...other }: BaseNumberField.Root.Props & {
|
|
4
|
+
label?: React.ReactNode;
|
|
5
|
+
size?: "small" | "medium";
|
|
6
|
+
error?: boolean;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.default = NumberField;
|
|
40
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
41
|
+
const React = __importStar(require("react"));
|
|
42
|
+
const number_field_1 = require("@base-ui/react/number-field");
|
|
43
|
+
const IconButton_1 = __importDefault(require("@mui/material/IconButton"));
|
|
44
|
+
const FormControl_1 = __importDefault(require("@mui/material/FormControl"));
|
|
45
|
+
const FormHelperText_1 = __importDefault(require("@mui/material/FormHelperText"));
|
|
46
|
+
const OutlinedInput_1 = __importDefault(require("@mui/material/OutlinedInput"));
|
|
47
|
+
const InputAdornment_1 = __importDefault(require("@mui/material/InputAdornment"));
|
|
48
|
+
const InputLabel_1 = __importDefault(require("@mui/material/InputLabel"));
|
|
49
|
+
const KeyboardArrowUp_1 = __importDefault(require("@mui/icons-material/KeyboardArrowUp"));
|
|
50
|
+
const KeyboardArrowDown_1 = __importDefault(require("@mui/icons-material/KeyboardArrowDown"));
|
|
51
|
+
/**
|
|
52
|
+
* This component is a placeholder for FormControl to correctly set the shrink label state on SSR.
|
|
53
|
+
*/
|
|
54
|
+
function SSRInitialFilled(_) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
SSRInitialFilled.muiName = "Input";
|
|
58
|
+
function NumberField({ id: idProp, label, error, size = "medium", ...other }) {
|
|
59
|
+
let id = React.useId();
|
|
60
|
+
if (idProp) {
|
|
61
|
+
id = idProp;
|
|
62
|
+
}
|
|
63
|
+
return ((0, jsx_runtime_1.jsxs)(number_field_1.NumberField.Root, { ...other, render: (props, state) => ((0, jsx_runtime_1.jsx)(FormControl_1.default, { size: size, ref: props.ref, disabled: state.disabled, required: state.required, error: error, variant: "outlined", children: props.children })), children: [(0, jsx_runtime_1.jsx)(SSRInitialFilled, { ...other }), (0, jsx_runtime_1.jsx)(InputLabel_1.default, { htmlFor: id, children: label }), (0, jsx_runtime_1.jsx)(number_field_1.NumberField.Input, { id: id, render: (props, state) => ((0, jsx_runtime_1.jsx)(OutlinedInput_1.default, { label: label, inputRef: props.ref, value: state.inputValue, onBlur: props.onBlur, onChange: props.onChange, onKeyUp: props.onKeyUp, onKeyDown: props.onKeyDown, onFocus: props.onFocus, slotProps: {
|
|
64
|
+
input: props
|
|
65
|
+
}, endAdornment: (0, jsx_runtime_1.jsxs)(InputAdornment_1.default, { position: "end", sx: {
|
|
66
|
+
flexDirection: "column",
|
|
67
|
+
maxHeight: "unset",
|
|
68
|
+
alignSelf: "stretch",
|
|
69
|
+
borderLeft: "1px solid",
|
|
70
|
+
borderColor: "divider",
|
|
71
|
+
ml: 0,
|
|
72
|
+
"& button": {
|
|
73
|
+
py: 0,
|
|
74
|
+
flex: 1,
|
|
75
|
+
borderRadius: 0.5
|
|
76
|
+
}
|
|
77
|
+
}, children: [(0, jsx_runtime_1.jsx)(number_field_1.NumberField.Increment, { render: (0, jsx_runtime_1.jsx)(IconButton_1.default, { size: size, "aria-label": "Increase" }), children: (0, jsx_runtime_1.jsx)(KeyboardArrowUp_1.default, { fontSize: size, sx: { transform: "translateY(2px)" } }) }), (0, jsx_runtime_1.jsx)(number_field_1.NumberField.Decrement, { render: (0, jsx_runtime_1.jsx)(IconButton_1.default, { size: size, "aria-label": "Decrease" }), children: (0, jsx_runtime_1.jsx)(KeyboardArrowDown_1.default, { fontSize: size, sx: { transform: "translateY(-2px)" } }) })] }), sx: { pr: 0 } })) }), (0, jsx_runtime_1.jsx)(FormHelperText_1.default, { sx: { ml: 0, "&:empty": { mt: 0 } }, children: "Enter value between 10 and 40" })] }));
|
|
78
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { NumberField as BaseNumberField } from "@base-ui/react/number-field";
|
|
3
|
+
export default function NumberSpinner({ id: idProp, label, error, size, ...other }: BaseNumberField.Root.Props & {
|
|
4
|
+
label?: React.ReactNode;
|
|
5
|
+
size?: "small" | "medium";
|
|
6
|
+
error?: boolean;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.default = NumberSpinner;
|
|
40
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
41
|
+
const React = __importStar(require("react"));
|
|
42
|
+
const number_field_1 = require("@base-ui/react/number-field");
|
|
43
|
+
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
44
|
+
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
45
|
+
const FormControl_1 = __importDefault(require("@mui/material/FormControl"));
|
|
46
|
+
const FormLabel_1 = __importDefault(require("@mui/material/FormLabel"));
|
|
47
|
+
const Add_1 = __importDefault(require("@mui/icons-material/Add"));
|
|
48
|
+
const Remove_1 = __importDefault(require("@mui/icons-material/Remove"));
|
|
49
|
+
const OutlinedInput_1 = __importDefault(require("@mui/material/OutlinedInput"));
|
|
50
|
+
const OpenInFull_1 = __importDefault(require("@mui/icons-material/OpenInFull"));
|
|
51
|
+
function NumberSpinner({ id: idProp, label, error, size = "medium", ...other }) {
|
|
52
|
+
let id = React.useId();
|
|
53
|
+
if (idProp) {
|
|
54
|
+
id = idProp;
|
|
55
|
+
}
|
|
56
|
+
return ((0, jsx_runtime_1.jsxs)(number_field_1.NumberField.Root, { ...other, render: (props, state) => ((0, jsx_runtime_1.jsx)(FormControl_1.default, { size: size, ref: props.ref, disabled: state.disabled, required: state.required, error: error, variant: "outlined", sx: {
|
|
57
|
+
"& .MuiButton-root": {
|
|
58
|
+
borderColor: "divider",
|
|
59
|
+
minWidth: 0,
|
|
60
|
+
bgcolor: "action.hover",
|
|
61
|
+
"&:not(.Mui-disabled)": {
|
|
62
|
+
color: "text.primary"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}, children: props.children })), children: [(0, jsx_runtime_1.jsxs)(number_field_1.NumberField.ScrubArea, { render: (0, jsx_runtime_1.jsx)(Box_1.default, { component: "span", sx: { userSelect: "none", width: "max-content" } }), children: [(0, jsx_runtime_1.jsx)(FormLabel_1.default, { htmlFor: id, sx: {
|
|
66
|
+
display: "inline-block",
|
|
67
|
+
cursor: "ew-resize",
|
|
68
|
+
fontSize: "0.875rem",
|
|
69
|
+
color: "text.primary",
|
|
70
|
+
fontWeight: 500,
|
|
71
|
+
lineHeight: 1.5,
|
|
72
|
+
mb: 0.5
|
|
73
|
+
}, children: label }), (0, jsx_runtime_1.jsx)(number_field_1.NumberField.ScrubAreaCursor, { children: (0, jsx_runtime_1.jsx)(OpenInFull_1.default, { fontSize: "small", sx: { transform: "translateY(12.5%) rotate(45deg)" } }) })] }), (0, jsx_runtime_1.jsxs)(Box_1.default, { sx: { display: "flex" }, children: [(0, jsx_runtime_1.jsx)(number_field_1.NumberField.Decrement, { render: (0, jsx_runtime_1.jsx)(Button_1.default, { variant: "outlined", "aria-label": "Decrease", size: size, sx: {
|
|
74
|
+
borderTopRightRadius: 0,
|
|
75
|
+
borderBottomRightRadius: 0,
|
|
76
|
+
borderRight: "0px",
|
|
77
|
+
"&.Mui-disabled": {
|
|
78
|
+
borderRight: "0px"
|
|
79
|
+
}
|
|
80
|
+
} }), children: (0, jsx_runtime_1.jsx)(Remove_1.default, { fontSize: size }) }), (0, jsx_runtime_1.jsx)(number_field_1.NumberField.Input, { id: id, render: (props, state) => ((0, jsx_runtime_1.jsx)(OutlinedInput_1.default, { inputRef: props.ref, value: state.inputValue, onBlur: props.onBlur, onChange: props.onChange, onKeyUp: props.onKeyUp, onKeyDown: props.onKeyDown, onFocus: props.onFocus, slotProps: {
|
|
81
|
+
input: {
|
|
82
|
+
...props,
|
|
83
|
+
size: Math.max((other.min?.toString() || "").length, state.inputValue.length || 1) + 1,
|
|
84
|
+
sx: {
|
|
85
|
+
textAlign: "center"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, sx: { pr: 0, borderRadius: 0, flex: 1 } })) }), (0, jsx_runtime_1.jsx)(number_field_1.NumberField.Increment, { render: (0, jsx_runtime_1.jsx)(Button_1.default, { variant: "outlined", "aria-label": "Increase", size: size, sx: {
|
|
89
|
+
borderTopLeftRadius: 0,
|
|
90
|
+
borderBottomLeftRadius: 0,
|
|
91
|
+
borderLeft: "0px",
|
|
92
|
+
"&.Mui-disabled": {
|
|
93
|
+
borderLeft: "0px"
|
|
94
|
+
}
|
|
95
|
+
} }), children: (0, jsx_runtime_1.jsx)(Add_1.default, { fontSize: size }) })] })] }));
|
|
96
|
+
}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -94,7 +94,9 @@ export * from "./MUGlobal";
|
|
|
94
94
|
export * from "./MUUtils";
|
|
95
95
|
export * from "./NotifierMU";
|
|
96
96
|
export * from "./NotifierPopupProps";
|
|
97
|
+
export * from "./NumberField";
|
|
97
98
|
export * from "./NumberInputField";
|
|
99
|
+
export * from "./NumberSpinner";
|
|
98
100
|
export * from "./OptionBool";
|
|
99
101
|
export * from "./OptionGroup";
|
|
100
102
|
export * from "./OptionGroupFlag";
|
package/lib/cjs/index.js
CHANGED
|
@@ -110,7 +110,9 @@ __exportStar(require("./MUGlobal"), exports);
|
|
|
110
110
|
__exportStar(require("./MUUtils"), exports);
|
|
111
111
|
__exportStar(require("./NotifierMU"), exports);
|
|
112
112
|
__exportStar(require("./NotifierPopupProps"), exports);
|
|
113
|
+
__exportStar(require("./NumberField"), exports);
|
|
113
114
|
__exportStar(require("./NumberInputField"), exports);
|
|
115
|
+
__exportStar(require("./NumberSpinner"), exports);
|
|
114
116
|
__exportStar(require("./OptionBool"), exports);
|
|
115
117
|
__exportStar(require("./OptionGroup"), exports);
|
|
116
118
|
__exportStar(require("./OptionGroupFlag"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { NumberField as BaseNumberField } from "@base-ui/react/number-field";
|
|
3
|
+
export default function NumberField({ id: idProp, label, error, size, ...other }: BaseNumberField.Root.Props & {
|
|
4
|
+
label?: React.ReactNode;
|
|
5
|
+
size?: "small" | "medium";
|
|
6
|
+
error?: boolean;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { NumberField as BaseNumberField } from "@base-ui/react/number-field";
|
|
4
|
+
import IconButton from "@mui/material/IconButton";
|
|
5
|
+
import FormControl from "@mui/material/FormControl";
|
|
6
|
+
import FormHelperText from "@mui/material/FormHelperText";
|
|
7
|
+
import OutlinedInput from "@mui/material/OutlinedInput";
|
|
8
|
+
import InputAdornment from "@mui/material/InputAdornment";
|
|
9
|
+
import InputLabel from "@mui/material/InputLabel";
|
|
10
|
+
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";
|
|
11
|
+
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
|
|
12
|
+
/**
|
|
13
|
+
* This component is a placeholder for FormControl to correctly set the shrink label state on SSR.
|
|
14
|
+
*/
|
|
15
|
+
function SSRInitialFilled(_) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
SSRInitialFilled.muiName = "Input";
|
|
19
|
+
export default function NumberField({ id: idProp, label, error, size = "medium", ...other }) {
|
|
20
|
+
let id = React.useId();
|
|
21
|
+
if (idProp) {
|
|
22
|
+
id = idProp;
|
|
23
|
+
}
|
|
24
|
+
return (_jsxs(BaseNumberField.Root, { ...other, render: (props, state) => (_jsx(FormControl, { size: size, ref: props.ref, disabled: state.disabled, required: state.required, error: error, variant: "outlined", children: props.children })), children: [_jsx(SSRInitialFilled, { ...other }), _jsx(InputLabel, { htmlFor: id, children: label }), _jsx(BaseNumberField.Input, { id: id, render: (props, state) => (_jsx(OutlinedInput, { label: label, inputRef: props.ref, value: state.inputValue, onBlur: props.onBlur, onChange: props.onChange, onKeyUp: props.onKeyUp, onKeyDown: props.onKeyDown, onFocus: props.onFocus, slotProps: {
|
|
25
|
+
input: props
|
|
26
|
+
}, endAdornment: _jsxs(InputAdornment, { position: "end", sx: {
|
|
27
|
+
flexDirection: "column",
|
|
28
|
+
maxHeight: "unset",
|
|
29
|
+
alignSelf: "stretch",
|
|
30
|
+
borderLeft: "1px solid",
|
|
31
|
+
borderColor: "divider",
|
|
32
|
+
ml: 0,
|
|
33
|
+
"& button": {
|
|
34
|
+
py: 0,
|
|
35
|
+
flex: 1,
|
|
36
|
+
borderRadius: 0.5
|
|
37
|
+
}
|
|
38
|
+
}, children: [_jsx(BaseNumberField.Increment, { render: _jsx(IconButton, { size: size, "aria-label": "Increase" }), children: _jsx(KeyboardArrowUpIcon, { fontSize: size, sx: { transform: "translateY(2px)" } }) }), _jsx(BaseNumberField.Decrement, { render: _jsx(IconButton, { size: size, "aria-label": "Decrease" }), children: _jsx(KeyboardArrowDownIcon, { fontSize: size, sx: { transform: "translateY(-2px)" } }) })] }), sx: { pr: 0 } })) }), _jsx(FormHelperText, { sx: { ml: 0, "&:empty": { mt: 0 } }, children: "Enter value between 10 and 40" })] }));
|
|
39
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { NumberField as BaseNumberField } from "@base-ui/react/number-field";
|
|
3
|
+
export default function NumberSpinner({ id: idProp, label, error, size, ...other }: BaseNumberField.Root.Props & {
|
|
4
|
+
label?: React.ReactNode;
|
|
5
|
+
size?: "small" | "medium";
|
|
6
|
+
error?: boolean;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { NumberField as BaseNumberField } from "@base-ui/react/number-field";
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
5
|
+
import Button from "@mui/material/Button";
|
|
6
|
+
import FormControl from "@mui/material/FormControl";
|
|
7
|
+
import FormLabel from "@mui/material/FormLabel";
|
|
8
|
+
import AddIcon from "@mui/icons-material/Add";
|
|
9
|
+
import RemoveIcon from "@mui/icons-material/Remove";
|
|
10
|
+
import OutlinedInput from "@mui/material/OutlinedInput";
|
|
11
|
+
import OpenInFullIcon from "@mui/icons-material/OpenInFull";
|
|
12
|
+
export default function NumberSpinner({ id: idProp, label, error, size = "medium", ...other }) {
|
|
13
|
+
let id = React.useId();
|
|
14
|
+
if (idProp) {
|
|
15
|
+
id = idProp;
|
|
16
|
+
}
|
|
17
|
+
return (_jsxs(BaseNumberField.Root, { ...other, render: (props, state) => (_jsx(FormControl, { size: size, ref: props.ref, disabled: state.disabled, required: state.required, error: error, variant: "outlined", sx: {
|
|
18
|
+
"& .MuiButton-root": {
|
|
19
|
+
borderColor: "divider",
|
|
20
|
+
minWidth: 0,
|
|
21
|
+
bgcolor: "action.hover",
|
|
22
|
+
"&:not(.Mui-disabled)": {
|
|
23
|
+
color: "text.primary"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}, children: props.children })), children: [_jsxs(BaseNumberField.ScrubArea, { render: _jsx(Box, { component: "span", sx: { userSelect: "none", width: "max-content" } }), children: [_jsx(FormLabel, { htmlFor: id, sx: {
|
|
27
|
+
display: "inline-block",
|
|
28
|
+
cursor: "ew-resize",
|
|
29
|
+
fontSize: "0.875rem",
|
|
30
|
+
color: "text.primary",
|
|
31
|
+
fontWeight: 500,
|
|
32
|
+
lineHeight: 1.5,
|
|
33
|
+
mb: 0.5
|
|
34
|
+
}, children: label }), _jsx(BaseNumberField.ScrubAreaCursor, { children: _jsx(OpenInFullIcon, { fontSize: "small", sx: { transform: "translateY(12.5%) rotate(45deg)" } }) })] }), _jsxs(Box, { sx: { display: "flex" }, children: [_jsx(BaseNumberField.Decrement, { render: _jsx(Button, { variant: "outlined", "aria-label": "Decrease", size: size, sx: {
|
|
35
|
+
borderTopRightRadius: 0,
|
|
36
|
+
borderBottomRightRadius: 0,
|
|
37
|
+
borderRight: "0px",
|
|
38
|
+
"&.Mui-disabled": {
|
|
39
|
+
borderRight: "0px"
|
|
40
|
+
}
|
|
41
|
+
} }), children: _jsx(RemoveIcon, { fontSize: size }) }), _jsx(BaseNumberField.Input, { id: id, render: (props, state) => (_jsx(OutlinedInput, { inputRef: props.ref, value: state.inputValue, onBlur: props.onBlur, onChange: props.onChange, onKeyUp: props.onKeyUp, onKeyDown: props.onKeyDown, onFocus: props.onFocus, slotProps: {
|
|
42
|
+
input: {
|
|
43
|
+
...props,
|
|
44
|
+
size: Math.max((other.min?.toString() || "").length, state.inputValue.length || 1) + 1,
|
|
45
|
+
sx: {
|
|
46
|
+
textAlign: "center"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, sx: { pr: 0, borderRadius: 0, flex: 1 } })) }), _jsx(BaseNumberField.Increment, { render: _jsx(Button, { variant: "outlined", "aria-label": "Increase", size: size, sx: {
|
|
50
|
+
borderTopLeftRadius: 0,
|
|
51
|
+
borderBottomLeftRadius: 0,
|
|
52
|
+
borderLeft: "0px",
|
|
53
|
+
"&.Mui-disabled": {
|
|
54
|
+
borderLeft: "0px"
|
|
55
|
+
}
|
|
56
|
+
} }), children: _jsx(AddIcon, { fontSize: size }) })] })] }));
|
|
57
|
+
}
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -94,7 +94,9 @@ export * from "./MUGlobal";
|
|
|
94
94
|
export * from "./MUUtils";
|
|
95
95
|
export * from "./NotifierMU";
|
|
96
96
|
export * from "./NotifierPopupProps";
|
|
97
|
+
export * from "./NumberField";
|
|
97
98
|
export * from "./NumberInputField";
|
|
99
|
+
export * from "./NumberSpinner";
|
|
98
100
|
export * from "./OptionBool";
|
|
99
101
|
export * from "./OptionGroup";
|
|
100
102
|
export * from "./OptionGroupFlag";
|
package/lib/mjs/index.js
CHANGED
|
@@ -94,7 +94,9 @@ export * from "./MUGlobal";
|
|
|
94
94
|
export * from "./MUUtils";
|
|
95
95
|
export * from "./NotifierMU";
|
|
96
96
|
export * from "./NotifierPopupProps";
|
|
97
|
+
export * from "./NumberField";
|
|
97
98
|
export * from "./NumberInputField";
|
|
99
|
+
export * from "./NumberSpinner";
|
|
98
100
|
export * from "./OptionBool";
|
|
99
101
|
export * from "./OptionGroup";
|
|
100
102
|
export * from "./OptionGroupFlag";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/materialui",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.28",
|
|
4
4
|
"description": "TypeScript Material-UI Implementation",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/ETSOO/ReactMU#readme",
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@base-ui/react": "^1.2.0",
|
|
39
40
|
"@dnd-kit/react": "^0.3.2",
|
|
40
41
|
"@emotion/react": "^11.14.0",
|
|
41
42
|
"@emotion/styled": "^11.14.1",
|
|
@@ -0,0 +1,113 @@
|
|
|
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 FormControl from "@mui/material/FormControl";
|
|
5
|
+
import FormHelperText from "@mui/material/FormHelperText";
|
|
6
|
+
import OutlinedInput from "@mui/material/OutlinedInput";
|
|
7
|
+
import InputAdornment from "@mui/material/InputAdornment";
|
|
8
|
+
import InputLabel from "@mui/material/InputLabel";
|
|
9
|
+
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";
|
|
10
|
+
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This component is a placeholder for FormControl to correctly set the shrink label state on SSR.
|
|
14
|
+
*/
|
|
15
|
+
function SSRInitialFilled(_: BaseNumberField.Root.Props) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
SSRInitialFilled.muiName = "Input";
|
|
19
|
+
|
|
20
|
+
export default function NumberField({
|
|
21
|
+
id: idProp,
|
|
22
|
+
label,
|
|
23
|
+
error,
|
|
24
|
+
size = "medium",
|
|
25
|
+
...other
|
|
26
|
+
}: BaseNumberField.Root.Props & {
|
|
27
|
+
label?: React.ReactNode;
|
|
28
|
+
size?: "small" | "medium";
|
|
29
|
+
error?: boolean;
|
|
30
|
+
}) {
|
|
31
|
+
let id = React.useId();
|
|
32
|
+
if (idProp) {
|
|
33
|
+
id = idProp;
|
|
34
|
+
}
|
|
35
|
+
return (
|
|
36
|
+
<BaseNumberField.Root
|
|
37
|
+
{...other}
|
|
38
|
+
render={(props, state) => (
|
|
39
|
+
<FormControl
|
|
40
|
+
size={size}
|
|
41
|
+
ref={props.ref}
|
|
42
|
+
disabled={state.disabled}
|
|
43
|
+
required={state.required}
|
|
44
|
+
error={error}
|
|
45
|
+
variant="outlined"
|
|
46
|
+
>
|
|
47
|
+
{props.children}
|
|
48
|
+
</FormControl>
|
|
49
|
+
)}
|
|
50
|
+
>
|
|
51
|
+
<SSRInitialFilled {...other} />
|
|
52
|
+
<InputLabel htmlFor={id}>{label}</InputLabel>
|
|
53
|
+
<BaseNumberField.Input
|
|
54
|
+
id={id}
|
|
55
|
+
render={(props, state) => (
|
|
56
|
+
<OutlinedInput
|
|
57
|
+
label={label}
|
|
58
|
+
inputRef={props.ref}
|
|
59
|
+
value={state.inputValue}
|
|
60
|
+
onBlur={props.onBlur}
|
|
61
|
+
onChange={props.onChange}
|
|
62
|
+
onKeyUp={props.onKeyUp}
|
|
63
|
+
onKeyDown={props.onKeyDown}
|
|
64
|
+
onFocus={props.onFocus}
|
|
65
|
+
slotProps={{
|
|
66
|
+
input: props
|
|
67
|
+
}}
|
|
68
|
+
endAdornment={
|
|
69
|
+
<InputAdornment
|
|
70
|
+
position="end"
|
|
71
|
+
sx={{
|
|
72
|
+
flexDirection: "column",
|
|
73
|
+
maxHeight: "unset",
|
|
74
|
+
alignSelf: "stretch",
|
|
75
|
+
borderLeft: "1px solid",
|
|
76
|
+
borderColor: "divider",
|
|
77
|
+
ml: 0,
|
|
78
|
+
"& button": {
|
|
79
|
+
py: 0,
|
|
80
|
+
flex: 1,
|
|
81
|
+
borderRadius: 0.5
|
|
82
|
+
}
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
<BaseNumberField.Increment
|
|
86
|
+
render={<IconButton size={size} aria-label="Increase" />}
|
|
87
|
+
>
|
|
88
|
+
<KeyboardArrowUpIcon
|
|
89
|
+
fontSize={size}
|
|
90
|
+
sx={{ transform: "translateY(2px)" }}
|
|
91
|
+
/>
|
|
92
|
+
</BaseNumberField.Increment>
|
|
93
|
+
|
|
94
|
+
<BaseNumberField.Decrement
|
|
95
|
+
render={<IconButton size={size} aria-label="Decrease" />}
|
|
96
|
+
>
|
|
97
|
+
<KeyboardArrowDownIcon
|
|
98
|
+
fontSize={size}
|
|
99
|
+
sx={{ transform: "translateY(-2px)" }}
|
|
100
|
+
/>
|
|
101
|
+
</BaseNumberField.Decrement>
|
|
102
|
+
</InputAdornment>
|
|
103
|
+
}
|
|
104
|
+
sx={{ pr: 0 }}
|
|
105
|
+
/>
|
|
106
|
+
)}
|
|
107
|
+
/>
|
|
108
|
+
<FormHelperText sx={{ ml: 0, "&:empty": { mt: 0 } }}>
|
|
109
|
+
Enter value between 10 and 40
|
|
110
|
+
</FormHelperText>
|
|
111
|
+
</BaseNumberField.Root>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { NumberField as BaseNumberField } from "@base-ui/react/number-field";
|
|
3
|
+
import Box from "@mui/material/Box";
|
|
4
|
+
import Button from "@mui/material/Button";
|
|
5
|
+
import FormControl from "@mui/material/FormControl";
|
|
6
|
+
import FormLabel from "@mui/material/FormLabel";
|
|
7
|
+
import AddIcon from "@mui/icons-material/Add";
|
|
8
|
+
import RemoveIcon from "@mui/icons-material/Remove";
|
|
9
|
+
import OutlinedInput from "@mui/material/OutlinedInput";
|
|
10
|
+
import OpenInFullIcon from "@mui/icons-material/OpenInFull";
|
|
11
|
+
|
|
12
|
+
export default function NumberSpinner({
|
|
13
|
+
id: idProp,
|
|
14
|
+
label,
|
|
15
|
+
error,
|
|
16
|
+
size = "medium",
|
|
17
|
+
...other
|
|
18
|
+
}: BaseNumberField.Root.Props & {
|
|
19
|
+
label?: React.ReactNode;
|
|
20
|
+
size?: "small" | "medium";
|
|
21
|
+
error?: boolean;
|
|
22
|
+
}) {
|
|
23
|
+
let id = React.useId();
|
|
24
|
+
if (idProp) {
|
|
25
|
+
id = idProp;
|
|
26
|
+
}
|
|
27
|
+
return (
|
|
28
|
+
<BaseNumberField.Root
|
|
29
|
+
{...other}
|
|
30
|
+
render={(props, state) => (
|
|
31
|
+
<FormControl
|
|
32
|
+
size={size}
|
|
33
|
+
ref={props.ref}
|
|
34
|
+
disabled={state.disabled}
|
|
35
|
+
required={state.required}
|
|
36
|
+
error={error}
|
|
37
|
+
variant="outlined"
|
|
38
|
+
sx={{
|
|
39
|
+
"& .MuiButton-root": {
|
|
40
|
+
borderColor: "divider",
|
|
41
|
+
minWidth: 0,
|
|
42
|
+
bgcolor: "action.hover",
|
|
43
|
+
"&:not(.Mui-disabled)": {
|
|
44
|
+
color: "text.primary"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
{props.children}
|
|
50
|
+
</FormControl>
|
|
51
|
+
)}
|
|
52
|
+
>
|
|
53
|
+
<BaseNumberField.ScrubArea
|
|
54
|
+
render={
|
|
55
|
+
<Box
|
|
56
|
+
component="span"
|
|
57
|
+
sx={{ userSelect: "none", width: "max-content" }}
|
|
58
|
+
/>
|
|
59
|
+
}
|
|
60
|
+
>
|
|
61
|
+
<FormLabel
|
|
62
|
+
htmlFor={id}
|
|
63
|
+
sx={{
|
|
64
|
+
display: "inline-block",
|
|
65
|
+
cursor: "ew-resize",
|
|
66
|
+
fontSize: "0.875rem",
|
|
67
|
+
color: "text.primary",
|
|
68
|
+
fontWeight: 500,
|
|
69
|
+
lineHeight: 1.5,
|
|
70
|
+
mb: 0.5
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
{label}
|
|
74
|
+
</FormLabel>
|
|
75
|
+
<BaseNumberField.ScrubAreaCursor>
|
|
76
|
+
<OpenInFullIcon
|
|
77
|
+
fontSize="small"
|
|
78
|
+
sx={{ transform: "translateY(12.5%) rotate(45deg)" }}
|
|
79
|
+
/>
|
|
80
|
+
</BaseNumberField.ScrubAreaCursor>
|
|
81
|
+
</BaseNumberField.ScrubArea>
|
|
82
|
+
<Box sx={{ display: "flex" }}>
|
|
83
|
+
<BaseNumberField.Decrement
|
|
84
|
+
render={
|
|
85
|
+
<Button
|
|
86
|
+
variant="outlined"
|
|
87
|
+
aria-label="Decrease"
|
|
88
|
+
size={size}
|
|
89
|
+
sx={{
|
|
90
|
+
borderTopRightRadius: 0,
|
|
91
|
+
borderBottomRightRadius: 0,
|
|
92
|
+
borderRight: "0px",
|
|
93
|
+
"&.Mui-disabled": {
|
|
94
|
+
borderRight: "0px"
|
|
95
|
+
}
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
}
|
|
99
|
+
>
|
|
100
|
+
<RemoveIcon fontSize={size} />
|
|
101
|
+
</BaseNumberField.Decrement>
|
|
102
|
+
|
|
103
|
+
<BaseNumberField.Input
|
|
104
|
+
id={id}
|
|
105
|
+
render={(props, state) => (
|
|
106
|
+
<OutlinedInput
|
|
107
|
+
inputRef={props.ref}
|
|
108
|
+
value={state.inputValue}
|
|
109
|
+
onBlur={props.onBlur}
|
|
110
|
+
onChange={props.onChange}
|
|
111
|
+
onKeyUp={props.onKeyUp}
|
|
112
|
+
onKeyDown={props.onKeyDown}
|
|
113
|
+
onFocus={props.onFocus}
|
|
114
|
+
slotProps={{
|
|
115
|
+
input: {
|
|
116
|
+
...props,
|
|
117
|
+
size:
|
|
118
|
+
Math.max(
|
|
119
|
+
(other.min?.toString() || "").length,
|
|
120
|
+
state.inputValue.length || 1
|
|
121
|
+
) + 1,
|
|
122
|
+
sx: {
|
|
123
|
+
textAlign: "center"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}}
|
|
127
|
+
sx={{ pr: 0, borderRadius: 0, flex: 1 }}
|
|
128
|
+
/>
|
|
129
|
+
)}
|
|
130
|
+
/>
|
|
131
|
+
|
|
132
|
+
<BaseNumberField.Increment
|
|
133
|
+
render={
|
|
134
|
+
<Button
|
|
135
|
+
variant="outlined"
|
|
136
|
+
aria-label="Increase"
|
|
137
|
+
size={size}
|
|
138
|
+
sx={{
|
|
139
|
+
borderTopLeftRadius: 0,
|
|
140
|
+
borderBottomLeftRadius: 0,
|
|
141
|
+
borderLeft: "0px",
|
|
142
|
+
"&.Mui-disabled": {
|
|
143
|
+
borderLeft: "0px"
|
|
144
|
+
}
|
|
145
|
+
}}
|
|
146
|
+
/>
|
|
147
|
+
}
|
|
148
|
+
>
|
|
149
|
+
<AddIcon fontSize={size} />
|
|
150
|
+
</BaseNumberField.Increment>
|
|
151
|
+
</Box>
|
|
152
|
+
</BaseNumberField.Root>
|
|
153
|
+
);
|
|
154
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -100,7 +100,9 @@ export * from "./MUGlobal";
|
|
|
100
100
|
export * from "./MUUtils";
|
|
101
101
|
export * from "./NotifierMU";
|
|
102
102
|
export * from "./NotifierPopupProps";
|
|
103
|
+
export * from "./NumberField";
|
|
103
104
|
export * from "./NumberInputField";
|
|
105
|
+
export * from "./NumberSpinner";
|
|
104
106
|
export * from "./OptionBool";
|
|
105
107
|
export * from "./OptionGroup";
|
|
106
108
|
export * from "./OptionGroupFlag";
|