@arcblock/ux 2.12.28 → 2.12.30
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.
@@ -1,13 +1,19 @@
|
|
1
1
|
import { SelectProps } from '@mui/material';
|
2
2
|
import type { CountryIso2 } from 'react-international-phone';
|
3
|
+
import { ParsedCountry } from 'react-international-phone/build/types';
|
3
4
|
export interface CountryDisplayOptions {
|
4
5
|
hideFlag?: boolean;
|
6
|
+
hideDialCode?: boolean;
|
5
7
|
}
|
6
|
-
export interface CountrySelectProps extends Omit<SelectProps, 'value' | 'onChange'> {
|
7
|
-
value: CountryIso2;
|
8
|
-
onChange?: (value: CountryIso2) => void;
|
8
|
+
export interface CountrySelectProps<T extends keyof ParsedCountry = 'iso2'> extends Omit<SelectProps, 'value' | 'onChange'> {
|
9
|
+
value: T extends 'iso2' ? CountryIso2 : string;
|
10
|
+
onChange?: (value: T extends 'iso2' ? CountryIso2 : string) => void;
|
9
11
|
selectCountryProps?: CountryDisplayOptions;
|
10
12
|
preview?: boolean;
|
13
|
+
valueField?: T;
|
11
14
|
}
|
12
|
-
|
15
|
+
type CountrySelectComponent = <T extends keyof ParsedCountry = 'iso2'>(props: CountrySelectProps<T> & {
|
16
|
+
ref?: React.ForwardedRef<HTMLDivElement>;
|
17
|
+
}) => React.ReactElement;
|
18
|
+
declare const CountrySelect: CountrySelectComponent;
|
13
19
|
export default CountrySelect;
|
@@ -4,15 +4,23 @@ import { Box, MenuItem, Select, Typography, TextField } from '@mui/material';
|
|
4
4
|
import { FlagEmoji, defaultCountries, parseCountry } from 'react-international-phone';
|
5
5
|
import ArrowDownwardIcon from '@arcblock/icons/lib/ArrowDown';
|
6
6
|
import { temp as colors } from '../Colors';
|
7
|
-
|
7
|
+
import { mergeSx } from '../Util/style';
|
8
|
+
|
9
|
+
// 定义组件类型
|
10
|
+
|
11
|
+
// 实现组件
|
12
|
+
const CountrySelectInner = /*#__PURE__*/forwardRef(({
|
8
13
|
value,
|
9
14
|
onChange,
|
10
15
|
sx = {},
|
11
16
|
selectCountryProps,
|
12
|
-
preview = false
|
17
|
+
preview = false,
|
18
|
+
valueField = 'iso2',
|
19
|
+
...rest
|
13
20
|
}, ref) => {
|
14
21
|
const {
|
15
|
-
hideFlag = true
|
22
|
+
hideFlag = true,
|
23
|
+
hideDialCode = false
|
16
24
|
} = selectCountryProps || {};
|
17
25
|
const [searchQuery, setSearchQuery] = useState('');
|
18
26
|
const countryDetail = useMemo(() => {
|
@@ -46,18 +54,19 @@ const CountrySelect = /*#__PURE__*/forwardRef(({
|
|
46
54
|
width: 24,
|
47
55
|
color: 'inherit'
|
48
56
|
}
|
49
|
-
}), /*#__PURE__*/
|
57
|
+
}), /*#__PURE__*/_jsx(Typography, {
|
50
58
|
component: "span",
|
51
59
|
sx: {
|
52
60
|
lineHeight: 1.5
|
53
61
|
},
|
54
|
-
children:
|
62
|
+
children: hideDialCode ? value : `+${countryDetail?.dialCode}`
|
55
63
|
})]
|
56
64
|
});
|
57
65
|
if (preview) {
|
58
66
|
return renderCountryContent;
|
59
67
|
}
|
60
68
|
return /*#__PURE__*/_jsxs(Select, {
|
69
|
+
...rest,
|
61
70
|
ref: ref,
|
62
71
|
MenuProps: {
|
63
72
|
style: {
|
@@ -73,7 +82,7 @@ const CountrySelect = /*#__PURE__*/forwardRef(({
|
|
73
82
|
horizontal: 'left'
|
74
83
|
}
|
75
84
|
},
|
76
|
-
sx: {
|
85
|
+
sx: mergeSx({
|
77
86
|
'&.Mui-focused:has(div[aria-expanded="false"])': {
|
78
87
|
fieldset: {
|
79
88
|
display: 'block'
|
@@ -97,9 +106,8 @@ const CountrySelect = /*#__PURE__*/forwardRef(({
|
|
97
106
|
},
|
98
107
|
'.MuiMenuItem-root': {
|
99
108
|
justifyContent: 'flex-start'
|
100
|
-
}
|
101
|
-
|
102
|
-
},
|
109
|
+
}
|
110
|
+
}, sx),
|
103
111
|
value: value,
|
104
112
|
onChange: e => onChange?.(e.target.value)
|
105
113
|
// eslint-disable-next-line react/no-unstable-nested-components
|
@@ -130,7 +138,7 @@ const CountrySelect = /*#__PURE__*/forwardRef(({
|
|
130
138
|
}), filteredCountries.map(c => {
|
131
139
|
const parsed = parseCountry(c);
|
132
140
|
return /*#__PURE__*/_jsxs(MenuItem, {
|
133
|
-
value: parsed
|
141
|
+
value: parsed[valueField],
|
134
142
|
children: [hideFlag ? null : /*#__PURE__*/_jsx(FlagEmoji, {
|
135
143
|
iso2: parsed.iso2,
|
136
144
|
style: {
|
@@ -140,7 +148,7 @@ const CountrySelect = /*#__PURE__*/forwardRef(({
|
|
140
148
|
}), /*#__PURE__*/_jsx(Typography, {
|
141
149
|
marginRight: 1,
|
142
150
|
children: parsed.name
|
143
|
-
}), /*#__PURE__*/_jsxs(Typography, {
|
151
|
+
}), hideDialCode ? null : /*#__PURE__*/_jsxs(Typography, {
|
144
152
|
color: "gray",
|
145
153
|
children: ["(+", parsed.dialCode, ")"]
|
146
154
|
})]
|
@@ -148,4 +156,7 @@ const CountrySelect = /*#__PURE__*/forwardRef(({
|
|
148
156
|
})]
|
149
157
|
});
|
150
158
|
});
|
159
|
+
|
160
|
+
// 正确导出泛型组件
|
161
|
+
const CountrySelect = CountrySelectInner;
|
151
162
|
export default CountrySelect;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.12.
|
3
|
+
"version": "2.12.30",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -68,12 +68,12 @@
|
|
68
68
|
"react": ">=18.2.0",
|
69
69
|
"react-router-dom": ">=6.22.3"
|
70
70
|
},
|
71
|
-
"gitHead": "
|
71
|
+
"gitHead": "97305a61162566787fbc38decf9d26dcdb556637",
|
72
72
|
"dependencies": {
|
73
73
|
"@arcblock/did-motif": "^1.1.13",
|
74
|
-
"@arcblock/icons": "^2.12.
|
75
|
-
"@arcblock/nft-display": "^2.12.
|
76
|
-
"@arcblock/react-hooks": "^2.12.
|
74
|
+
"@arcblock/icons": "^2.12.30",
|
75
|
+
"@arcblock/nft-display": "^2.12.30",
|
76
|
+
"@arcblock/react-hooks": "^2.12.30",
|
77
77
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
78
78
|
"@fontsource/inter": "^5.0.16",
|
79
79
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
@@ -1,24 +1,46 @@
|
|
1
1
|
import { useMemo, forwardRef, useState } from 'react';
|
2
|
-
import { Box, MenuItem, Select, Typography, SelectProps, TextField } from '@mui/material';
|
2
|
+
import { Box, MenuItem, Select, Typography, SelectProps, TextField, SxProps } from '@mui/material';
|
3
3
|
import { FlagEmoji, defaultCountries, parseCountry } from 'react-international-phone';
|
4
4
|
import type { CountryIso2 } from 'react-international-phone';
|
5
|
+
import { ParsedCountry } from 'react-international-phone/build/types';
|
5
6
|
import ArrowDownwardIcon from '@arcblock/icons/lib/ArrowDown';
|
6
7
|
import { temp as colors } from '../Colors';
|
8
|
+
import { mergeSx } from '../Util/style';
|
7
9
|
|
8
10
|
export interface CountryDisplayOptions {
|
9
11
|
hideFlag?: boolean;
|
12
|
+
hideDialCode?: boolean;
|
10
13
|
}
|
11
14
|
|
12
|
-
export interface CountrySelectProps extends
|
13
|
-
value
|
14
|
-
|
15
|
+
export interface CountrySelectProps<T extends keyof ParsedCountry = 'iso2'>
|
16
|
+
extends Omit<SelectProps, 'value' | 'onChange'> {
|
17
|
+
value: T extends 'iso2' ? CountryIso2 : string;
|
18
|
+
onChange?: (value: T extends 'iso2' ? CountryIso2 : string) => void;
|
15
19
|
selectCountryProps?: CountryDisplayOptions;
|
16
20
|
preview?: boolean;
|
21
|
+
valueField?: T;
|
17
22
|
}
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
24
|
+
// 定义组件类型
|
25
|
+
type CountrySelectComponent = <T extends keyof ParsedCountry = 'iso2'>(
|
26
|
+
props: CountrySelectProps<T> & { ref?: React.ForwardedRef<HTMLDivElement> }
|
27
|
+
) => React.ReactElement;
|
28
|
+
|
29
|
+
// 实现组件
|
30
|
+
const CountrySelectInner = forwardRef(
|
31
|
+
<T extends keyof ParsedCountry = 'iso2'>(
|
32
|
+
{
|
33
|
+
value,
|
34
|
+
onChange,
|
35
|
+
sx = {},
|
36
|
+
selectCountryProps,
|
37
|
+
preview = false,
|
38
|
+
valueField = 'iso2' as T,
|
39
|
+
...rest
|
40
|
+
}: CountrySelectProps<T>,
|
41
|
+
ref: React.ForwardedRef<HTMLDivElement>
|
42
|
+
) => {
|
43
|
+
const { hideFlag = true, hideDialCode = false } = selectCountryProps || {};
|
22
44
|
const [searchQuery, setSearchQuery] = useState('');
|
23
45
|
|
24
46
|
const countryDetail = useMemo(() => {
|
@@ -49,7 +71,7 @@ const CountrySelect = forwardRef<HTMLDivElement, CountrySelectProps>(
|
|
49
71
|
sx={{ cursor: preview ? 'default' : 'pointer' }}>
|
50
72
|
{hideFlag ? null : <FlagEmoji iso2={value} style={{ display: 'flex', width: 24, color: 'inherit' }} />}
|
51
73
|
<Typography component="span" sx={{ lineHeight: 1.5 }}>
|
52
|
-
|
74
|
+
{hideDialCode ? value : `+${countryDetail?.dialCode}`}
|
53
75
|
</Typography>
|
54
76
|
</Box>
|
55
77
|
);
|
@@ -60,29 +82,32 @@ const CountrySelect = forwardRef<HTMLDivElement, CountrySelectProps>(
|
|
60
82
|
|
61
83
|
return (
|
62
84
|
<Select
|
85
|
+
{...rest}
|
63
86
|
ref={ref}
|
64
87
|
MenuProps={{
|
65
88
|
style: { maxHeight: 400, top: 2 },
|
66
89
|
anchorOrigin: { vertical: 'bottom', horizontal: 'left' },
|
67
90
|
transformOrigin: { vertical: 'top', horizontal: 'left' },
|
68
91
|
}}
|
69
|
-
sx={
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
92
|
+
sx={mergeSx(
|
93
|
+
{
|
94
|
+
'&.Mui-focused:has(div[aria-expanded="false"])': { fieldset: { display: 'block' } },
|
95
|
+
'.MuiSelect-select': { padding: 1, paddingRight: '24px !important' },
|
96
|
+
svg: { right: 4, top: 10 },
|
97
|
+
'&:hover': {
|
98
|
+
'fieldset.MuiOutlinedInput-notchedOutline': {
|
99
|
+
borderColor: colors.dividerColor,
|
100
|
+
},
|
101
|
+
},
|
74
102
|
'fieldset.MuiOutlinedInput-notchedOutline': {
|
75
103
|
borderColor: colors.dividerColor,
|
76
104
|
},
|
105
|
+
'.MuiMenuItem-root': { justifyContent: 'flex-start' },
|
77
106
|
},
|
78
|
-
|
79
|
-
|
80
|
-
},
|
81
|
-
'.MuiMenuItem-root': { justifyContent: 'flex-start' },
|
82
|
-
...sx,
|
83
|
-
}}
|
107
|
+
sx as SxProps
|
108
|
+
)}
|
84
109
|
value={value}
|
85
|
-
onChange={(e) => onChange?.(e.target.value as CountryIso2)}
|
110
|
+
onChange={(e) => onChange?.(e.target.value as T extends 'iso2' ? CountryIso2 : string)}
|
86
111
|
// eslint-disable-next-line react/no-unstable-nested-components
|
87
112
|
IconComponent={(props) => <ArrowDownwardIcon {...props} width={20} height={20} />}
|
88
113
|
renderValue={() => renderCountryContent}>
|
@@ -101,10 +126,10 @@ const CountrySelect = forwardRef<HTMLDivElement, CountrySelectProps>(
|
|
101
126
|
{filteredCountries.map((c) => {
|
102
127
|
const parsed = parseCountry(c);
|
103
128
|
return (
|
104
|
-
<MenuItem key={parsed.iso2} value={parsed
|
129
|
+
<MenuItem key={parsed.iso2} value={parsed[valueField]}>
|
105
130
|
{hideFlag ? null : <FlagEmoji iso2={parsed.iso2} style={{ marginRight: 8, width: 24 }} />}
|
106
131
|
<Typography marginRight={1}>{parsed.name}</Typography>
|
107
|
-
<Typography color="gray">(+{parsed.dialCode})</Typography>
|
132
|
+
{hideDialCode ? null : <Typography color="gray">(+{parsed.dialCode})</Typography>}
|
108
133
|
</MenuItem>
|
109
134
|
);
|
110
135
|
})}
|
@@ -113,4 +138,7 @@ const CountrySelect = forwardRef<HTMLDivElement, CountrySelectProps>(
|
|
113
138
|
}
|
114
139
|
);
|
115
140
|
|
141
|
+
// 正确导出泛型组件
|
142
|
+
const CountrySelect = CountrySelectInner as CountrySelectComponent;
|
143
|
+
|
116
144
|
export default CountrySelect;
|