@etsoo/materialui 1.0.79 → 1.0.81
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/lib/CountryList.d.ts +30 -0
- package/lib/CountryList.js +22 -0
- package/lib/DataSteps.d.ts +1 -1
- package/lib/DataSteps.js +4 -10
- package/lib/Tiplist.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +1 -1
- package/src/CountryList.tsx +68 -0
- package/src/DataSteps.tsx +5 -12
- package/src/Tiplist.tsx +1 -1
- package/src/index.ts +1 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AddressRegionDb, RegionsRQ } from '@etsoo/appscript';
|
|
3
|
+
import { DataTypes } from '@etsoo/shared';
|
|
4
|
+
import { TiplistProps } from './Tiplist';
|
|
5
|
+
/**
|
|
6
|
+
* Country list props
|
|
7
|
+
*/
|
|
8
|
+
export type CountryListProps = Omit<DataTypes.Optional<TiplistProps<AddressRegionDb, 'id'>, 'name'>, 'loadData'> & {
|
|
9
|
+
/**
|
|
10
|
+
* Load data
|
|
11
|
+
* @param rq Request data
|
|
12
|
+
* @returns Result
|
|
13
|
+
*/
|
|
14
|
+
loadData: (rq: RegionsRQ) => Promise<AddressRegionDb[] | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Load favored country ids
|
|
17
|
+
* @returns Result
|
|
18
|
+
*/
|
|
19
|
+
loadFavoredIds?: () => Promise<string[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Max items to display
|
|
22
|
+
*/
|
|
23
|
+
items?: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Country list
|
|
27
|
+
* @param props Props
|
|
28
|
+
* @returns Component
|
|
29
|
+
*/
|
|
30
|
+
export declare function CountryList(props: CountryListProps): JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Tiplist } from './Tiplist';
|
|
3
|
+
/**
|
|
4
|
+
* Country list
|
|
5
|
+
* @param props Props
|
|
6
|
+
* @returns Component
|
|
7
|
+
*/
|
|
8
|
+
export function CountryList(props) {
|
|
9
|
+
// Destruct
|
|
10
|
+
const { items = 16, loadData, loadFavoredIds, name = 'countryId', ...rest } = props;
|
|
11
|
+
// Ref
|
|
12
|
+
const favoredIds = React.useRef([]);
|
|
13
|
+
// Ready
|
|
14
|
+
React.useEffect(() => {
|
|
15
|
+
if (loadFavoredIds)
|
|
16
|
+
loadFavoredIds().then((ids) => {
|
|
17
|
+
favoredIds.current = ids;
|
|
18
|
+
});
|
|
19
|
+
}, [loadFavoredIds]);
|
|
20
|
+
// Layout
|
|
21
|
+
return (React.createElement(Tiplist, { name: name, loadData: (keyword, id) => loadData({ id, keyword, favoredIds: favoredIds.current, items }), ...rest }));
|
|
22
|
+
}
|
package/lib/DataSteps.d.ts
CHANGED
package/lib/DataSteps.js
CHANGED
|
@@ -25,14 +25,12 @@ export function DataSteps(props) {
|
|
|
25
25
|
(_a = InputLabelProps.shrink) !== null && _a !== void 0 ? _a : (InputLabelProps.shrink = MUGlobal.searchFieldShrink);
|
|
26
26
|
// Current index
|
|
27
27
|
const indexRef = React.useRef(-1);
|
|
28
|
-
// Current data
|
|
29
|
-
const dataRef = React.useRef({});
|
|
30
28
|
// Current value
|
|
31
29
|
const [localValue, setLocalValue] = React.useState(value);
|
|
32
30
|
// Get step
|
|
33
31
|
const showStep = (index) => {
|
|
34
32
|
indexRef.current = index;
|
|
35
|
-
const [{ callback, ...rest }, more] = steps(index,
|
|
33
|
+
const [{ callback, ...rest }, more] = steps(index, jsonValue);
|
|
36
34
|
app.showInputDialog({
|
|
37
35
|
...rest,
|
|
38
36
|
buttons: (n, callback) => (React.createElement(HBox, { paddingLeft: 2, paddingRight: 2, paddingBottom: 2, gap: 2, justifyContent: "space-between" },
|
|
@@ -49,10 +47,9 @@ export function DataSteps(props) {
|
|
|
49
47
|
const result = await callback(event);
|
|
50
48
|
if (!result)
|
|
51
49
|
return;
|
|
52
|
-
|
|
53
|
-
setLocalValue(valueFormatter(value));
|
|
50
|
+
setLocalValue(valueFormatter(jsonValue));
|
|
54
51
|
if (onValueChange)
|
|
55
|
-
onValueChange(
|
|
52
|
+
onValueChange(jsonValue);
|
|
56
53
|
} }, labels.submit)))),
|
|
57
54
|
callback: (form) => {
|
|
58
55
|
if (form == null)
|
|
@@ -69,10 +66,7 @@ export function DataSteps(props) {
|
|
|
69
66
|
event.preventDefault();
|
|
70
67
|
};
|
|
71
68
|
React.useEffect(() => {
|
|
72
|
-
|
|
73
|
-
dataRef.current = JSON.parse(jsonValue);
|
|
74
|
-
setLocalValue(valueFormatter(dataRef.current));
|
|
75
|
-
}
|
|
69
|
+
setLocalValue(valueFormatter(jsonValue));
|
|
76
70
|
}, [jsonValue]);
|
|
77
71
|
return (React.createElement(TextField, { InputLabelProps: InputLabelProps, inputProps: { style: { cursor: 'pointer' } }, InputProps: {
|
|
78
72
|
onKeyDown: (event) => {
|
package/lib/Tiplist.js
CHANGED
|
@@ -153,5 +153,5 @@ export function Tiplist(props) {
|
|
|
153
153
|
open: false,
|
|
154
154
|
...(!states.value && { options: [] })
|
|
155
155
|
});
|
|
156
|
-
}, loading: states.loading, sx: sx, renderInput: (params) => search ? (React.createElement(SearchField, { onChange: changeHandle, ...params, readOnly: readOnly, label: label, name: name + 'Input', margin: inputMargin, variant: inputVariant, required: inputRequired, autoComplete: inputAutoComplete, error: inputError, helperText: inputHelperText })) : (React.createElement(InputField, { onChange: changeHandle, ...addReadOnly(params), label: label, name: name + 'Input', margin: inputMargin, variant: inputVariant, required: inputRequired, autoComplete: inputAutoComplete, error: inputError, helperText: inputHelperText })), isOptionEqualToValue: (option, value) => option[idField] === value[idField], ...rest })));
|
|
156
|
+
}, loading: states.loading, sx: sx, renderInput: (params) => search ? (React.createElement(SearchField, { onChange: changeHandle, ...addReadOnly(params), readOnly: readOnly, label: label, name: name + 'Input', margin: inputMargin, variant: inputVariant, required: inputRequired, autoComplete: inputAutoComplete, error: inputError, helperText: inputHelperText })) : (React.createElement(InputField, { onChange: changeHandle, ...addReadOnly(params), label: label, name: name + 'Input', margin: inputMargin, variant: inputVariant, required: inputRequired, autoComplete: inputAutoComplete, error: inputError, helperText: inputHelperText })), isOptionEqualToValue: (option, value) => option[idField] === value[idField], ...rest })));
|
|
157
157
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export * from './BridgeCloseButton';
|
|
|
29
29
|
export * from './ButtonLink';
|
|
30
30
|
export * from './ComboBox';
|
|
31
31
|
export * from './CountdownButton';
|
|
32
|
+
export * from './CountryList';
|
|
32
33
|
export * from './CustomFabProps';
|
|
33
34
|
export * from './DataGridEx';
|
|
34
35
|
export * from './DataGridRenderers';
|
package/lib/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export * from './BridgeCloseButton';
|
|
|
29
29
|
export * from './ButtonLink';
|
|
30
30
|
export * from './ComboBox';
|
|
31
31
|
export * from './CountdownButton';
|
|
32
|
+
export * from './CountryList';
|
|
32
33
|
export * from './CustomFabProps';
|
|
33
34
|
export * from './DataGridEx';
|
|
34
35
|
export * from './DataGridRenderers';
|
package/package.json
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AddressRegionDb, RegionsRQ } from '@etsoo/appscript';
|
|
2
|
+
import { DataTypes } from '@etsoo/shared';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Tiplist, TiplistProps } from './Tiplist';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Country list props
|
|
8
|
+
*/
|
|
9
|
+
export type CountryListProps = Omit<
|
|
10
|
+
DataTypes.Optional<TiplistProps<AddressRegionDb, 'id'>, 'name'>,
|
|
11
|
+
'loadData'
|
|
12
|
+
> & {
|
|
13
|
+
/**
|
|
14
|
+
* Load data
|
|
15
|
+
* @param rq Request data
|
|
16
|
+
* @returns Result
|
|
17
|
+
*/
|
|
18
|
+
loadData: (rq: RegionsRQ) => Promise<AddressRegionDb[] | undefined>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Load favored country ids
|
|
22
|
+
* @returns Result
|
|
23
|
+
*/
|
|
24
|
+
loadFavoredIds?: () => Promise<string[]>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Max items to display
|
|
28
|
+
*/
|
|
29
|
+
items?: number;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Country list
|
|
34
|
+
* @param props Props
|
|
35
|
+
* @returns Component
|
|
36
|
+
*/
|
|
37
|
+
export function CountryList(props: CountryListProps) {
|
|
38
|
+
// Destruct
|
|
39
|
+
const {
|
|
40
|
+
items = 16,
|
|
41
|
+
loadData,
|
|
42
|
+
loadFavoredIds,
|
|
43
|
+
name = 'countryId',
|
|
44
|
+
...rest
|
|
45
|
+
} = props;
|
|
46
|
+
|
|
47
|
+
// Ref
|
|
48
|
+
const favoredIds = React.useRef<string[]>([]);
|
|
49
|
+
|
|
50
|
+
// Ready
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
if (loadFavoredIds)
|
|
53
|
+
loadFavoredIds().then((ids) => {
|
|
54
|
+
favoredIds.current = ids;
|
|
55
|
+
});
|
|
56
|
+
}, [loadFavoredIds]);
|
|
57
|
+
|
|
58
|
+
// Layout
|
|
59
|
+
return (
|
|
60
|
+
<Tiplist<AddressRegionDb, 'id'>
|
|
61
|
+
name={name}
|
|
62
|
+
loadData={(keyword, id) =>
|
|
63
|
+
loadData({ id, keyword, favoredIds: favoredIds.current, items })
|
|
64
|
+
}
|
|
65
|
+
{...rest}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
}
|
package/src/DataSteps.tsx
CHANGED
|
@@ -36,7 +36,7 @@ export type DataStepsProps<T extends object> = Omit<
|
|
|
36
36
|
/**
|
|
37
37
|
* JSON value
|
|
38
38
|
*/
|
|
39
|
-
jsonValue
|
|
39
|
+
jsonValue: T;
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Value formatter
|
|
@@ -83,16 +83,13 @@ export function DataSteps<T extends object>(props: DataStepsProps<T>) {
|
|
|
83
83
|
// Current index
|
|
84
84
|
const indexRef = React.useRef<number>(-1);
|
|
85
85
|
|
|
86
|
-
// Current data
|
|
87
|
-
const dataRef = React.useRef({} as T);
|
|
88
|
-
|
|
89
86
|
// Current value
|
|
90
87
|
const [localValue, setLocalValue] = React.useState(value);
|
|
91
88
|
|
|
92
89
|
// Get step
|
|
93
90
|
const showStep = (index: number) => {
|
|
94
91
|
indexRef.current = index;
|
|
95
|
-
const [{ callback, ...rest }, more] = steps(index,
|
|
92
|
+
const [{ callback, ...rest }, more] = steps(index, jsonValue);
|
|
96
93
|
|
|
97
94
|
app.showInputDialog({
|
|
98
95
|
...rest,
|
|
@@ -145,10 +142,9 @@ export function DataSteps<T extends object>(props: DataStepsProps<T>) {
|
|
|
145
142
|
const result = await callback(event);
|
|
146
143
|
if (!result) return;
|
|
147
144
|
|
|
148
|
-
|
|
149
|
-
setLocalValue(valueFormatter(value));
|
|
145
|
+
setLocalValue(valueFormatter(jsonValue));
|
|
150
146
|
|
|
151
|
-
if (onValueChange) onValueChange(
|
|
147
|
+
if (onValueChange) onValueChange(jsonValue);
|
|
152
148
|
}}
|
|
153
149
|
>
|
|
154
150
|
{labels.submit}
|
|
@@ -172,10 +168,7 @@ export function DataSteps<T extends object>(props: DataStepsProps<T>) {
|
|
|
172
168
|
};
|
|
173
169
|
|
|
174
170
|
React.useEffect(() => {
|
|
175
|
-
|
|
176
|
-
dataRef.current = JSON.parse(jsonValue);
|
|
177
|
-
setLocalValue(valueFormatter(dataRef.current));
|
|
178
|
-
}
|
|
171
|
+
setLocalValue(valueFormatter(jsonValue));
|
|
179
172
|
}, [jsonValue]);
|
|
180
173
|
|
|
181
174
|
return (
|
package/src/Tiplist.tsx
CHANGED
package/src/index.ts
CHANGED
|
@@ -32,6 +32,7 @@ export * from './BridgeCloseButton';
|
|
|
32
32
|
export * from './ButtonLink';
|
|
33
33
|
export * from './ComboBox';
|
|
34
34
|
export * from './CountdownButton';
|
|
35
|
+
export * from './CountryList';
|
|
35
36
|
export * from './CustomFabProps';
|
|
36
37
|
export * from './DataGridEx';
|
|
37
38
|
export * from './DataGridRenderers';
|