mui-fast-start 0.3.2 → 0.3.3

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.
Files changed (62) hide show
  1. package/README.md +403 -403
  2. package/README_KR.md +403 -403
  3. package/dist/components/Object/Select/ObjSelectRecord.d.ts +2 -1
  4. package/dist/components/Object/Select/ObjSelectRecord.d.ts.map +1 -1
  5. package/dist/components/Single/Select/SingleSelectRecord.d.ts +2 -1
  6. package/dist/components/Single/Select/SingleSelectRecord.d.ts.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/styles/FastStartProps.d.ts +2 -1
  9. package/dist/styles/FastStartProps.d.ts.map +1 -1
  10. package/dist/types/props.d.ts +1 -1
  11. package/dist/types/props.d.ts.map +1 -1
  12. package/dist/types/provider.d.ts +2 -1
  13. package/dist/types/provider.d.ts.map +1 -1
  14. package/examples/basic/README.md +73 -73
  15. package/examples/basic/eslint.config.js +23 -23
  16. package/examples/basic/index.html +13 -13
  17. package/examples/basic/package.json +37 -37
  18. package/examples/basic/src/App.css +4 -4
  19. package/examples/basic/src/App.tsx +28 -28
  20. package/examples/basic/src/index.css +29 -29
  21. package/examples/basic/src/main.tsx +50 -50
  22. package/examples/basic/src/pages/ObjPage.tsx +175 -175
  23. package/examples/basic/src/pages/SinglePage.tsx +137 -137
  24. package/examples/basic/tsconfig.app.json +43 -43
  25. package/examples/basic/tsconfig.json +7 -7
  26. package/examples/basic/tsconfig.node.json +40 -40
  27. package/examples/basic/vite.config.ts +28 -28
  28. package/mui-fast-start-0.1.4.tgz +0 -0
  29. package/package.json +67 -67
  30. package/src/components/Object/Checkbox/ObjCheckIcon.tsx +29 -29
  31. package/src/components/Object/Checkbox/ObjCheckbox.tsx +31 -31
  32. package/src/components/Object/Select/ObjSelectOne.tsx +33 -33
  33. package/src/components/Object/Select/ObjSelectRecord.tsx +33 -33
  34. package/src/components/Object/Textfield/ObjNumber.tsx +51 -51
  35. package/src/components/Object/Textfield/ObjText.tsx +29 -29
  36. package/src/components/Single/Checkbox/SingleCheckIcon.tsx +27 -27
  37. package/src/components/Single/Checkbox/SingleCheckbox.tsx +33 -33
  38. package/src/components/Single/Select/BaseSingleSelect.tsx +45 -45
  39. package/src/components/Single/Select/SingleSelectOne.tsx +56 -56
  40. package/src/components/Single/Select/SingleSelectRecord.tsx +51 -51
  41. package/src/components/Single/TextField/SingleNumber.tsx +18 -18
  42. package/src/components/Single/TextField/SingleText.tsx +13 -13
  43. package/src/components/index.ts +15 -15
  44. package/src/hooks/index.ts +3 -3
  45. package/src/hooks/splits/useSplitNumberProps.ts +161 -161
  46. package/src/hooks/splits/useSplitTextProps.ts +36 -36
  47. package/src/hooks/state/useObjToSingle.ts +24 -24
  48. package/src/index.ts +7 -7
  49. package/src/styles/FastStartProps.ts +82 -81
  50. package/src/styles/FastStartProvider.tsx +25 -25
  51. package/src/types/index.ts +3 -3
  52. package/src/types/props.internal.ts +21 -21
  53. package/src/types/props.ts +81 -81
  54. package/src/types/provider.ts +72 -71
  55. package/src/types/types.ts +9 -9
  56. package/src/utils/index.ts +2 -2
  57. package/src/utils/number/calculate.ts +102 -102
  58. package/src/utils/object/error.ts +15 -15
  59. package/src/utils/object/merge.ts +47 -47
  60. package/tsconfig.json +34 -34
  61. package/tsconfig.lib.json +9 -9
  62. package/vite.config.ts +35 -35
