@etsoo/materialui 1.1.39 → 1.1.42

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 (42) hide show
  1. package/lib/AuditDisplay.d.ts +5 -5
  2. package/lib/AuditDisplay.js +17 -19
  3. package/lib/BridgeCloseButton.d.ts +2 -2
  4. package/lib/BridgeCloseButton.js +7 -8
  5. package/lib/DataSteps.d.ts +4 -4
  6. package/lib/DataSteps.js +17 -14
  7. package/lib/DataTable.d.ts +33 -0
  8. package/lib/DataTable.js +56 -0
  9. package/lib/ListMoreDisplay.d.ts +5 -5
  10. package/lib/ListMoreDisplay.js +8 -10
  11. package/lib/OptionBool.js +2 -1
  12. package/lib/SelectBool.js +2 -1
  13. package/lib/ShowDataComparison.d.ts +1 -1
  14. package/lib/ShowDataComparison.js +27 -20
  15. package/lib/SwitchAnt.d.ts +3 -3
  16. package/lib/SwitchAnt.js +11 -8
  17. package/lib/SwitchField.d.ts +45 -0
  18. package/lib/SwitchField.js +33 -0
  19. package/lib/Tiplist.js +4 -4
  20. package/lib/UserAvatar.js +7 -8
  21. package/lib/app/ReactApp.d.ts +7 -7
  22. package/lib/app/ReactApp.js +26 -26
  23. package/lib/index.d.ts +2 -0
  24. package/lib/index.js +2 -0
  25. package/lib/pages/ViewPage.d.ts +7 -7
  26. package/lib/pages/ViewPage.js +30 -29
  27. package/package.json +3 -2
  28. package/src/AuditDisplay.tsx +92 -99
  29. package/src/BridgeCloseButton.tsx +48 -50
  30. package/src/DataSteps.tsx +188 -185
  31. package/src/DataTable.tsx +124 -0
  32. package/src/ListMoreDisplay.tsx +184 -188
  33. package/src/OptionBool.tsx +1 -1
  34. package/src/SelectBool.tsx +1 -1
  35. package/src/ShowDataComparison.tsx +88 -76
  36. package/src/SwitchAnt.tsx +82 -78
  37. package/src/SwitchField.tsx +133 -0
  38. package/src/Tiplist.tsx +5 -4
  39. package/src/UserAvatar.tsx +43 -45
  40. package/src/app/ReactApp.ts +485 -489
  41. package/src/index.ts +2 -0
  42. package/src/pages/ViewPage.tsx +272 -277
package/src/SwitchAnt.tsx CHANGED
@@ -1,25 +1,26 @@
1
- import { Stack, Typography } from '@mui/material';
2
- import Switch, { SwitchProps } from '@mui/material/Switch';
3
- import React from 'react';
1
+ import { Stack, Typography } from "@mui/material";
2
+ import Switch, { SwitchProps } from "@mui/material/Switch";
3
+ import React from "react";
4
+ import { globalApp } from "./app/ReactApp";
4
5
 
5
6
  /**
6
7
  * Ant style switch props
7
8
  */
8
9
  export interface SwitchAntProps extends SwitchProps {
9
- /**
10
- * Active color
11
- */
12
- activeColor?: string;
10
+ /**
11
+ * Active color
12
+ */
13
+ activeColor?: string;
13
14
 
14
- /**
15
- * Start label
16
- */
17
- startLabel: string;
15
+ /**
16
+ * Start label
17
+ */
18
+ startLabel?: string;
18
19
 
19
- /**
20
- * End label
21
- */
22
- endLabel: string;
20
+ /**
21
+ * End label
22
+ */
23
+ endLabel?: string;
23
24
  }
24
25
 
25
26
  /**
@@ -28,72 +29,75 @@ export interface SwitchAntProps extends SwitchProps {
28
29
  * @returns Component
29
30
  */
