@sonardigital/carbon-ui 1.1.86 → 1.1.88

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.1.86",
3
+ "version": "1.1.88",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -2,19 +2,24 @@ import { Card, Grow, Stack } from '@mui/material';
2
2
  import { Controller } from 'react-hook-form';
3
3
  import CheckCircleIcon from '@mui/icons-material/CheckCircle';
4
4
 
5
+ export interface FormBoxProps {
6
+ value: string;
7
+ color?: string;
8
+ children: React.ReactNode;
9
+ sx?: Record<string, unknown>;
10
+ }
11
+
12
+ interface LocalFormBoxProps extends FormBoxProps {
13
+ name: string;
14
+ }
15
+
5
16
  export function FormBox({
6
17
  name,
7
18
  children,
8
19
  value,
9
20
  color,
10
21
  sx,
11
- }: {
12
- name: string;
13
- children: React.ReactNode;
14
- value: string;
15
- color?: string;
16
- sx?: Record<string, unknown>;
17
- }): React.ReactElement {
22
+ }: LocalFormBoxProps): React.ReactElement {
18
23
  return (
19
24
  <Controller
20
25
  name={name}
@@ -0,0 +1,61 @@
1
+ import { Controller } from 'react-hook-form';
2
+ import { FormBox, FormBoxProps } from './FormBox';
3
+ import { Typography } from '@mui/material';
4
+
5
+ interface LocalFormBoxProps extends FormBoxProps {
6
+ label: string;
7
+ }
8
+
9
+ export function FormBoxes({
10
+ name,
11
+ options,
12
+ sx,
13
+ }: {
14
+ name: string;
15
+ options: LocalFormBoxProps[];
16
+ sx?: Record<string, unknown>;
17
+ }): React.ReactElement {
18
+ return (
19
+ <>
20
+ {options.map(option => (
21
+ <Controller
22
+ name={name}
23
+ render={({ field }) => {
24
+ const isEmpty =
25
+ option.value === undefined || option.value === null;
26
+ const isSelected = option.value === field.value;
27
+ return (
28
+ <>
29
+ <FormBox
30
+ key={option.value}
31
+ name={name}
32
+ value={option.value}
33
+ color={option.color}
34
+ sx={{
35
+ height: 90,
36
+ transition: 'all 0.1s',
37
+ opacity: isEmpty ? 1 : isSelected ? 1 : 0.5,
38
+ ...sx,
39
+ ...option.sx,
40
+ }}
41
+ >
42
+ {option.children}
43
+ </FormBox>
44
+ <Typography
45
+ paddingTop={0.5}
46
+ variant="body2"
47
+ textAlign="center"
48
+ sx={{
49
+ opacity: isEmpty ? 1 : isSelected ? 1 : 0.5,
50
+ }}
51
+ >
52
+ {option.label}
53
+ </Typography>
54
+ </>
55
+ );
56
+ }}
57
+ />
58
+ ))}
59
+ </>
60
+ );
61
+ }
@@ -7,3 +7,4 @@ export * from './FormSwitch';
7
7
  export * from './form-list/FormList';
8
8
  export * from './FormDatePicker';
9
9
  export * from './FormBox';
10
+ export * from './FormBoxes';