@etsoo/react 1.4.34 → 1.4.35

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.
@@ -21,6 +21,14 @@ export interface TabBoxPros extends BoxProps {
21
21
  * Container props
22
22
  */
23
23
  container?: Omit<TabsProps, 'value'>;
24
+ /**
25
+ * Default selected index
26
+ */
27
+ defaultIndex?: number;
28
+ /**
29
+ * Current index
30
+ */
31
+ index?: number;
24
32
  /**
25
33
  * Add a hidden input and its name
26
34
  */
package/lib/mu/TabBox.js CHANGED
@@ -8,10 +8,15 @@ import React from 'react';
8
8
  */
9
9
  export function TabBox(props) {
10
10
  // Destruct
11
- const { inputName, root, container = {}, tabs } = props;
11
+ const { index, inputName, root, container = {}, defaultIndex = 0, tabs } = props;
12
12
  const { onChange, ...rest } = container;
13
13
  // State
14
- const [value, setValue] = React.useState(0);
14
+ const [value, setValue] = React.useState(defaultIndex);
15
+ React.useEffect(() => {
16
+ if (index == null)
17
+ return;
18
+ setValue(index);
19
+ }, [index]);
15
20
  // Layout
16
21
  return (React.createElement(React.Fragment, null,
17
22
  inputName && (React.createElement("input", { type: "hidden", name: inputName, value: value })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.34",
3
+ "version": "1.4.35",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/src/mu/TabBox.tsx CHANGED
@@ -26,6 +26,16 @@ export interface TabBoxPros extends BoxProps {
26
26
  */
27
27
  container?: Omit<TabsProps, 'value'>;
28
28
 
29
+ /**
30
+ * Default selected index
31
+ */
32
+ defaultIndex?: number;
33
+
34
+ /**
35
+ * Current index
36
+ */
37
+ index?: number;
38
+
29
39
  /**
30
40
  * Add a hidden input and its name
31
41
  */
@@ -49,11 +59,23 @@ export interface TabBoxPros extends BoxProps {
49
59
  */
50
60
  export function TabBox(props: TabBoxPros) {
51
61
  // Destruct
52
- const { inputName, root, container = {}, tabs } = props;
62
+ const {
63
+ index,
64
+ inputName,
65
+ root,
66
+ container = {},
67
+ defaultIndex = 0,
68
+ tabs
69
+ } = props;
53
70
  const { onChange, ...rest } = container;
54
71
 
55
72
  // State
56
- const [value, setValue] = React.useState(0);
73
+ const [value, setValue] = React.useState(defaultIndex);
74
+
75
+ React.useEffect(() => {
76
+ if (index == null) return;
77
+ setValue(index);
78
+ }, [index]);
57
79
 
58
80
  // Layout
59
81
  return (