@@ -1,51 +1,51 @@
1
- import {useContext} from "react";
2
- import useObjToSingle from "../../../hooks/state/useObjToSingle.ts";
3
- import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
4
- import {errorObjectToString} from "../../../utils/object/error.ts";
5
- import {SingleFloat, SingleInteger} from "../../Single/TextField/SingleNumber.tsx";
6
- import {MfsObjectNumberProps} from "../../../types";
7
- import {TextFieldProps} from "@mui/material";
8
-
9
- type ObjNumberProps<T extends object> = Omit<TextFieldProps, 'name'> & MfsObjectNumberProps<T>;
10
-
11
- export const ObjFloat = <T extends object>(customProps: ObjNumberProps<T>) => {
12
- const defaultProps = useContext(FastStartContext)?.Object?.MfsFloat;
13
- const {
14
- get, set, err, name,
15
- ...props
16
- } = defaultProps == null
17
- ? customProps
18
- : Object.assign({...defaultProps}, customProps);
19
-
20
- const [value, setValue] = useObjToSingle<T, number>(name, get, set);
21
-
22
- return (
23
- <SingleFloat
24
- get={value} set={setValue}
25
- name={name?.toString()}
26
- err={errorObjectToString(name, err)}
27
- {...props}
28
- />
29
- )
30
- }
31
-
32
- export const ObjInteger = <T extends object>(customProps: ObjNumberProps<T>) => {
33
- const defaultProps = useContext(FastStartContext)?.Object?.MfsInteger;
34
- const {
35
- get, set, err, name,
36
- ...props
37
- } = defaultProps == null
38
- ? customProps
39
- : Object.assign({...defaultProps}, customProps);
40
-
41
- const [value, setValue] = useObjToSingle<T, number>(name, get, set);
42
-
43
- return (
44
- <SingleInteger
45
- get={value} set={setValue}
46
- name={name?.toString()}
47
- err={errorObjectToString(name, err)}
48
- {...props}
49
- />
50
- )
51
- }
1
+ import {useContext} from "react";
2
+ import useObjToSingle from "../../../hooks/state/useObjToSingle.ts";
3
+ import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
4
+ import {errorObjectToString} from "../../../utils/object/error.ts";
5
+ import {SingleFloat, SingleInteger} from "../../Single/TextField/SingleNumber.tsx";
6
+ import {MfsObjectNumberProps} from "../../../types";
7
+ import {TextFieldProps} from "@mui/material";
8
+
9
+ type ObjNumberProps<T extends object> = Omit<TextFieldProps, 'name'> & MfsObjectNumberProps<T>;
10
+
11
+ export const ObjFloat = <T extends object>(customProps: ObjNumberProps<T>) => {
12
+ const defaultProps = useContext(FastStartContext)?.Object?.MfsFloat;
13
+ const {
14
+ get, set, err, name,
15
+ ...props
16
+ } = defaultProps == null
17
+ ? customProps
18
+ : Object.assign({...defaultProps}, customProps);
19
+
20
+ const [value, setValue] = useObjToSingle<T, number>(name, get, set);
21
+
22
+ return (
23
+ <SingleFloat
24
+ get={value} set={setValue}
25
+ name={name?.toString()}
26
+ err={errorObjectToString(name, err)}
27
+ {...props}
28
+ />
29
+ )
30
+ }
31
+
32
+ export const ObjInteger = <T extends object>(customProps: ObjNumberProps<T>) => {
33
+ const defaultProps = useContext(FastStartContext)?.Object?.MfsInteger;
34
+ const {
35
+ get, set, err, name,
36
+ ...props
37
+ } = defaultProps == null
38
+ ? customProps
39
+ : Object.assign({...defaultProps}, customProps);
40
+
41
+ const [value, setValue] = useObjToSingle<T, number>(name, get, set);
42
+
43
+ return (
44
+ <SingleInteger
45
+ get={value} set={setValue}
46
+ name={name?.toString()}
47
+ err={errorObjectToString(name, err)}
48
+ {...props}
49
+ />
50
+ )
51
+ }
@@ -1,29 +1,29 @@
1
- import {useContext} from "react";
2
- import {MfsObjectTextProps} from "../../../types";
3
- import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
4
- import useObjToSingle from "../../../hooks/state/useObjToSingle.ts";
5
- import {SingleText} from "../../Single/TextField/SingleText.tsx";
6
- import {errorObjectToString} from "../../../utils/object/error.ts";
7
- import {TextFieldProps} from "@mui/material";
8
-
9
-
10
- export const ObjText = <T extends object>(
11
- customProps: Omit<TextFieldProps, 'name'> & MfsObjectTextProps<T>
12
- ) => {
13
- const defaultProps = useContext(FastStartContext)?.Object?.MfsText;
14
- const {
15
- get, set, err, name,
16
- ...props
17
- } = defaultProps == null ? customProps : Object.assign({...defaultProps}, customProps);
18
-
19
- const [value, setValue] = useObjToSingle<T, string>(name, get, set);
20
-
21
- return (
22
- <SingleText
23
- get={value} set={setValue}
24
- name={name?.toString()}
25
- err={errorObjectToString(name, err)}
26
- {...props}
27
- />
28
- );
29
- };
1
+ import {useContext} from "react";
2
+ import {MfsObjectTextProps} from "../../../types";
3
+ import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
4
+ import useObjToSingle from "../../../hooks/state/useObjToSingle.ts";
5
+ import {SingleText} from "../../Single/TextField/SingleText.tsx";
6
+ import {errorObjectToString} from "../../../utils/object/error.ts";
7
+ import {TextFieldProps} from "@mui/material";
8
+
9
+
10
+ export const ObjText = <T extends object>(
11
+ customProps: Omit<TextFieldProps, 'name'> & MfsObjectTextProps<T>
12
+ ) => {
13
+ const defaultProps = useContext(FastStartContext)?.Object?.MfsText;
14
+ const {
15
+ get, set, err, name,
16
+ ...props
17
+ } = defaultProps == null ? customProps : Object.assign({...defaultProps}, customProps);
18
+
19
+ const [value, setValue] = useObjToSingle<T, string>(name, get, set);
20
+
21
+ return (
22
+ <SingleText
23
+ get={value} set={setValue}
24
+ name={name?.toString()}
25
+ err={errorObjectToString(name, err)}
26
+ {...props}
27
+ />
28
+ );
29
+ };
@@ -1,27 +1,27 @@
1
- import {useCallback, useContext} from "react";
2
- import {IconButton, IconButtonProps} from "@mui/material";
3
- import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
4
- import {MfsSingleCheckIconProps} from "../../../types";
5
-
6
- export type SingleCheckIconProps = IconButtonProps & MfsSingleCheckIconProps;
7
-
8
- export const SingleCheckIcon = (customProps: SingleCheckIconProps) => {
9
- const defaultProps = useContext(FastStartContext)?.Single?.MfsCheckIcon;
10
- const {
11
- get, set, on, off,
12
- ...props
13
- } = defaultProps == null
14
- ? customProps
15
- : Object.assign({...defaultProps}, customProps);
16
-
17
- const onClick = useCallback(() => set((state) => !state), [set]);
18
-
19
- return (
20
- <IconButton
21
- onClick={onClick}
22
- {...props}
23
- >
24
- {get ? on : off}
25
- </IconButton>
26
- )
27
- }
1
+ import {useCallback, useContext} from "react";
2
+ import {IconButton, IconButtonProps} from "@mui/material";
3
+ import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
4
+ import {MfsSingleCheckIconProps} from "../../../types";
5
+
6
+ export type SingleCheckIconProps = IconButtonProps & MfsSingleCheckIconProps;
7
+
8
+ export const SingleCheckIcon = (customProps: SingleCheckIconProps) => {
9
+ const defaultProps = useContext(FastStartContext)?.Single?.MfsCheckIcon;
10
+ const {
11
+ get, set, on, off,
12
+ ...props
13
+ } = defaultProps == null
14
+ ? customProps
15
+ : Object.assign({...defaultProps}, customProps);
16
+
17
+ const onClick = useCallback(() => set((state) => !state), [set]);
18
+
19
+ return (
20
+ <IconButton
21
+ onClick={onClick}
22
+ {...props}
23
+ >
24
+ {get ? on : off}
25
+ </IconButton>
26
+ )
27
+ }
@@ -1,33 +1,33 @@
1
- import {Checkbox, CheckboxProps, FormControlLabel} from "@mui/material";
2
- import React, {useCallback, useContext} from "react";
3
- import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
4
- import {MfsSingleCheckboxProps} from "../../../types";
5
-
6
- export type SingleCheckboxProps = CheckboxProps & MfsSingleCheckboxProps;
7
-
8
- export const SingleCheckbox = (customProps: SingleCheckboxProps) => {
9
- const defaultProps = useContext(FastStartContext)?.Single?.MfsCheckbox;
10
- const {
11
- get, set, label,
12
- ...props
13
- } = defaultProps == null
14
- ? customProps
15
- : Object.assign({...defaultProps}, customProps);
16
-
17
- const onChange = useCallback(() => set((state) => !state), [set]);
18
-
19
- return label == null ? (
20
- <Checkbox
21
- checked={get}
22
- onChange={onChange}
23
- {...props}
24
- />
25
- ) : (
26
- <FormControlLabel
27
- checked={get}
28
- label={label}
29
- onChange={onChange}
30
- control={<Checkbox {...props}/>}
31
- />
32
- );
33
- };
1
+ import {Checkbox, CheckboxProps, FormControlLabel} from "@mui/material";
2
+ import React, {useCallback, useContext} from "react";
3
+ import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
4
+ import {MfsSingleCheckboxProps} from "../../../types";
5
+
6
+ export type SingleCheckboxProps = CheckboxProps & MfsSingleCheckboxProps;
7
+
8
+ export const SingleCheckbox = (customProps: SingleCheckboxProps) => {
9
+ const defaultProps = useContext(FastStartContext)?.Single?.MfsCheckbox;
10
+ const {
11
+ get, set, label,
12
+ ...props
13
+ } = defaultProps == null
14
+ ? customProps
15
+ : Object.assign({...defaultProps}, customProps);
16
+
17
+ const onChange = useCallback(() => set((state) => !state), [set]);
18
+
19
+ return label == null ? (
20
+ <Checkbox
21
+ checked={get}
22
+ onChange={onChange}
23
+ {...props}
24
+ />
25
+ ) : (
26
+ <FormControlLabel
27
+ checked={get}
28
+ label={label}
29
+ onChange={onChange}
30
+ control={<Checkbox {...props}/>}
31
+ />
32
+ );
33
+ };
@@ -1,46 +1,46 @@
1
- import {FormControl, FormHelperText, InputLabel, MenuItem, Select, SelectProps} from "@mui/material";
2
- import React, {useId} from "react";
3
- import {MfsSingleError} from "../../../types/props.internal.ts";
4
-
5
- const BaseSingleSelect = <Value,>(props: {
6
- emptyItem?: React.ReactNode,
7
- label?: React.ReactNode,
8
- err: MfsSingleError,
9
- items: React.ReactNode,
10
- get: Value,
11
- onChange: SelectProps['onChange'],
12
- selectProps: SelectProps
13
- }) => {
14
- const {emptyItem, label, selectProps} = props;
15
- const labelId = useId();
16
-
17
- const isError: boolean = !!props.err;
18
- return (
19
- <FormControl
20
- error={isError}
21
- fullWidth={selectProps.fullWidth}
22
- variant={selectProps.variant}
23
- size={selectProps.size}
24
- sx={selectProps.sx}
25
- disabled={selectProps.disabled}
26
- required={selectProps.required}
27
- margin={selectProps.margin}
28
- >
29
- {label && <InputLabel id={labelId}>{label}</InputLabel>}
30
- <Select
31
- labelId={labelId}
32
- error={isError}
33
- label={label}
34
- value={props.get ?? ''}
35
- onChange={props.onChange}
36
- {...selectProps}
37
- >
38
- {emptyItem && <MenuItem key='' value=''>{emptyItem}</MenuItem>}
39
- {props.items}
40
- </Select>
41
- {isError && <FormHelperText>{props.err}</FormHelperText>}
42
- </FormControl>
43
- )
44
- }
45
-
1
+ import {FormControl, FormHelperText, InputLabel, MenuItem, Select, SelectProps} from "@mui/material";
2
+ import React, {useId} from "react";
3
+ import {MfsSingleError} from "../../../types/props.internal.ts";
4
+
5
+ const BaseSingleSelect = <Value,>(props: {
6
+ emptyItem?: React.ReactNode,
7
+ label?: React.ReactNode,
8
+ err: MfsSingleError,
9
+ items: React.ReactNode,
10
+ get: Value,
11
+ onChange: SelectProps['onChange'],
12
+ selectProps: SelectProps
13
+ }) => {
14
+ const {emptyItem, label, selectProps} = props;
15
+ const labelId = useId();
16
+
17
+ const isError: boolean = !!props.err;
18
+ return (
19
+ <FormControl
20
+ error={isError}
21
+ fullWidth={selectProps.fullWidth}
22
+ variant={selectProps.variant}
23
+ size={selectProps.size}
24
+ sx={selectProps.sx}
25
+ disabled={selectProps.disabled}
26
+ required={selectProps.required}
27
+ margin={selectProps.margin}
28
+ >
29
+ {label && <InputLabel id={labelId}>{label}</InputLabel>}
30
+ <Select
31
+ labelId={labelId}
32
+ error={isError}
33
+ label={label}
34
+ value={props.get ?? ''}
35
+ onChange={props.onChange}
36
+ {...selectProps}
37
+ >
38
+ {emptyItem && <MenuItem key='' value=''>{emptyItem}</MenuItem>}
39
+ {props.items}
40
+ </Select>
41
+ {isError && <FormHelperText>{props.err}</FormHelperText>}
42
+ </FormControl>
43
+ )
44
+ }
45
+
46
46
  export default BaseSingleSelect;