30
31
  export function SwitchAnt(props: SwitchAntProps) {
31
- // Destruct
32
- const {
33
- activeColor,
34
- checked,
35
- defaultChecked,
36
- defaultValue,
37
- endLabel,
38
- startLabel,
39
- onChange,
40
- value = 'true',
41
- ...rest
42
- } = props;
32
+ // Labels
33
+ const { yes = "Yes", no = "No" } = globalApp?.getLabels("yes", "no") ?? {};
43
34
 
44
- // Checked state
45
- const [controlChecked, setControlChecked] = React.useState(
46
- checked ?? defaultChecked ?? defaultValue == value
47
- );
35
+ // Destruct
36
+ const {
37
+ activeColor,
38
+ checked,
39
+ defaultChecked,
40
+ defaultValue,
41
+ endLabel = yes,
42
+ startLabel = no,
43
+ onChange,
44
+ value = "true",
45
+ ...rest
46
+ } = props;
48
47
 
49
- // Ref
50
- const ref = React.useRef<HTMLButtonElement>(null);
48
+ // Checked state
49
+ const [controlChecked, setControlChecked] = React.useState(
50
+ checked ?? defaultChecked ?? defaultValue == value
51
+ );
51
52
 
52
- React.useEffect(() => {
53
- if (checked) setControlChecked(checked);
54
- }, [checked]);
53
+ // Ref
54
+ const ref = React.useRef<HTMLButtonElement>(null);
55
55
 
56
- // On change
57
- const onChangeLocal = (
58
- event: React.ChangeEvent<HTMLInputElement>,
59
- checked: boolean
60
- ) => {
61
- if (onChange) onChange(event, checked);
62
- setControlChecked(checked);
63
- };
56
+ React.useEffect(() => {
57
+ if (checked) setControlChecked(checked);
58
+ }, [checked]);
64
59
 
65
- // Layout
66
- return (
67
- <Stack direction="row" spacing={1} alignItems="center">
68
- <Typography
69
- onClick={() => controlChecked && ref.current?.click()}
70
- sx={{
71
- cursor: 'pointer',
72
- color: controlChecked
73
- ? undefined
74
- : (theme) => activeColor ?? theme.palette.warning.main
75
- }}
76
- >
77
- {startLabel}
78
- </Typography>
79
- <Switch
80
- checked={controlChecked}
81
- inputRef={ref}
82
- value={value}
83
- onChange={onChangeLocal}
84
- {...rest}
85
- />
86
- <Typography
87
- onClick={() => !controlChecked && ref.current?.click()}
88
- sx={{
89
- cursor: 'pointer',
90
- color: controlChecked
91
- ? (theme) => activeColor ?? theme.palette.warning.main
92
- : undefined
93
- }}
94
- >
95
- {endLabel}
96
- </Typography>
97
- </Stack>
98
- );
60
+ // On change
61
+ const onChangeLocal = (
62
+ event: React.ChangeEvent<HTMLInputElement>,
63
+ checked: boolean
64
+ ) => {
65
+ if (onChange) onChange(event, checked);
66
+ setControlChecked(checked);
67
+ };
68
+
69
+ // Layout
70
+ return (
71
+ <Stack direction="row" spacing={1} alignItems="center">
72
+ <Typography
73
+ onClick={() => controlChecked && ref.current?.click()}
74
+ sx={{
75
+ cursor: "pointer",
76
+ color: controlChecked
77
+ ? undefined
78
+ : (theme) => activeColor ?? theme.palette.warning.main
79
+ }}
80
+ >
81
+ {startLabel}
82
+ </Typography>
83
+ <Switch
84
+ checked={controlChecked}
85
+ inputRef={ref}
86
+ value={value}
87
+ onChange={onChangeLocal}
88
+ {...rest}
89
+ />
90
+ <Typography
91
+ onClick={() => !controlChecked && ref.current?.click()}
92
+ sx={{
93
+ cursor: "pointer",
94
+ color: controlChecked
95
+ ? (theme) => activeColor ?? theme.palette.warning.main
96
+ : undefined
97
+ }}
98
+ >
99
+ {endLabel}
100
+ </Typography>
101
+ </Stack>
102
+ );
99
103
  }
