@performant-software/semantic-components 1.1.0 → 1.1.1-beta.1

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": "@performant-software/semantic-components",
3
- "version": "1.1.0",
3
+ "version": "1.1.1-beta.1",
4
4
  "description": "A package of shared components based on the Semantic UI Framework.",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",
@@ -12,7 +12,7 @@
12
12
  "build": "webpack --mode production && flow-copy-source -v src types"
13
13
  },
14
14
  "dependencies": {
15
- "@performant-software/shared-components": "^1.1.0",
15
+ "@performant-software/shared-components": "^1.1.1-beta.1",
16
16
  "@react-google-maps/api": "^2.8.1",
17
17
  "axios": "^0.26.1",
18
18
  "i18next": "^19.4.4",
@@ -2,7 +2,12 @@
2
2
 
3
3
  import { Timer } from '@performant-software/shared-components';
4
4
  import React, { Component, type ComponentType } from 'react';
5
- import { Button, Dropdown, Message } from 'semantic-ui-react';
5
+ import {
6
+ Button,
7
+ Dropdown,
8
+ Message,
9
+ type ButtonProps
10
+ } from 'semantic-ui-react';
6
11
  import _ from 'underscore';
7
12
  import EditModal from './EditModal';
8
13
  import i18n from '../i18n/i18n';
@@ -16,6 +21,7 @@ type Option = {
16
21
  };
17
22
 
18
23
  type Props = {
24
+ buttons?: Array<ButtonProps>,
19
25
  className?: string,
20
26
  collectionName: string,
21
27
  header?: ComponentType<any>,
@@ -45,6 +51,10 @@ type State = {
45
51
  value: ?number | ?string
46
52
  };
47
53
 
54
+ const BUTTON_ADD = 'add';
55
+ const BUTTON_CLEAR = 'clear';
56
+ const BUTTON_EDIT = 'edit';
57
+
48
58
  const TIMEOUT = 500;
49
59
 
50
60
  class AssociatedDropdown extends Component<Props, State> {
@@ -243,13 +253,33 @@ class AssociatedDropdown extends Component<Props, State> {
243
253
  return null;
244
254
  }
245
255
 
256
+ return this.renderButton(BUTTON_ADD, {
257
+ basic: true,
258
+ content: i18n.t('Common.buttons.add'),
259
+ icon: 'plus',
260
+ onClick: () => this.setState({ modalAdd: true }),
261
+ type: 'button'
262
+ });
263
+ }
264
+
265
+ /**
266
+ * Renders the button with the passed name using the provided props.
267
+ *
268
+ * @param name
269
+ * @param defaults
270
+ *
271
+ * @returns {JSX.Element|null}
272
+ */
273
+ renderButton(name, defaults) {
274
+ const button = _.findWhere(this.props.buttons, { name }) || {};
275
+
276
+ if (button.accept && !button.accept()) {
277
+ return null;
278
+ }
279
+
246
280
  return (
247
281
  <Button
248
- basic
249
- content={i18n.t('Common.buttons.add')}
250
- icon='plus'
251
- onClick={() => this.setState({ modalAdd: true })}
252
- type='button'
282
+ {..._.defaults(button, defaults)}
253
283
  />
254
284
  );
255
285
  }
@@ -264,15 +294,13 @@ class AssociatedDropdown extends Component<Props, State> {
264
294
  return null;
265
295
  }
266
296
 
267
- return (
268
- <Button
269
- basic
270
- content={i18n.t('Common.buttons.clear')}
271
- icon='times'
272
- onClick={this.onClear.bind(this)}
273
- type='button'
274
- />
275
- );
297
+ return this.renderButton(BUTTON_CLEAR, {
298
+ basic: true,
299
+ content: i18n.t('Common.buttons.clear'),
300
+ icon: 'times',
301
+ onClick: this.onClear.bind(this),
302
+ type: 'button'
303
+ });
276
304
  }
277
305
 
278
306
  /**
@@ -285,15 +313,13 @@ class AssociatedDropdown extends Component<Props, State> {
285
313
  return null;
286
314
  }
287
315
 
288
- return (
289
- <Button
290
- basic
291
- content={i18n.t('Common.buttons.edit')}
292
- icon='pencil'
293
- onClick={() => this.setState({ modalEdit: true })}
294
- type='button'
295
- />
296
- );
316
+ return this.renderButton(BUTTON_EDIT, {
317
+ basic: true,
318
+ content: i18n.t('Common.buttons.edit'),
319
+ icon: 'pencil',
320
+ onClick: () => this.setState({ modalEdit: true }),
321
+ type: 'button'
322
+ });
297
323
  }
298
324
 
299
325
  /**
@@ -43,7 +43,12 @@ type Props = ListProps & {
43
43
  * If a <code>render</code> callback is provided, the item will be passed to the function and the return JSX
44
44
  * will display as the property value.
45
45
  */
46
- columns: Array<Column>
46
+ columns: Array<Column>,
47
+
48
+ /**
49
+ * If <code>true</code>, columns can be shown/hidden by the user.
50
+ */
51
+ configurable?: boolean
47
52
  };
48
53
 
49
54
  type State = {
@@ -139,7 +144,9 @@ const useColumnSelector = (WrappedComponent: ComponentType<any>) => (
139
144
  {...this.props}
140
145
  className={`data-table-column-selector ${this.props.className}`}
141
146
  columns={this.state.columns}
142
- renderListHeader={this.renderHeader.bind(this)}
147
+ renderListHeader={this.props.configurable
148
+ ? this.renderHeader.bind(this)
149
+ : undefined}
143
150
  />
144
151
  );
145
152
  }