@@ -1,56 +1,56 @@
1
- import {MenuItem, SelectProps} from "@mui/material";
2
- import {MfsSingleSelectOneProps} from "../../../types";
3
- import React, {useContext, useMemo} from "react";
4
- import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
5
- import BaseSingleSelect from "./BaseSingleSelect.tsx";
6
-
7
- export type SingleSelectOneProps<Item> = SelectProps & MfsSingleSelectOneProps<Item>;
8
-
9
- export const SingleSelectOne = <Item,>(customProps: SingleSelectOneProps<Item>) => {
10
- const defaultProps = useContext(FastStartContext)?.Single?.MfsSelectOne;
11
- const {
12
- get, set, err, label,
13
- items, renderMenuItem,
14
- emptyItem, emptyValue,
15
- getKey, ...props
16
- } = defaultProps == null
17
- ? customProps
18
- : Object.assign({...defaultProps}, customProps);
19
-
20
- const getKeyOrValue = useMemo(() => (
21
- getKey ?? ((item: Item) => item as string | number)
22
- ), [getKey]);
23
-
24
- const onChange: SelectProps['onChange'] = (event) => {
25
- const value = event.target.value;
26
- if (getKey == null) {
27
- set((value == "" ? emptyValue : value) as Item);
28
- } else {
29
- const item: Item | undefined = items.find((item: Item) => getKeyOrValue(item) === value);
30
- set(item as Item);
31
- }
32
- }
33
-
34
- const MenuItems = useMemo(() => {
35
- if (renderMenuItem != null) {
36
- return items.map(renderMenuItem);
37
- } else {
38
- return items.map((item) => {
39
- const key = getKeyOrValue(item);
40
- return <MenuItem key={key} value={key}>{key}</MenuItem>;
41
- })
42
- }
43
- }, [getKeyOrValue, items, renderMenuItem]);
44
-
45
- return (
46
- <BaseSingleSelect
47
- label={label}
48
- items={MenuItems}
49
- emptyItem={emptyItem}
50
- get={get}
51
- err={err}
52
- onChange={onChange}
53
- selectProps={props}
54
- />
55
- );
56
- }
1
+ import {MenuItem, SelectProps} from "@mui/material";
2
+ import {MfsSingleSelectOneProps} from "../../../types";
3
+ import React, {useContext, useMemo} from "react";
4
+ import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
5
+ import BaseSingleSelect from "./BaseSingleSelect.tsx";
6
+
7
+ export type SingleSelectOneProps<Item> = SelectProps & MfsSingleSelectOneProps<Item>;
8
+
9
+ export const SingleSelectOne = <Item,>(customProps: SingleSelectOneProps<Item>) => {
10
+ const defaultProps = useContext(FastStartContext)?.Single?.MfsSelectOne;
11
+ const {
12
+ get, set, err, label,
13
+ items, renderMenuItem,
14
+ emptyItem, emptyValue,
15
+ getKey, ...props
16
+ } = defaultProps == null
17
+ ? customProps
18
+ : Object.assign({...defaultProps}, customProps);
19
+
20
+ const getKeyOrValue = useMemo(() => (
21
+ getKey ?? ((item: Item) => item as string | number)
22
+ ), [getKey]);
23
+
24
+ const onChange: SelectProps['onChange'] = (event) => {
25
+ const value = event.target.value;
26
+ if (getKey == null) {
27
+ set((value == "" ? emptyValue : value) as Item);
28
+ } else {
29
+ const item: Item | undefined = items.find((item: Item) => getKeyOrValue(item) === value);
30
+ set(item as Item);
31
+ }
32
+ }
33
+
34
+ const MenuItems = useMemo(() => {
35
+ if (renderMenuItem != null) {
36
+ return items.map(renderMenuItem);
37
+ } else {
38
+ return items.map((item) => {
39
+ const key = getKeyOrValue(item);
40
+ return <MenuItem key={key} value={key}>{key}</MenuItem>;
41
+ })
42
+ }
43
+ }, [getKeyOrValue, items, renderMenuItem]);
44
+
45
+ return (
46
+ <BaseSingleSelect
47
+ label={label}
48
+ items={MenuItems}
49
+ emptyItem={emptyItem}
50
+ get={get}
51
+ err={err}
52
+ onChange={onChange}
53
+ selectProps={props}
54
+ />
55
+ );
56
+ }
@@ -1,52 +1,52 @@
1
- import {MenuItem, SelectProps} from "@mui/material";
2
- import {MfsSingleSelectRecordProps} from "../../../types";
3
- import React, {useContext, useMemo} from "react";
4
- import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
5
- import BaseSingleSelect from "./BaseSingleSelect.tsx";
6
-
7
-
8
- export const SingleSelectRecord = <
9
- T extends Record<string, unknown>,
10
- Value = keyof T | undefined | null
11
- >(customProps: SelectProps & MfsSingleSelectRecordProps<T, Value>) => {
12
- const defaultProps = useContext(FastStartContext)?.Single?.MfsSelectRecord;
13
- const {
14
- get, set, err, label,
15
- items, renderMenuItem,
16
- emptyItem, emptyValue,
17
- ...props
18
- } = defaultProps == null
19
- ? customProps
20
- : Object.assign({...defaultProps}, customProps);
21
-
22
- const onChange: SelectProps['onChange'] = (event) => {
23
- const value = event.target.value;
24
- set((value == "" ? emptyValue : value) as Value);
25
- }
26
-
27
- const MenuItems = useMemo(() => {
28
- if (renderMenuItem != null) {
29
- return Object.entries(items).map(([key, value], i) => (
30
- renderMenuItem(key, value as T[keyof T], i)
31
- ));
32
- } else {
33
- return Object.entries(items).map(([key, value]) => (
34
- <MenuItem key={key} value={key}>
35
- {value?.toString()}
36
- </MenuItem>
37
- ));
38
- }
39
- }, [items, renderMenuItem]);
40
-
41
- return (
42
- <BaseSingleSelect
43
- label={label}
44
- items={MenuItems}
45
- emptyItem={emptyItem}
46
- get={get}
47
- err={err}
48
- onChange={onChange}
49
- selectProps={props}
50
- />
51
- )
1
+ import {MenuItem, SelectProps} from "@mui/material";
2
+ import {MfsSingleSelectRecordProps} from "../../../types";
3
+ import React, {useContext, useMemo} from "react";
4
+ import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
5
+ import BaseSingleSelect from "./BaseSingleSelect.tsx";
6
+
7
+
8
+ export const SingleSelectRecord = <
9
+ T extends Record<string, React.ReactNode>,
10
+ Value = keyof T | undefined | null
11
+ >(customProps: SelectProps & MfsSingleSelectRecordProps<T, Value>) => {
12
+ const defaultProps = useContext(FastStartContext)?.Single?.MfsSelectRecord;
13
+ const {
14
+ get, set, err, label,
15
+ items, renderMenuItem,
16
+ emptyItem, emptyValue,
17
+ ...props
18
+ } = defaultProps == null
19
+ ? customProps
20
+ : Object.assign({...defaultProps}, customProps);
21
+
22
+ const onChange: SelectProps['onChange'] = (event) => {
23
+ const value = event.target.value;
24
+ set((value == "" ? emptyValue : value) as Value);
25
+ }
26
+
27
+ const MenuItems = useMemo(() => {
28
+ if (renderMenuItem != null) {
29
+ return Object.entries(items).map(([key, value], i) => (
30
+ renderMenuItem(key, value as T[keyof T], i)
31
+ ));
32
+ } else {
33
+ return Object.entries(items).map(([key, value]) => (
34
+ <MenuItem key={key} value={key}>
35
+ {value}
36
+ </MenuItem>
37
+ ));
38
+ }
39
+ }, [items, renderMenuItem]);
40
+
41
+ return (
42
+ <BaseSingleSelect
43
+ label={label}
44
+ items={MenuItems}
45
+ emptyItem={emptyItem}
46
+ get={get}
47
+ err={err}
48
+ onChange={onChange}
49
+ selectProps={props}
50
+ />
51
+ )
52
52
  }
@@ -1,19 +1,19 @@
1
- import {useContext} from "react";
2
- import {TextField, TextFieldProps} from "@mui/material";
3
- import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
4
- import {MfsSingleNumberProps} from "../../../types";
5
- import {useSplitSingleFloatProps, useSplitSingleIntegerProps} from "../../../hooks";
6
-
7
- export type SingleNumberProps = TextFieldProps & MfsSingleNumberProps;
8
-
9
- export const SingleFloat = (customProps: SingleNumberProps) => {
10
- const defaultProps = useContext(FastStartContext)?.Single?.MfsFloat;
11
- const props = useSplitSingleFloatProps(defaultProps, customProps);
12
- return <TextField {...props}/>;
13
- }
14
-
15
- export const SingleInteger = (customProps: SingleNumberProps) => {
16
- const defaultProps = useContext(FastStartContext)?.Single?.MfsInteger;
17
- const props = useSplitSingleIntegerProps(defaultProps, customProps);
18
- return <TextField {...props}/>;
1
+ import {useContext} from "react";
2
+ import {TextField, TextFieldProps} from "@mui/material";
3
+ import {FastStartContext} from "../../../styles/FastStartProvider.tsx";
4
+ import {MfsSingleNumberProps} from "../../../types";
5
+ import {useSplitSingleFloatProps, useSplitSingleIntegerProps} from "../../../hooks";
6
+
7
+ export type SingleNumberProps = TextFieldProps & MfsSingleNumberProps;
8
+
9
+ export const SingleFloat = (customProps: SingleNumberProps) => {
10
+ const defaultProps = useContext(FastStartContext)?.Single?.MfsFloat;
11
+ const props = useSplitSingleFloatProps(defaultProps, customProps);
12
+ return <TextField {...props}/>;
13
+ }
14
+
15
+ export const SingleInteger = (customProps: SingleNumberProps) => {
16
+ const defaultProps = useContext(FastStartContext)?.Single?.MfsInteger;
17
+ const props = useSplitSingleIntegerProps(defaultProps, customProps);
18
+ return <TextField {...props}/>;
19
19
  }