@performant-software/semantic-components 0.5.10 → 0.5.11

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/build/main.css CHANGED
@@ -436,6 +436,10 @@ div.react-calendar {
436
436
  padding-bottom: 20%;
437
437
  text-align: center;
438
438
  }
439
+ .lazy-document .react-pdf__Page__canvas {
440
+ width: 100% !important;
441
+ height: 100% !important;
442
+ }
439
443
 
440
444
  .photo-viewer {
441
445
  padding: 30px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@performant-software/semantic-components",
3
- "version": "0.5.10",
3
+ "version": "0.5.11",
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": "^0.5.10",
15
+ "@performant-software/shared-components": "^0.5.11",
16
16
  "@react-google-maps/api": "^2.8.1",
17
17
  "axios": "^0.26.1",
18
18
  "i18next": "^19.4.4",
@@ -21,6 +21,7 @@
21
21
  "react-dnd": "^11.1.3",
22
22
  "react-dnd-html5-backend": "^11.1.3",
23
23
  "react-i18next": "^11.4.0",
24
+ "react-pdf": "^5.7.2",
24
25
  "react-syntax-highlighter": "^15.5.0",
25
26
  "react-uuid": "^1.0.2",
26
27
  "semantic-ui-less": "^2.4.1",
@@ -32,7 +33,7 @@
32
33
  "react-dom": ">= 16.13.1 < 18.0.0"
33
34
  },