@@ -9,11 +9,6 @@ import useDataList, { SORT_ASCENDING, SORT_DESCENDING, type Props as DataListPro
9
9
  import './ListTable.css';
10
10
 
11
11
  type Props = DataListProps & DataTableProps & {
12
- /**
13
- * If true, columns can be shown/hidden by the user.
14
- */
15
- configurable?: boolean,
16
-
17
12
  /**
18
13
  * The name of the default sort column.
19
14
  */
@@ -2,7 +2,12 @@
2
2
 
3
3
  import { Timer } from '@performant-software/shared-components';
4
4
  import React, { Component, type ComponentType } from 'react';
5
- import { Button, Dropdown, Message } from 'semantic-ui-react';
5
+ import {
6
+ Button,
7
+ Dropdown,
8
+ Message,
9
+ type ButtonProps
10
+ } from 'semantic-ui-react';
6
11
  import _ from 'underscore';
7
12
  import EditModal from './EditModal';
8
13
  import i18n from '../i18n/i18n';
@@ -16,6 +21,7 @@ type Option = {
16
21
  };
17
22
 
18
23
  type Props = {
24
+ buttons?: Array<ButtonProps>,
19
25
  className?: string,
20
26
  collectionName: string,
21
27
  header?: ComponentType<any>,
@@ -45,6 +51,10 @@ type State = {
45
51
  value: ?number | ?string
46
52
  };
47
53
 
54
+ const BUTTON_ADD = 'add';
55
+ const BUTTON_CLEAR = 'clear';
56
+ const BUTTON_EDIT = 'edit';
57
+
48
58
  const TIMEOUT = 500;
49
59
 
50
60
  class AssociatedDropdown extends Component<Props, State> {
@@ -243,13 +253,33 @@ class AssociatedDropdown extends Component<Props, State> {
243
253
  return null;
244
254
  }
245
255
 
256
+ return this.renderButton(BUTTON_ADD, {
257
+ basic: true,
258
+ content: i18n.t('Common.buttons.add'),
259
+ icon: 'plus',
260
+ onClick: () => this.setState({ modalAdd: true }),
261
+ type: 'button'
262
+ });
263
+ }
264
+
265
+ /**
266
+ * Renders the button with the passed name using the provided props.
267
+ *
268
+ * @param name
269
+ * @param defaults
270
+ *
271
+ * @returns {JSX.Element|null}
272
+ */
273
+ renderButton(name, defaults) {
274
+ const button = _.findWhere(this.props.buttons, { name }) || {};
275
+
276
+ if (button.accept && !button.accept()) {
277
+ return null;
278
+ }
279
+
246
280
  return (
247
281
  <Button
248
- basic
249
- content={i18n.t('Common.buttons.add')}
250
- icon='plus'
251
- onClick={() => this.setState({ modalAdd: true })}
252
- type='button'
282
+ {..._.defaults(button, defaults)}
253
283
  />
254
284
  );
255
285
  }
@@ -264,15 +294,13 @@ class AssociatedDropdown extends Component<Props, State> {
264
294
  return null;
265
295
  }
266
296
 
267
- return (
268
- <Button
269
- basic
270
- content={i18n.t('Common.buttons.clear')}
271
- icon='times'
272
- onClick={this.onClear.bind(this)}
273
- type='button'
274
- />
275
- );
297
+ return this.renderButton(BUTTON_CLEAR, {
298
+ basic: true,
299
+ content: i18n.t('Common.buttons.clear'),
300
+ icon: 'times',
301
+ onClick: this.onClear.bind(this),
302
+ type: 'button'
303
+ });
276
304
  }
277
305
 
278
306
  /**
@@ -285,15 +313,13 @@ class AssociatedDropdown extends Component<Props, State> {
285
313
  return null;
286
314
  }
287
315
 
288
- return (
289
- <Button
290
- basic
291
- content={i18n.t('Common.buttons.edit')}
292
- icon='pencil'
293
- onClick={() => this.setState({ modalEdit: true })}
294
- type='button'
295
- />
296
- );
316
+ return this.renderButton(BUTTON_EDIT, {
317
+ basic: true,
318
+ content: i18n.t('Common.buttons.edit'),
319
+ icon: 'pencil',
320
+ onClick: () => this.setState({ modalEdit: true }),
321
+ type: 'button'
322
+ });
297
323
  }
298
324
 
299
325
  /**
@@ -43,7 +43,12 @@ type Props = ListProps & {
43
43
  * If a <code>render</code> callback is provided, the item will be passed to the function and the return JSX
44
44
  * will display as the property value.
45
45
  */
46
- columns: Array<Column>
46
+ columns: Array<Column>,
47
+
48
+ /**
49
+ * If <code>true</code>, columns can be shown/hidden by the user.
50
+ */
51
+ configurable?: boolean
47
52
  };
48
53
 
49
54
  type State = {
@@ -139,7 +144,9 @@ const useColumnSelector = (WrappedComponent: ComponentType<any>) => (
139
144
  {...this.props}
140
145
  className={`data-table-column-selector ${this.props.className}`}
141
146
  columns={this.state.columns}
142
- renderListHeader={this.renderHeader.bind(this)}
147
+ renderListHeader={this.props.configurable
148
+ ? this.renderHeader.bind(this)
149
+ : undefined}
143
150
  />
144
151
  );
145
152
  }
@@ -9,11 +9,6 @@ import useDataList, { SORT_ASCENDING, SORT_DESCENDING, type Props as DataListPro
9
9
  import './ListTable.css';
10
10
 
11
11
  type Props = DataListProps & DataTableProps & {
12
- /**
13
- * If true, columns can be shown/hidden by the user.
14
- */
15
- configurable?: boolean,
16
-
17
12
  /**
18
13
  * The name of the default sort column.
19
14
  */