@bosonprotocol/react-kit 0.33.0-alpha.9 → 0.33.0
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/dist/cjs/components/buttons/BaseButton.d.ts +1 -0
- package/dist/cjs/components/buttons/BaseButton.d.ts.map +1 -1
- package/dist/cjs/components/buttons/BaseButton.js +1 -0
- package/dist/cjs/components/buttons/BaseButton.js.map +1 -1
- package/dist/cjs/components/buttons/CommitButtonView.d.ts.map +1 -1
- package/dist/cjs/components/buttons/CommitButtonView.js +4 -0
- package/dist/cjs/components/buttons/CommitButtonView.js.map +1 -1
- package/dist/cjs/components/error/SimpleError.d.ts +2 -2
- package/dist/cjs/components/error/SimpleError.d.ts.map +1 -1
- package/dist/cjs/components/error/SimpleError.js.map +1 -1
- package/dist/cjs/components/form/BaseCheckbox.d.ts +5 -0
- package/dist/cjs/components/form/BaseCheckbox.d.ts.map +1 -0
- package/dist/cjs/components/form/BaseCheckbox.js +69 -0
- package/dist/cjs/components/form/BaseCheckbox.js.map +1 -0
- package/dist/cjs/components/form/Checkbox.d.ts +13 -2
- package/dist/cjs/components/form/Checkbox.d.ts.map +1 -1
- package/dist/cjs/components/form/Checkbox.js +18 -61
- package/dist/cjs/components/form/Checkbox.js.map +1 -1
- package/dist/cjs/components/form/CountrySelect.d.ts +26 -11
- package/dist/cjs/components/form/CountrySelect.d.ts.map +1 -1
- package/dist/cjs/components/form/CountrySelect.js +64 -31
- package/dist/cjs/components/form/CountrySelect.js.map +1 -1
- package/dist/cjs/components/form/Field.styles.d.ts +36 -2
- package/dist/cjs/components/form/Field.styles.d.ts.map +1 -1
- package/dist/cjs/components/form/Field.styles.js +83 -24
- package/dist/cjs/components/form/Field.styles.js.map +1 -1
- package/dist/cjs/components/form/FormField.d.ts +2 -1
- package/dist/cjs/components/form/FormField.d.ts.map +1 -1
- package/dist/cjs/components/form/FormField.js +14 -2
- package/dist/cjs/components/form/FormField.js.map +1 -1
- package/dist/cjs/components/form/Select.d.ts +2 -1
- package/dist/cjs/components/form/Select.d.ts.map +1 -1
- package/dist/cjs/components/form/Select.js +32 -20
- package/dist/cjs/components/form/Select.js.map +1 -1
- package/dist/cjs/components/form/Upload/BaseUpload.d.ts +71 -0
- package/dist/cjs/components/form/Upload/BaseUpload.d.ts.map +1 -0
- package/dist/cjs/components/form/Upload/BaseUpload.js +264 -0
- package/dist/cjs/components/form/Upload/BaseUpload.js.map +1 -0
- package/dist/cjs/components/form/Upload/Upload.d.ts +3 -41
- package/dist/cjs/components/form/Upload/Upload.d.ts.map +1 -1
- package/dist/cjs/components/form/Upload/Upload.js +7 -258
- package/dist/cjs/components/form/Upload/Upload.js.map +1 -1
- package/dist/cjs/components/form/Upload/UploadedFile.js +2 -2
- package/dist/cjs/components/form/Upload/UploadedFile.js.map +1 -1
- package/dist/cjs/components/form/Upload/WithUploadToIpfs.d.ts.map +1 -1
- package/dist/cjs/components/form/Upload/WithUploadToIpfs.js +9 -12
- package/dist/cjs/components/form/Upload/WithUploadToIpfs.js.map +1 -1
- package/dist/cjs/components/form/index.d.ts +6 -4
- package/dist/cjs/components/form/index.d.ts.map +1 -1
- package/dist/cjs/components/form/index.js +7 -3
- package/dist/cjs/components/form/index.js.map +1 -1
- package/dist/cjs/components/form/types.d.ts +31 -3
- package/dist/cjs/components/form/types.d.ts.map +1 -1
- package/dist/cjs/components/ui/IpfsImage.d.ts +4 -3
- package/dist/cjs/components/ui/IpfsImage.d.ts.map +1 -1
- package/dist/cjs/components/ui/IpfsImage.js +2 -2
- package/dist/cjs/components/ui/IpfsImage.js.map +1 -1
- package/dist/cjs/components/ui/Video.d.ts +3 -3
- package/dist/cjs/components/ui/Video.d.ts.map +1 -1
- package/dist/cjs/components/ui/Video.js +7 -3
- package/dist/cjs/components/ui/Video.js.map +1 -1
- package/dist/cjs/hooks/ipfs/useIpfsStorage.d.ts.map +1 -1
- package/dist/cjs/hooks/ipfs/useIpfsStorage.js +2 -1
- package/dist/cjs/hooks/ipfs/useIpfsStorage.js.map +1 -1
- package/dist/cjs/hooks/useIpfsMetadataStorage.d.ts +2 -2
- package/dist/cjs/hooks/useIpfsMetadataStorage.d.ts.map +1 -1
- package/dist/cjs/hooks/useIpfsMetadataStorage.js +6 -6
- package/dist/cjs/hooks/useIpfsMetadataStorage.js.map +1 -1
- package/dist/cjs/hooks/useIpfsStorage.d.ts.map +1 -1
- package/dist/cjs/hooks/useIpfsStorage.js +2 -1
- package/dist/cjs/hooks/useIpfsStorage.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/bytes/bytesToSize.d.ts +1 -1
- package/dist/cjs/lib/bytes/bytesToSize.d.ts.map +1 -1
- package/dist/cjs/lib/bytes/bytesToSize.js +2 -1
- package/dist/cjs/lib/bytes/bytesToSize.js.map +1 -1
- package/dist/cjs/lib/const/chainInfo.d.ts.map +1 -1
- package/dist/cjs/lib/const/chainInfo.js +10 -0
- package/dist/cjs/lib/const/chainInfo.js.map +1 -1
- package/dist/esm/components/buttons/BaseButton.d.ts +1 -0
- package/dist/esm/components/buttons/BaseButton.d.ts.map +1 -1
- package/dist/esm/components/buttons/BaseButton.js +1 -0
- package/dist/esm/components/buttons/BaseButton.js.map +1 -1
- package/dist/esm/components/buttons/CommitButtonView.d.ts.map +1 -1
- package/dist/esm/components/buttons/CommitButtonView.js +4 -0
- package/dist/esm/components/buttons/CommitButtonView.js.map +1 -1
- package/dist/esm/components/error/SimpleError.d.ts +2 -2
- package/dist/esm/components/error/SimpleError.d.ts.map +1 -1
- package/dist/esm/components/error/SimpleError.js.map +1 -1
- package/dist/esm/components/form/BaseCheckbox.d.ts +5 -0
- package/dist/esm/components/form/BaseCheckbox.d.ts.map +1 -0
- package/dist/esm/components/form/BaseCheckbox.js +27 -0
- package/dist/esm/components/form/BaseCheckbox.js.map +1 -0
- package/dist/esm/components/form/Checkbox.d.ts +13 -2
- package/dist/esm/components/form/Checkbox.d.ts.map +1 -1
- package/dist/esm/components/form/Checkbox.js +16 -25
- package/dist/esm/components/form/Checkbox.js.map +1 -1
- package/dist/esm/components/form/CountrySelect.d.ts +26 -11
- package/dist/esm/components/form/CountrySelect.d.ts.map +1 -1
- package/dist/esm/components/form/CountrySelect.js +97 -67
- package/dist/esm/components/form/CountrySelect.js.map +1 -1
- package/dist/esm/components/form/Field.styles.d.ts +36 -2
- package/dist/esm/components/form/Field.styles.d.ts.map +1 -1
- package/dist/esm/components/form/Field.styles.js +58 -20
- package/dist/esm/components/form/Field.styles.js.map +1 -1
- package/dist/esm/components/form/FormField.d.ts +2 -1
- package/dist/esm/components/form/FormField.d.ts.map +1 -1
- package/dist/esm/components/form/FormField.js +2 -2
- package/dist/esm/components/form/FormField.js.map +1 -1
- package/dist/esm/components/form/Select.d.ts +2 -1
- package/dist/esm/components/form/Select.d.ts.map +1 -1
- package/dist/esm/components/form/Select.js +52 -30
- package/dist/esm/components/form/Select.js.map +1 -1
- package/dist/esm/components/form/Upload/BaseUpload.d.ts +71 -0
- package/dist/esm/components/form/Upload/BaseUpload.d.ts.map +1 -0
- package/dist/esm/components/form/Upload/BaseUpload.js +226 -0
- package/dist/esm/components/form/Upload/BaseUpload.js.map +1 -0
- package/dist/esm/components/form/Upload/Upload.d.ts +3 -41
- package/dist/esm/components/form/Upload/Upload.d.ts.map +1 -1
- package/dist/esm/components/form/Upload/Upload.js +5 -225
- package/dist/esm/components/form/Upload/Upload.js.map +1 -1
- package/dist/esm/components/form/Upload/UploadedFile.js +1 -1
- package/dist/esm/components/form/Upload/UploadedFile.js.map +1 -1
- package/dist/esm/components/form/Upload/WithUploadToIpfs.d.ts.map +1 -1
- package/dist/esm/components/form/Upload/WithUploadToIpfs.js +8 -11
- package/dist/esm/components/form/Upload/WithUploadToIpfs.js.map +1 -1
- package/dist/esm/components/form/index.d.ts +6 -4
- package/dist/esm/components/form/index.d.ts.map +1 -1
- package/dist/esm/components/form/index.js +4 -2
- package/dist/esm/components/form/index.js.map +1 -1
- package/dist/esm/components/form/types.d.ts +31 -3
- package/dist/esm/components/form/types.d.ts.map +1 -1
- package/dist/esm/components/ui/IpfsImage.d.ts +4 -3
- package/dist/esm/components/ui/IpfsImage.d.ts.map +1 -1
- package/dist/esm/components/ui/IpfsImage.js +2 -2
- package/dist/esm/components/ui/IpfsImage.js.map +1 -1
- package/dist/esm/components/ui/Video.d.ts +3 -3
- package/dist/esm/components/ui/Video.d.ts.map +1 -1
- package/dist/esm/components/ui/Video.js +5 -3
- package/dist/esm/components/ui/Video.js.map +1 -1
- package/dist/esm/hooks/ipfs/useIpfsStorage.d.ts.map +1 -1
- package/dist/esm/hooks/ipfs/useIpfsStorage.js +2 -1
- package/dist/esm/hooks/ipfs/useIpfsStorage.js.map +1 -1
- package/dist/esm/hooks/useIpfsMetadataStorage.d.ts +2 -2
- package/dist/esm/hooks/useIpfsMetadataStorage.d.ts.map +1 -1
- package/dist/esm/hooks/useIpfsMetadataStorage.js +6 -6
- package/dist/esm/hooks/useIpfsMetadataStorage.js.map +1 -1
- package/dist/esm/hooks/useIpfsStorage.d.ts.map +1 -1
- package/dist/esm/hooks/useIpfsStorage.js +2 -1
- package/dist/esm/hooks/useIpfsStorage.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/bytes/bytesToSize.d.ts +1 -1
- package/dist/esm/lib/bytes/bytesToSize.d.ts.map +1 -1
- package/dist/esm/lib/bytes/bytesToSize.js +1 -1
- package/dist/esm/lib/bytes/bytesToSize.js.map +1 -1
- package/dist/esm/lib/const/chainInfo.d.ts.map +1 -1
- package/dist/esm/lib/const/chainInfo.js +10 -0
- package/dist/esm/lib/const/chainInfo.js.map +1 -1
- package/package.json +5 -5
- package/src/components/buttons/BaseButton.tsx +4 -0
- package/src/components/buttons/CommitButtonView.tsx +4 -0
- package/src/components/error/SimpleError.tsx +2 -2
- package/src/components/form/BaseCheckbox.tsx +50 -0
- package/src/components/form/Checkbox.tsx +17 -40
- package/src/components/form/CountrySelect.tsx +178 -130
- package/src/components/form/Field.styles.ts +113 -24
- package/src/components/form/FormField.tsx +4 -1
- package/src/components/form/Select.tsx +65 -34
- package/src/components/form/Upload/BaseUpload.tsx +367 -0
- package/src/components/form/Upload/Upload.tsx +8 -360
- package/src/components/form/Upload/UploadedFile.tsx +1 -1
- package/src/components/form/Upload/WithUploadToIpfs.tsx +8 -11
- package/src/components/form/index.ts +6 -4
- package/src/components/form/types.ts +31 -3
- package/src/components/ui/IpfsImage.tsx +14 -7
- package/src/components/ui/Video.tsx +7 -5
- package/src/hooks/ipfs/useIpfsStorage.ts +2 -0
- package/src/hooks/useIpfsMetadataStorage.tsx +6 -4
- package/src/hooks/useIpfsStorage.ts +2 -0
- package/src/index.tsx +2 -0
- package/src/lib/bytes/bytesToSize.ts +1 -1
- package/src/lib/const/chainInfo.ts +10 -1
- package/src/stories/buttons/Upload.stories.tsx +8 -0
- package/src/stories/form/BaseCheckbox.stories.tsx +113 -0
- package/src/stories/selects/CountrySelect.stories.tsx +49 -11
- package/src/stories/selects/Select.stories.tsx +117 -0
|
@@ -4,18 +4,31 @@ import { GlobeHemisphereWest } from "phosphor-react";
|
|
|
4
4
|
import React, { forwardRef, useState, useEffect } from "react";
|
|
5
5
|
import type { Country as CountryCode } from "react-phone-number-input";
|
|
6
6
|
import PhoneInput from "react-phone-number-input";
|
|
7
|
-
import Select, {
|
|
7
|
+
import Select, {
|
|
8
|
+
CSSObjectWithLabel,
|
|
9
|
+
GroupBase,
|
|
10
|
+
StylesConfig,
|
|
11
|
+
components
|
|
12
|
+
} from "react-select";
|
|
8
13
|
import styled, { CSSProperties } from "styled-components";
|
|
9
14
|
import { zIndex } from "../ui/zIndex";
|
|
10
15
|
import Error from "./Error";
|
|
11
16
|
import type { InputProps } from "./types";
|
|
12
17
|
import { SelectDataProps } from "./types";
|
|
13
18
|
import { theme as importedTheme } from "../../theme";
|
|
19
|
+
import { checkIfValueIsEmpty } from "../../lib/object/checkIfValueIsEmpty";
|
|
14
20
|
export type { Country as CountryCode } from "react-phone-number-input";
|
|
15
21
|
|
|
16
22
|
const colors = importedTheme.colors.light;
|
|
17
|
-
const customStyles =
|
|
18
|
-
|
|
23
|
+
const customStyles = (
|
|
24
|
+
error: unknown,
|
|
25
|
+
customTheme: CountrySelectProps["theme"]
|
|
26
|
+
): StylesConfig<
|
|
27
|
+
SelectDataProps<string>,
|
|
28
|
+
false,
|
|
29
|
+
GroupBase<SelectDataProps<string>>
|
|
30
|
+
> => ({
|
|
31
|
+
control: (provided, state: any) => {
|
|
19
32
|
const before = state.selectProps.label
|
|
20
33
|
? {
|
|
21
34
|
":before": {
|
|
@@ -25,26 +38,27 @@ const customStyles = {
|
|
|
25
38
|
}
|
|
26
39
|
}
|
|
27
40
|
: null;
|
|
28
|
-
const { theme } = state;
|
|
29
41
|
return {
|
|
30
42
|
...provided,
|
|
31
|
-
borderRadius: theme.borderRadius,
|
|
32
|
-
height: theme.controlHeight,
|
|
33
43
|
alignContent: "center",
|
|
34
44
|
padding: "0.4rem 1rem",
|
|
35
45
|
boxShadow: "none",
|
|
46
|
+
background: colors.lightGrey,
|
|
47
|
+
...customTheme?.control,
|
|
48
|
+
border: state.isFocused
|
|
49
|
+
? customTheme?.control?.focus?.border ?? `1px solid ${colors.secondary}`
|
|
50
|
+
: !checkIfValueIsEmpty(error)
|
|
51
|
+
? customTheme?.control?.error?.border ?? `1px solid ${colors.orange}`
|
|
52
|
+
: customTheme?.control?.border ?? `1px solid ${colors.border}`,
|
|
36
53
|
":hover": {
|
|
37
|
-
borderColor:
|
|
38
|
-
borderWidth: "1px"
|
|
54
|
+
borderColor: colors.secondary,
|
|
55
|
+
borderWidth: "1px",
|
|
56
|
+
...customTheme?.control?.hover
|
|
39
57
|
},
|
|
40
|
-
background: theme.colors.controlBackground,
|
|
41
|
-
border: state.isFocused
|
|
42
|
-
? `1px solid ${theme.colors.controlFocusBorderColor}`
|
|
43
|
-
: `1px solid ${theme.colors.controlUnfocusedBorderColor}`,
|
|
44
58
|
...before
|
|
45
59
|
};
|
|
46
60
|
},
|
|
47
|
-
container: (provided
|
|
61
|
+
container: (provided, state) => {
|
|
48
62
|
return {
|
|
49
63
|
...provided,
|
|
50
64
|
zIndex: state.isFocused ? zIndex.Select + 1 : zIndex.Select,
|
|
@@ -52,34 +66,56 @@ const customStyles = {
|
|
|
52
66
|
width: "100%"
|
|
53
67
|
};
|
|
54
68
|
},
|
|
55
|
-
option: (provided
|
|
56
|
-
const { theme } = state;
|
|
69
|
+
option: (provided, state: any) => {
|
|
57
70
|
return {
|
|
58
71
|
...provided,
|
|
72
|
+
...customTheme?.option,
|
|
59
73
|
cursor: state.isDisabled ? "not-allowed" : "pointer",
|
|
60
|
-
opacity: state.isDisabled
|
|
74
|
+
opacity: state.isDisabled
|
|
75
|
+
? customTheme?.option?.disabled?.opacity ?? "0.5"
|
|
76
|
+
: customTheme?.option?.opacity ?? "1",
|
|
61
77
|
background:
|
|
62
78
|
state.isOptionSelected || state.isSelected || state.isFocused
|
|
63
|
-
?
|
|
64
|
-
:
|
|
79
|
+
? customTheme?.option?.selected?.background ?? colors.lightGrey
|
|
80
|
+
: customTheme?.option?.background ?? colors.white,
|
|
65
81
|
color:
|
|
66
82
|
state.isOptionSelected || state.isSelected
|
|
67
|
-
?
|
|
68
|
-
:
|
|
83
|
+
? customTheme?.option?.selected?.color ?? colors.secondary
|
|
84
|
+
: customTheme?.option?.color ?? colors.black,
|
|
85
|
+
...(state.isDisabled && customTheme?.option?.disabled),
|
|
86
|
+
...((state.isOptionSelected || state.isSelected) &&
|
|
87
|
+
customTheme?.option?.selected),
|
|
88
|
+
...(state.isFocused && customTheme?.option?.focus),
|
|
89
|
+
...(!checkIfValueIsEmpty(error) && customTheme?.option?.error)
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
menu: (provided) => {
|
|
93
|
+
return {
|
|
94
|
+
...provided,
|
|
95
|
+
overflow: "hidden",
|
|
96
|
+
...customTheme?.menu,
|
|
97
|
+
...(!checkIfValueIsEmpty(error) && customTheme?.menu?.error)
|
|
69
98
|
};
|
|
70
99
|
},
|
|
71
|
-
menu: (provided) => ({
|
|
72
|
-
...provided,
|
|
73
|
-
overflow: "hidden"
|
|
74
|
-
}),
|
|
75
100
|
indicatorSeparator: () => ({
|
|
76
101
|
display: "none"
|
|
102
|
+
}),
|
|
103
|
+
placeholder: (provided) => ({
|
|
104
|
+
...provided,
|
|
105
|
+
...customTheme?.placeholder,
|
|
106
|
+
...(!checkIfValueIsEmpty(error) && customTheme?.placeholder?.error)
|
|
107
|
+
}),
|
|
108
|
+
input: (provided) => ({
|
|
109
|
+
...provided,
|
|
110
|
+
...customTheme?.input,
|
|
111
|
+
...(!checkIfValueIsEmpty(error) && customTheme?.input?.error)
|
|
112
|
+
}),
|
|
113
|
+
singleValue: (provided) => ({
|
|
114
|
+
...provided,
|
|
115
|
+
...customTheme?.singleValue,
|
|
116
|
+
...(!checkIfValueIsEmpty(error) && customTheme?.singleValue?.error)
|
|
77
117
|
})
|
|
78
|
-
}
|
|
79
|
-
SelectDataProps<string>,
|
|
80
|
-
false,
|
|
81
|
-
GroupBase<SelectDataProps<string>>
|
|
82
|
-
>;
|
|
118
|
+
});
|
|
83
119
|
|
|
84
120
|
const ControlGrid = styled.div`
|
|
85
121
|
display: flex;
|
|
@@ -88,6 +124,7 @@ const ControlGrid = styled.div`
|
|
|
88
124
|
align-items: center;
|
|
89
125
|
justify-content: space-between;
|
|
90
126
|
.PhoneInputCountryIcon {
|
|
127
|
+
max-width: fit-content;
|
|
91
128
|
min-width: 40px;
|
|
92
129
|
display: inline;
|
|
93
130
|
height: 27px;
|
|
@@ -95,6 +132,9 @@ const ControlGrid = styled.div`
|
|
|
95
132
|
max-width: 40px;
|
|
96
133
|
}
|
|
97
134
|
}
|
|
135
|
+
svg {
|
|
136
|
+
max-width: 40px;
|
|
137
|
+
}
|
|
98
138
|
`;
|
|
99
139
|
const OptionGrid = styled.div`
|
|
100
140
|
display: grid;
|
|
@@ -122,38 +162,57 @@ const PhoneWrapper = styled.div`
|
|
|
122
162
|
|
|
123
163
|
export type CountrySelectProps = InputProps & {
|
|
124
164
|
countries?: CountryCode[];
|
|
165
|
+
fieldValueIsCountryCode?: boolean; // if true, the field.value will be the countryCodeOrName, otherwise the country name
|
|
125
166
|
theme?: Partial<{
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
167
|
+
control: Partial<CSSProperties> &
|
|
168
|
+
Partial<{
|
|
169
|
+
hover: Partial<CSSProperties>;
|
|
170
|
+
focus: Partial<CSSProperties>;
|
|
171
|
+
error: Partial<CSSProperties>;
|
|
172
|
+
}>;
|
|
173
|
+
option: Partial<CSSProperties> &
|
|
174
|
+
Partial<{
|
|
175
|
+
selected: Partial<CSSProperties>;
|
|
176
|
+
disabled: Partial<CSSProperties>;
|
|
177
|
+
focus: Partial<CSSProperties>;
|
|
178
|
+
error: CSSProperties;
|
|
179
|
+
}>;
|
|
180
|
+
placeholder: Partial<CSSProperties> &
|
|
181
|
+
Partial<{ error: CSSObjectWithLabel }>;
|
|
182
|
+
input: Partial<CSSProperties> & Partial<{ error: CSSObjectWithLabel }>;
|
|
183
|
+
singleValue: Partial<CSSProperties> &
|
|
184
|
+
Partial<{ error: CSSObjectWithLabel }>;
|
|
185
|
+
menu: Partial<CSSProperties> & Partial<{ error: CSSObjectWithLabel }>;
|
|
136
186
|
}>;
|
|
137
187
|
};
|
|
138
|
-
|
|
188
|
+
type CountryName = string;
|
|
139
189
|
export function CountrySelect({
|
|
140
190
|
name,
|
|
141
191
|
countries,
|
|
142
192
|
theme: selectTheme,
|
|
193
|
+
fieldValueIsCountryCode,
|
|
143
194
|
...rest
|
|
144
195
|
}: CountrySelectProps) {
|
|
145
196
|
const { status } = useFormikContext();
|
|
146
197
|
const [initialized, setInitialized] = useState<boolean>(false);
|
|
147
198
|
const [field, meta, helpers] = useField(name);
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
|
|
199
|
+
const errorMessage = meta.error || status?.[name];
|
|
200
|
+
const displayErrorMessage =
|
|
201
|
+
meta.error && meta.touched && !errorMessage
|
|
202
|
+
? meta.error
|
|
203
|
+
: meta.error && meta.touched && errorMessage
|
|
204
|
+
? errorMessage
|
|
205
|
+
: "";
|
|
206
|
+
const displayError =
|
|
207
|
+
typeof displayErrorMessage === "string" && displayErrorMessage !== "";
|
|
151
208
|
const [phone, setPhone] = useState<string | undefined>(undefined);
|
|
152
|
-
const [
|
|
209
|
+
const [countryCodeOrName, setCountryCodeOrName] = useState<
|
|
210
|
+
CountryCode | CountryName | undefined
|
|
211
|
+
>();
|
|
153
212
|
|
|
154
213
|
useEffect(() => {
|
|
155
214
|
if (!initialized && field.value) {
|
|
156
|
-
|
|
215
|
+
setCountryCodeOrName(field.value);
|
|
157
216
|
setInitialized(true);
|
|
158
217
|
}
|
|
159
218
|
}, [field.value, initialized]); // eslint-disable-line
|
|
@@ -167,94 +226,83 @@ export function CountrySelect({
|
|
|
167
226
|
<div></div>
|
|
168
227
|
))}
|
|
169
228
|
addInternationalOption={false}
|
|
170
|
-
country={
|
|
229
|
+
country={countryCodeOrName}
|
|
171
230
|
value={phone}
|
|
172
231
|
onChange={(value) => setPhone((value || "").replace(/\+/g, ""))}
|
|
173
232
|
countries={countries}
|
|
174
|
-
countrySelectComponent={({ iconComponent: Icon, ...props }) =>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
)}
|
|
248
|
-
{props.label}
|
|
249
|
-
</OptionGrid>
|
|
250
|
-
</components.Option>
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
}}
|
|
254
|
-
/>
|
|
255
|
-
</div>
|
|
256
|
-
</>
|
|
257
|
-
)}
|
|
233
|
+
countrySelectComponent={({ iconComponent: Icon, ...props }) => {
|
|
234
|
+
const value = (props?.options || []).find((o: SelectDataProps) =>
|
|
235
|
+
fieldValueIsCountryCode
|
|
236
|
+
? o.value === countryCodeOrName
|
|
237
|
+
: o.label === countryCodeOrName
|
|
238
|
+
);
|
|
239
|
+
return (
|
|
240
|
+
<>
|
|
241
|
+
<div>
|
|
242
|
+
<Select
|
|
243
|
+
{...rest}
|
|
244
|
+
{...props}
|
|
245
|
+
isDisabled={rest.disabled}
|
|
246
|
+
styles={customStyles(displayErrorMessage, selectTheme)}
|
|
247
|
+
name="countrySelect"
|
|
248
|
+
value={value}
|
|
249
|
+
onChange={(o: SelectDataProps) => {
|
|
250
|
+
if (!meta.touched) {
|
|
251
|
+
helpers.setTouched(true);
|
|
252
|
+
}
|
|
253
|
+
const value = fieldValueIsCountryCode ? o.value : o.label;
|
|
254
|
+
setCountryCodeOrName(value);
|
|
255
|
+
helpers.setValue(value);
|
|
256
|
+
}}
|
|
257
|
+
onBlur={() => {
|
|
258
|
+
if (!meta.touched) {
|
|
259
|
+
helpers.setTouched(true);
|
|
260
|
+
}
|
|
261
|
+
}}
|
|
262
|
+
components={{
|
|
263
|
+
Control: (props) => {
|
|
264
|
+
const country =
|
|
265
|
+
(props?.getValue()[0] as any)?.value || null;
|
|
266
|
+
return (
|
|
267
|
+
<components.Control {...props}>
|
|
268
|
+
<ControlGrid>
|
|
269
|
+
{country ? (
|
|
270
|
+
<Icon
|
|
271
|
+
country={country as CountryCode}
|
|
272
|
+
label=""
|
|
273
|
+
/>
|
|
274
|
+
) : (
|
|
275
|
+
<GlobeHemisphereWest />
|
|
276
|
+
)}
|
|
277
|
+
{props.children as any}
|
|
278
|
+
</ControlGrid>
|
|
279
|
+
</components.Control>
|
|
280
|
+
);
|
|
281
|
+
},
|
|
282
|
+
Option: (props) => {
|
|
283
|
+
const country = (props?.data as any)?.value || null;
|
|
284
|
+
return (
|
|
285
|
+
<components.Option {...props}>
|
|
286
|
+
<OptionGrid>
|
|
287
|
+
{country ? (
|
|
288
|
+
<Icon
|
|
289
|
+
country={country as CountryCode}
|
|
290
|
+
label={props.label}
|
|
291
|
+
/>
|
|
292
|
+
) : (
|
|
293
|
+
<GlobeHemisphereWest />
|
|
294
|
+
)}
|
|
295
|
+
{props.label}
|
|
296
|
+
</OptionGrid>
|
|
297
|
+
</components.Option>
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
}}
|
|
301
|
+
/>
|
|
302
|
+
</div>
|
|
303
|
+
</>
|
|
304
|
+
);
|
|
305
|
+
}}
|
|
258
306
|
/>
|
|
259
307
|
</PhoneWrapper>
|
|
260
308
|
<Error display={!rest.hideError && displayError} message={errorMessage} />
|
|
@@ -115,7 +115,21 @@ export const FieldInput = styled.input<{
|
|
|
115
115
|
`};
|
|
116
116
|
`;
|
|
117
117
|
|
|
118
|
-
export
|
|
118
|
+
export type FileUploadWrapperTheme = Partial<{
|
|
119
|
+
borderColor: CSSProperties["borderColor"];
|
|
120
|
+
borderRadius: CSSProperties["borderRadius"];
|
|
121
|
+
background: CSSProperties["background"];
|
|
122
|
+
focus: Partial<{
|
|
123
|
+
borderColor: CSSProperties["borderColor"];
|
|
124
|
+
}>;
|
|
125
|
+
error: Partial<{
|
|
126
|
+
borderColor: CSSProperties["borderColor"];
|
|
127
|
+
}>;
|
|
128
|
+
}>;
|
|
129
|
+
export const FileUploadWrapper = styled.div<{
|
|
130
|
+
$error: unknown;
|
|
131
|
+
theme: FileUploadWrapperTheme | undefined;
|
|
132
|
+
}>`
|
|
119
133
|
position: relative;
|
|
120
134
|
overflow: hidden;
|
|
121
135
|
display: flex;
|
|
@@ -144,28 +158,33 @@ export const FileUploadWrapper = styled.div<{ error: any }>`
|
|
|
144
158
|
}
|
|
145
159
|
}
|
|
146
160
|
|
|
147
|
-
background: ${colors.lightGrey};
|
|
148
|
-
|
|
161
|
+
background: ${({ theme }) => theme?.background || colors.lightGrey};
|
|
162
|
+
${({ theme }) =>
|
|
163
|
+
theme.borderRadius !== undefined &&
|
|
164
|
+
css`
|
|
165
|
+
border-radius: ${theme.borderRadius};
|
|
166
|
+
`};
|
|
149
167
|
outline: none;
|
|
150
168
|
|
|
151
|
-
${({ error }) =>
|
|
152
|
-
!checkIfValueIsEmpty(error)
|
|
169
|
+
${({ $error, theme }) =>
|
|
170
|
+
!checkIfValueIsEmpty($error)
|
|
153
171
|
? css`
|
|
154
|
-
border: 1px solid ${colors.orange};
|
|
172
|
+
border: 1px solid ${theme?.error?.borderColor || colors.orange};
|
|
155
173
|
`
|
|
156
174
|
: css`
|
|
157
|
-
border: 1px solid ${colors.border};
|
|
175
|
+
border: 1px solid ${theme?.borderColor || colors.border};
|
|
158
176
|
`}
|
|
159
177
|
|
|
160
178
|
${transition};
|
|
161
179
|
|
|
162
180
|
&:focus,
|
|
163
181
|
&:hover {
|
|
164
|
-
border: 1px solid
|
|
182
|
+
border: 1px solid
|
|
183
|
+
${({ theme }) => theme?.hover?.borderColor || colors.lightGrey};
|
|
165
184
|
}
|
|
166
185
|
|
|
167
186
|
/* prettier-ignore */
|
|
168
|
-
[data-disabled=true] {
|
|
187
|
+
:disabled, [data-disabled=true] {
|
|
169
188
|
cursor: not-allowed;
|
|
170
189
|
opacity: 0.5;
|
|
171
190
|
}
|
|
@@ -319,7 +338,31 @@ export const FormFieldWrapper = styled(Grid)`
|
|
|
319
338
|
}
|
|
320
339
|
`;
|
|
321
340
|
|
|
322
|
-
export
|
|
341
|
+
export type CheckboxTheme = Partial<{
|
|
342
|
+
backgroundColor: CSSProperties["backgroundColor"];
|
|
343
|
+
borderColor: CSSProperties["borderColor"];
|
|
344
|
+
borderRadius: CSSProperties["borderRadius"];
|
|
345
|
+
color: CSSProperties["color"];
|
|
346
|
+
hover: Partial<{
|
|
347
|
+
borderColor: CSSProperties["borderColor"];
|
|
348
|
+
backgroundColor: CSSProperties["backgroundColor"];
|
|
349
|
+
color: CSSProperties["color"];
|
|
350
|
+
}>;
|
|
351
|
+
error: Partial<{
|
|
352
|
+
borderColor: CSSProperties["borderColor"];
|
|
353
|
+
backgroundColor: CSSProperties["backgroundColor"];
|
|
354
|
+
color: CSSProperties["color"];
|
|
355
|
+
}>;
|
|
356
|
+
checked: Partial<{
|
|
357
|
+
borderColor: CSSProperties["borderColor"];
|
|
358
|
+
backgroundColor: CSSProperties["backgroundColor"];
|
|
359
|
+
color: CSSProperties["color"];
|
|
360
|
+
}>;
|
|
361
|
+
}>;
|
|
362
|
+
export const CheckboxWrapper = styled.label<{
|
|
363
|
+
$error: unknown;
|
|
364
|
+
theme: CheckboxTheme;
|
|
365
|
+
}>`
|
|
323
366
|
display: flex;
|
|
324
367
|
align-items: center;
|
|
325
368
|
justify-content: flex-start;
|
|
@@ -336,7 +379,18 @@ export const CheckboxWrapper = styled.label<{ error: any }>`
|
|
|
336
379
|
+ div {
|
|
337
380
|
cursor: pointer;
|
|
338
381
|
&:hover {
|
|
339
|
-
border: 1px solid
|
|
382
|
+
border: 1px solid
|
|
383
|
+
${({ theme }) => theme?.hover?.borderColor || colors.border};
|
|
384
|
+
${({ theme }) =>
|
|
385
|
+
theme?.hover?.backgroundColor &&
|
|
386
|
+
css`
|
|
387
|
+
background-color: ${theme?.hover?.backgroundColor};
|
|
388
|
+
`};
|
|
389
|
+
${({ theme }) =>
|
|
390
|
+
theme?.hover?.color &&
|
|
391
|
+
css`
|
|
392
|
+
color: ${theme?.hover?.color};
|
|
393
|
+
`};
|
|
340
394
|
svg {
|
|
341
395
|
opacity: 0.25;
|
|
342
396
|
}
|
|
@@ -356,8 +410,19 @@ export const CheckboxWrapper = styled.label<{ error: any }>`
|
|
|
356
410
|
width: 1.5rem;
|
|
357
411
|
height: 1.5rem;
|
|
358
412
|
|
|
359
|
-
background: ${
|
|
360
|
-
|
|
413
|
+
background-color: ${({ theme }) =>
|
|
414
|
+
theme?.backgroundColor || colors.lightGrey};
|
|
415
|
+
border: 1px solid ${({ theme }) => theme?.borderColor};
|
|
416
|
+
${({ theme }) =>
|
|
417
|
+
theme?.color &&
|
|
418
|
+
css`
|
|
419
|
+
color: ${theme?.color};
|
|
420
|
+
`};
|
|
421
|
+
${({ theme }) =>
|
|
422
|
+
theme?.borderRadius !== undefined &&
|
|
423
|
+
css`
|
|
424
|
+
border-radius: ${theme?.borderRadius};
|
|
425
|
+
`};
|
|
361
426
|
margin-right: 0.5rem;
|
|
362
427
|
}
|
|
363
428
|
|
|
@@ -366,6 +431,23 @@ export const CheckboxWrapper = styled.label<{ error: any }>`
|
|
|
366
431
|
+ div svg {
|
|
367
432
|
opacity: 1;
|
|
368
433
|
}
|
|
434
|
+
+ div {
|
|
435
|
+
${({ theme }) =>
|
|
436
|
+
theme?.checked?.backgroundColor &&
|
|
437
|
+
css`
|
|
438
|
+
background-color: ${theme?.checked?.backgroundColor};
|
|
439
|
+
`};
|
|
440
|
+
${({ theme }) =>
|
|
441
|
+
theme?.checked?.borderColor &&
|
|
442
|
+
css`
|
|
443
|
+
border: 1px solid ${theme?.checked?.borderColor};
|
|
444
|
+
`};
|
|
445
|
+
${({ theme }) =>
|
|
446
|
+
theme?.checked?.color &&
|
|
447
|
+
css`
|
|
448
|
+
color: ${theme?.checked?.color};
|
|
449
|
+
`};
|
|
450
|
+
}
|
|
369
451
|
}
|
|
370
452
|
&:not(:checked) {
|
|
371
453
|
+ div svg {
|
|
@@ -374,17 +456,24 @@ export const CheckboxWrapper = styled.label<{ error: any }>`
|
|
|
374
456
|
}
|
|
375
457
|
}
|
|
376
458
|
|
|
377
|
-
${({ error }) =>
|
|
378
|
-
!checkIfValueIsEmpty(error)
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
459
|
+
${({ $error, theme }) =>
|
|
460
|
+
!checkIfValueIsEmpty($error) &&
|
|
461
|
+
css`
|
|
462
|
+
> div {
|
|
463
|
+
border: 1px solid ${theme?.error?.borderColor || colors.orange}};
|
|
464
|
+
${
|
|
465
|
+
theme?.error?.backgroundColor &&
|
|
466
|
+
css`
|
|
467
|
+
background-color: ${theme?.error?.backgroundColor};
|
|
468
|
+
`
|
|
469
|
+
};
|
|
470
|
+
${
|
|
471
|
+
theme?.error?.color &&
|
|
472
|
+
css`
|
|
473
|
+
color: ${theme?.error?.color};
|
|
474
|
+
`
|
|
475
|
+
};
|
|
476
|
+
}
|
|
388
477
|
`}
|
|
389
478
|
`;
|
|
390
479
|
|
|
@@ -10,6 +10,7 @@ import { Grid } from "../ui/Grid";
|
|
|
10
10
|
import { Typography } from "../ui/Typography";
|
|
11
11
|
import { CopyButton, FormFieldWrapper } from "./Field.styles";
|
|
12
12
|
import type { FormFieldProps } from "./types";
|
|
13
|
+
export type { FormFieldProps } from "./types";
|
|
13
14
|
|
|
14
15
|
const colors = theme.colors.light;
|
|
15
16
|
|
|
@@ -22,7 +23,8 @@ export function FormField({
|
|
|
22
23
|
children,
|
|
23
24
|
style = {},
|
|
24
25
|
valueToCopy,
|
|
25
|
-
copyIconColor = colors.secondary
|
|
26
|
+
copyIconColor = colors.secondary,
|
|
27
|
+
...rest
|
|
26
28
|
}: FormFieldProps) {
|
|
27
29
|
return (
|
|
28
30
|
<FormFieldWrapper
|
|
@@ -31,6 +33,7 @@ export function FormField({
|
|
|
31
33
|
alignItems="flex-start"
|
|
32
34
|
flexGrow="1"
|
|
33
35
|
style={style}
|
|
36
|
+
{...rest}
|
|
34
37
|
>
|
|
35
38
|
<>
|
|
36
39
|
<Grid justifyContent="flex-start" margin="0 0 0.375rem 0">
|