@imposium-hub/components 1.38.17 → 1.39.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/Entry.ts CHANGED
@@ -33,6 +33,7 @@ import NoAccess from './components/no-access/NoAccess';
33
33
  import ServiceIcon from './components/service-icon/ServiceIcon';
34
34
  import DeterminateLoader from './components/determinate-loader/DeterminateLoader';
35
35
  import AssetsTableDateCell from './components/assets/AssetsTableDateCell';
36
+ import AssetsTablePreviewCell from './components/assets/AssetsTablePreviewCell';
36
37
  import AssetsTableDurationCell from './components/assets/AssetsTableDurationCell';
37
38
  import AssetField from './components/assets/AssetField';
38
39
  import AssetsTableDropzone from './components/assets/AssetsTableDropzone';
@@ -163,6 +164,7 @@ export {
163
164
  AssetsTypeIcon,
164
165
  AssetsTableDateCell,
165
166
  AssetsTableDropzone,
167
+ AssetsTablePreviewCell,
166
168
  AssetsTableSelectFilter,
167
169
  AssetsTableSelectCell,
168
170
  AssetsTableTypeFilter,
@@ -0,0 +1,113 @@
1
+ import * as React from 'react';
2
+ import {ASSET_TYPES, VideoPreview, AssetsTypeIcon, ImagePreview} from '../../Entry';
3
+ export const PREVIEW_MAX_WIDTH : number = 400;
4
+ export const PREVIEW_MAX_HEIGHT : number = 400;
5
+ export const HEADER_HEIGHT : number = 30;
6
+
7
+ interface IAssetsTablePreviewCell {
8
+ cell : any;
9
+ showMedia : boolean;
10
+ onClick() : void;
11
+ onRequestClose() : void;
12
+ }
13
+
14
+ class AssetsTablePreviewCell extends React.PureComponent<IAssetsTablePreviewCell> {
15
+ private iconRef : any = React.createRef<HTMLDivElement>();
16
+ private evtHandlers : any;
17
+ constructor(props) {
18
+ super(props);
19
+ this.evtHandlers = {
20
+ onClose: () => this.handleClose(),
21
+ onClick: () => this.handlePreviewClick()
22
+ };
23
+ }
24
+
25
+ private handleClose() {
26
+ const {onRequestClose} = this.props;
27
+ onRequestClose();
28
+ }
29
+
30
+ private handlePreviewClick() {
31
+ const {onClick, showMedia} = this.props;
32
+ if (!showMedia) {
33
+ onClick();
34
+ return;
35
+ }
36
+ return;
37
+ }
38
+
39
+ public render() {
40
+
41
+ const getMediaPreviewStyle = (mediaWidth : number, mediaHeight : number) => {
42
+
43
+ if (!this.iconRef.current) {
44
+ return;
45
+ }
46
+ if (!mediaWidth) {
47
+ mediaWidth = PREVIEW_MAX_WIDTH;
48
+ }
49
+ if (!mediaHeight) {
50
+ mediaHeight = PREVIEW_MAX_HEIGHT;
51
+ }
52
+ const icon = this.iconRef.current;
53
+ const iconRect = icon.getBoundingClientRect();
54
+ const aspect = mediaWidth / mediaHeight;
55
+ let width = PREVIEW_MAX_WIDTH;
56
+ let height = width / aspect;
57
+
58
+ if (height > PREVIEW_MAX_HEIGHT) {
59
+ height = PREVIEW_MAX_HEIGHT;
60
+ width = height * aspect;
61
+ }
62
+
63
+ // try top left
64
+ let left = iconRect.x + iconRect.width - width;
65
+ let top = iconRect.y + iconRect.height - height - 20;
66
+ // if the preview is off on the left, switch to the right of the icon
67
+ if (left < 0) {
68
+ left = iconRect.x ;
69
+ }
70
+ // if the preview is off on the top, switch to bottom of the icon
71
+ if (top < HEADER_HEIGHT) {
72
+ top = iconRect.y + 20;
73
+ }
74
+
75
+ return {top, left, width, height, position: 'absolute', zIndex: 9000} as React.CSSProperties;
76
+ };
77
+
78
+ const {cell, showMedia} = this.props;
79
+ const playbackSettings = {
80
+ autoPlay: true,
81
+ loop: false
82
+ };
83
+
84
+ return(
85
+ <div ref = {this.iconRef} className = 'asset-type-cell' onClick={this.evtHandlers.onClick} >
86
+ <AssetsTypeIcon type = {cell.row.values.type} />
87
+ {cell.row.values.type === ASSET_TYPES.IMAGE &&
88
+ (
89
+ <ImagePreview
90
+ style={{...getMediaPreviewStyle(cell.row.original.width, cell.row.original.height)}}
91
+ showMedia={showMedia}
92
+ url={cell.row.original.url}
93
+ onRequestClose={this.evtHandlers.onClose}
94
+ />
95
+ )
96
+ }
97
+ {cell.row.values.type === ASSET_TYPES.VIDEO &&
98
+ (<VideoPreview
99
+ playbackSettings={playbackSettings}
100
+ style={getMediaPreviewStyle(cell.row.original.width, cell.row.original.height)}
101
+ showMedia={showMedia}
102
+ url={cell.row.original.url}
103
+ onRequestClose={this.evtHandlers.onClose}
104
+ />
105
+ )
106
+ }
107
+ </div>
108
+ );
109
+ }
110
+ }
111
+
112
+ const AssetsTablePreviewCellMemoized = React.memo(AssetsTablePreviewCell);
113
+ export default AssetsTablePreviewCellMemoized;
@@ -224,26 +224,6 @@ const DataTable : React.FC<IDataTableProps> = (props : IDataTableProps) => {
224
224
  [sortBy]
225
225
  );
226
226
 
227
- React.useEffect(
228
- () => {
229
- if (didMount && activeRowRef.current && wrapperRef.current) {
230
- const container = wrapperRef.current.children[0];
231
- const element = activeRowRef.current;
232
- const cTop = container.scrollTop;
233
- const cBottom = cTop + container.clientHeight;
234
- const eTop = element.offsetTop;
235
- const eBottom = eTop + element.clientHeight;
236
-
237
- if (eTop < cTop) {
238
- container.scrollTop -= (cTop - eTop) + 30;
239
- } else if (eBottom > cBottom) {
240
- container.scrollTop += (eBottom - cBottom);
241
- }
242
- }
243
- },
244
- [props.highlightBy]
245
- );
246
-
247
227
  return (
248
228
  <section
249
229
  ref = {wrapperRef}
@@ -1,29 +1,55 @@
1
1
  import * as React from 'react';
2
2
  import Portal from '../portal/Portal';
3
-
3
+ import {ICON_TIMES} from '../../constants/icons';
4
+ import Button from '../button/Button';
5
+ import {assets as copy} from '../../constants/copy';
4
6
  interface IVideoPreviewProps {
5
7
  showMedia : boolean;
6
8
  url : string;
7
9
  playbackSettings? : any;
8
10
  style? : React.CSSProperties | any;
11
+ onRequestClose?(e) : void;
9
12
  }
10
13
 
11
14
  class ImagePreview extends React.PureComponent<IVideoPreviewProps> {
12
15
  private imageNode : any = null;
16
+ private evtHandlers : any;
13
17
  constructor(props) {
14
18
  super(props);
15
19
  this.imageNode = React.createRef();
20
+ this.evtHandlers = {
21
+ onClose: (e) => this.onClose(e)
22
+ };
23
+ }
24
+
25
+ private onClose(e) {
26
+
27
+ const {onRequestClose} = this.props;
28
+
29
+ onRequestClose(e);
16
30
  }
17
31
  public render() {
18
32
  const {showMedia, url, style} = this.props;
19
33
  if (showMedia) {
20
34
  return (
21
35
  <Portal id='portal-root'>
36
+ <div style={{...style}} className={'close-icon-preview'}>
37
+ <Button
38
+ key = 'btn-filter'
39
+ onClick = {this.evtHandlers.onClose}
40
+ size={'large'}
41
+ style = 'subtle'
42
+ tooltip = {copy.field.tooltipFilter}
43
+ >
44
+ {ICON_TIMES}
45
+ </Button>
46
+ </div>
22
47
  <img
23
48
  src={url}
24
49
  ref={this.imageNode}
25
- className='media-preview'
26
- style={style}/>
50
+ className='asset-preview-background'
51
+ style={style}
52
+ />
27
53
  </Portal>
28
54
  );
29
55
  } else {
@@ -1,24 +1,50 @@
1
1
  import * as React from 'react';
2
2
  import Portal from '../portal/Portal';
3
+ import Button from '../button/Button';
4
+ import {assets as copy} from '../../constants/copy';
5
+ import {ICON_TIMES} from '../../constants/icons';
3
6
 
4
7
  interface IVideoPreviewProps {
5
8
  showMedia : boolean;
6
9
  url : string;
7
10
  playbackSettings? : any;
8
11
  style? : React.CSSProperties | {};
12
+ onRequestClose?(e) : void;
9
13
  }
10
14
 
11
15
  class VideoPreview extends React.PureComponent<IVideoPreviewProps> {
12
16
  private videoNode : any = null;
17
+ private evtHandlers : any;
13
18
  constructor(props) {
14
19
  super(props);
15
20
  this.videoNode = React.createRef();
21
+ this.evtHandlers = {
22
+ onClose: (e) => this.onClose(e)
23
+ };
24
+ }
25
+
26
+ private onClose(e) {
27
+
28
+ const {onRequestClose} = this.props;
29
+
30
+ onRequestClose(e);
16
31
  }
17
32
  public render() {
18
33
  const {showMedia, url, playbackSettings, style} = this.props;
19
34
  if (showMedia) {
20
35
  return (
21
36
  <Portal id='portal-root'>
37
+ <div style={{...style}} className={'close-icon-preview'}>
38
+ <Button
39
+ key = 'btn-filter'
40
+ onClick = {this.evtHandlers.onClose}
41
+ size={'large'}
42
+ style = 'subtle'
43
+ tooltip = {copy.field.tooltipFilter}
44
+ >
45
+ {ICON_TIMES}
46
+ </Button>
47
+ </div>
22
48
  <video
23
49
  style = {style}
24
50
  muted
@@ -28,7 +54,8 @@ class VideoPreview extends React.PureComponent<IVideoPreviewProps> {
28
54
  controls
29
55
  preload = 'preload'
30
56
  src={url}
31
- className='media-preview' />
57
+ className='asset-preview-background'
58
+ />
32
59
  </Portal>
33
60
  );
34
61
  } else {