@campxdev/shared 1.4.15 → 1.4.17

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.15",
3
+ "version": "1.4.17",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -33,7 +33,6 @@
33
33
  "@mui/icons-material": "^5.6.2",
34
34
  "@mui/lab": "^5.0.0-alpha.112",
35
35
  "@mui/material": "^5.7.0",
36
- "@mui/x-date-pickers": "^5.0.0-alpha.3",
37
36
  "axios": "^0.27.2",
38
37
  "date-fns": "^2.28.0",
39
38
  "js-cookie": "^3.0.1",
@@ -77,7 +76,6 @@
77
76
  "eslint-plugin-prettier": "^4.2.1",
78
77
  "eslint-plugin-react": "^7.31.1",
79
78
  "eslint-plugin-storybook": "^0.6.8",
80
- "lerna": "^5.5.1",
81
79
  "prettier": "^2.5.0",
82
80
  "react-scripts": "^5.0.1",
83
81
  "storybook-addon-react-router-v6": "^0.2.1",
@@ -0,0 +1,39 @@
1
+ import { Tune } from '@mui/icons-material'
2
+ import { Box, styled } from '@mui/material'
3
+
4
+ const StyledButtonWrapper = styled(Box)<{ size: 'regular' | 'large' }>(
5
+ ({ theme, size }) => ({
6
+ width: size === 'regular' ? '40px' : '50px',
7
+ height: size === 'regular' ? '40px' : '50px',
8
+ border: theme.borders.grayLight,
9
+ display: 'flex',
10
+ alignItems: 'center',
11
+ justifyContent: 'center',
12
+ borderRadius: '10px',
13
+ cursor: 'pointer',
14
+ '&:active': {
15
+ border: `1px solid ${theme.palette.primary.main}`,
16
+ },
17
+ transition: 'border 0.1s ease-in-out',
18
+ }),
19
+ )
20
+
21
+ export default function FilterButton({
22
+ onClick,
23
+ size = 'large',
24
+ ...props
25
+ }: {
26
+ onClick: (e: any) => void
27
+ size?: 'regular' | 'large'
28
+ }) {
29
+ const handleClick = (e) => {
30
+ e.stopPropagation()
31
+ if (!onClick) return
32
+ onClick(e)
33
+ }
34
+ return (
35
+ <StyledButtonWrapper size={size} {...props} onClick={handleClick}>
36
+ <Tune />
37
+ </StyledButtonWrapper>
38
+ )
39
+ }
@@ -0,0 +1,40 @@
1
+ import { Search } from '@mui/icons-material'
2
+ import { InputAdornment } from '@mui/material'
3
+ import _ from 'lodash'
4
+ import { useMemo, useState } from 'react'
5
+ import { TextField } from '../Input'
6
+ import { ITextFieldProps } from '../Input/TextField'
7
+
8
+ interface SearchBarProps {
9
+ onSearch: (v: string) => void
10
+ textFieldProps?: ITextFieldProps
11
+ }
12
+
13
+ export default function SearchBar({ onSearch, ...restProps }: SearchBarProps) {
14
+ const [, setSearch] = useState('')
15
+
16
+ const debouncedChangeHandler = useMemo(
17
+ () =>
18
+ _.debounce((e) => {
19
+ setSearch(e.target.value)
20
+ onSearch(e.target.value)
21
+ }, 300),
22
+ [],
23
+ )
24
+
25
+ return (
26
+ <TextField
27
+ label="Search"
28
+ placeholder="Search"
29
+ onChange={debouncedChangeHandler}
30
+ InputProps={{
31
+ endAdornment: (
32
+ <InputAdornment position="end">
33
+ <Search />
34
+ </InputAdornment>
35
+ ),
36
+ }}
37
+ {...restProps.textFieldProps}
38
+ />
39
+ )
40
+ }
@@ -249,9 +249,9 @@ export const DateRangeIcon = () => {
249
249
  return (
250
250
  <svg
251
251
  xmlns="http://www.w3.org/2000/svg"
252
- width="18.647"
253
- height="14.651"
254
- viewBox="0 0 18.647 14.651"
252
+ width="20"
253
+ height="15"
254
+ viewBox="0 0 20 15"
255
255
  >
256
256
  <g id="transfer" transform="translate(0 -51.198)" opacity="0.501">
257
257
  <g id="Group_807" data-name="Group 807" transform="translate(0 51.198)">
@@ -8,6 +8,7 @@ interface ImageProps {
8
8
  width: string | number
9
9
  fit?: 'cover' | 'contain' | 'fill'
10
10
  radius?: string | number
11
+ defaultImage?: any
11
12
  }
12
13
 
13
14
  export default function Image({
@@ -17,6 +18,7 @@ export default function Image({
17
18
  width,
18
19
  fit = 'contain',
19
20
  radius = '10px',
21
+ defaultImage = null,
20
22
  }: ImageProps) {
21
23
  return (
22
24
  <Box
@@ -32,10 +34,10 @@ export default function Image({
32
34
  }}
33
35
  >
34
36
  <img
35
- src={src}
37
+ src={src || defaultImage}
36
38
  alt={alt}
37
39
  onError={(e: any) => {
38
- e.target.src = brokenImage
40
+ e.target.src = defaultImage ? defaultImage : brokenImage
39
41
  }}
40
42
  />
41
43
  </Box>
@@ -6,7 +6,7 @@ import Flatpickr, { DateTimePickerProps } from 'react-flatpickr'
6
6
  import TextField from './TextField'
7
7
 
8
8
  export interface IDatePicker {
9
- label: ReactNode
9
+ label?: ReactNode
10
10
  name?: string
11
11
  control?: any
12
12
  minDate?: Date | string | number
@@ -1,131 +1,84 @@
1
+ import { Box, styled, SvgIcon } from '@mui/material'
2
+ import { useEffect, useState } from 'react'
1
3
  import { DateRangeIcon } from '../IconButtons'
2
- import { Box, styled, TextField } from '@mui/material'
3
- import { DatePicker, LocalizationProvider } from '@mui/x-date-pickers'
4
- import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment'
5
- import { useState } from 'react'
4
+ import DateTimePicker from './DateTimePicker'
5
+
6
+ const StyledDateRangePicker = styled(Box)<{ size: 'small' | 'medium' }>(
7
+ ({ theme, size }) => ({
8
+ borderRadius: '10px',
9
+ height: '50px',
10
+ display: 'flex',
11
+ justifyContent: 'space-between',
12
+ alignItems: 'center',
13
+ border: theme.borders.grayLight,
14
+ '& .MuiOutlinedInput-notchedOutline': {
15
+ display: 'none',
16
+ },
17
+ '& .MuiSvgIcon-root': {
18
+ margin: '0 20px',
19
+ marginTop: '8px',
20
+ },
21
+ ...(size === 'small' && {
22
+ borderRadius: '5px',
23
+ height: '40px',
24
+ '& .MuiSvgIcon-root': {
25
+ margin: '0 20px',
26
+ marginTop: '8px',
27
+ },
28
+ }),
29
+ }),
30
+ )
31
+
6
32
  interface Props {
7
- label?: string
8
- name?: string
33
+ value: [Date, Date]
34
+ onChange: (value: [Date, Date]) => void
35
+ enableTime?: boolean
9
36
  size?: 'small' | 'medium'
10
- control?: any
11
- minDate?: any
12
- maxDate?: any
13
- required?: boolean
14
-
15
- onChangeFromDate: any
16
- onChangeToDate: any
17
- fromValue: any
18
- toValue: any
19
37
  }
20
- export default function DateRangePicker(props: Props) {
21
- const {
22
- name,
23
- size = 'small',
24
- label = '',
25
- minDate,
26
- maxDate,
27
- required = false,
28
- fromValue,
29
- toValue,
30
- onChangeFromDate,
31
- onChangeToDate,
32
- } = props
33
- const [fromOpen, setFromOpen] = useState(false)
34
- const [toOpen, setToOpen] = useState(false)
38
+ export default function DateRangePicker({
39
+ value,
40
+ onChange,
41
+ enableTime = false,
42
+ size = 'medium',
43
+ }: Props) {
44
+ const [state, setState] = useState([null, null])
45
+
46
+ useEffect(() => {
47
+ setState(value)
48
+ }, [value])
49
+
35
50
  return (
36
- <LocalizationProvider dateAdapter={AdapterMoment}>
37
- <Box
38
- sx={{
39
- display: 'flex',
40
- justifyContent: 'space-between',
41
- alignItems: 'center',
42
- border: '1px solid #0000001A',
43
- borderRadius: '10px',
44
- padding: '5px',
51
+ <StyledDateRangePicker size={size}>
52
+ <DateTimePicker
53
+ value={state[0]}
54
+ placeholder="From Date"
55
+ onChange={(value) => {
56
+ setState((prev) => [value, prev[1]])
57
+ onChange([value, state[1]])
45
58
  }}
46
- >
47
- <StyledDatepicker
48
- value={fromValue}
49
- onChange={onChangeFromDate}
50
- label={'start date'}
51
- mask="__/__/____"
52
- inputFormat="DD/MM/yyyy"
53
- closeOnSelect={true}
54
- OpenPickerButtonProps={{
55
- onFocus: (e) => {
56
- setFromOpen(true)
57
- },
58
- }}
59
- onClose={() => {
60
- setFromOpen(false)
61
- }}
62
- PopperProps={{
63
- disablePortal: true,
64
- }}
65
- InputProps={{
66
- onFocus: () => {
67
- setFromOpen(true)
68
- },
69
- }}
70
- open={fromOpen}
71
- renderInput={(params) => (
72
- <TextField sx={{ width: '200px' }} size={'small'} {...params} />
73
- )}
74
- />
75
- <Box>
76
- <DateRangeIcon />
77
- </Box>
78
- <StyledDatepicker
79
- onChange={onChangeToDate}
80
- value={toValue}
81
- label={'end date'}
82
- mask="__/__/____"
83
- inputFormat="DD/MM/yyyy"
84
- OpenPickerButtonProps={{
85
- onFocus: (e) => {
86
- setToOpen(true)
87
- },
88
- }}
89
- onClose={() => {
90
- setToOpen(false)
91
- }}
92
- PopperProps={{
93
- disablePortal: true,
94
- }}
95
- InputProps={{
96
- onFocus: () => {
97
- setToOpen(true)
98
- },
99
- }}
100
- open={toOpen}
101
- renderInput={(params) => (
102
- <TextField sx={{ width: '200px' }} size={'small'} {...params} />
103
- )}
104
- />
105
- </Box>
106
- {/* {error && (
107
- <Typography
108
- variant="caption"
109
- component={'div'}
110
- sx={{ pl: '2px' }}
111
- color="rgb(211, 47, 47)"
112
- >
113
- {error.message}
114
- </Typography>
115
- )} */}
116
- </LocalizationProvider>
59
+ enableTime={enableTime}
60
+ inputProps={{
61
+ InputProps: null,
62
+ size: size,
63
+ }}
64
+ />
65
+ <SvgIcon>
66
+ <DateRangeIcon />
67
+ </SvgIcon>
68
+ <DateTimePicker
69
+ value={state[1]}
70
+ minDate={state[0]}
71
+ placeholder="To Date"
72
+ enableTime={enableTime}
73
+ onChange={(value) => {
74
+ setState((prev) => [prev[0], value])
75
+ onChange([state[0], value])
76
+ }}
77
+ inputProps={{
78
+ InputProps: null,
79
+ size: size,
80
+ }}
81
+ />
82
+ </StyledDateRangePicker>
117
83
  )
118
84
  }
119
-
120
- const StyledDatepicker = styled(DatePicker)({
121
- '& .MuiFormLabel-root .Mui-focused': {
122
- display: 'none',
123
- },
124
- '& .MuiInputAdornment-root': {
125
- display: 'none',
126
- },
127
-
128
- '& fieldset': {
129
- display: 'none',
130
- },
131
- })
@@ -17,6 +17,7 @@ export interface IDateTimePicker {
17
17
  onChange: (value: Date) => void
18
18
  placeholder?: string
19
19
  inputProps?: TextFieldProps
20
+ enableTime?: boolean
20
21
  }
21
22
 
22
23
  export default function DateTimePicker({
@@ -30,13 +31,14 @@ export default function DateTimePicker({
30
31
  onChange,
31
32
  value,
32
33
  placeholder,
34
+ enableTime = true,
33
35
  ...rest
34
36
  }: IDateTimePicker) {
35
37
  return (
36
38
  <Flatpickr
37
39
  options={{
38
- enableTime: true,
39
- dateFormat: 'd-m-Y h:i K',
40
+ enableTime,
41
+ dateFormat: enableTime ? 'd-m-Y h:i K' : 'd-m-Y',
40
42
  minDate,
41
43
  maxDate,
42
44
  minTime,
@@ -18,7 +18,7 @@ const StyledTextField = styled(MuiTextField)(({ theme }) => ({
18
18
  },
19
19
  }))
20
20
 
21
- type TextFieldProps = {
21
+ export type ITextFieldProps = {
22
22
  containerProps?: BoxProps
23
23
  } & MuiTextFieldProps
24
24
 
@@ -30,7 +30,7 @@ export default function TextField({
30
30
  required = false,
31
31
  containerProps,
32
32
  ...rest
33
- }: TextFieldProps) {
33
+ }: ITextFieldProps) {
34
34
  return (
35
35
  <Box width="100%" {...containerProps}>
36
36
  <FieldLabel label={label} required={required} name={name} />
@@ -71,7 +71,7 @@ export default function DialogButton({
71
71
  fullWidth
72
72
  onClose={onClose}
73
73
  open={open}
74
- transitionDuration={100}
74
+ transitionDuration={140}
75
75
  TransitionComponent={Transition}
76
76
  sx={{
77
77
  '& .MuiBackdrop-root': {
@@ -1,6 +1,5 @@
1
1
  import { Close } from '@mui/icons-material'
2
2
  import {
3
- alpha,
4
3
  Box,
5
4
  ButtonProps,
6
5
  DialogTitle,
@@ -54,7 +53,7 @@ export default function DrawerButton({
54
53
  {anchor({ open: onOpen })}
55
54
  <Drawer
56
55
  anchor="right"
57
- elevation={10}
56
+ elevation={2}
58
57
  onClose={onClose}
59
58
  open={open}
60
59
  PaperProps={{
@@ -70,7 +69,7 @@ export default function DrawerButton({
70
69
  backgroundColor: 'rgba(0, 0, 0, 0.4)',
71
70
  },
72
71
  }}
73
- transitionDuration={200}
72
+ transitionDuration={140}
74
73
  >
75
74
  <StyledDrawerHeader>
76
75
  <DialogTitle>{title}</DialogTitle>
@@ -4,7 +4,7 @@ import ImageUpload from './ImageUpload'
4
4
  import FloatingContainer from './FloatingContainer'
5
5
  import TabsContainer from './Tabs/TabsContainer'
6
6
  import { StyledTableContainer } from './StyledTableContainer'
7
- import SearchBar from './SearchBar'
7
+ import SearchBar from './FilterComponents/SearchBar'
8
8
  import { DrawerButton, DialogButton } from './ModalButtons'
9
9
  import DetailsGrid from './DetailsGrid'
10
10
  import AppHeader from './Layout/Header'
@@ -217,7 +217,7 @@ const muiTheme = createTheme({
217
217
  '& .MuiOutlinedInput-notchedOutline': {
218
218
  top: 1,
219
219
  minHeight: '50px',
220
- borderColor: alpha(colors.common.black, 0.15),
220
+ border: borders.grayLight,
221
221
  '& legend': {
222
222
  '& > span': {
223
223
  paddingRight: 2,
@@ -225,7 +225,7 @@ const muiTheme = createTheme({
225
225
  },
226
226
  },
227
227
  '&:hover .MuiOutlinedInput-notchedOutline': {
228
- borderColor: alpha(colors.common.black, 0.3),
228
+ borderColor: alpha(colors.common.black, 0.2),
229
229
  },
230
230
  '&.Mui-focused .MuiOutlinedInput-notchedOutline': {
231
231
  borderColor: colors.primary.main,
@@ -4,5 +4,4 @@ export { default as romanize } from './romanize'
4
4
 
5
5
  export { default as withRouteWrapper } from './withRouteWrapper'
6
6
  export { default as withSuspense } from './withSuspense'
7
- export { default as withLocalization } from './withLocalization'
8
7
  export { default as onLogout } from './logout'