zavadil-react-common 2.0.1 → 2.0.4
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/component/forms/EntityIdSelect.d.ts +12 -0
- package/dist/component/forms/EntitySelect.d.ts +12 -0
- package/dist/component/forms/EntityWithNameIdSelect.d.ts +11 -0
- package/dist/component/forms/EntityWithNameSelect.d.ts +11 -0
- package/package.json +1 -1
- package/src/component/forms/EntityIdSelect.tsx +49 -0
- package/src/component/forms/EntitySelect.tsx +38 -0
- package/src/component/forms/EntityWithNameIdSelect.tsx +29 -0
- package/src/component/forms/EntityWithNameSelect.tsx +29 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EntityBase } from "zavadil-ts-common";
|
|
2
|
+
export type EntityIdSelectProps<T extends EntityBase> = {
|
|
3
|
+
id?: number | null;
|
|
4
|
+
onChange: (n: number | null | undefined) => any;
|
|
5
|
+
options?: Array<T> | null;
|
|
6
|
+
showEmptyOption?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
emptyOptionLabel?: string;
|
|
9
|
+
sort?: boolean;
|
|
10
|
+
labelGetter: (item: T) => string;
|
|
11
|
+
};
|
|
12
|
+
export declare function EntityIdSelect<T extends EntityBase>({ id, sort, disabled, labelGetter, onChange, options, showEmptyOption, emptyOptionLabel }: EntityIdSelectProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EntityBase } from "zavadil-ts-common";
|
|
2
|
+
export type EntitySelectProps<T extends EntityBase> = {
|
|
3
|
+
value?: T | null;
|
|
4
|
+
onChange: (e: T | null | undefined) => any;
|
|
5
|
+
options?: Array<T> | null;
|
|
6
|
+
showEmptyOption?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
emptyOptionLabel?: string;
|
|
9
|
+
sort?: boolean;
|
|
10
|
+
labelGetter: (item: T) => string;
|
|
11
|
+
};
|
|
12
|
+
export declare function EntitySelect<T extends EntityBase>({ value, sort, disabled, labelGetter, onChange, options, showEmptyOption, emptyOptionLabel }: EntitySelectProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EntityWithName } from "zavadil-ts-common";
|
|
2
|
+
export type EntityWithNameIdSelectProps<T extends EntityWithName> = {
|
|
3
|
+
id?: number | null;
|
|
4
|
+
onChange: (n: number | null | undefined) => any;
|
|
5
|
+
options?: Array<T> | null;
|
|
6
|
+
showEmptyOption?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
emptyOptionLabel?: string;
|
|
9
|
+
sort?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function EntityWithNameIdSelect<T extends EntityWithName>({ id, sort, disabled, onChange, options, showEmptyOption, emptyOptionLabel }: EntityWithNameIdSelectProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EntityWithName } from "zavadil-ts-common";
|
|
2
|
+
export type EntityWithNameSelectProps<T extends EntityWithName> = {
|
|
3
|
+
value?: T | null;
|
|
4
|
+
onChange: (e: T | null | undefined) => any;
|
|
5
|
+
options?: Array<T> | null;
|
|
6
|
+
showEmptyOption?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
emptyOptionLabel?: string;
|
|
9
|
+
sort?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function EntityWithNameSelect<T extends EntityWithName>({ value, sort, disabled, onChange, options, showEmptyOption, emptyOptionLabel }: EntityWithNameSelectProps<T>): import("react/jsx-runtime").JSX.Element;
|
package/package.json
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {useMemo} from "react";
|
|
2
|
+
import {NumberSelect} from "./NumberSelect";
|
|
3
|
+
import {EntityBase} from "zavadil-ts-common";
|
|
4
|
+
import {GenericSelectOption} from "./StringSelect";
|
|
5
|
+
|
|
6
|
+
export type EntityIdSelectProps<T extends EntityBase> = {
|
|
7
|
+
id?: number | null;
|
|
8
|
+
onChange: (n: number | null | undefined) => any;
|
|
9
|
+
options?: Array<T> | null;
|
|
10
|
+
showEmptyOption?: boolean;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
emptyOptionLabel?: string;
|
|
13
|
+
sort?: boolean;
|
|
14
|
+
labelGetter: (item: T) => string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function EntityIdSelect<T extends EntityBase>(
|
|
18
|
+
{id, sort, disabled, labelGetter, onChange, options, showEmptyOption, emptyOptionLabel}: EntityIdSelectProps<T>
|
|
19
|
+
) {
|
|
20
|
+
const lOptions: GenericSelectOption<number>[] = useMemo(
|
|
21
|
+
() => {
|
|
22
|
+
let result: Array<T> = []
|
|
23
|
+
if (options) {
|
|
24
|
+
result = sort ? options.sort((a, b) => labelGetter(a) > labelGetter(b) ? 1 : -1) : options;
|
|
25
|
+
}
|
|
26
|
+
return result
|
|
27
|
+
.map(
|
|
28
|
+
(o) => {
|
|
29
|
+
return {
|
|
30
|
+
id: o.id,
|
|
31
|
+
label: labelGetter(o)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
},
|
|
36
|
+
[options]
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<NumberSelect
|
|
41
|
+
disabled={disabled}
|
|
42
|
+
value={id}
|
|
43
|
+
options={lOptions}
|
|
44
|
+
onChange={onChange}
|
|
45
|
+
showEmptyOption={showEmptyOption}
|
|
46
|
+
emptyOptionLabel={emptyOptionLabel}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {EntityBase} from "zavadil-ts-common";
|
|
2
|
+
import {EntityIdSelect} from "./EntityIdSelect";
|
|
3
|
+
|
|
4
|
+
export type EntitySelectProps<T extends EntityBase> = {
|
|
5
|
+
value?: T | null;
|
|
6
|
+
onChange: (e: T | null | undefined) => any;
|
|
7
|
+
options?: Array<T> | null;
|
|
8
|
+
showEmptyOption?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
emptyOptionLabel?: string;
|
|
11
|
+
sort?: boolean;
|
|
12
|
+
labelGetter: (item: T) => string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function EntitySelect<T extends EntityBase>(
|
|
16
|
+
{value, sort, disabled, labelGetter, onChange, options, showEmptyOption, emptyOptionLabel}: EntitySelectProps<T>
|
|
17
|
+
) {
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<EntityIdSelect
|
|
21
|
+
disabled={disabled}
|
|
22
|
+
id={value ? value.id : null}
|
|
23
|
+
options={options}
|
|
24
|
+
onChange={
|
|
25
|
+
(id) => {
|
|
26
|
+
if (!options || !id) {
|
|
27
|
+
onChange(undefined);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
onChange(options.find((o) => o.id === id));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
labelGetter={labelGetter}
|
|
34
|
+
showEmptyOption={showEmptyOption}
|
|
35
|
+
emptyOptionLabel={emptyOptionLabel}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {EntityWithName} from "zavadil-ts-common";
|
|
2
|
+
import {EntityIdSelect} from "./EntityIdSelect";
|
|
3
|
+
|
|
4
|
+
export type EntityWithNameIdSelectProps<T extends EntityWithName> = {
|
|
5
|
+
id?: number | null;
|
|
6
|
+
onChange: (n: number | null | undefined) => any;
|
|
7
|
+
options?: Array<T> | null;
|
|
8
|
+
showEmptyOption?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
emptyOptionLabel?: string;
|
|
11
|
+
sort?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function EntityWithNameIdSelect<T extends EntityWithName>(
|
|
15
|
+
{id, sort, disabled, onChange, options, showEmptyOption, emptyOptionLabel}: EntityWithNameIdSelectProps<T>
|
|
16
|
+
) {
|
|
17
|
+
return (
|
|
18
|
+
<EntityIdSelect
|
|
19
|
+
id={id}
|
|
20
|
+
labelGetter={(e) => e.name}
|
|
21
|
+
disabled={disabled}
|
|
22
|
+
sort={sort}
|
|
23
|
+
options={options}
|
|
24
|
+
onChange={onChange}
|
|
25
|
+
showEmptyOption={showEmptyOption}
|
|
26
|
+
emptyOptionLabel={emptyOptionLabel}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {EntityWithName} from "zavadil-ts-common";
|
|
2
|
+
import {EntitySelect} from "./EntitySelect";
|
|
3
|
+
|
|
4
|
+
export type EntityWithNameSelectProps<T extends EntityWithName> = {
|
|
5
|
+
value?: T | null;
|
|
6
|
+
onChange: (e: T | null | undefined) => any;
|
|
7
|
+
options?: Array<T> | null;
|
|
8
|
+
showEmptyOption?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
emptyOptionLabel?: string;
|
|
11
|
+
sort?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function EntityWithNameSelect<T extends EntityWithName>(
|
|
15
|
+
{value, sort, disabled, onChange, options, showEmptyOption, emptyOptionLabel}: EntityWithNameSelectProps<T>
|
|
16
|
+
) {
|
|
17
|
+
return (
|
|
18
|
+
<EntitySelect
|
|
19
|
+
value={value}
|
|
20
|
+
labelGetter={(e) => e.name}
|
|
21
|
+
disabled={disabled}
|
|
22
|
+
sort={sort}
|
|
23
|
+
options={options}
|
|
24
|
+
onChange={onChange}
|
|
25
|
+
showEmptyOption={showEmptyOption}
|
|
26
|
+
emptyOptionLabel={emptyOptionLabel}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|