zavadil-react-common 2.0.3 → 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.
|
@@ -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 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,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 {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
|
+
}
|