react-crud-mobile 0.1.7

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.
Files changed (101) hide show
  1. package/dist/elements/UI.d.ts +48 -0
  2. package/dist/elements/UI.d.ts.map +1 -0
  3. package/dist/elements/UIChildren.d.ts +15 -0
  4. package/dist/elements/UIChildren.d.ts.map +1 -0
  5. package/dist/elements/UIComplete.d.ts +4 -0
  6. package/dist/elements/UIComplete.d.ts.map +1 -0
  7. package/dist/elements/UIElement.d.ts +4 -0
  8. package/dist/elements/UIElement.d.ts.map +1 -0
  9. package/dist/elements/UITag.d.ts +8 -0
  10. package/dist/elements/UITag.d.ts.map +1 -0
  11. package/dist/elements/card/ElCard.d.ts +4 -0
  12. package/dist/elements/card/ElCard.d.ts.map +1 -0
  13. package/dist/elements/charts/ElChart.d.ts +4 -0
  14. package/dist/elements/charts/ElChart.d.ts.map +1 -0
  15. package/dist/elements/core/AutoComplete.d.ts +3 -0
  16. package/dist/elements/core/AutoComplete.d.ts.map +1 -0
  17. package/dist/elements/core/Button.d.ts +3 -0
  18. package/dist/elements/core/Button.d.ts.map +1 -0
  19. package/dist/elements/core/Icon.d.ts +3 -0
  20. package/dist/elements/core/Icon.d.ts.map +1 -0
  21. package/dist/elements/core/Input.d.ts +3 -0
  22. package/dist/elements/core/Input.d.ts.map +1 -0
  23. package/dist/elements/core/Link.d.ts +3 -0
  24. package/dist/elements/core/Link.d.ts.map +1 -0
  25. package/dist/elements/core/Option.d.ts +3 -0
  26. package/dist/elements/core/Option.d.ts.map +1 -0
  27. package/dist/elements/core/Radio.d.ts +3 -0
  28. package/dist/elements/core/Radio.d.ts.map +1 -0
  29. package/dist/elements/core/Select.d.ts +3 -0
  30. package/dist/elements/core/Select.d.ts.map +1 -0
  31. package/dist/elements/core/Switch.d.ts +3 -0
  32. package/dist/elements/core/Switch.d.ts.map +1 -0
  33. package/dist/elements/grid/ElGrid.d.ts +4 -0
  34. package/dist/elements/grid/ElGrid.d.ts.map +1 -0
  35. package/dist/elements/grid/ElGridBotom.d.ts +4 -0
  36. package/dist/elements/grid/ElGridBotom.d.ts.map +1 -0
  37. package/dist/elements/grid/ElGridCheck.d.ts +4 -0
  38. package/dist/elements/grid/ElGridCheck.d.ts.map +1 -0
  39. package/dist/elements/grid/ElGridColumn.d.ts +12 -0
  40. package/dist/elements/grid/ElGridColumn.d.ts.map +1 -0
  41. package/dist/elements/grid/ElGridFilter.d.ts +4 -0
  42. package/dist/elements/grid/ElGridFilter.d.ts.map +1 -0
  43. package/dist/elements/grid/ElGridPaginator.d.ts +13 -0
  44. package/dist/elements/grid/ElGridPaginator.d.ts.map +1 -0
  45. package/dist/elements/grid/ElGridRow.d.ts +4 -0
  46. package/dist/elements/grid/ElGridRow.d.ts.map +1 -0
  47. package/dist/elements/grid/ElGridTop.d.ts +4 -0
  48. package/dist/elements/grid/ElGridTop.d.ts.map +1 -0
  49. package/dist/elements/grid/ElInclude.d.ts +4 -0
  50. package/dist/elements/grid/ElInclude.d.ts.map +1 -0
  51. package/dist/elements/grid/ElLabel.d.ts +8 -0
  52. package/dist/elements/grid/ElLabel.d.ts.map +1 -0
  53. package/dist/elements/grid/ElRepeat.d.ts +4 -0
  54. package/dist/elements/grid/ElRepeat.d.ts.map +1 -0
  55. package/dist/elements/grid/ElRepeatRow.d.ts +4 -0
  56. package/dist/elements/grid/ElRepeatRow.d.ts.map +1 -0
  57. package/dist/elements/index.d.ts +2 -0
  58. package/dist/elements/index.d.ts.map +1 -0
  59. package/dist/elements/tabs/ElTabs.d.ts +4 -0
  60. package/dist/elements/tabs/ElTabs.d.ts.map +1 -0
  61. package/dist/index.d.ts +2 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +8 -0
  64. package/dist/react-crud-mobile.cjs.development.js +1260 -0
  65. package/dist/react-crud-mobile.cjs.development.js.map +1 -0
  66. package/dist/react-crud-mobile.cjs.production.min.js +2 -0
  67. package/dist/react-crud-mobile.cjs.production.min.js.map +1 -0
  68. package/dist/react-crud-mobile.esm.js +1253 -0
  69. package/dist/react-crud-mobile.esm.js.map +1 -0
  70. package/package.json +95 -0
  71. package/src/elements/UI.tsx +57 -0
  72. package/src/elements/UIChildren.tsx +117 -0
  73. package/src/elements/UIComplete.tsx +15 -0
  74. package/src/elements/UIElement.tsx +379 -0
  75. package/src/elements/UITag.tsx +13 -0
  76. package/src/elements/card/ElCard.tsx +26 -0
  77. package/src/elements/charts/ElChart.tsx +10 -0
  78. package/src/elements/core/AutoComplete.tsx +18 -0
  79. package/src/elements/core/Button.tsx +18 -0
  80. package/src/elements/core/Icon.tsx +18 -0
  81. package/src/elements/core/Input.tsx +18 -0
  82. package/src/elements/core/Link.tsx +18 -0
  83. package/src/elements/core/Option.tsx +18 -0
  84. package/src/elements/core/Radio.tsx +18 -0
  85. package/src/elements/core/Select.tsx +18 -0
  86. package/src/elements/core/Switch.tsx +18 -0
  87. package/src/elements/grid/ElGrid.tsx +50 -0
  88. package/src/elements/grid/ElGridBotom.tsx +21 -0
  89. package/src/elements/grid/ElGridCheck.tsx +67 -0
  90. package/src/elements/grid/ElGridColumn.tsx +32 -0
  91. package/src/elements/grid/ElGridFilter.tsx +5 -0
  92. package/src/elements/grid/ElGridPaginator.tsx +82 -0
  93. package/src/elements/grid/ElGridRow.tsx +123 -0
  94. package/src/elements/grid/ElGridTop.tsx +45 -0
  95. package/src/elements/grid/ElInclude.tsx +40 -0
  96. package/src/elements/grid/ElLabel.tsx +50 -0
  97. package/src/elements/grid/ElRepeat.tsx +24 -0
  98. package/src/elements/grid/ElRepeatRow.tsx +40 -0
  99. package/src/elements/index.ts +1 -0
  100. package/src/elements/tabs/ElTabs.tsx +178 -0
  101. package/src/index.ts +1 -0