@@ -0,0 +1,133 @@
1
+ import {
2
+ Box,
3
+ FormControl,
4
+ FormControlProps,
5
+ FormHelperText,
6
+ InputLabel
7
+ } from "@mui/material";
8
+ import NotchedOutline from "@mui/material/OutlinedInput";
9
+ import React from "react";
10
+ import { SwitchAnt } from "./SwitchAnt";
11
+
12
+ /**
13
+ * SwitchField props
14
+ */
15
+ export type SwitchFieldProps = Omit<
16
+ FormControlProps<"fieldset">,
17
+ "defaultValue"
18
+ > & {
19
+ /**
20
+ * Helper text
21
+ */
22
+ helperText?: React.ReactNode;
23
+
24
+ /**
25
+ * Label
26
+ */
27
+ label?: string;
28
+
29
+ /**
30
+ * Checked
31
+ */
32
+ checked?: boolean;
33
+
34
+ /**
35
+ * Active color
36
+ */
37
+ activeColor?: string;
38
+
39
+ /**
40
+ * Start label
41
+ */
42
+ startLabel?: string;
43
+
44
+ /**
45
+ * End label
46
+ */
47
+ endLabel?: string;
48
+
49
+ /**
50
+ * Height in px
51
+ */
52
+ height?: number;
53
+
54
+ /**
55
+ * Value, default is true
56
+ */
57
+ value?: unknown;
58
+ };
59
+
60
+ /**
61
+ * SwitchField
62
+ * @param props Props
63
+ * @returns Component
64
+ */
65
+ export function SwitchField(props: SwitchFieldProps) {
66
+ // Destruct
67
+ const {
68
+ activeColor,
69
+ startLabel,
70
+ endLabel,
71
+ value = true,
72
+
73
+ fullWidth,
74
+ height = 56,
75
+ helperText,
76
+ label,
77
+ name,
78
+ required,
79
+ sx = {},
80
+ checked,
81
+ variant = "outlined",
82
+ ...rest
83
+ } = props;
84
+
85
+ // Outlined
86
+ const outlined = variant === "outlined";
87
+
88
+ if (sx) {
89
+ Object.assign(sx, { height: outlined ? `${height}px` : undefined });
90
+ }
91
+
92
+ // Layout
93
+ return (
94
+ <React.Fragment>
95
+ <FormControl component="fieldset" fullWidth={fullWidth} sx={sx} {...rest}>
96
+ {label && (
97
+ <InputLabel required={required} variant={variant} shrink>
98
+ {label}
99
+ </InputLabel>
100
+ )}
101
+ {outlined && (
102
+ <NotchedOutline
103
+ label={label && required ? label + " *" : label}
104
+ notched
105
+ sx={{
106
+ cursor: "default",
107
+ position: "absolute",
108
+ width: fullWidth ? "100%" : "auto",
109
+ "& input": {
110
+ visibility: "hidden"
111
+ }
112
+ }}
113
+ />
114
+ )}
115
+ <Box
116
+ paddingLeft={2}
117
+ paddingY="7px"
118
+ position={outlined ? "absolute" : undefined}
119
+ >
120
+ <SwitchAnt
121
+ activeColor={activeColor}
122
+ name={name}
123
+ startLabel={startLabel ?? "NO"}
124
+ endLabel={endLabel ?? "YES"}
125
+ value={value}
126
+ checked={checked}
127
+ />
128
+ </Box>
129
+ </FormControl>
130
+ {helperText && <FormHelperText>{helperText}</FormHelperText>}
131
+ </React.Fragment>
132
+ );
133
+ }
package/src/Tiplist.tsx CHANGED
@@ -47,7 +47,8 @@ export function Tiplist<
47
47
  D extends DataTypes.Keys<T> = IdDefaultType<T>
