@onehat/ui 0.2.78 → 0.2.80

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,365 +1,9 @@
1
- import React, { useState, useEffect, useId, } from 'react';
2
- import {
3
- Button,
4
- Column,
5
- Icon,
6
- Pressable,
7
- Row,
8
- Text,
9
- } from 'native-base';
10
- import {
11
- HORIZONTAL,
12
- VERTICAL,
13
- } from '../../Constants/Directions.js';
14
- import UiGlobals from '../../UiGlobals.js';
15
- import IconButton from '../Buttons/IconButton.js';
16
- import Minimize from '../Icons/Minimize.js';
17
- import Maximize from '../Icons/Maximize.js';
1
+ import TabBar from '../Tab/TabBar.js'
18
2
  import Panel from './Panel.js';
19
- import getSaved from '../../Functions/getSaved.js';
20
- import setSaved from '../../Functions/setSaved.js';
21
- import _ from 'lodash';
22
3
 
23
4
 
24
5
  export default function TabPanel(props) {
25
- const {
26
- tabs = [],
27
- direction = HORIZONTAL,
28
- tabWidth = 150, // used on VERTICAL mode only
29
- tabHeight = '44px', // used on HORIZONTAL mode only
30
- additionalButtons,
31
- initialTab = 0,
32
- startsCollapsed = true,
33
- onChangeCurrentTab,
34
- onChangeIsCollapsed,
35
- saveCurrentTab = true,
36
- ...propsToPass
37
- } = props,
38
- styles = UiGlobals.styles,
39
- id = useId(),
40
- [isReady, setIsReady] = useState(false),
41
- [currentTab, setCurrentTabRaw] = useState(initialTab),
42
- [isCollapsed, setIsCollapsedRaw] = useState(startsCollapsed),
43
- setIsCollapsed = (isCollapsed) => {
44
- setIsCollapsedRaw(isCollapsed);
45
- if (onChangeIsCollapsed) {
46
- onChangeIsCollapsed(isCollapsed);
47
- }
48
- setSaved(id + '-isCollapsed', isCollapsed);
49
- },
50
- setCurrentTab = (ix) => {
51
- setCurrentTabRaw(ix);
52
- if (onChangeCurrentTab) {
53
- onChangeCurrentTab(ix);
54
- }
55
- if (saveCurrentTab) {
56
- setSaved(id + '-currentTab', ix);
57
- }
58
- },
59
- getButtonProps = () => {
60
- const
61
- iconProps = {
62
- size: 'md',
63
- },
64
- textProps = {},
65
- buttonProps = {
66
- bg: styles.TAB_BG,
67
- color: styles.TAB_COLOR,
68
- fontSize: styles.TAB_FONTSIZE,
69
- textAlign: 'left',
70
- justifyContent: isCollapsed ? 'center' : 'flex-start',
71
- };
72
- switch(direction) {
73
- case VERTICAL:
74
- buttonProps.borderLeftRadius = 4;
75
- buttonProps.borderRightRadius = 0;
76
- buttonProps.w = '100%';
77
- buttonProps.mb = 1;
78
- textProps.w = '100%';
79
- textProps.py = 0;
80
- textProps.pl = 3;
81
- textProps.mb = 1;
82
- break;
83
- case HORIZONTAL:
84
- buttonProps.borderTopRadius = 4;
85
- buttonProps.borderBottomRadius = 0;
86
- textProps.borderTopRadius = 4;
87
- buttonProps.mr = 1;
88
- buttonProps.py = 1;
89
- textProps.mr = 1;
90
- textProps.px = 1;
91
- textProps.py = 1;
92
- break;
93
- default:
94
- }
95
- return {
96
- buttonProps,
97
- textProps,
98
- iconProps,
99
- };
100
- },
101
- renderTabs = () => {
102
- const
103
- {
104
- buttonProps,
105
- textProps,
106
- iconProps,
107
- } = getButtonProps(),
108
- buttons = [];
109
-
110
- _.each(tabs, (tab, ix) => {
111
- if (!tab._icon) {
112
- throw new Error('tab._icon required!');
113
- }
114
- let button;
115
- const
116
- isCurrentTab = ix === currentTab,
117
- thisButtonProps = {};
118
- if (isCollapsed) {
119
- button = <IconButton
120
- key={'tab' + ix}
121
- onPress={() => setCurrentTab(ix)}
122
- {...buttonProps}
123
- // {...thisButtonProps}
124
- _icon={{
125
- color: isCurrentTab ? styles.TAB_ACTIVE_ICON_COLOR : styles.TAB_ICON_COLOR,
126
- ...iconProps,
127
- ...tab._icon,
128
- }}
129
- _hover={{
130
- bg: isCurrentTab? styles.TAB_ACTIVE_HOVER_BG : styles.TAB_HOVER_BG,
131
- }}
132
- bg={isCurrentTab ? styles.TAB_ACTIVE_BG : styles.TAB_BG}
133
- tooltip={tab.title}
134
- />;
135
- } else {
136
- button = <Button
137
- key={'tab' + ix}
138
- onPress={() => setCurrentTab(ix)}
139
- leftIcon={<Icon
140
- color={isCurrentTab ? styles.TAB_ACTIVE_ICON_COLOR : styles.TAB_ICON_COLOR}
141
- {...iconProps}
142
- {...tab._icon}
143
- />}
144
- {...buttonProps}
145
- {...thisButtonProps}
146
- _hover={{
147
- bg: isCurrentTab? styles.TAB_ACTIVE_HOVER_BG : styles.TAB_HOVER_BG,
148
- }}
149
- bg={isCurrentTab ? styles.TAB_ACTIVE_BG : styles.TAB_BG}
150
- >
151
- <Text
152
- color={isCurrentTab ? styles.TAB_ACTIVE_COLOR : styles.TAB_COLOR}
153
- fontSize={styles.TAB_FONTSIZE}
154
- numberOfLines={1}
155
- ellipsizeMode="head"
156
- {...textProps}
157
- >{tab.title}</Text>
158
- </Button>;
159
- }
160
- buttons.push(button);
161
- });
162
-
163
- if (additionalButtons) {
164
- _.each(additionalButtons, (additionalButton, ix) => {
165
- if (!additionalButton._icon) {
166
- throw new Error('additionalButton._icon required!');
167
- }
168
- let button;
169
- const thisButtonProps = {};
170
- if (!ix) {
171
- // First button should have gap before it
172
- switch(direction) {
173
- case VERTICAL:
174
- thisButtonProps.mt = 6;
175
- break;
176
- case HORIZONTAL:
177
- thisButtonProps.ml = 6;
178
- break;
179
- default:
180
- }
181
- }
182
- if (isCollapsed) {
183
- button = <IconButton
184
- key={'additionalBtn' + ix}
185
- onPress={additionalButton.onPress}
186
- {...buttonProps}
187
- {...thisButtonProps}
188
- _icon={{
189
- ...additionalButton._icon,
190
- color: styles.TAB_ICON_COLOR,
191
- }}
192
- _hover={{
193
- bg: styles.TAB_HOVER_BG,
194
- }}
195
- bg={styles.TAB_BG}
196
- tooltip={additionalButton.text}
197
- />;
198
- } else {
199
- button = <Button
200
- key={'additionalBtn' + ix}
201
- onPress={additionalButton.onPress}
202
- leftIcon={<Icon
203
- color={styles.TAB_ICON_COLOR}
204
- {...additionalButton._icon}
205
- />}
206
- _hover={{
207
- bg: styles.TAB_HOVER_BG,
208
- }}
209
- bg={styles.TAB_BG}
210
- {...buttonProps}
211
- {...thisButtonProps}
212
- >
213
- <Text
214
- color={styles.TAB_COLOR}
215
- fontSize={styles.TAB_FONTSIZE}
216
- numberOfLines={1}
217
- ellipsizeMode="head"
218
- {...textProps}
219
- >{additionalButton.text}</Text>
220
- </Button>;
221
- }
222
- buttons.push(button);
223
- });
224
- }
225
-
226
- return buttons;
227
- },
228
- renderCurrentTabContent = () => {
229
- if (tabs[currentTab].content) {
230
- return tabs[currentTab].content;
231
- }
232
- return _.map(tabs[currentTab].items, (item, ix) => {
233
- return React.cloneElement(item, { key: ix });
234
- });
235
- },
236
- renderToggleButton = () => {
237
- const
238
- {
239
- buttonProps,
240
- textProps,
241
- } = getButtonProps();
242
-
243
- let button;
244
- if (isCollapsed) {
245
- button = <IconButton
246
- key="toggleBtn"
247
- onPress={onToggleCollapse}
248
- {...buttonProps}
249
- _icon={{
250
- as: Maximize,
251
- color: styles.TAB_ICON_COLOR,
252
- }}
253
- _hover={{
254
- bg: styles.TAB_HOVER_BG,
255
- }}
256
- bg={styles.TAB_BG}
257
- tooltip={isCollapsed ? 'Expand' : 'Collapse'}
258
- />;
259
- } else {
260
- button = <Button
261
- key="toggleBtn"
262
- onPress={onToggleCollapse}
263
- leftIcon={<Icon
264
- as={Minimize}
265
- color={styles.TAB_ICON_COLOR}
266
- />}
267
- _hover={{
268
- bg: styles.TAB_HOVER_BG,
269
- }}
270
- bg={styles.TAB_BG}
271
- {...buttonProps}
272
- // {...thisButtonProps}
273
- >
274
- <Text
275
- color={styles.TAB_COLOR}
276
- fontSize={styles.TAB_FONTSIZE}
277
- numberOfLines={1}
278
- ellipsizeMode="head"
279
- {...textProps}
280
- >Collapse</Text>
281
- </Button>;
282
- }
283
- return button;
284
- },
285
- onToggleCollapse = () => {
286
- setIsCollapsed(!isCollapsed);
287
- };
288
-
289
- useEffect(() => {
290
- // Restore saved settings
291
- (async () => {
292
- let key, val;
293
- key = id + '-isCollapsed';
294
- val = await getSaved(key);
295
- if (!_.isNil(val)) {
296
- setIsCollapsed(val);
297
- }
298
-
299
- key = id + '-currentTab';
300
- val = await getSaved(key);
301
- if (!_.isNil(val)) {
302
- setCurrentTab(val);
303
- }
304
-
305
- if (!isReady) {
306
- setIsReady(true);
307
- }
308
- })();
309
- }, []);
310
-
311
- if (!isReady) {
312
- return null;
313
- }
314
-
315
- if (direction === VERTICAL) {
316
- return <Panel {...propsToPass}>
317
- <Row flex={1} w="100%">
318
- <Column
319
- alignItems="center"
320
- justifyContent="flex-start"
321
- py={2}
322
- pl={isCollapsed ? 1 : 4}
323
- bg={styles.TAB_BAR_BG}
324
- w={isCollapsed ? '50px' : tabWidth}
325
- >
326
- {renderTabs()}
327
- <Column flex={1} w="100%" justifyContent="flex-end">
328
- {renderToggleButton()}
329
- </Column>
330
- </Column>
331
- <Column
332
- alignItems="center"
333
- justifyContent="flex-start"
334
- flex={1}
335
- >
336
- {renderCurrentTabContent()}
337
- </Column>
338
- </Row>
339
- </Panel>;
340
- }
341
-
342
- // HORIZONTAL
343
- return <Panel flex={1} w="100%" {...propsToPass} {...props._panel}>
344
- <Column flex={1} w="100%">
345
- <Row
346
- alignItems="center"
347
- justifyContent="flex-start"
348
- p={2}
349
- pb={0}
350
- bg={styles.TAB_BAR_BG}
351
- h={isCollapsed ? '30px' : tabHeight}
352
- >
353
- {renderTabs()}
354
- <Row flex={1} h="100%" justifyContent="flex-end">
355
- <Row h="100%">
356
- {renderToggleButton()}
357
- </Row>
358
- </Row>
359
- </Row>
360
- <Row flex={1}>
361
- {renderCurrentTabContent()}
362
- </Row>
363
- </Column>
6
+ return <Panel flex={1} w="100%" {...props._panel}>
7
+ <TabBar {...props} />
364
8
  </Panel>;
365
9
  }
