@campxdev/shared 1.4.7 → 1.4.8

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": "@campxdev/shared",
3
- "version": "1.4.7",
3
+ "version": "1.4.8",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -1,62 +1,64 @@
1
- import { Box, FormGroup, FormHelperText } from '@mui/material'
1
+ import { Box, BoxProps, FormGroup, FormHelperText } from '@mui/material'
2
+ import { ReactNode } from 'react'
2
3
  import { Controller } from 'react-hook-form'
3
4
  import FormLabel from './FormLabel'
4
5
  import SingleCheckbox from './SingleCheckbox'
5
6
 
6
7
  interface Props {
7
- label?: string
8
+ label?: ReactNode
8
9
  name: string
9
10
  size?: 'small' | 'medium'
10
- control: any
11
- options: Array<{ label: string; value: string }>
11
+ options: Array<{ label: ReactNode; value: any }>
12
12
  required?: boolean
13
13
  row?: boolean
14
+ error?: boolean
15
+ helperText?: ReactNode
16
+ value: { label: string; value: any }[]
17
+ onChange: (value: { label: ReactNode; value: any }[]) => void
18
+ containerProps?: BoxProps
14
19
  }
15
20
 
16
- export default function MultiCheckbox(props: Props) {
17
- const {
18
- name,
19
- control,
20
- label = '',
21
- options = [],
22
- required = false,
23
- row = true,
24
- } = props
25
-
21
+ export default function MultiCheckbox({
22
+ name,
23
+ label,
24
+ options = [],
25
+ required = false,
26
+ value = [],
27
+ onChange,
28
+ error,
29
+ helperText,
30
+ row = true,
31
+ containerProps,
32
+ ...rest
33
+ }: Props) {
26
34
  return (
27
- <Controller
28
- name={name}
29
- control={control}
30
- render={({ field, fieldState: { error } }) => (
31
- <Box width="100%">
32
- <FormLabel label={label} required={required} name={name} />
33
- <FormGroup row={row} sx={{ flexWrap: 'wrap' }}>
34
- {options?.map((item, index) => (
35
- <SingleCheckbox
36
- name={name}
37
- key={index}
38
- label={item.label}
39
- checked={field?.value
40
- ?.map((item: any) => item?.value)
41
- ?.includes(item?.value)}
42
- onChange={(e) => {
43
- let value = field.value || []
44
- if (e.target.checked) {
45
- let newValue = [...value, item]
46
- field.onChange(newValue)
47
- } else {
48
- let filteredValue = value.filter(
49
- (opt: any) => opt?.value !== item.value,
50
- )
51
- field.onChange(filteredValue)
52
- }
53
- }}
54
- />
55
- ))}
56
- </FormGroup>
57
- {error && <FormHelperText>{error.message}</FormHelperText>}
58
- </Box>
59
- )}
60
- />
35
+ <Box width="100%" {...containerProps}>
36
+ <FormLabel label={label} required={required} name={name} />
37
+ <FormGroup row={row} sx={{ flexWrap: 'wrap' }}>
38
+ {options?.map((item, index) => (
39
+ <SingleCheckbox
40
+ name={name}
41
+ key={index}
42
+ label={item.label}
43
+ checked={value
44
+ ?.map((item: any) => item?.value)
45
+ ?.includes(item?.value)}
46
+ onChange={(e) => {
47
+ if (e.target.checked) {
48
+ let newValue = [...value, item]
49
+ onChange(newValue)
50
+ } else {
51
+ let filteredValue = value.filter(
52
+ (opt: any) => opt?.value !== item.value,
53
+ )
54
+ onChange(filteredValue)
55
+ }
56
+ }}
57
+ {...rest}
58
+ />
59
+ ))}
60
+ </FormGroup>
61
+ {error && <FormHelperText>{helperText}</FormHelperText>}
62
+ </Box>
61
63
  )
62
64
  }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  Box,
3
+ BoxProps,
3
4
  FormControlLabel,
4
5
  Radio,
5
6
  RadioGroup as MuiRadioGroup,
@@ -56,6 +57,7 @@ interface Props extends RadioGroupProps {
56
57
  row?: boolean
57
58
  required?: boolean
58
59
  options: { value: any; label: string | ReactNode }[]
60
+ containerProps?: BoxProps
59
61
  }
60
62
 
61
63
  export default function RadioGroup(props: Props) {
@@ -67,10 +69,11 @@ export default function RadioGroup(props: Props) {
67
69
  required = false,
68
70
  value,
69
71
  onChange,
72
+ containerProps,
70
73
  ...rest
71
74
  } = props
72
75
  return (
73
- <Box width="100%">
76
+ <Box width="100%" {...containerProps}>
74
77
  <FormLabel label={label} name={name} required={required} />
75
78
  <MuiRadioGroup
76
79
  value={value}
@@ -7,18 +7,11 @@ import {
7
7
  Select,
8
8
  FormHelperText,
9
9
  Box,
10
+ BoxProps,
10
11
  } from '@mui/material'
11
12
  import { ReactNode } from 'react'
12
13
  import FormLabel from './FormLabel'
13
14
 
14
- type Props = {
15
- options: Array<{ label: ReactNode; value: any }>
16
- onChange?: (value: any) => void
17
- required?: boolean
18
- firstItemEmpty?: boolean
19
- helperText?: string
20
- } & SelectProps
21
-
22
15
  const StyledFormControl = styled(FormControl)(({ theme }) => ({
23
16
  '& .MuiInputBase-root': {
24
17
  '& legend': { display: 'none' },
@@ -39,7 +32,6 @@ const PaperProps = {
39
32
  maxHeight: 360,
40
33
  marginTop: '1px',
41
34
  '& .MuiList-root': {
42
- minWidth: '240px',
43
35
  padding: 0,
44
36
  '& li': {
45
37
  height: '60px',
@@ -55,6 +47,15 @@ const PaperProps = {
55
47
  },
56
48
  }
57
49
 
50
+ type Props = {
51
+ options: Array<{ label: ReactNode; value: any }>
52
+ onChange?: (value: any) => void
53
+ required?: boolean
54
+ firstItemEmpty?: boolean
55
+ helperText?: string
56
+ containerProps?: BoxProps
57
+ } & SelectProps
58
+
58
59
  export default function SingleSelect({
59
60
  name = 'select',
60
61
  options = [],
@@ -63,6 +64,7 @@ export default function SingleSelect({
63
64
  required,
64
65
  value,
65
66
  helperText,
67
+ containerProps,
66
68
  firstItemEmpty = false,
67
69
  ...props
68
70
  }: Props) {
@@ -71,7 +73,7 @@ export default function SingleSelect({
71
73
  : options
72
74
 
73
75
  return (
74
- <Box width="100%">
76
+ <Box width="100%" {...containerProps}>
75
77
  <FormLabel required={required} label={label} name={name} />
76
78
  <StyledFormControl fullWidth>
77
79
  <Select
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  Box,
3
+ BoxProps,
3
4
  styled,
4
5
  TextField as MuiTextField,
5
6
  TextFieldProps as MuiTextFieldProps,
@@ -17,7 +18,9 @@ const StyledTextField = styled(MuiTextField)(({ theme }) => ({
17
18
  },
18
19
  }))
19
20
 
20
- type TextFieldProps = {} & MuiTextFieldProps
21
+ type TextFieldProps = {
22
+ containerProps?: BoxProps
23
+ } & MuiTextFieldProps
21
24
 
22
25
  export default function TextField({
23
26
  name,
@@ -25,10 +28,11 @@ export default function TextField({
25
28
  value,
26
29
  onChange,
27
30
  required = false,
31
+ containerProps,
28
32
  ...rest
29
33
  }: TextFieldProps) {
30
34
  return (
31
- <Box width="100%">
35
+ <Box width="100%" {...containerProps}>
32
36
  <FieldLabel label={label} required={required} name={name} />
33
37
  <StyledTextField
34
38
  id={name}