@remvst/configurable-react 1.2.0 → 1.2.1
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,8 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { EnumConfigurable } from '@remvst/configurable';
|
|
3
3
|
import { ComponentProps } from './component-props';
|
|
4
|
-
|
|
4
|
+
interface State<T> {
|
|
5
|
+
value: T;
|
|
6
|
+
}
|
|
7
|
+
export default class EnumConfigurableComponent extends React.Component<ComponentProps<EnumConfigurable<any>>, State<any>> {
|
|
8
|
+
constructor(props: ComponentProps<EnumConfigurable<any>>);
|
|
5
9
|
private onChange;
|
|
6
10
|
private get mapping();
|
|
7
11
|
render(): JSX.Element;
|
|
8
12
|
}
|
|
13
|
+
export {};
|
|
@@ -5,11 +5,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const react_1 = __importDefault(require("react"));
|
|
7
7
|
class EnumConfigurableComponent extends react_1.default.Component {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super(props);
|
|
10
|
+
this.state = {
|
|
11
|
+
'value': props.configurable.read(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
8
14
|
onChange(event) {
|
|
9
15
|
const { configurable } = this.props;
|
|
10
16
|
const { mapping } = this;
|
|
11
17
|
configurable.write(mapping.get(event.target.value));
|
|
12
|
-
event.target.
|
|
18
|
+
this.setState({ 'value': mapping.get(event.target.value) }, () => {
|
|
19
|
+
event.target.blur();
|
|
20
|
+
});
|
|
13
21
|
}
|
|
14
22
|
get mapping() {
|
|
15
23
|
const { configurable } = this.props;
|
|
@@ -25,13 +33,13 @@ class EnumConfigurableComponent extends react_1.default.Component {
|
|
|
25
33
|
const { configurable } = this.props;
|
|
26
34
|
const configurableValue = configurable.read();
|
|
27
35
|
const { mapping } = this;
|
|
28
|
-
let
|
|
36
|
+
let valueKey = '';
|
|
29
37
|
for (const [key, value] of mapping) {
|
|
30
38
|
if (value === configurableValue) {
|
|
31
|
-
|
|
39
|
+
valueKey = key;
|
|
32
40
|
}
|
|
33
41
|
}
|
|
34
|
-
return (react_1.default.createElement("select", {
|
|
42
|
+
return (react_1.default.createElement("select", { value: valueKey, onChange: (e) => this.onChange(e) }, Array.from(configurable.categories).map((category) => {
|
|
35
43
|
return (react_1.default.createElement("optgroup", { label: category.label || '', key: category.label }, category.items.map((item) => {
|
|
36
44
|
return (react_1.default.createElement("option", { key: item.key, value: item.key }, item.key));
|
|
37
45
|
})));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remvst/configurable-react",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@remvst/configurable": "^1.3.
|
|
16
|
+
"@remvst/configurable": "^1.3.1",
|
|
17
17
|
"react": "^18.2.0",
|
|
18
18
|
"react-dom": "^18.2.0",
|
|
19
19
|
"@types/react-dom": "^18.0.6",
|
|
@@ -2,13 +2,27 @@ import React from 'react';
|
|
|
2
2
|
import { EnumConfigurable } from '@remvst/configurable';
|
|
3
3
|
import { ComponentProps } from './component-props';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
interface State<T> {
|
|
6
|
+
value: T;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default class EnumConfigurableComponent extends React.Component<ComponentProps<EnumConfigurable<any>>, State<any>> {
|
|
10
|
+
|
|
11
|
+
constructor(props: ComponentProps<EnumConfigurable<any>>) {
|
|
12
|
+
super(props);
|
|
13
|
+
this.state = {
|
|
14
|
+
'value': props.configurable.read(),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
6
17
|
|
|
7
18
|
private onChange(event: React.ChangeEvent<HTMLSelectElement>) {
|
|
8
19
|
const { configurable } = this.props;
|
|
9
20
|
const { mapping } = this;
|
|
10
21
|
configurable.write(mapping.get(event.target.value));
|
|
11
|
-
|
|
22
|
+
|
|
23
|
+
this.setState({'value': mapping.get(event.target.value)}, () => {
|
|
24
|
+
event.target.blur();
|
|
25
|
+
});
|
|
12
26
|
}
|
|
13
27
|
|
|
14
28
|
private get mapping(): Map<string, any> {
|
|
@@ -28,15 +42,15 @@ export default class EnumConfigurableComponent extends React.Component<Component
|
|
|
28
42
|
const configurableValue = configurable.read();
|
|
29
43
|
const { mapping } = this;
|
|
30
44
|
|
|
31
|
-
let
|
|
45
|
+
let valueKey = '';
|
|
32
46
|
for (const [key, value] of mapping) {
|
|
33
47
|
if (value === configurableValue) {
|
|
34
|
-
|
|
48
|
+
valueKey = key;
|
|
35
49
|
}
|
|
36
50
|
}
|
|
37
51
|
|
|
38
52
|
return (
|
|
39
|
-
<select
|
|
53
|
+
<select value={valueKey} onChange={(e) => this.onChange(e)}>
|
|
40
54
|
{Array.from(configurable.categories).map((category) => {
|
|
41
55
|
return (<optgroup label={category.label || ''} key={category.label}>
|
|
42
56
|
{category.items.map((item) => {
|