goobs-frontend 0.7.67 → 0.7.68
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 +13 -16
- package/src/app/_app.tsx +8 -8
- package/src/components/Button/index.tsx +95 -203
- package/src/components/ConfirmationCodeInput/index.tsx +4 -6
- package/src/components/Content/Structure/button/useButton.tsx +1 -35
- package/src/components/Content/Structure/datefield/useDateField.tsx +55 -0
- package/src/components/Content/Structure/dropdown/useDropdown.tsx +55 -0
- package/src/components/Content/Structure/incremementNumberField/useIncremementNumberField.tsx +65 -0
- package/src/components/Content/Structure/numberField/useNumberField.tsx +55 -0
- package/src/components/Content/Structure/passwordField/usePasswordField.tsx +57 -0
- package/src/components/Content/Structure/phoneNumber/usePhoneNumber.tsx +0 -0
- package/src/components/Content/Structure/searchbar/useSearchbar.tsx +55 -0
- package/src/components/Content/Structure/textfield/useTextField.tsx +84 -0
- package/src/components/Content/index.tsx +41 -7
- package/src/components/DateField/index.tsx +112 -0
- package/src/components/Dropdown/index.tsx +91 -0
- package/src/components/Form/Popup/index.tsx +1 -1
- package/src/components/IncrementNumberField/index.tsx +123 -0
- package/src/components/Nav/HorizontalVariant/index.tsx +18 -12
- package/src/components/Nav/VerticalVariant/index.tsx +14 -10
- package/src/components/NumberField/index.tsx +95 -0
- package/src/components/PasswordField/index.tsx +105 -0
- package/src/components/PhoneNumberField/index.tsx +102 -0
- package/src/components/PricingTable/index.tsx +10 -8
- package/src/components/Searchbar/index.tsx +77 -0
- package/src/components/TextField/index.tsx +130 -0
- package/src/components/Toolbar/index.tsx +11 -10
- package/src/index.ts +49 -8
- package/src/components/Button/hook/useHelperFooter.tsx +0 -214
- package/src/components/Content/Structure/styledcomponent/useStyledComponent.tsx +0 -104
- package/src/components/StyledComponent/adornment/index.tsx +0 -125
- package/src/components/StyledComponent/hooks/useDropdown.tsx +0 -150
- package/src/components/StyledComponent/hooks/useInputHelperFooter.tsx +0 -524
- package/src/components/StyledComponent/hooks/usePhoneNumber.tsx +0 -99
- package/src/components/StyledComponent/hooks/useRequiredFieldsValidator.tsx +0 -190
- package/src/components/StyledComponent/hooks/useSearchbar.tsx +0 -46
- package/src/components/StyledComponent/hooks/useSplitButton.tsx +0 -70
- package/src/components/StyledComponent/index.tsx +0 -473
- package/src/components/StyledComponent/useCallbacks/index.tsx +0 -46
- package/src/styles/StyledComponent/Label/index.ts +0 -76
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import IncrementNumberField, {
|
|
4
|
+
IncrementNumberFieldProps,
|
|
5
|
+
} from './../../../IncrementNumberField'
|
|
6
|
+
import { columnconfig, cellconfig } from '../../../Grid'
|
|
7
|
+
|
|
8
|
+
export interface ExtendedIncrementNumberFieldProps
|
|
9
|
+
extends IncrementNumberFieldProps {
|
|
10
|
+
columnconfig?: Partial<columnconfig>
|
|
11
|
+
cellconfig?: cellconfig
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const useIncrementNumberField = (grid: {
|
|
15
|
+
incrementNumberField?:
|
|
16
|
+
| ExtendedIncrementNumberFieldProps
|
|
17
|
+
| ExtendedIncrementNumberFieldProps[]
|
|
18
|
+
}) => {
|
|
19
|
+
if (!grid.incrementNumberField) return null
|
|
20
|
+
|
|
21
|
+
const renderIncrementNumberField = (
|
|
22
|
+
incrementNumberFieldItem: ExtendedIncrementNumberFieldProps,
|
|
23
|
+
index: number
|
|
24
|
+
): columnconfig => {
|
|
25
|
+
const {
|
|
26
|
+
columnconfig: itemColumnConfig,
|
|
27
|
+
cellconfig,
|
|
28
|
+
...restProps
|
|
29
|
+
} = incrementNumberFieldItem
|
|
30
|
+
|
|
31
|
+
if (
|
|
32
|
+
!itemColumnConfig ||
|
|
33
|
+
typeof itemColumnConfig !== 'object' ||
|
|
34
|
+
typeof itemColumnConfig.row !== 'number' ||
|
|
35
|
+
typeof itemColumnConfig.column !== 'number'
|
|
36
|
+
) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
'columnconfig must be an object with row and column as numbers'
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const mergedConfig: columnconfig = {
|
|
43
|
+
...(itemColumnConfig as columnconfig),
|
|
44
|
+
cellconfig: {
|
|
45
|
+
...cellconfig,
|
|
46
|
+
},
|
|
47
|
+
component: (
|
|
48
|
+
<IncrementNumberField
|
|
49
|
+
key={`increment-number-field-${index}`}
|
|
50
|
+
{...restProps}
|
|
51
|
+
/>
|
|
52
|
+
),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return mergedConfig
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (Array.isArray(grid.incrementNumberField)) {
|
|
59
|
+
return grid.incrementNumberField.map(renderIncrementNumberField)
|
|
60
|
+
} else {
|
|
61
|
+
return [renderIncrementNumberField(grid.incrementNumberField, 0)]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default useIncrementNumberField
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import NumberField, { NumberFieldProps } from './../../../NumberField'
|
|
4
|
+
import { columnconfig, cellconfig } from '../../../Grid'
|
|
5
|
+
|
|
6
|
+
export interface ExtendedNumberFieldProps extends NumberFieldProps {
|
|
7
|
+
columnconfig?: Partial<columnconfig>
|
|
8
|
+
cellconfig?: cellconfig
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const useNumberField = (grid: {
|
|
12
|
+
numberField?: ExtendedNumberFieldProps | ExtendedNumberFieldProps[]
|
|
13
|
+
}) => {
|
|
14
|
+
if (!grid.numberField) return null
|
|
15
|
+
|
|
16
|
+
const renderNumberField = (
|
|
17
|
+
numberFieldItem: ExtendedNumberFieldProps,
|
|
18
|
+
index: number
|
|
19
|
+
): columnconfig => {
|
|
20
|
+
const {
|
|
21
|
+
columnconfig: itemColumnConfig,
|
|
22
|
+
cellconfig,
|
|
23
|
+
...restProps
|
|
24
|
+
} = numberFieldItem
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
!itemColumnConfig ||
|
|
28
|
+
typeof itemColumnConfig !== 'object' ||
|
|
29
|
+
typeof itemColumnConfig.row !== 'number' ||
|
|
30
|
+
typeof itemColumnConfig.column !== 'number'
|
|
31
|
+
) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
'columnconfig must be an object with row and column as numbers'
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const mergedConfig: columnconfig = {
|
|
38
|
+
...(itemColumnConfig as columnconfig),
|
|
39
|
+
cellconfig: {
|
|
40
|
+
...cellconfig,
|
|
41
|
+
},
|
|
42
|
+
component: <NumberField key={`number-field-${index}`} {...restProps} />,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return mergedConfig
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (Array.isArray(grid.numberField)) {
|
|
49
|
+
return grid.numberField.map(renderNumberField)
|
|
50
|
+
} else {
|
|
51
|
+
return [renderNumberField(grid.numberField, 0)]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default useNumberField
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import PasswordField, { PasswordFieldProps } from './../../../PasswordField'
|
|
4
|
+
import { columnconfig, cellconfig } from '../../../Grid'
|
|
5
|
+
|
|
6
|
+
export interface ExtendedPasswordFieldProps extends PasswordFieldProps {
|
|
7
|
+
columnconfig?: Partial<columnconfig>
|
|
8
|
+
cellconfig?: cellconfig
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const usePasswordField = (grid: {
|
|
12
|
+
passwordField?: ExtendedPasswordFieldProps | ExtendedPasswordFieldProps[]
|
|
13
|
+
}) => {
|
|
14
|
+
if (!grid.passwordField) return null
|
|
15
|
+
|
|
16
|
+
const renderPasswordField = (
|
|
17
|
+
passwordFieldItem: ExtendedPasswordFieldProps,
|
|
18
|
+
index: number
|
|
19
|
+
): columnconfig => {
|
|
20
|
+
const {
|
|
21
|
+
columnconfig: itemColumnConfig,
|
|
22
|
+
cellconfig,
|
|
23
|
+
...restProps
|
|
24
|
+
} = passwordFieldItem
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
!itemColumnConfig ||
|
|
28
|
+
typeof itemColumnConfig !== 'object' ||
|
|
29
|
+
typeof itemColumnConfig.row !== 'number' ||
|
|
30
|
+
typeof itemColumnConfig.column !== 'number'
|
|
31
|
+
) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
'columnconfig must be an object with row and column as numbers'
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const mergedConfig: columnconfig = {
|
|
38
|
+
...(itemColumnConfig as columnconfig),
|
|
39
|
+
cellconfig: {
|
|
40
|
+
...cellconfig,
|
|
41
|
+
},
|
|
42
|
+
component: (
|
|
43
|
+
<PasswordField key={`password-field-${index}`} {...restProps} />
|
|
44
|
+
),
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return mergedConfig
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (Array.isArray(grid.passwordField)) {
|
|
51
|
+
return grid.passwordField.map(renderPasswordField)
|
|
52
|
+
} else {
|
|
53
|
+
return [renderPasswordField(grid.passwordField, 0)]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default usePasswordField
|
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import Searchbar, { SearchbarProps } from './../../../Searchbar'
|
|
4
|
+
import { columnconfig, cellconfig } from '../../../Grid'
|
|
5
|
+
|
|
6
|
+
export interface ExtendedSearchbarProps extends SearchbarProps {
|
|
7
|
+
columnconfig?: Partial<columnconfig>
|
|
8
|
+
cellconfig?: cellconfig
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const useSearchbar = (grid: {
|
|
12
|
+
searchbar?: ExtendedSearchbarProps | ExtendedSearchbarProps[]
|
|
13
|
+
}) => {
|
|
14
|
+
if (!grid.searchbar) return null
|
|
15
|
+
|
|
16
|
+
const renderSearchbar = (
|
|
17
|
+
searchbarItem: ExtendedSearchbarProps,
|
|
18
|
+
index: number
|
|
19
|
+
): columnconfig => {
|
|
20
|
+
const {
|
|
21
|
+
columnconfig: itemColumnConfig,
|
|
22
|
+
cellconfig,
|
|
23
|
+
...restProps
|
|
24
|
+
} = searchbarItem
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
!itemColumnConfig ||
|
|
28
|
+
typeof itemColumnConfig !== 'object' ||
|
|
29
|
+
typeof itemColumnConfig.row !== 'number' ||
|
|
30
|
+
typeof itemColumnConfig.column !== 'number'
|
|
31
|
+
) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
'columnconfig must be an object with row and column as numbers'
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const mergedConfig: columnconfig = {
|
|
38
|
+
...(itemColumnConfig as columnconfig),
|
|
39
|
+
cellconfig: {
|
|
40
|
+
...cellconfig,
|
|
41
|
+
},
|
|
42
|
+
component: <Searchbar key={`searchbar-${index}`} {...restProps} />,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return mergedConfig
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (Array.isArray(grid.searchbar)) {
|
|
49
|
+
return grid.searchbar.map(renderSearchbar)
|
|
50
|
+
} else {
|
|
51
|
+
return [renderSearchbar(grid.searchbar, 0)]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default useSearchbar
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import TextField, {
|
|
3
|
+
CustomTextFieldProps,
|
|
4
|
+
} from '../../../../components/TextField'
|
|
5
|
+
import { columnconfig, cellconfig } from '../../../Grid'
|
|
6
|
+
|
|
7
|
+
type ExtendedColumnConfig = Omit<columnconfig, 'component'> & {
|
|
8
|
+
component?: columnconfig['component']
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ExtendedTextFieldProps
|
|
12
|
+
extends Omit<CustomTextFieldProps, 'columnconfig'> {
|
|
13
|
+
columnconfig?: ExtendedColumnConfig
|
|
14
|
+
cellconfig?: cellconfig
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const useTextField = (grid: {
|
|
18
|
+
textfield?: ExtendedTextFieldProps | ExtendedTextFieldProps[]
|
|
19
|
+
}): columnconfig | columnconfig[] | null => {
|
|
20
|
+
if (!grid.textfield) return null
|
|
21
|
+
|
|
22
|
+
const renderTextField = (
|
|
23
|
+
component: ExtendedTextFieldProps,
|
|
24
|
+
index: number
|
|
25
|
+
): columnconfig => {
|
|
26
|
+
const {
|
|
27
|
+
name,
|
|
28
|
+
label,
|
|
29
|
+
placeholder,
|
|
30
|
+
value,
|
|
31
|
+
onChange,
|
|
32
|
+
onFocus,
|
|
33
|
+
onBlur,
|
|
34
|
+
error,
|
|
35
|
+
InputProps,
|
|
36
|
+
columnconfig: itemColumnConfig,
|
|
37
|
+
cellconfig,
|
|
38
|
+
...restProps
|
|
39
|
+
} = component
|
|
40
|
+
|
|
41
|
+
if (
|
|
42
|
+
!itemColumnConfig ||
|
|
43
|
+
typeof itemColumnConfig !== 'object' ||
|
|
44
|
+
typeof itemColumnConfig.row !== 'number' ||
|
|
45
|
+
typeof itemColumnConfig.column !== 'number'
|
|
46
|
+
) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
'columnconfig must be an object with row and column as numbers'
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const mergedConfig: columnconfig = {
|
|
53
|
+
...itemColumnConfig,
|
|
54
|
+
cellconfig: {
|
|
55
|
+
...cellconfig,
|
|
56
|
+
},
|
|
57
|
+
component: (
|
|
58
|
+
<TextField
|
|
59
|
+
key={`textfield-${index}`}
|
|
60
|
+
name={name}
|
|
61
|
+
label={label}
|
|
62
|
+
placeholder={placeholder}
|
|
63
|
+
value={value}
|
|
64
|
+
onChange={onChange}
|
|
65
|
+
onFocus={onFocus}
|
|
66
|
+
onBlur={onBlur}
|
|
67
|
+
error={error}
|
|
68
|
+
InputProps={InputProps}
|
|
69
|
+
{...restProps}
|
|
70
|
+
/>
|
|
71
|
+
),
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return mergedConfig
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (Array.isArray(grid.textfield)) {
|
|
78
|
+
return grid.textfield.map(renderTextField)
|
|
79
|
+
} else {
|
|
80
|
+
return renderTextField(grid.textfield, 0)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export default useTextField
|
|
@@ -5,9 +5,6 @@ import CustomGrid, { columnconfig, gridconfig } from '../../components/Grid'
|
|
|
5
5
|
import useGridTypography, {
|
|
6
6
|
ExtendedTypographyProps as TypographyProps,
|
|
7
7
|
} from './Structure/typography/useGridTypography'
|
|
8
|
-
import useStyledComponent, {
|
|
9
|
-
ExtendedStyledComponentProps,
|
|
10
|
-
} from '../../components/Content/Structure/styledcomponent/useStyledComponent'
|
|
11
8
|
import useGridRadioGroup, {
|
|
12
9
|
ExtendedRadioGroupProps,
|
|
13
10
|
} from './Structure/radiogroup/useRadioGroup'
|
|
@@ -38,6 +35,27 @@ import useCard, {
|
|
|
38
35
|
import useCodeCopy, {
|
|
39
36
|
ExtendedCodeCopyProps,
|
|
40
37
|
} from './../../components/Content/Structure/codecopy/useCodeCopy'
|
|
38
|
+
import useTextField, {
|
|
39
|
+
ExtendedTextFieldProps,
|
|
40
|
+
} from './Structure/textfield/useTextField'
|
|
41
|
+
import useDateField, {
|
|
42
|
+
ExtendedDateFieldProps,
|
|
43
|
+
} from './Structure/datefield/useDateField'
|
|
44
|
+
import useDropdown, {
|
|
45
|
+
ExtendedDropdownProps,
|
|
46
|
+
} from './Structure/dropdown/useDropdown'
|
|
47
|
+
import useIncrementNumberField, {
|
|
48
|
+
ExtendedIncrementNumberFieldProps,
|
|
49
|
+
} from './Structure/incremementNumberField/useIncremementNumberField'
|
|
50
|
+
import useSearchbar, {
|
|
51
|
+
ExtendedSearchbarProps,
|
|
52
|
+
} from './Structure/searchbar/useSearchbar'
|
|
53
|
+
import useNumberField, {
|
|
54
|
+
ExtendedNumberFieldProps,
|
|
55
|
+
} from './Structure/numberField/useNumberField'
|
|
56
|
+
import usePasswordField, {
|
|
57
|
+
ExtendedPasswordFieldProps,
|
|
58
|
+
} from './Structure/passwordField/usePasswordField'
|
|
41
59
|
|
|
42
60
|
/**
|
|
43
61
|
* Props for the ContentSection component.
|
|
@@ -52,9 +70,6 @@ export interface ContentSectionProps {
|
|
|
52
70
|
| ExtendedConfirmationCodeInputsProps
|
|
53
71
|
| ExtendedConfirmationCodeInputsProps[]
|
|
54
72
|
typography?: TypographyProps | TypographyProps[]
|
|
55
|
-
styledcomponent?:
|
|
56
|
-
| ExtendedStyledComponentProps
|
|
57
|
-
| ExtendedStyledComponentProps[]
|
|
58
73
|
radiogroup?: ExtendedRadioGroupProps | ExtendedRadioGroupProps[]
|
|
59
74
|
link?: LinkProps | LinkProps[]
|
|
60
75
|
button?: ExtendedButtonProps | ExtendedButtonProps[]
|
|
@@ -64,6 +79,15 @@ export interface ContentSectionProps {
|
|
|
64
79
|
transferlist?: ExtendedTransferListProps | ExtendedTransferListProps[]
|
|
65
80
|
card?: ExtendedCardProps | ExtendedCardProps[]
|
|
66
81
|
codecopy?: ExtendedCodeCopyProps | ExtendedCodeCopyProps[]
|
|
82
|
+
textfield?: ExtendedTextFieldProps | ExtendedTextFieldProps[]
|
|
83
|
+
datefield?: ExtendedDateFieldProps | ExtendedDateFieldProps[]
|
|
84
|
+
dropdown?: ExtendedDropdownProps | ExtendedDropdownProps[]
|
|
85
|
+
incrementNumberField?:
|
|
86
|
+
| ExtendedIncrementNumberFieldProps
|
|
87
|
+
| ExtendedIncrementNumberFieldProps[]
|
|
88
|
+
searchbar?: ExtendedSearchbarProps | ExtendedSearchbarProps[]
|
|
89
|
+
numberField?: ExtendedNumberFieldProps | ExtendedNumberFieldProps[]
|
|
90
|
+
passwordField?: ExtendedPasswordFieldProps | ExtendedPasswordFieldProps[]
|
|
67
91
|
}>
|
|
68
92
|
width?: number
|
|
69
93
|
}
|
|
@@ -90,7 +114,6 @@ const RenderContent: React.FC<
|
|
|
90
114
|
|
|
91
115
|
// Add configurations for each content type
|
|
92
116
|
addToColumnConfigs(useGridTypography(props))
|
|
93
|
-
addToColumnConfigs(useStyledComponent(props))
|
|
94
117
|
addToColumnConfigs(useGridRadioGroup(props))
|
|
95
118
|
addToColumnConfigs(
|
|
96
119
|
useConfirmationInput({ confirmationcodeinput: props.confirmationcodeinput })
|
|
@@ -103,6 +126,17 @@ const RenderContent: React.FC<
|
|
|
103
126
|
addToColumnConfigs(useTransferList(props))
|
|
104
127
|
addToColumnConfigs(useCard(props))
|
|
105
128
|
addToColumnConfigs(useCodeCopy(props))
|
|
129
|
+
addToColumnConfigs(useTextField(props))
|
|
130
|
+
addToColumnConfigs(useDateField(props))
|
|
131
|
+
addToColumnConfigs(useDropdown(props))
|
|
132
|
+
addToColumnConfigs(
|
|
133
|
+
useIncrementNumberField({
|
|
134
|
+
incrementNumberField: props.incrementNumberField,
|
|
135
|
+
})
|
|
136
|
+
)
|
|
137
|
+
addToColumnConfigs(useSearchbar(props))
|
|
138
|
+
addToColumnConfigs(useNumberField({ numberField: props.numberField }))
|
|
139
|
+
addToColumnConfigs(usePasswordField({ passwordField: props.passwordField }))
|
|
106
140
|
|
|
107
141
|
const updatedGridConfig: gridconfig = {
|
|
108
142
|
...grid.gridconfig,
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import React, { useState, useRef } from 'react'
|
|
3
|
+
import { TextField, InputAdornment, TextFieldProps } from '@mui/material'
|
|
4
|
+
import { styled } from '@mui/material/styles'
|
|
5
|
+
import DatePicker from 'react-datepicker'
|
|
6
|
+
import 'react-datepicker/dist/react-datepicker.css'
|
|
7
|
+
import CalendarTodayIcon from '@mui/icons-material/CalendarToday'
|
|
8
|
+
|
|
9
|
+
export interface DateFieldProps extends Omit<TextFieldProps, 'onChange'> {
|
|
10
|
+
onChange?: () => void
|
|
11
|
+
backgroundcolor?: string
|
|
12
|
+
outlinecolor?: string
|
|
13
|
+
fontcolor?: string
|
|
14
|
+
label?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const StyledTextField = styled(TextField)<{
|
|
18
|
+
backgroundcolor?: string
|
|
19
|
+
outlinecolor?: string
|
|
20
|
+
fontcolor?: string
|
|
21
|
+
}>(({ theme, backgroundcolor, outlinecolor, fontcolor }) => ({
|
|
22
|
+
'& .MuiOutlinedInput-root': {
|
|
23
|
+
backgroundColor: backgroundcolor || theme.palette.background.paper,
|
|
24
|
+
'& fieldset': {
|
|
25
|
+
borderColor: outlinecolor || theme.palette.primary.main,
|
|
26
|
+
},
|
|
27
|
+
'&:hover fieldset': {
|
|
28
|
+
borderColor: outlinecolor || theme.palette.primary.main,
|
|
29
|
+
},
|
|
30
|
+
'&.Mui-focused fieldset': {
|
|
31
|
+
borderColor: outlinecolor || theme.palette.primary.main,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
'& .MuiInputLabel-root': {
|
|
35
|
+
color: fontcolor || theme.palette.text.primary,
|
|
36
|
+
'&.Mui-focused': {
|
|
37
|
+
color: fontcolor || theme.palette.primary.main,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
'& .MuiInputBase-input': {
|
|
41
|
+
color: fontcolor || theme.palette.text.primary,
|
|
42
|
+
},
|
|
43
|
+
}))
|
|
44
|
+
|
|
45
|
+
const DateField: React.FC<DateFieldProps> = ({
|
|
46
|
+
onChange,
|
|
47
|
+
backgroundcolor,
|
|
48
|
+
outlinecolor,
|
|
49
|
+
fontcolor,
|
|
50
|
+
label = 'Select Date Range',
|
|
51
|
+
...rest
|
|
52
|
+
}) => {
|
|
53
|
+
const [dateRange, setDateRange] = useState<[Date | null, Date | null]>([
|
|
54
|
+
null,
|
|
55
|
+
null,
|
|
56
|
+
])
|
|
57
|
+
const datePickerRef = useRef<DatePicker>(null)
|
|
58
|
+
|
|
59
|
+
const handleChange = (dates: [Date | null, Date | null]) => {
|
|
60
|
+
setDateRange(dates)
|
|
61
|
+
onChange?.()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const formatDateRange = (range: [Date | null, Date | null]) => {
|
|
65
|
+
const [start, end] = range
|
|
66
|
+
if (start && end) {
|
|
67
|
+
return `${start.toLocaleDateString()} - ${end.toLocaleDateString()}`
|
|
68
|
+
} else if (start) {
|
|
69
|
+
return start.toLocaleDateString()
|
|
70
|
+
}
|
|
71
|
+
return ''
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const openDatePicker = () => {
|
|
75
|
+
if (datePickerRef.current) {
|
|
76
|
+
datePickerRef.current.setOpen(true)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<StyledTextField
|
|
82
|
+
label={label}
|
|
83
|
+
value={formatDateRange(dateRange)}
|
|
84
|
+
InputProps={{
|
|
85
|
+
endAdornment: (
|
|
86
|
+
<InputAdornment position="end">
|
|
87
|
+
<CalendarTodayIcon />
|
|
88
|
+
</InputAdornment>
|
|
89
|
+
),
|
|
90
|
+
readOnly: true,
|
|
91
|
+
}}
|
|
92
|
+
backgroundcolor={backgroundcolor}
|
|
93
|
+
outlinecolor={outlinecolor}
|
|
94
|
+
fontcolor={fontcolor}
|
|
95
|
+
onClick={openDatePicker}
|
|
96
|
+
{...rest}
|
|
97
|
+
>
|
|
98
|
+
<DatePicker
|
|
99
|
+
ref={datePickerRef}
|
|
100
|
+
selectsRange={true}
|
|
101
|
+
startDate={dateRange[0] || undefined}
|
|
102
|
+
endDate={dateRange[1] || undefined}
|
|
103
|
+
onChange={(update: [Date | null, Date | null]) => {
|
|
104
|
+
handleChange(update)
|
|
105
|
+
}}
|
|
106
|
+
customInput={<input style={{ display: 'none' }} />}
|
|
107
|
+
/>
|
|
108
|
+
</StyledTextField>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export default DateField
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
Select,
|
|
4
|
+
MenuItem,
|
|
5
|
+
FormControl,
|
|
6
|
+
InputLabel,
|
|
7
|
+
SelectChangeEvent,
|
|
8
|
+
} from '@mui/material'
|
|
9
|
+
import { styled } from '@mui/material/styles'
|
|
10
|
+
|
|
11
|
+
export interface DropdownProps {
|
|
12
|
+
label: string
|
|
13
|
+
options: string[]
|
|
14
|
+
defaultOption?: string
|
|
15
|
+
onChange?: () => void
|
|
16
|
+
backgroundcolor?: string
|
|
17
|
+
outlinecolor?: string
|
|
18
|
+
fontcolor?: string
|
|
19
|
+
shrunkfontcolor?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const StyledFormControl = styled(FormControl)<{
|
|
23
|
+
backgroundcolor?: string
|
|
24
|
+
outlinecolor?: string
|
|
25
|
+
}>(({ theme, backgroundcolor, outlinecolor }) => ({
|
|
26
|
+
width: '100%',
|
|
27
|
+
'& .MuiOutlinedInput-root': {
|
|
28
|
+
backgroundColor: backgroundcolor || theme.palette.background.paper,
|
|
29
|
+
'& fieldset': {
|
|
30
|
+
borderColor: outlinecolor || theme.palette.primary.main,
|
|
31
|
+
},
|
|
32
|
+
'&:hover fieldset': {
|
|
33
|
+
borderColor: outlinecolor || theme.palette.primary.main,
|
|
34
|
+
},
|
|
35
|
+
'&.Mui-focused fieldset': {
|
|
36
|
+
borderColor: outlinecolor || theme.palette.primary.main,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
}))
|
|
40
|
+
|
|
41
|
+
const StyledInputLabel = styled(InputLabel)<{ shrunkfontcolor?: string }>(
|
|
42
|
+
({ theme, shrunkfontcolor }) => ({
|
|
43
|
+
'&.Mui-focused': {
|
|
44
|
+
color: shrunkfontcolor || theme.palette.primary.main,
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
const Dropdown: React.FC<DropdownProps> = ({
|
|
50
|
+
label,
|
|
51
|
+
options,
|
|
52
|
+
defaultOption,
|
|
53
|
+
onChange,
|
|
54
|
+
backgroundcolor,
|
|
55
|
+
outlinecolor,
|
|
56
|
+
fontcolor,
|
|
57
|
+
shrunkfontcolor,
|
|
58
|
+
}) => {
|
|
59
|
+
const [selectedValue, setSelectedValue] = useState(defaultOption || '')
|
|
60
|
+
|
|
61
|
+
const handleChange = (event: SelectChangeEvent) => {
|
|
62
|
+
const newValue = event.target.value as string
|
|
63
|
+
setSelectedValue(newValue)
|
|
64
|
+
onChange?.()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<StyledFormControl
|
|
69
|
+
backgroundcolor={backgroundcolor}
|
|
70
|
+
outlinecolor={outlinecolor}
|
|
71
|
+
>
|
|
72
|
+
<StyledInputLabel shrunkfontcolor={shrunkfontcolor}>
|
|
73
|
+
{label}
|
|
74
|
+
</StyledInputLabel>
|
|
75
|
+
<Select
|
|
76
|
+
value={selectedValue}
|
|
77
|
+
onChange={handleChange}
|
|
78
|
+
label={label}
|
|
79
|
+
sx={{ color: fontcolor }}
|
|
80
|
+
>
|
|
81
|
+
{options.map(option => (
|
|
82
|
+
<MenuItem key={option} value={option}>
|
|
83
|
+
{option}
|
|
84
|
+
</MenuItem>
|
|
85
|
+
))}
|
|
86
|
+
</Select>
|
|
87
|
+
</StyledFormControl>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default Dropdown
|