34
35
  "devDependencies": {
35
- "@performant-software/webpack-config": "^0.5.10",
36
+ "@performant-software/webpack-config": "^0.5.11",
36
37
  "flow-copy-source": "^2.0.9",
37
38
  "less": "^4.1.2",
38
39
  "less-loader": "^11.0.0",
@@ -437,7 +437,7 @@ class DataTable extends Component<Props, State> {
437
437
  <Table.HeaderCell
438
438
  key={column.name}
439
439
  sorted={this.props.sortColumn === column.name ? this.props.sortDirection : null}
440
- onClick={this.props.onColumnClick.bind(this, column)}
440
+ onClick={() => this.props.onColumnClick(column)}
441
441
  >
442
442
  { column.label }
443
443
  <ColumnResize
@@ -25,6 +25,8 @@ type Props = {
25
25
  className?: string,
26
26
  columns: Array<Column>,
27
27
  configurable: boolean,
28
+ defaultSort?: string,
29
+ defaultSortDirection?: string,
28
30
  items: Array<any>,
29
31
  modal?: {
30
32
  component: ComponentType<any>,
@@ -77,10 +79,16 @@ class EmbeddedList extends Component<Props, State> {
77
79
  * Sorts the table by the first column.
78
80
  */
79
81
  componentDidMount() {
80
- const column = _.find(this.props.columns, (c) => c.sortable !== false);
82
+ let column;
83
+
84
+ if (this.props.defaultSort) {
85
+ column = _.findWhere(this.props.columns, { name: this.props.defaultSort });
86
+ } else {
87
+ column = _.find(this.props.columns, (c) => c.sortable !== false);
88
+ }
81
89
 
82
90
  if (column) {
83
- this.onColumnClick(column);
91
+ this.onColumnClick(column, this.props.defaultSortDirection);
84
92
  }
85
93
  }
86
94
 
@@ -101,7 +109,7 @@ class EmbeddedList extends Component<Props, State> {
101
109
  *
102
110
  * @param column
103
111
  */
104
- onColumnClick(column: Column) {
112
+ onColumnClick(column: Column, direction: string = SORT_ASCENDING) {
105
113
  /*
106
114
  * We'll disable the column sorting if the table rows are draggable. Making the table rows draggable implies
107
115
  * that the sorting will be done manually. Allowing column click sorting could make things confusing.
@@ -119,7 +127,7 @@ class EmbeddedList extends Component<Props, State> {
119
127
  }
120
128
 
121
129
  const sortColumn = column.name;
122
- let sortDirection = SORT_ASCENDING;
130
+ let sortDirection = direction || SORT_ASCENDING;
123
131
 
124
132
  if (column.name === this.state.sortColumn) {
125
133
  sortDirection = this.state.sortDirection === SORT_ASCENDING ? SORT_DESCENDING : SORT_ASCENDING;
@@ -276,3 +284,8 @@ EmbeddedList.defaultProps = {
276
284
  };
277
285
 
278
286
  export default EmbeddedList;
287
+
288
+ export {
289
+ SORT_ASCENDING,
290
+ SORT_DESCENDING
291
+ };
@@ -18,4 +18,9 @@
18
18
  padding-top: 20%;
19
19
  padding-bottom: 20%;
20
20
  text-align: center;
21
- }
21
+ }
22
+
23
+ .lazy-document .react-pdf__Page__canvas {
24
+ width: 100% !important;
25
+ height: 100% !important;
26
+ }
@@ -1,6 +1,7 @@
1
1
  // @flow
2
2
 
3
- import React, { useState, type Node } from 'react';
3
+ import React, { useState, useEffect, type Node } from 'react';
4
+ import { Document, Page } from 'react-pdf/dist/esm/entry.webpack';
4
5
  import {
5
6
  Dimmer,
6
7
  Icon,
@@ -27,6 +28,15 @@ type Props = {
27
28
  const LazyDocument = (props: Props) => {
28
29
  const [visible, setVisible] = useState(false);
29
30
  const [dimmer, setDimmer] = useState(false);
31
+ const [contentType, setContentType] = useState('');
32
+
33
+ useEffect(() => {
34
+ if (props.src && !props.preview) {
35
+ fetch(props.src)
36
+ .then((response) => response.blob())
37
+ .then((blob) => setContentType(blob.type));
38
+ }
39
+ }, [props.preview, props.src]);
30
40
 
31
41
  if (!visible) {
32
42
  return (
@@ -65,7 +75,21 @@ const LazyDocument = (props: Props) => {
65
75
  size={props.size}
66
76
  />
67
77
  )}
68
- { !props.preview && (
78
+ { !props.preview && props.src && contentType === 'application/pdf' && (
79
+ <Image
80
+ {...props.image}
81
+ size={props.size}
82
+ >
83
+ <Document
84
+ file={props.src}
85
+ >
86
+ <Page
87
+ pageNumber={1}
88
+ />
89
+ </Document>
90
+ </Image>
91
+ )}
92
+ { !props.preview && (!props.src || contentType !== 'application/pdf') && (
69
93
  <Image
70
94
  {...props.image}
71
95
  className='placeholder-image'
@@ -70,7 +70,17 @@ const LazyVideo = (props: Props) => {
70
70
  size={props.size}
71
71
  />
72
72
  )}
73
- { !props.preview && (
73
+ { !props.preview && props.src && (
74
+ <Image
75
+ {...props.image}
76
+ size={props.size}
77
+ >
78
+ <video
79
+ src={props.src}
80
+ />
81
+ </Image>
82
+ )}
83
+ { !props.preview && !props.src && (
74
84
  <Image
75
85
  {...props.image}
76
86
  className='placeholder-image'
@@ -437,7 +437,7 @@ class DataTable extends Component<Props, State> {
437
437
  <Table.HeaderCell
438
438
  key={column.name}
439
439
  sorted={this.props.sortColumn === column.name ? this.props.sortDirection : null}
440
- onClick={this.props.onColumnClick.bind(this, column)}
440
+ onClick={() => this.props.onColumnClick(column)}
441
441
  >
442
442
  { column.label }
443
443
  <ColumnResize
@@ -25,6 +25,8 @@ type Props = {
25
25
  className?: string,
26
26
  columns: Array<Column>,
27
27
  configurable: boolean,
28
+ defaultSort?: string,
29
+ defaultSortDirection?: string,
28
30
  items: Array<any>,
29
31
  modal?: {
30
32
  component: ComponentType<any>,
@@ -77,10 +79,16 @@ class EmbeddedList extends Component<Props, State> {
77
79
  * Sorts the table by the first column.
78
80
  */
79
81
  componentDidMount() {
80
- const column = _.find(this.props.columns, (c) => c.sortable !== false);
82
+ let column;
83
+
84
+ if (this.props.defaultSort) {
85
+ column = _.findWhere(this.props.columns, { name: this.props.defaultSort });
86
+ } else {
87
+ column = _.find(this.props.columns, (c) => c.sortable !== false);
88
+ }
81
89
 
82
90
  if (column) {
83
- this.onColumnClick(column);
91
+ this.onColumnClick(column, this.props.defaultSortDirection);
84
92
  }
85
93
  }
86
94
 
@@ -101,7 +109,7 @@ class EmbeddedList extends Component<Props, State> {
101
109
  *
102
110
  * @param column
103
111
  */
104
- onColumnClick(column: Column) {
112
+ onColumnClick(column: Column, direction: string = SORT_ASCENDING) {
105
113
  /*
106
114
  * We'll disable the column sorting if the table rows are draggable. Making the table rows draggable implies
107
115
  * that the sorting will be done manually. Allowing column click sorting could make things confusing.
@@ -119,7 +127,7 @@ class EmbeddedList extends Component<Props, State> {
119
127
  }
120
128
 
121
129
  const sortColumn = column.name;
122
- let sortDirection = SORT_ASCENDING;
130
+ let sortDirection = direction || SORT_ASCENDING;
123
131
 
124
132
  if (column.name === this.state.sortColumn) {
125
133
  sortDirection = this.state.sortDirection === SORT_ASCENDING ? SORT_DESCENDING : SORT_ASCENDING;
@@ -276,3 +284,8 @@ EmbeddedList.defaultProps = {
276
284
  };
277
285
 
278
286
  export default EmbeddedList;
287
+
288
+ export {
289
+ SORT_ASCENDING,
290
+ SORT_DESCENDING
291
+ };
@@ -1,6 +1,7 @@
1
1
  // @flow
2
2
 
3
- import React, { useState, type Node } from 'react';
3
+ import React, { useState, useEffect, type Node } from 'react';
4
+ import { Document, Page } from 'react-pdf/dist/esm/entry.webpack';
4
5
  import {
5
6
  Dimmer,
6
7
  Icon,
@@ -27,6 +28,15 @@ type Props = {
27
28
  const LazyDocument = (props: Props) => {
28
29
  const [visible, setVisible] = useState(false);
29
30
  const [dimmer, setDimmer] = useState(false);
31
+ const [contentType, setContentType] = useState('');
32
+
33
+ useEffect(() => {
34
+ if (props.src && !props.preview) {
35
+ fetch(props.src)
36
+ .then((response) => response.blob())
37
+ .then((blob) => setContentType(blob.type));
38
+ }
39
+ }, [props.preview, props.src]);
30
40
 
31
41
  if (!visible) {
32
42
  return (
@@ -65,7 +75,21 @@ const LazyDocument = (props: Props) => {
65
75
  size={props.size}
66
76
  />
67
77
  )}
68
- { !props.preview && (
78
+ { !props.preview && props.src && contentType === 'application/pdf' && (
79
+ <Image
80
+ {...props.image}
81
+ size={props.size}
82
+ >
83
+ <Document
84
+ file={props.src}
85
+ >
86
+ <Page
87
+ pageNumber={1}
88
+ />
89
+ </Document>
90
+ </Image>
91
+ )}
92
+ { !props.preview && (!props.src || contentType !== 'application/pdf') && (
69
93
  <Image
70
94
  {...props.image}
71
95
  className='placeholder-image'
@@ -70,7 +70,17 @@ const LazyVideo = (props: Props) => {
70
70
  size={props.size}
71
71
  />
72
72
  )}
73
- { !props.preview && (
73
+ { !props.preview && props.src && (
74
+ <Image
75
+ {...props.image}
76
+ size={props.size}
77
+ >
78
+ <video
79
+ src={props.src}
80
+ />
81
+ </Image>
82
+ )}
83
+ { !props.preview && !props.src && (
74
84
  <Image
75
85
  {...props.image}
76
86
  className='placeholder-image'