@@ -0,0 +1,67 @@
1
+ import UI from '../UI';
2
+ import Ionicons from '@expo/vector-icons/Ionicons';
3
+ import { useState } from 'react';
4
+ import { GridRowType, Utils } from 'react-crud-utils';
5
+
6
+ export default function ElGridCheck({ scope, value, rowIndex }: GridRowType) {
7
+ let original = scope.original;
8
+ let [index, setIndex] = useState(0);
9
+ let key = scope.key('check', rowIndex, 's', index);
10
+
11
+ let check = () => {
12
+ let cs = scope.crudSearch;
13
+
14
+ if (cs) {
15
+ if (!cs.selecteds) {
16
+ cs.selecteds = {};
17
+ }
18
+
19
+ let itemValue = Utils.nvl(original.itemValue, 'id');
20
+ let key = value[itemValue];
21
+
22
+ if (typeof key !== 'undefined') {
23
+ if (typeof cs.selecteds[key] === 'undefined') {
24
+ cs.selecteds[key] = value;
25
+ } else {
26
+ delete cs.selecteds[key];
27
+ }
28
+ }
29
+ }
30
+ setIndex(++index);
31
+ };
32
+
33
+ let getCheckIcon = () => {
34
+ if (isChecked()) {
35
+ return <Ionicons />;
36
+ }
37
+ return <Ionicons />;
38
+ };
39
+
40
+ let isChecked = () => {
41
+ let cs = scope.crudSearch;
42
+
43
+ if (cs) {
44
+ if (!cs.selecteds) {
45
+ cs.selecteds = {};
46
+ }
47
+
48
+ let itemValue = Utils.nvl(original.itemValue, 'id');
49
+ let key = value[itemValue];
50
+
51
+ if (typeof key !== 'undefined') {
52
+ if (typeof cs.selecteds[key] !== 'undefined') {
53
+ return true;
54
+ }
55
+ }
56
+ }
57
+ return false;
58
+ };
59
+
60
+ return (
61
+ <UI.Button
62
+ key={key}
63
+ icon={getCheckIcon()}
64
+ click={{ action: check }}
65
+ ></UI.Button>
66
+ );
67
+ }
@@ -0,0 +1,32 @@
1
+ import React, { useState } from "react";
2
+ import UIChildren from "../UIChildren";
3
+ import { Scope, Utils } from "react-crud-utils";
4
+
5
+ interface ElGridColumnType {
6
+ scope: Scope;
7
+ styleClass?: string;
8
+ children?: any;
9
+ colspan?: number;
10
+ column?: any;
11
+ }
12
+
13
+ export default function ElGridColumn(props: ElGridColumnType) {
14
+ let scope = props.scope;
15
+ let col = Utils.nvl(props.column?.props, {});
16
+ let [colScope] = useState(new Scope(col, scope, scope.crud));
17
+
18
+ let getStyleClass = () => {
19
+ let def = Utils.nvl(props.styleClass, "");
20
+
21
+ return "ui-grid-col " + def + " " + colScope.getStyleClass("column");
22
+ };
23
+ return (
24
+ <td
25
+ className={getStyleClass()}
26
+ style={colScope.getStyle("column")}
27
+ colSpan={props.colspan}
28
+ >
29
+ <UIChildren scope={scope}>{props.children}</UIChildren>
30
+ </td>
31
+ );
32
+ }
@@ -0,0 +1,5 @@
1
+ import { ChildType } from "react-crud-utils";
2
+
3
+ export default function ElGridFilter(props: ChildType) {
4
+ return <></>;
5
+ }
@@ -0,0 +1,82 @@
1
+ import React, { useState } from 'react';
2
+ import UI from '../UI';
3
+ import { ChildType, Utils } from 'react-crud-utils';
4
+ import Ionicons from '@expo/vector-icons/Ionicons';
5
+
6
+ interface ElGridPaginatorType extends ChildType {
7
+ next?: boolean;
8
+ previous?: boolean;
9
+ first?: boolean;
10
+ size?: boolean;
11
+ last?: boolean;
12
+ position: string;
13
+ }
14
+
15
+ export default function ElGridPaginator({
16
+ scope,
17
+ next,
18
+ previous,
19
+ first,
20
+ size,
21
+ last,
22
+ position,
23
+ }: ElGridPaginatorType) {
24
+ let [sizes] = useState([10, 20, 30, 50, 100, 200, 500]);
25
+ let defaults = {
26
+ crud: scope.crudSearch,
27
+ owner: scope,
28
+ variant: scope.attr('variant', 'text'),
29
+ };
30
+
31
+ let paginatorPosition = Utils.nvl(scope.original.paginatorPosition, 'bottom');
32
+
33
+ if (paginatorPosition !== position) {
34
+ return <></>;
35
+ }
36
+
37
+ return (
38
+ <>
39
+ <UI.Button
40
+ field="first"
41
+ space={0}
42
+ rendered={first !== false}
43
+ {...defaults}
44
+ click="first"
45
+ icon={<Ionicons />}
46
+ ></UI.Button>
47
+ <UI.Button
48
+ field="previous"
49
+ space={0}
50
+ rendered={previous !== false}
51
+ click="previous"
52
+ {...defaults}
53
+ icon={<Ionicons />}
54
+ ></UI.Button>
55
+ <UI.Select
56
+ field="size"
57
+ space={0}
58
+ rendered={size !== false}
59
+ default={10}
60
+ {...defaults}
61
+ data={sizes}
62
+ change="search"
63
+ ></UI.Select>
64
+ <UI.Button
65
+ field="next"
66
+ space={0}
67
+ rendered={next !== false}
68
+ {...defaults}
69
+ click="next"
70
+ icon={<Ionicons />}
71
+ ></UI.Button>
72
+ <UI.Button
73
+ field="last"
74
+ space={0}
75
+ rendered={last !== false}
76
+ {...defaults}
77
+ click="last"
78
+ icon={<Ionicons />}
79
+ ></UI.Button>
80
+ </>
81
+ );
82
+ }
@@ -0,0 +1,123 @@
1
+ import React, { useState } from 'react';
2
+ import ElGridColumn from './ElGridColumn';
3
+ import ElGridCheck from './ElGridCheck';
4
+ import Ionicons from '@expo/vector-icons/Ionicons';
5
+ import UI from '../UI';
6
+ import UIChildren from '../UIChildren';
7
+ import {
8
+ ComponentUtils,
9
+ CrudUtils,
10
+ ListType,
11
+ RowType,
12
+ Scope,
13
+ Utils,
14
+ } from 'react-crud-utils';
15
+
16
+ export default function ElGridRow(props: RowType) {
17
+ let expansion = props.expansion;
18
+ let value = props.value;
19
+ let scope = props.scope;
20
+ let index = props.index;
21
+ let original: ListType = scope.original;
22
+
23
+ let row = CrudUtils.create('row', {
24
+ index,
25
+ row: true,
26
+ itemVar: scope.original.itemVar,
27
+ parent: scope.crudSearch,
28
+ data: value,
29
+ });
30
+
31
+ let [expanded, setExpanded] = useState(false);
32
+ let [rowScope] = useState(new Scope(scope.original, scope, row));
33
+
34
+ let getRowStyleClass = () => {
35
+ let s = 'ui-grid-row';
36
+
37
+ s = s + ' ui-grid-row-';
38
+
39
+ if (index % 2 == 0) {
40
+ s = s + 'even';
41
+ } else {
42
+ s = s + 'odd';
43
+ }
44
+ return s;
45
+ };
46
+
47
+ let cols = ComponentUtils.getChild(props, 'Column');
48
+ let colspan = cols.length;
49
+
50
+ let ExpansionStatus = () => {
51
+ return (
52
+ <>
53
+ {!expanded && <Ionicons />}
54
+ {expanded && <Ionicons />}
55
+ </>
56
+ );
57
+ };
58
+
59
+ let onExpansion = () => {
60
+ setExpanded(!expanded);
61
+ };
62
+
63
+ let hasExpansion = !Utils.isEmpty(expansion);
64
+ let multiple = original.multiple;
65
+
66
+ if (hasExpansion) colspan++;
67
+ if (multiple) colspan++;
68
+
69
+ return (
70
+ <>
71
+ <tr className={getRowStyleClass()} style={rowScope.getStyle('row')}>
72
+ {hasExpansion && (
73
+ <ElGridColumn
74
+ key={'r' + index + 'e'}
75
+ scope={rowScope}
76
+ styleClass="ui-click ui-icon-only ui-expansion"
77
+ >
78
+ <UI.Button
79
+ icon={<ExpansionStatus />}
80
+ click={onExpansion}
81
+ ></UI.Button>
82
+ </ElGridColumn>
83
+ )}
84
+ {multiple && (
85
+ <ElGridColumn
86
+ key={'r' + index + 'c'}
87
+ scope={rowScope}
88
+ styleClass="ui-click ui-icon-only ui-multiple"
89
+ >
90
+ <ElGridCheck
91
+ key={'check-' + index}
92
+ scope={scope}
93
+ value={value}
94
+ rowIndex={index}
95
+ />
96
+ </ElGridColumn>
97
+ )}
98
+ {cols.map((col: any, i: number) => (
99
+ <ElGridColumn
100
+ column={col}
101
+ key={'r' + index + 'c' + i}
102
+ scope={rowScope}
103
+ >
104
+ {col}
105
+ </ElGridColumn>
106
+ ))}
107
+ </tr>
108
+ {expanded && (
109
+ <tr className={getRowStyleClass()} style={rowScope.getStyle('row')}>
110
+ <ElGridColumn
111
+ key={'r' + index + '-expanded'}
112
+ scope={rowScope}
113
+ colspan={colspan}
114
+ >
115
+ <UIChildren {...props} crud={row}>
116
+ {expansion}
117
+ </UIChildren>
118
+ </ElGridColumn>
119
+ </tr>
120
+ )}
121
+ </>
122
+ );
123
+ }
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import UI from '../UI';
3
+ import Ionicons from '@expo/vector-icons/Ionicons';
4
+ import ElGridPaginator from './ElGridPaginator';
5
+ import { ChildType } from 'react-crud-utils';
6
+
7
+ export default function ElGridTop(props: ChildType) {
8
+ let scope = props.scope;
9
+
10
+ return (
11
+ <>
12
+ <UI.Output styleClass="ui-grid-top">
13
+ <UI.Output field="search" position="left" space={4}>
14
+ <UI.Include {...props} transient name="top" position="left" />
15
+ <UI.Text
16
+ field="query"
17
+ space={0}
18
+ label="Pesquisar"
19
+ placeholder={scope.attr('placeholder', 'Pesquisar')}
20
+ >
21
+ <UI.Define name="right">
22
+ <UI.Button
23
+ field="search"
24
+ icon={<Ionicons />}
25
+ space={0}
26
+ variant="text"
27
+ owner={scope}
28
+ click={'search'}
29
+ ></UI.Button>
30
+ </UI.Define>
31
+ </UI.Text>
32
+ </UI.Output>
33
+ <UI.Output position="right" space={8}>
34
+ <UI.Include {...props} transient name="top" position="right" />
35
+ <ElGridPaginator
36
+ scope={scope}
37
+ last={false}
38
+ first={false}
39
+ position="top"
40
+ ></ElGridPaginator>
41
+ </UI.Output>
42
+ </UI.Output>
43
+ </>
44
+ );
45
+ }
@@ -0,0 +1,40 @@
1
+ import UIChildren from "../UIChildren";
2
+ import { ComponentUtils, DefineType, Utils } from "react-crud-utils";
3
+
4
+ export default function ElInclude(props: DefineType) {
5
+ if (props.rendered === false) {
6
+ return <></>;
7
+ }
8
+
9
+ let includes = ComponentUtils.getDefine(props, props.name, props.position);
10
+
11
+ if (Utils.isEmpty(includes)) {
12
+ includes = props.default;
13
+ }
14
+
15
+ if (!Utils.isEmpty(includes)) {
16
+ let Aux = (tagProp: any) => {
17
+ let Tag: any = props.tag;
18
+
19
+ if (!Utils.isEmpty(Tag)) {
20
+ return <Tag {...tagProp}>{tagProp.children}</Tag>;
21
+ }
22
+ return <>{tagProp.children}</>;
23
+ };
24
+
25
+ return (
26
+ <Aux {...props.tagProps}>
27
+ <UIChildren
28
+ transient
29
+ {...props}
30
+ scope={props.scope}
31
+ crud={props.crud}
32
+ part={props.name}
33
+ >
34
+ {includes}
35
+ </UIChildren>
36
+ </Aux>
37
+ );
38
+ }
39
+ return <>{includes}</>;
40
+ }
@@ -0,0 +1,50 @@
1
+ import React from 'react';
2
+ import UI from '../UI';
3
+ import { ChildType, Utils } from 'react-crud-utils';
4
+ import Icon from '../core/Icon';
5
+
6
+ interface ElLabelType extends ChildType {
7
+ position?: string;
8
+ }
9
+ export default function ElLabel(props: ElLabelType) {
10
+ let scope = props.scope;
11
+ let original = scope.original;
12
+ let defaultPos = 'outside';
13
+
14
+ let elPos = Utils.nvl(original.labelPos, defaultPos);
15
+ let lbPos = Utils.nvl(props.position, defaultPos);
16
+
17
+ if (elPos != lbPos) {
18
+ return <></>;
19
+ }
20
+
21
+ const CustomIcon = () => {
22
+ if (!scope.is('type', 'list', 'grid')) {
23
+ return <></>;
24
+ }
25
+
26
+ if (typeof original.icon === 'string') {
27
+ return (
28
+ <div className="ui-label-icon">
29
+ <Icon className={scope.getIcon()}></Icon>
30
+ </div>
31
+ );
32
+ }
33
+ return <div className="ui-label-icon">{original.icon}</div>;
34
+ };
35
+
36
+ let label = scope.getLabel();
37
+
38
+ return (
39
+ <div className={'ui-label ui-label-' + lbPos}>
40
+ <div className="ui-label-left">
41
+ <UI.Include {...props} transient name="label" position="left" />
42
+ <CustomIcon />
43
+ {label && <div className="ui-label-value">{label}</div>}
44
+ </div>
45
+ <div className="ui-label-right">
46
+ <UI.Include {...props} transient name="label" position="right" />
47
+ </div>
48
+ </div>
49
+ );
50
+ }
@@ -0,0 +1,24 @@
1
+ import ElRepeatRow from './ElRepeatRow';
2
+ import { ChildType, Scope } from 'react-crud-utils';
3
+
4
+ export default function ElRepeat(props: ChildType) {
5
+ let scope: Scope = props.scope;
6
+ let items: any = scope.getItems();
7
+
8
+ return (
9
+ <div
10
+ className={scope.getStyleClass('inner')}
11
+ style={scope.getStyle('inner')}
12
+ >
13
+ {items.map((row: any, i: number) => (
14
+ <ElRepeatRow
15
+ {...props}
16
+ key={'r' + i}
17
+ scope={scope}
18
+ value={row}
19
+ index={i}
20
+ />
21
+ ))}
22
+ </div>
23
+ );
24
+ }
@@ -0,0 +1,40 @@
1
+ import React, { useState } from "react";
2
+ import UIChildren from "../UIChildren";
3
+ import { CrudUtils, RowType, Scope } from "react-crud-utils";
4
+
5
+ export default function ElRepeatRow(props: RowType) {
6
+ let value = props.value;
7
+ let scope = props.scope;
8
+ let index = props.index;
9
+
10
+ let row = CrudUtils.create("row", {
11
+ index,
12
+ row: true,
13
+ itemVar: scope.original.itemVar,
14
+ parent: scope.crudSearch,
15
+ data: value,
16
+ });
17
+
18
+ let [rowScope] = useState(new Scope(scope.original, scope, row));
19
+
20
+ let getRowStyleClass = () => {
21
+ let s = rowScope.getStyleClass("row");
22
+
23
+ s = s + " ui-repeat-row-";
24
+
25
+ if (index % 2 == 0) {
26
+ s = s + "even";
27
+ } else {
28
+ s = s + "odd";
29
+ }
30
+ return s;
31
+ };
32
+
33
+ return (
34
+ <div className={getRowStyleClass()} style={rowScope.getStyle("row")}>
35
+ <UIChildren transient {...props} crud={row}>
36
+ {props.children}
37
+ </UIChildren>
38
+ </div>
39
+ );
40
+ }
@@ -0,0 +1 @@
1
+ export { default as UI } from "./UI";
@@ -0,0 +1,178 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import UIChildren from '../UIChildren';
3
+ import UI from '../UI';
4
+
5
+ import Ionicons from '@expo/vector-icons/Ionicons';
6
+ import { ChildType, CrudUtils, Utils } from 'react-crud-utils';
7
+
8
+ export default function ElTabs(props: ChildType) {
9
+ let scope = props.scope;
10
+ let [selectedIndex, setSelectedIndex]: any = useState(0);
11
+ let element = scope.original;
12
+ let items = scope.getItems();
13
+ let counter = 0;
14
+
15
+ let tabs: any = [];
16
+ let [selected, setSelected]: any = useState(null);
17
+
18
+ const onChangeTab = (tab: any, validate = true) => {
19
+ if (tab) {
20
+ scope.execute({
21
+ event: {
22
+ validate,
23
+ validateScope: element.validateScope,
24
+ action: () => {
25
+ scope.changeValue(tab.data);
26
+
27
+ selected = tab;
28
+ selectedIndex = tab.index;
29
+
30
+ setSelectedIndex(selectedIndex);
31
+ setSelected(tab);
32
+ },
33
+ },
34
+ });
35
+ }
36
+ };
37
+
38
+ const getStyleClass = (t: any) => {
39
+ let s = 'ui-tabs-item ui-click';
40
+
41
+ if (selected?.index === t.index) {
42
+ s = s + ' ui-tab-selected';
43
+ }
44
+ return s;
45
+ };
46
+
47
+ const addTab = (child: any, item: any) => {
48
+ let original = { ...child.props };
49
+
50
+ if (!item) {
51
+ item = scope.crud.data;
52
+ }
53
+
54
+ let crudTab = CrudUtils.create('tabs', {
55
+ data: item,
56
+ changed: item,
57
+ parent: scope.crud,
58
+ });
59
+
60
+ let element = Utils.resolve(original, crudTab);
61
+
62
+ if (element.rendered === false) {
63
+ return;
64
+ }
65
+
66
+ tabs.push({
67
+ ...element,
68
+ child,
69
+ element,
70
+ original,
71
+ index: counter++,
72
+ data: item,
73
+ });
74
+ };
75
+
76
+ React.Children.map(props.children, (child, index) => {
77
+ if (Utils.isEmpty(items)) {
78
+ addTab(child, {});
79
+ } else {
80
+ for (const i in items) {
81
+ let o = items[i];
82
+
83
+ addTab(child, o);
84
+ }
85
+ }
86
+ });
87
+
88
+ if (!selected) {
89
+ onChangeTab(tabs[selectedIndex], false);
90
+ }
91
+
92
+ const nav = (i: any) => {
93
+ let t = tabs[selectedIndex + i];
94
+
95
+ onChangeTab(t);
96
+ };
97
+
98
+ const previous = () => {
99
+ nav(-1);
100
+ };
101
+
102
+ const next = () => {
103
+ nav(1);
104
+ };
105
+
106
+ let isStepper = element.layout === 'stepper';
107
+
108
+ return (
109
+ <div
110
+ className={scope.getStyleClass('inner')}
111
+ style={scope.getStyle('inner')}
112
+ >
113
+ <div className="ui-tabs-content">
114
+ <div className="ui-tabs-items">
115
+ {tabs.map((t: any, i: number) => (
116
+ <div
117
+ key={Utils.key(element.id, 'tab', i)}
118
+ className={getStyleClass(t)}
119
+ onClick={() => {
120
+ onChangeTab(t);
121
+ }}
122
+ >
123
+ {isStepper && <div className="ui-tab-item-divisor" />}
124
+ <div className="ui-tab-item-inner">
125
+ {isStepper && <div className="ui-step-line" />}
126
+ <div className="ui-tab-item-label">
127
+ {isStepper ? t.index + 1 : t.label}
128
+ </div>
129
+ </div>
130
+ </div>
131
+ ))}
132
+ </div>
133
+ {selected && (
134
+ <>
135
+ {isStepper && <div className="ui-tabs-label">{selected.label}</div>}
136
+ <div className="ui-tabs-area">
137
+ <UIChildren {...props} scope={scope}>
138
+ {selected.child}
139
+ </UIChildren>
140
+ </div>
141
+ {element.layout === 'stepper' && (
142
+ <div className="ui-tabs-actions">
143
+ <UI.Output space={6} layout="left">
144
+ <UI.Include
145
+ {...props}
146
+ transient
147
+ name="left"
148
+ default={
149
+ <UI.Button
150
+ rendered={selectedIndex > 0}
151
+ icon={<Ionicons />}
152
+ click={previous}
153
+ />
154
+ }
155
+ />
156
+ </UI.Output>
157
+ <UI.Output space={6} layout="right">
158
+ <UI.Include
159
+ {...props}
160
+ transient
161
+ name="right"
162
+ default={
163
+ <UI.Button
164
+ rendered={selectedIndex < tabs.length - 1}
165
+ icon={<Ionicons />}
166
+ click={next}
167
+ />
168
+ }
169
+ />
170
+ </UI.Output>
171
+ </div>
172
+ )}
173
+ </>
174
+ )}
175
+ </div>
176
+ </div>
177
+ );
178
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./elements";