@onehat/ui 0.3.30 → 0.3.31

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.3.30",
3
+ "version": "0.3.31",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -0,0 +1,58 @@
1
+ import React from 'react';
2
+ import {
3
+ Icon,
4
+ Pressable,
5
+ Text,
6
+ } from 'native-base';
7
+ import UiGlobals from '../../UiGlobals.js';
8
+
9
+ export default function SquareButton(props) {
10
+ const {
11
+ text,
12
+ isActive = false,
13
+ disableInteractions = false,
14
+ ...propsToPass
15
+ } = props,
16
+ styles = UiGlobals.styles,
17
+ color = isActive ? '#fff' : '#000';
18
+ const propsIcon = props._icon || {};
19
+ let icon = props.icon;
20
+ if (!icon) {
21
+ throw Error('icon missing');
22
+ }
23
+ if (!text) {
24
+ throw Error('text missing');
25
+ }
26
+
27
+ if (React.isValidElement(icon)) {
28
+ if (!_.isEmpty(propsIcon)) {
29
+ icon = React.cloneElement(icon, {...propsIcon});
30
+ }
31
+ } else {
32
+ icon = <Icon as={icon} {...propsIcon} />;
33
+ }
34
+
35
+ const
36
+ hoverProps = {},
37
+ pressedProps = {};
38
+ if (!disableInteractions) {
39
+ hoverProps.bg = styles.ICON_BUTTON_BG_HOVER;
40
+ pressedProps.bg = styles.ICON_BUTTON_BG_PRESSED;
41
+ }
42
+
43
+ return <Pressable
44
+ borderRadius="md"
45
+ flexDirection="column"
46
+ justifyContent="center"
47
+ alignItems="center"
48
+ p={2}
49
+ {...propsToPass}
50
+ bg={isActive ? '#56a6f8' : '#fff'}
51
+ _hover={hoverProps}
52
+ _pressed={pressedProps}
53
+ >
54
+ <Icon as={icon} color={color} size="xl" />
55
+ <Text fontSize={20} color={color}>{text}</Text>
56
+ </Pressable>;
57
+ }
58
+
@@ -46,27 +46,34 @@ export default function withPdfButton(WrappedComponent) {
46
46
  const modalItems = _.map(_.cloneDeep(items), (item, ix) => buildNextLayer(item, ix, columnDefaults)); // clone, as we don't want to alter the item by reference
47
47
 
48
48
  if (!_.isEmpty(ancillaryItems)) {
49
+ const
50
+ ancillaryItemsClone = _.cloneDeep(ancillaryItems),
51
+ items = [];
52
+ _.each(ancillaryItemsClone, (ancillaryItem) => { // clone, as we don't want to alter the item by reference
53
+ let name;
54
+ if (ancillaryItem.model) {
55
+ name = Inflector.underscore(ancillaryItem.model);
56
+ } else {
57
+ name = ancillaryItem.title;
58
+ }
59
+ if (!inArray(name, ['Photos', 'Videos', 'Files'])) {
60
+ return;
61
+ }
62
+ name = 'ancillary___' + name;
63
+ items.push({
64
+ title: ancillaryItem.title,
65
+ label: ancillaryItem.title,
66
+ name,
67
+ type: 'Checkbox',
68
+ });
69
+ });
49
70
  modalItems.push({
50
71
  type: 'FieldSet',
51
72
  title: 'Ancillary Items',
52
73
  defaults: {
53
74
  labelWidth: '90%',
54
75
  },
55
- items: _.map(_.cloneDeep(ancillaryItems), (ancillaryItem) => { // clone, as we don't want to alter the item by reference
56
- let name;
57
- if (ancillaryItem.model) {
58
- name = Inflector.underscore(ancillaryItem.model);
59
- } else {
60
- name = ancillaryItem.title;
61
- }
62
- name = 'ancillary___' + name;
63
- return {
64
- title: ancillaryItem.title,
65
- label: ancillaryItem.title,
66
- name,
67
- type: 'Checkbox',
68
- };
69
- }),
76
+ items,
70
77
  showToggleAllCheckbox: true,
71
78
  isCollapsible: false,
72
79
  });
@@ -35,6 +35,9 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
35
35
  contextMenuItems,
36
36
  additionalToolbarButtons,
37
37
  onChangeColumnsConfig,
38
+ verifyCanEdit,
39
+ verifyCanDelete,
40
+ verifyCanDuplicate,
38
41
  ...propsToPass
39
42
  } = props,
40
43
  {
@@ -146,6 +149,9 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
146
149
  if (_.isEmpty(selection) || (_.isArray(selection) && selection.length > 1)) {
147
150
  isDisabled = true;
148
151
  }
152
+ if (verifyCanEdit && !verifyCanEdit(selection)) {
153
+ isDisabled = true;
154
+ }
149
155
  break;
150
156
  case 'delete':
151
157
  text = 'Delete';
@@ -157,6 +163,9 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
157
163
  if (_.isEmpty(selection) || (_.isArray(selection) && selection.length > 1)) {
158
164
  isDisabled = true;
159
165
  }
166
+ if (verifyCanDelete && !verifyCanDelete(selection)) {
167
+ isDisabled = true;
168
+ }
160
169
  break;
161
170
  case 'view':
162
171
  text = 'View';
@@ -193,6 +202,9 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
193
202
  if (_.isEmpty(selection) || selection.length > 1) {
194
203
  isDisabled = true;
195
204
  }
205
+ if (verifyCanDuplicate && !verifyCanDuplicate(selection)) {
206
+ isDisabled = true;
207
+ }
196
208
  break;
197
209
  // case 'print':
198
210
  // text = 'Print';
@@ -109,6 +109,7 @@ function Viewer(props) {
109
109
 
110
110
  let element = <Element
111
111
  value={value}
112
+ isEditable={false}
112
113
  {...propsToPass}
113
114
  />;
114
115
  if (label) {
@@ -37,6 +37,7 @@ import Panel from './Panel/Panel.js';
37
37
  // import Picker from '../Components/Panel/Picker.js';
38
38
  import PlusMinusButton from './Buttons/PlusMinusButton.js';
39
39
  import RadioGroup from './Form/Field/RadioGroup/RadioGroup.js';
40
+ import SquareButton from './Buttons/SquareButton.js';
40
41
  import TabPanel from './Panel/TabPanel.js';
41
42
  import Tag from './Form/Field/Combo/Tag.js';
42
43
  import TagViewer from './Viewer/TagViewer.js';
@@ -88,6 +89,7 @@ const components = {
88
89
  // Picker,
89
90
  PlusMinusButton,
90
91
  RadioGroup,
92
+ SquareButton,
91
93
  TabPanel,
92
94
  Tag,
93
95
  TagViewer,