@onehat/ui 0.2.54 → 0.2.55

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.2.54",
3
+ "version": "0.2.55",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "license": "UNLICENSED",
21
21
  "dependencies": {
22
- "@onehat/data": "^1.16.10",
22
+ "@onehat/data": "^1.17.0",
23
23
  "@hookform/resolvers": "^2.9.11",
24
24
  "@k-renwick/colour-mixer": "^1.2.1",
25
25
  "ckeditor5-custom-build": "file:ckeditor5",
@@ -27,7 +27,7 @@ export default function Editor(props) {
27
27
  onEditMode = () => {
28
28
  setEditorMode(EDITOR_MODE__EDIT);
29
29
  },
30
- onBack = () => {
30
+ onViewMode = () => {
31
31
  setEditorMode(EDITOR_MODE__VIEW);
32
32
  };
33
33
 
@@ -49,7 +49,7 @@ export default function Editor(props) {
49
49
 
50
50
  return <Form
51
51
  record={selection}
52
- onBack={onBack}
52
+ onViewMode={onViewMode}
53
53
  onCancel={onCancel}
54
54
  onSave={onSave}
55
55
  onClose={onClose}
@@ -147,16 +147,16 @@ function FileElement(props) {
147
147
  setIsDropping(false);
148
148
  };
149
149
 
150
- useEffect(() => {
151
- const {
152
- dataUri,
153
- control,
154
- filename,
155
- } = value;
156
- setLocalDataUri(localDataUri);
157
- setLocalControl(localControl);
158
- setLocalFilename(localFilename);
159
- }, []);
150
+ // useEffect(() => {
151
+ // const {
152
+ // dataUri,
153
+ // control,
154
+ // filename,
155
+ // } = value;
156
+ // setLocalDataUri(dataUri);
157
+ // setLocalControl(control);
158
+ // setLocalFilename(filename);
159
+ // }, []);
160
160
 
161
161
  if (CURRENT_MODE === UI_MODE_REACT_NATIVE) {
162
162
  throw new Error('Not yet implemented for RN.');
@@ -282,14 +282,10 @@ function Form(props) {
282
282
  });
283
283
  return <Element key={ix} title={title} {...defaults} {...propsToPass} {...editorTypeProps}>{children}</Element>;
284
284
  }
285
-
286
- if (!name) {
287
- throw new Error('name is required');
288
- }
289
285
 
290
286
  if (isViewOnly || !isEditable) {
291
287
  const Text = getComponentFromType('Text');
292
- if (!label && Repository) {
288
+ if (!label && Repository && model.titles?.[name]) {
293
289
  label = model.titles[name];
294
290
  }
295
291
  const value = (record && record[name]) || (startingValues && startingValues[name]) || null;
@@ -307,7 +303,7 @@ function Form(props) {
307
303
  return <Row key={ix} px={2} pb={1}>{element}</Row>;
308
304
  }
309
305
 
310
- if (!label && Repository) {
306
+ if (!label && Repository && model.titles?.[name]) {
311
307
  label = model.titles[name];
312
308
  }
313
309
 
@@ -10,7 +10,7 @@ export default function Label(props) {
10
10
  } = props;
11
11
  return <Row
12
12
  w={w}
13
- // maxWidth="30%"
13
+ minWidth="220px"
14
14
  alignItems="center"
15
15
  pl={2}
16
16
  {...props}
@@ -52,18 +52,6 @@ import _ from 'lodash';
52
52
  // The default export is *with* the HOC. A separate *raw* component is
53
53
  // exported which can be combined with many HOCs for various functionality.
54
54
 
55
- // Desired features: ---------
56
- // Rows
57
- // Rows with ability to use multiple lines (I was thinking custom render fns on rows, could possibly already do this!)
58
- // selection
59
- // Draggable selection (not super important)
60
- // editor
61
- // [ ] Show inline editor for selected row
62
- // Dragging of window (see withWindowedEditor)
63
- // custom cell types
64
- // Most would use text, and depend on @onehat/data for formatting
65
- // Display tree data
66
-
67
55
  export function Grid(props) {
68
56
  const {
69
57
 
@@ -74,9 +62,6 @@ export function Grid(props) {
74
62
  return {
75
63
  borderBottomWidth: 1,
76
64
  borderBottomColor: 'trueGray.500',
77
- py: 2,
78
- pl: 4,
79
- pr: 2,
80
65
  };
81
66
  },
82
67
  flatListProps = {},
@@ -363,8 +348,10 @@ export function Grid(props) {
363
348
  mixWith = styles.GRID_ROW_HOVER_BG;
364
349
  }
365
350
  if (mixWith) {
366
- const mixWithObj = nbToRgb(mixWith);
367
- bg = colourMixer.blend(bg, 0.9, mixWithObj.color);
351
+ const
352
+ mixWithObj = nbToRgb(mixWith),
353
+ ratio = mixWithObj.alpha ? 1 - mixWithObj.alpha : 0.5;
354
+ bg = colourMixer.blend(bg, ratio, mixWithObj.color);
368
355
  }
369
356
  let WhichGridRow = GridRow,
370
357
  rowReorderProps = {};
@@ -676,6 +663,7 @@ export function Grid(props) {
676
663
  sortable = true,
677
664
  w,
678
665
  flex,
666
+ ...propsToPass
679
667
  } = columnConfig,
680
668
 
681
669
  config = {
@@ -693,6 +681,7 @@ export function Grid(props) {
693
681
  w,
694
682
  flex,
695
683
  showDragHandles: false,
684
+ ...propsToPass,
696
685
  };
697
686
 
698
687
  if (!config.w && !config.flex) {
@@ -32,10 +32,39 @@ export default function GridRow(props) {
32
32
  const renderColumns = (item) => {
33
33
  if (_.isArray(columnsConfig)) {
34
34
  return _.map(columnsConfig, (config, key) => {
35
+ const propsToPass = columnProps[key] || {};
36
+ if (config.w) {
37
+ propsToPass.w = config.w;
38
+ } else if (config.flex) {
39
+ propsToPass.flex = config.flex;
40
+ propsToPass.minWidth = 100;
41
+ } else {
42
+ propsToPass.flex = 1;
43
+ }
44
+ propsToPass.p = 1;
45
+ propsToPass.justifyContent = 'center';
46
+
35
47
  let value;
36
48
  if (_.isPlainObject(config)) {
37
49
  if (config.renderer) {
38
- return config.renderer(item, key);
50
+ const extraProps = _.omit(config, [
51
+ 'columnId',
52
+ 'header',
53
+ 'fieldName',
54
+ 'type',
55
+ 'isEditable',
56
+ 'editor',
57
+ 'format',
58
+ 'renderer',
59
+ 'reorderable',
60
+ 'resizable',
61
+ 'sortable',
62
+ 'w',
63
+ 'flex',
64
+ 'showDragHandles',
65
+ ]);
66
+
67
+ return <Row key={key} {...propsToPass} {...extraProps}>{config.renderer(item)}</Row>;
39
68
  }
40
69
  if (config.fieldName) {
41
70
  if (item.properties && item.properties[config.fieldName]) {
@@ -63,16 +92,6 @@ export default function GridRow(props) {
63
92
  if (_.isFunction(value)) {
64
93
  return value(key);
65
94
  }
66
-
67
- const propsToPass = columnProps[key] || {};
68
- if (config.w) {
69
- propsToPass.w = config.w;
70
- } else if (config.flex) {
71
- propsToPass.flex = config.flex;
72
- propsToPass.minWidth = 100;
73
- } else {
74
- propsToPass.flex = 1;
75
- }
76
95
 
77
96
  return <Text
78
97
  key={key}
@@ -51,10 +51,8 @@ export default function withData(WrappedComponent) {
51
51
  Repository = oneHatData.getRepository(model);
52
52
  }
53
53
 
54
-
55
- if (autoLoad && Repository && !Repository.isLoaded && Repository.isRemote && !Repository.isAutoLoad && !Repository.isLoading) {
54
+ if (Repository && (autoLoad || Repository.autoLoad) && !Repository.isLoaded && Repository.isRemote && !Repository.isAutoLoad && !Repository.isLoading) {
56
55
  await Repository.load();
57
- // TODO: Implement some method by which I can detect if Repository is still loading and wait until it's done!
58
56
  }
59
57
 
60
58
  setLocalRepository(Repository);
@@ -33,7 +33,7 @@ const defaults = {
33
33
  FORM_INPUT_BG: WHITE,
34
34
  FORM_INPUT_FONTSIZE: DEFAULT_FONTSIZE,
35
35
  FORM_INPUT_FOCUS_BG: FOCUS,
36
- FORM_LABEL_WIDTH: '170px',
36
+ FORM_LABEL_WIDTH: '30%',
37
37
  FORM_LABEL_FONTSIZE: DEFAULT_FONTSIZE,
38
38
  FORM_NUMBER_FONTSIZE: DEFAULT_FONTSIZE,
39
39
  FORM_TEXT_FONTSIZE: DEFAULT_FONTSIZE,
@@ -12,6 +12,8 @@ function isRgb(color) {
12
12
  // Try to convert this to actual RGB colors.
13
13
  export default function nbToRgb(color) {
14
14
 
15
+ let regex, alpha, matches;
16
+
15
17
  if (isRgb(color)) {
16
18
  // already in RGB format; simply return it
17
19
  return {
@@ -25,13 +27,12 @@ export default function nbToRgb(color) {
25
27
  color = themeOverrideColors[color];
26
28
  }
27
29
 
28
- let regex, alpha, matches;
29
-
30
+ // Detect 'primary.100:alpha.20' format
30
31
  regex = /^([\w#\.]+)(:alpha\.([\d]{1,2}))?$/;
31
32
  matches = color.match(regex);
32
33
  if (matches[3]) {
33
34
  // alpha part exists. parse it
34
- alpha = parseInt(matches[3], 10) / 100;
35
+ alpha = parseInt(matches[3], 10) / 100; // convert '20' to .2
35
36
  }
36
37
  if (matches[1]) {
37
38
  // color part exists. parse it
@@ -3,11 +3,10 @@ import UiGlobals from '../UiGlobals.js';
3
3
  import _ from 'lodash';
4
4
 
5
5
  export default async function setSaved(key, value) {
6
- const Repo = oneHatData.getRepository(UiGlobals.uiSavesRepo);
7
- if (!Repo) {
8
- return null;
9
- }
10
-
6
+ const
7
+ Repo = oneHatData.getRepository(UiGlobals.uiSavesRepo),
8
+ entity = Repo?.getById(key);
9
+
11
10
  let isOneBuild = false,
12
11
  isJson = false,
13
12
  model = null;
@@ -33,8 +32,6 @@ export default async function setSaved(key, value) {
33
32
  }
34
33
  isJson = true;
35
34
  }
36
-
37
- const entity = Repo.getById(key);
38
35
  if (entity) {
39
36
  entity.setValues({
40
37
  value,
@@ -3,7 +3,7 @@ import useWindowSize from './useWindowSize.js';
3
3
  // This hook takes the submitted window size and adjusts it
4
4
  // to fit the actual screen size
5
5
 
6
- export default function(width, height, percentage = 0.9) {
6
+ export default function(width, height, percentage = 1) {
7
7
 
8
8
  const windowSize = useWindowSize();
9
9
 
@@ -1,16 +1,25 @@
1
1
  // from https://designcode.io/react-hooks-usewindowsize-hook
2
2
 
3
3
  import { useLayoutEffect, useState } from 'react';
4
+ import _ from 'lodash';
4
5
 
5
6
  // For web only!
6
7
  export default function useWindowSize() {
7
- const [windowSize, setWindowSize] = useState({ width: 0, height: 0 });
8
+ const [windowSize, setWindowSize] = useState({
9
+ width: window.innerWidth,
10
+ height: window.innerHeight
11
+ });
8
12
 
9
13
  const handleSize = () => {
10
- setWindowSize({
11
- width: window.innerWidth,
12
- height: window.innerHeight
13
- });
14
+ const
15
+ existingSize = windowSize,
16
+ newSize = {
17
+ width: window.innerWidth,
18
+ height: window.innerHeight
19
+ };
20
+ if (!_.isEqual(existingSize, newSize)) {
21
+ setWindowSize(newSize);
22
+ }
14
23
  };
15
24
 
16
25
  useLayoutEffect(() => {
@@ -14,9 +14,9 @@ const ThemeOverrides = {
14
14
  // secondary: {
15
15
  // 500: '#1F3854', // default for buttons
16
16
  // },
17
- selected: '#ffc',
18
- hover: '#eee',
19
- selectedHover: '#eeb',
17
+ selected: '#ff0:alpha.20',
18
+ hover: '#000:alpha.10',
19
+ selectedHover: '#cc0',
20
20
  unselected: '#bbb',
21
21
  disabled: '#ccc',
22
22
  control: '#1B518C',