@sonardigital/carbon-ui 1.1.91 → 1.1.93

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.91",
3
+ "version": "1.1.93",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -2,67 +2,85 @@ 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;
5
+ export interface FormBoxProps<T> {
6
+ value: T;
7
7
  color?: string;
8
+ multiple?: boolean;
8
9
  children: React.ReactNode;
9
10
  sx?: Record<string, unknown>;
10
11
  }
11
12
 
12
- interface LocalFormBoxProps extends FormBoxProps {
13
+ interface LocalFormBoxProps<T> extends FormBoxProps<T> {
13
14
  name: string;
14
15
  }
15
16
 
16
- export function FormBox({
17
+ export function FormBox<T>({
17
18
  name,
19
+ multiple,
18
20
  children,
19
21
  value,
20
22
  color,
21
23
  sx,
22
- }: LocalFormBoxProps): React.ReactElement {
24
+ }: LocalFormBoxProps<T>): React.ReactElement {
23
25
  return (
24
26
  <Controller
25
27
  name={name}
26
- render={({ field }) => (
27
- <Stack sx={{ position: 'relative' }}>
28
- {value === field.value && (
29
- <Grow in={true} timeout={250}>
30
- <CheckCircleIcon
31
- sx={{
32
- width: 19,
33
- height: 19,
34
- position: 'absolute',
35
- top: 10,
36
- right: 10,
37
- color: `${color}.main`,
38
- }}
39
- />
40
- </Grow>
41
- )}
42
- <Card
43
- // eslint-disable-next-line
44
- // @ts-ignore
45
- variant="numeric"
46
- sx={{
47
- bgcolor: `${color}.light`,
48
- height: 65,
49
- width: '100%',
50
- borderRadius: 2.2,
51
- border: 2,
52
- transition: '0.2s',
53
- borderColor: `${color}.${value === field.value ? 'main' : 'light'}`,
54
- ...sx,
55
- }}
56
- onClick={() =>
57
- field.value === value
58
- ? field.onChange(null)
59
- : field.onChange(value)
28
+ render={({ field }) => {
29
+ const onChange = () => {
30
+ if (multiple) {
31
+ if (!field.value) {
32
+ field.onChange([value] as T[]);
33
+ return;
34
+ } else {
35
+ if (field.value.includes(value)) {
36
+ field.onChange(
37
+ field.value.filter((v: T) => v !== value) as T[],
38
+ );
39
+ } else {
40
+ field.onChange([...field.value, value] as T[]);
41
+ }
60
42
  }
61
- >
62
- {children}
63
- </Card>
64
- </Stack>
65
- )}
43
+ }
44
+ field.onChange(value as T);
45
+ };
46
+
47
+ return (
48
+ <Stack sx={{ position: 'relative' }}>
49
+ {value === field.value && (
50
+ <Grow in={true} timeout={250}>
51
+ <CheckCircleIcon
52
+ sx={{
53
+ width: 19,
54
+ height: 19,
55
+ position: 'absolute',
56
+ top: 10,
57
+ right: 10,
58
+ color: `${color}.main`,
59
+ }}
60
+ />
61
+ </Grow>
62
+ )}
63
+ <Card
64
+ // eslint-disable-next-line
65
+ // @ts-ignore
66
+ variant="numeric"
67
+ sx={{
68
+ bgcolor: `${color}.light`,
69
+ height: 65,
70
+ width: '100%',
71
+ borderRadius: 2.2,
72
+ border: 2,
73
+ transition: '0.2s',
74
+ borderColor: `${color}.${value === field.value ? 'main' : 'light'}`,
75
+ ...sx,
76
+ }}
77
+ onClick={onChange}
78
+ >
79
+ {children}
80
+ </Card>
81
+ </Stack>
82
+ );
83
+ }}
66
84
  />
67
85
  );
68
86
  }
@@ -2,38 +2,44 @@ import { Controller } from 'react-hook-form';
2
2
  import { FormBox, FormBoxProps } from './FormBox';
3
3
  import { Grid, Typography } from '@mui/material';
4
4
 
5
- interface LocalFormBoxProps extends FormBoxProps {
5
+ interface LocalFormBoxProps<T> extends FormBoxProps<T> {
6
6
  label: string;
7
7
  size?: { xs: number; sm: number; md: number };
8
8
  }
9
9
 
10
- export function FormBoxes({
10
+ export function FormBoxes<T>({
11
11
  name,
12
12
  options,
13
+ multiple,
13
14
  sx,
14
15
  }: {
15
16
  name: string;
16
- options: LocalFormBoxProps[];
17
+ multiple: boolean;
18
+ options: LocalFormBoxProps<T>[];
17
19
  sx?: Record<string, unknown>;
18
20
  }): React.ReactElement {
19
21
  return (
20
22
  <Grid container width="100%" spacing={2}>
21
- {options.map(option => (
23
+ {options.map((option, i) => (
22
24
  <Controller
23
25
  name={name}
24
26
  render={({ field }) => {
25
- const isEmpty =
26
- field.value === undefined || field.value === null;
27
- const isSelected = option.value === field.value;
27
+ const isEmpty = multiple
28
+ ? field.value.length === 0
29
+ : field.value === undefined || field.value === null;
30
+ const isSelected = multiple
31
+ ? field.value?.includes(option.value)
32
+ : option.value === field.value;
28
33
  return (
29
34
  <Grid
30
35
  size={{ xs: 6, sm: 4, md: 3, ...option.size }}
31
- key={option.value}
36
+ key={i}
32
37
  >
33
38
  <FormBox
34
39
  name={name}
35
40
  value={option.value}
36
41
  color={option.color}
42
+ multiple={multiple}
37
43
  sx={{
38
44
  height: 90,
39
45
  transition: 'all 0.1s',
@@ -54,7 +54,7 @@ export const useMultisteps = ({
54
54
  steps,
55
55
  currentStepIndex: index,
56
56
  currentStep: steps[index - 1] || null,
57
- percentage: maths.formatNumber(maths.percentage(index, steps.length)),
57
+ percentage: maths.parseNumber(maths.percentage(index, steps.length)),
58
58
  hover,
59
59
  setHover,
60
60
  goBack,
@@ -5,7 +5,7 @@ export interface MultistepsContextType {
5
5
  steps: Step[];
6
6
  currentStepIndex: number;
7
7
  currentStep: Step | null;
8
- percentage: string;
8
+ percentage: number;
9
9
  hover: number | null;
10
10
  setHover: (index: number | null) => void;
11
11
  goNext: () => void;
@@ -18,7 +18,7 @@ export const MultistepsContext: Context<MultistepsContextType> =
18
18
  steps: [],
19
19
  currentStepIndex: 1,
20
20
  currentStep: null,
21
- percentage: '0.00',
21
+ percentage: 0,
22
22
  hover: null,
23
23
  setHover: () => {},
24
24
  goBack: () => {},