48
48
  >(props: TiplistProps<T, D>) {
49
49
  // Labels
50
- const labels = globalApp?.getLabels("noOptions", "loading", "more");
50
+ const { noOptions, loading, more } =
51
+ globalApp?.getLabels("noOptions", "loading", "more") ?? {};
51
52
 
52
53
  // Destruct
53
54
  const {
@@ -71,8 +72,8 @@ export function Tiplist<
71
72
  onChange,
72
73
  openOnFocus = true,
73
74
  sx = { minWidth: "180px" },
74
- noOptionsText = labels?.noOptions,
75
- loadingText = labels?.loading,
75
+ noOptionsText = noOptions,
76
+ loadingText = loading,
76
77
  getOptionLabel,
77
78
  getOptionDisabled,
78
79
  ...rest
@@ -318,7 +319,7 @@ export function Tiplist<
318
319
  }}
319
320
  getOptionLabel={(item) => {
320
321
  if (typeof item !== "object") return `${item}`;
321
- if (item[idField] === "n/a") return (labels.more ?? "More") + "...";
322
+ if (item[idField] === "n/a") return (more ?? "More") + "...";
322
323
  return getOptionLabel
323
324
  ? getOptionLabel(item)
324
325
  : "label" in item
@@ -1,26 +1,26 @@
1
- import React from 'react';
2
- import { Avatar } from '@mui/material';
3
- import { BusinessUtils } from '@etsoo/appscript';
4
- import { globalApp } from './app/ReactApp';
1
+ import React from "react";
2
+ import { Avatar } from "@mui/material";
3
+ import { BusinessUtils } from "@etsoo/appscript";
4
+ import { globalApp } from "./app/ReactApp";
5
5
 
6
6
  /**
7
7
  * User avatar props
8
8
  */
9
9
  export interface UserAvatarProps {
10
- /**
11
- * Photo src
12
- */
13
- src?: string;
10
+ /**
11
+ * Photo src
12
+ */
13
+ src?: string;
14
14
 
15
- /**
16
- * Format title
17
- */
18
- formatTitle?: (title?: string) => string;
15
+ /**
16
+ * Format title
17
+ */
18
+ formatTitle?: (title?: string) => string;
19
19
 
20
- /**
21
- * Title of the user
22
- */
23
- title?: string;
20
+ /**
21
+ * Title of the user
22
+ */
23
+ title?: string;
24
24
  }
25
25
 
26
26
  /**
@@ -29,36 +29,34 @@ export interface UserAvatarProps {
29
29
  * @returns Component
30
30
  */
31
31
  export function UserAvatar(props: UserAvatarProps) {
32
- // Destruct
33
- const {
34
- src,
32
+ // Destruct
33
+ const {
34
+ src,
35
+ title,
36
+ formatTitle = (title?: string) => {
37
+ return BusinessUtils.formatAvatarTitle(
35
38
  title,
36
- formatTitle = (title?: string) => {
37
- return BusinessUtils.formatAvatarTitle(
38
- title,
39
- 3,
40
- typeof globalApp === 'undefined'
41
- ? 'ME'
42
- : globalApp.get<string>('me')
43
- );
44
- }
45
- } = props;
39
+ 3,
40
+ globalApp?.get<string>("me") ?? "ME"
41
+ );
42
+ }
43
+ } = props;
46
44
 
47
- // Format
48
- const fTitle = formatTitle(title);
49
- const count = fTitle.length;
45
+ // Format
46
+ const fTitle = formatTitle(title);
47
+ const count = fTitle.length;
50
48
 
51
- return (
52
- <Avatar
53
- title={title}
54
- src={src}
55
- sx={{
56
- width: 48,
57
- height: 32,
58
- fontSize: count <= 2 ? '15px' : '12px'
59
- }}
60
- >
61
- {fTitle}
62
- </Avatar>
63
- );
49
+ return (
50
+ <Avatar
51
+ title={title}
52
+ src={src}
53
+ sx={{
54
+ width: 48,
55
+ height: 32,
56
+ fontSize: count <= 2 ? "15px" : "12px"
57
+ }}
58
+ >
59
+ {fTitle}
60
+ </Avatar>
61
+ );
64
62
  }