@onehat/ui 0.2.53 → 0.2.54

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.53",
3
+ "version": "0.2.54",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -19,8 +19,9 @@
19
19
  },
20
20
  "license": "UNLICENSED",
21
21
  "dependencies": {
22
- "@onehat/data": "^1.16.9",
22
+ "@onehat/data": "^1.16.10",
23
23
  "@hookform/resolvers": "^2.9.11",
24
+ "@k-renwick/colour-mixer": "^1.2.1",
24
25
  "ckeditor5-custom-build": "file:ckeditor5",
25
26
  "js-cookie": "^3.0.1",
26
27
  "native-base": "^3.4.25",
@@ -0,0 +1,15 @@
1
+ import IconButton from './IconButton.js';
2
+ import SquareCheck from '../Icons/SquareCheck.js';
3
+ import Square from '../Icons/Square.js';
4
+
5
+ export default function CheckboxButton(props) {
6
+ const {
7
+ isChecked,
8
+ } = props;
9
+
10
+ return <IconButton
11
+ icon={isChecked ? SquareCheck : Square }
12
+ {...props}
13
+ />;
14
+ }
15
+
@@ -17,10 +17,14 @@ const IconButton = React.forwardRef((props, ref) => {
17
17
  tooltipPlacement = 'bottom',
18
18
  } = props;
19
19
  const propsIcon = props._icon || {};
20
- let icon = props.icon || <Icon {...propsIcon} />;
20
+ let icon = props.icon || <Icon {...propsIcon} />,
21
+ ret;
21
22
  if (isLoading) {
22
23
  icon = <Spinner {..._spinner} />;
23
24
  }
25
+ if (!React.isValidElement(icon)) {
26
+ icon = <Icon as={icon} {...propsIcon} />;
27
+ }
24
28
  const pressable = <Pressable
25
29
  ref={ref}
26
30
  borderRadius="md"
@@ -29,16 +33,23 @@ const IconButton = React.forwardRef((props, ref) => {
29
33
  justifyContent="center"
30
34
  alignItems="center"
31
35
  p={2}
36
+ // bg={styles.ICON_BUTTON_BG}
37
+ _hover={{
38
+ bg: styles.ICON_BUTTON_BG_HOVER,
39
+ }}
32
40
  _disabled={{
33
41
  bg: styles.ICON_BUTTON_BG_DISABLED,
34
42
  }}
43
+ _pressed={{
44
+ bg: styles.ICON_BUTTON_BG_PRESSED,
45
+ }}
35
46
  {...props}
36
47
  >
37
- {icon}
48
+ {icon}
38
49
  </Pressable>;
39
- let ret = pressable;
50
+ ret = pressable;
40
51
  if (tooltip) {
41
- ret = <Tooltip label={tooltip} placement={tooltipPlacement}>{pressable}</Tooltip>;
52
+ ret = <Tooltip label={tooltip} placement={tooltipPlacement}>{ret}</Tooltip>;
42
53
  }
43
54
  return ret;
44
55
  });
@@ -412,6 +412,7 @@ export function Combo(props) {
412
412
  flex={1}
413
413
  h="100%"
414
414
  m={0}
415
+ autoSubmitDelay={0}
415
416
  borderTopRightRadius={0}
416
417
  borderBottomRightRadius={0}
417
418
  fontSize={styles.FORM_COMBO_INPUT_FONTSIZE}
@@ -21,6 +21,7 @@ import {
21
21
  DROP_POSITION_BEFORE,
22
22
  DROP_POSITION_AFTER,
23
23
  } from '../../Constants/Grid.js';
24
+ import * as colourMixer from '@k-renwick/colour-mixer'
24
25
  import UiGlobals from '../../UiGlobals.js';
25
26
  import useForceUpdate from '../../Hooks/useForceUpdate.js';
26
27
  import withContextMenu from '../Hoc/withContextMenu.js';
@@ -35,6 +36,7 @@ import withSelection from '../Hoc/withSelection.js';
35
36
  import withWindowedEditor from '../Hoc/withWindowedEditor.js';
36
37
  import withInlineEditor from '../Hoc/withInlineEditor.js';
37
38
  import testProps from '../../Functions/testProps.js';
39
+ import nbToRgb from '../../Functions/nbToRgb.js';
38
40
  import GridHeaderRow from './GridHeaderRow.js';
39
41
  import GridRow, { ReorderableGridRow } from './GridRow.js';
40
42
  import IconButton from '../Buttons/IconButton.js';
@@ -45,6 +47,7 @@ import NoReorderRows from '../Icons/NoReorderRows.js';
45
47
  import ReorderRows from '../Icons/ReorderRows.js';
46
48
  import _ from 'lodash';
47
49
 
50
+
48
51
  // Grid requires the use of HOC withSelection() whenever it's used.
49
52
  // The default export is *with* the HOC. A separate *raw* component is
50
53
  // exported which can be combined with many HOCs for various functionality.
@@ -67,7 +70,7 @@ export function Grid(props) {
67
70
  columnsConfig = [], // json configurations for each column
68
71
 
69
72
  columnProps = {},
70
- getRowProps = () => {
73
+ getRowProps = (item) => {
71
74
  return {
72
75
  borderBottomWidth: 1,
73
76
  borderBottomColor: 'trueGray.500',
@@ -348,19 +351,20 @@ export function Grid(props) {
348
351
  />;
349
352
  }
350
353
 
351
- let bg = styles.GRID_ROW_BG;
354
+ let bg = rowProps.bg || styles.GRID_ROW_BG,
355
+ mixWith;
352
356
  if (isSelected) {
353
357
  if (showHovers && isHovered) {
354
- bg = styles.GRID_ROW_SELECTED_HOVER_BG;
358
+ mixWith = styles.GRID_ROW_SELECTED_HOVER_BG;
355
359
  } else {
356
- bg = styles.GRID_ROW_SELECTED_BG;
357
- }
358
- } else {
359
- if (showHovers && isHovered) {
360
- bg = styles.GRID_ROW_HOVER_BG;
361
- } else {
362
- bg = styles.GRID_ROW_BG;
360
+ mixWith = styles.GRID_ROW_SELECTED_BG;
363
361
  }
362
+ } else if (showHovers && isHovered) {
363
+ mixWith = styles.GRID_ROW_HOVER_BG;
364
+ }
365
+ if (mixWith) {
366
+ const mixWithObj = nbToRgb(mixWith);
367
+ bg = colourMixer.blend(bg, 0.9, mixWithObj.color);
364
368
  }
365
369
  let WhichGridRow = GridRow,
366
370
  rowReorderProps = {};
@@ -12,6 +12,8 @@ import FormPanel from '../Panel/FormPanel.js';
12
12
  import Ban from '../Icons/Ban.js';
13
13
  import Gear from '../Icons/Gear.js';
14
14
  import Toolbar from '../Toolbar/Toolbar.js';
15
+ import getSaved from '../../Functions/getSaved.js';
16
+ import setSaved from '../../Functions/setSaved.js';
15
17
  import UiGlobals from '../../UiGlobals.js';
16
18
  import _ from 'lodash';
17
19
 
@@ -34,8 +36,6 @@ export default function withFilters(WrappedComponent) {
34
36
  customFilters = [], // of shape: { title, type, field, value, getRepoFilters(value) }
35
37
  minFilters = 3,
36
38
  maxFilters = 6,
37
- getSaved,
38
- setSaved,
39
39
 
40
40
  // withData
41
41
  Repository,
@@ -166,7 +166,7 @@ export default function withFilters(WrappedComponent) {
166
166
  }
167
167
  setSlots(newSlots);
168
168
  }
169
- if (save && setSaved) {
169
+ if (save) {
170
170
  setSaved(id + '-filters', filters);
171
171
  }
172
172
  },
@@ -204,9 +204,12 @@ export default function withFilters(WrappedComponent) {
204
204
  const filter = getFilterByField(field);
205
205
  return filter?.type;
206
206
  },
207
- getIsFilterRange = (field) => {
208
- // determines if filter is a "range" filter
207
+ getIsFilterRange = (filter) => {
208
+ let field = _.isString(filter) ? filter : filter.field;
209
209
  const filterType = getFilterType(field);
210
+ if (filterType?.type) {
211
+ return inArray(filterType.type, ['NumberRange', 'DateRange'])
212
+ }
210
213
  return inArray(filterType, ['NumberRange', 'DateRange']);
211
214
  },
212
215
  renderFilters = () => {
@@ -272,7 +275,7 @@ export default function withFilters(WrappedComponent) {
272
275
  const newRepoFilters = [];
273
276
  let filtersToUse = filters
274
277
 
275
- if (!isReady && getSaved) {
278
+ if (!isReady) {
276
279
  const savedFilters = await getSaved(id + '-filters');
277
280
  if (!_.isEmpty(savedFilters)) {
278
281
  // load saved filters
@@ -295,7 +298,7 @@ export default function withFilters(WrappedComponent) {
295
298
  field,
296
299
  value,
297
300
  } = filter,
298
- isFilterRange = getIsFilterRange(field);
301
+ isFilterRange = getIsFilterRange(filter);
299
302
  if (isFilterRange) {
300
303
  if (!!value) {
301
304
  const
@@ -45,16 +45,14 @@ export default function TabPanel(props) {
45
45
  if (onChangeIsCollapsed) {
46
46
  onChangeIsCollapsed(isCollapsed);
47
47
  }
48
- if (setSaved) {
49
- setSaved(id + '-isCollapsed', isCollapsed);
50
- }
48
+ setSaved(id + '-isCollapsed', isCollapsed);
51
49
  },
52
50
  setCurrentTab = (ix) => {
53
51
  setCurrentTabRaw(ix);
54
52
  if (onChangeCurrentTab) {
55
53
  onChangeCurrentTab(ix);
56
54
  }
57
- if (setSaved && saveCurrentTab) {
55
+ if (saveCurrentTab) {
58
56
  setSaved(id + '-currentTab', ix);
59
57
  }
60
58
  },
@@ -311,7 +311,5 @@ export default function DataMgt(props) {
311
311
  east={east}
312
312
  isEastCollapsed={isEastCollapsed}
313
313
  setIsEastCollapsed={setIsEastCollapsed}
314
- getSaved={getSaved}
315
- setSaved={setSaved}
316
314
  />;
317
315
  }
@@ -41,9 +41,6 @@ export default function Pagination(props) {
41
41
  return useMemo(() => {
42
42
  const
43
43
  iconButtonProps = {
44
- _hover: {
45
- bg: 'trueGray.400',
46
- },
47
44
  // mx: 1,
48
45
  },
49
46
  iconProps = {
@@ -12,6 +12,7 @@ export default function PaginationToolbar(props) {
12
12
  } = props,
13
13
  [minimize, setMinimize] = useState(false),
14
14
  propsToPass = _.omit(props, 'toolbarItems'),
15
+ showPagination = props.Repository?.totalPages > 1,
15
16
  onLayout = (e) => {
16
17
  // Note to future self: this is using hard-coded values.
17
18
  // Eventually might want to make it responsive to actual sizes
@@ -30,6 +31,16 @@ export default function PaginationToolbar(props) {
30
31
  }
31
32
  };
32
33
 
34
+ let toolbarProps = {};
35
+ if (showPagination) {
36
+ toolbarProps = {
37
+ borderLeftWidth: 1,
38
+ borderLeftColor: 'trueGray.400',
39
+ pl: 3,
40
+ ml: 3,
41
+ };
42
+ }
43
+
33
44
  return <Toolbar
34
45
  bg="trueGray.200"
35
46
  borderTopWidth={1}
@@ -37,7 +48,7 @@ export default function PaginationToolbar(props) {
37
48
  w="100%"
38
49
  onLayout={(e) => onLayout(e)}
39
50
  >
40
- <Pagination {...propsToPass} w={toolbarItems.length ? null : '100%'} minimize={minimize} />
41
- {toolbarItems.length ? <Row flex={1} borderLeftWidth={1} borderLeftColor="trueGray.400" pl={3} ml={3}>{toolbarItems}</Row> : null}
51
+ {showPagination && <Pagination {...propsToPass} w={toolbarItems.length ? null : '100%'} minimize={minimize} />}
52
+ {toolbarItems.length ? <Row flex={1} {...toolbarProps}>{toolbarItems}</Row> : null}
42
53
  </Toolbar>;
43
54
  };
@@ -61,7 +61,10 @@ const defaults = {
61
61
  GRID_TOOLBAR_ITEMS_COLOR: 'trueGray.800',
62
62
  GRID_TOOLBAR_ITEMS_DISABLED_COLOR: 'disabled',
63
63
  GRID_TOOLBAR_ITEMS_ICON_SIZE: 'sm',
64
+ ICON_BUTTON_BG: 'trueGray.200:alpha.0',
64
65
  ICON_BUTTON_BG_DISABLED: 'trueGray.200',
66
+ ICON_BUTTON_BG_HOVER: '#000:alpha.20',
67
+ ICON_BUTTON_BG_PRESSED: '#000:alpha.30',
65
68
  PANEL_FOOTER_BG: 'primary.100', // :alpha.50
66
69
  PANEL_HEADER_BG: 'primary.100',
67
70
  PANEL_HEADER_BG_VERTICAL: 'primary.100',
@@ -0,0 +1,63 @@
1
+ import UiGlobals from '../UiGlobals.js';
2
+ import _ from 'lodash';
3
+
4
+ function isRgb(color) {
5
+ const
6
+ regex = /^#[\w]{3,6}$/,
7
+ matches = color.match(regex);
8
+ return !!matches?.[0];
9
+ }
10
+
11
+ // 'color' might be in a format NativeBase uses, like '#000:alpha.20' or 'primary.200'
12
+ // Try to convert this to actual RGB colors.
13
+ export default function nbToRgb(color) {
14
+
15
+ if (isRgb(color)) {
16
+ // already in RGB format; simply return it
17
+ return {
18
+ color,
19
+ alpha,
20
+ };
21
+ }
22
+
23
+ const themeOverrideColors = UiGlobals?.ThemeOverrides?.colors || {};
24
+ if (themeOverrideColors[color]) {
25
+ color = themeOverrideColors[color];
26
+ }
27
+
28
+ let regex, alpha, matches;
29
+
30
+ regex = /^([\w#\.]+)(:alpha\.([\d]{1,2}))?$/;
31
+ matches = color.match(regex);
32
+ if (matches[3]) {
33
+ // alpha part exists. parse it
34
+ alpha = parseInt(matches[3], 10) / 100;
35
+ }
36
+ if (matches[1]) {
37
+ // color part exists. parse it
38
+ color = matches[1];
39
+ regex = /^(.+)\.([\d]{3})$/;
40
+ matches = color.match(regex);
41
+ if (matches) {
42
+ // color is in dot notation, like 'primary.200'
43
+ color = matches[1];
44
+ const whichValue = parseInt(matches[2], 10);
45
+ if (themeOverrideColors[color]?.[whichValue]) {
46
+ color = themeOverrideColors[color][whichValue];
47
+ }
48
+ } else if (themeOverrideColors[color]) {
49
+ // color is of form 'hover'
50
+ color = themeOverrideColors[color];
51
+ }
52
+
53
+ if (!isRgb(color)) {
54
+ color = nbToRgb(color).color;
55
+ }
56
+ }
57
+
58
+
59
+ return {
60
+ color,
61
+ alpha,
62
+ };
63
+ }
@@ -3,14 +3,11 @@ import UiGlobals from '../UiGlobals.js';
3
3
  import _ from 'lodash';
4
4
 
5
5
  export default async function setSaved(key, value) {
6
- const
7
- Repo = oneHatData.getRepository(UiGlobals.uiSavesRepo),
8
- entity = Repo?.getById(key);
9
-
10
- if (!entity) {
6
+ const Repo = oneHatData.getRepository(UiGlobals.uiSavesRepo);
7
+ if (!Repo) {
11
8
  return null;
12
9
  }
13
-
10
+
14
11
  let isOneBuild = false,
15
12
  isJson = false,
16
13
  model = null;
@@ -36,6 +33,8 @@ export default async function setSaved(key, value) {
36
33
  }
37
34
  isJson = true;
38
35
  }
36
+
37
+ const entity = Repo.getById(key);
39
38
  if (entity) {
40
39
  entity.setValues({
41
40
  value,
@@ -0,0 +1,5 @@
1
+ import UiGlobals from '../UiGlobals.js';
2
+
3
+ export default function setThemeOverrides(ThemeOverrides) {
4
+ UiGlobals.ThemeOverrides = ThemeOverrides;
5
+ }