@@ -1,38 +1,31 @@
1
- import { useEffect, useState, } from 'react';
2
1
  import Panel from './Panel.js';
3
- import { Tree, } from '../Tree/Tree.js';
2
+ import Tree, { WindowedTreeEditor, SideTreeEditor, } from '../Tree/Tree.js';
3
+ import {
4
+ EDITOR_TYPE__WINDOWED,
5
+ EDITOR_TYPE__SIDE,
6
+ } from '../../Constants/Editor.js';
4
7
  import _ from 'lodash';
5
8
 
6
9
  export function TreePanel(props) {
7
10
  const {
8
- disableTitleChange = false,
9
- selectorSelected,
10
- } = props,
11
- originalTitle = props.title,
12
- [isReady, setIsReady] = useState(disableTitleChange),
13
- [title, setTitle] = useState(originalTitle);
11
+ isEditor = false,
12
+ editorType = EDITOR_TYPE__WINDOWED,
13
+ } = props;
14
14
 
15
- useEffect(() => {
16
- if (!disableTitleChange && originalTitle) {
17
- let newTitle = originalTitle;
18
- if (selectorSelected?.[0]?.displayValue) {
19
- newTitle = originalTitle + ' for ' + selectorSelected[0].displayValue;
20
- }
21
- if (newTitle !== title) {
22
- setTitle(newTitle);
23
- }
15
+ let WhichTree = Tree;
16
+ if (isEditor) {
17
+ switch(editorType) {
18
+ case EDITOR_TYPE__WINDOWED:
19
+ WhichTree = WindowedTreeEditor;
20
+ break;
21
+ case EDITOR_TYPE__SIDE:
22
+ WhichTree = SideTreeEditor;
23
+ break;
24
24
  }
25
- if (!isReady) {
26
- setIsReady(true);
27
- }
28
- }, [selectorSelected, disableTitleChange, originalTitle]);
29
-
30
- if (!isReady) {
31
- return null;
32
25
  }
33
26
 
34
- return <Panel {...props} title={title}>
35
- <Tree {...props} />
27
+ return <Panel {...props._panel}>
28
+ <WhichTree {...props} />
36
29
  </Panel>;
37
30
  }
38
31