-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathThumbnailCanvasGrouping.js
More file actions
110 lines (104 loc) · 3.47 KB
/
ThumbnailCanvasGrouping.js
File metadata and controls
110 lines (104 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import classNames from 'classnames';
import IIIFThumbnail from '../containers/IIIFThumbnail';
import ns from '../config/css-ns';
const StyledCanvas = styled('div')(({ theme }) => ({
boxSizing: 'border-box',
color: theme.palette.common.white,
cursor: 'pointer',
display: 'inline-block',
whiteSpace: 'nowrap',
}));
/** */
export class ThumbnailCanvasGrouping extends PureComponent {
/** */
constructor(props) {
super(props);
this.setCanvas = this.setCanvas.bind(this);
}
/** */
setCanvas(e) {
const { setCanvas } = this.props;
setCanvas(e.currentTarget.dataset.canvasId);
}
/**
* Determines whether the current index is the rendered canvas, providing
* a useful class.
*/
currentCanvasClass(canvasIndices) {
const { index } = this.props;
if (canvasIndices.includes(index)) return 'current-canvas-grouping';
return '';
}
/** */
render() {
const {
index, style, data, currentCanvasId,
} = this.props;
const {
canvasGroupings, position, height,
} = data;
const currentGroupings = canvasGroupings[index];
const SPACING = 8;
const isSelected = currentGroupings.map(canvas => canvas.id).includes(currentCanvasId);
return (
<div
style={{
...style,
boxSizing: 'content-box',
height: (Number.isInteger(style.height)) ? style.height - SPACING : null,
left: (Number.isInteger(style.left)) ? style.left + SPACING : null,
top: style.top + SPACING,
width: (Number.isInteger(style.width)) ? style.width - SPACING : null,
}}
className={ns('thumbnail-nav-container')}
role="gridcell"
aria-selected={isSelected}
aria-colindex={index + 1}
>
<StyledCanvas
role="button"
data-canvas-id={currentGroupings[0].id}
data-canvas-index={currentGroupings[0].index}
onKeyUp={this.setCanvas}
onClick={this.setCanvas}
tabIndex={-1}
sx={theme => ({
'&:hover': {
outline: `9px solid ${theme.palette.action.hover}`,
outlineOffset: '-2px',
},
height: (position === 'far-right') ? 'auto' : `${height - SPACING}px`,
outline: isSelected ? `2px solid ${theme.palette.primary.main}` : 0,
...isSelected && {
outlineOffset: '3px',
},
width: (position === 'far-bottom') ? 'auto' : `${style.width}px`,
})}
className={classNames(
ns(['thumbnail-nav-canvas', `thumbnail-nav-canvas-${index}`, this.currentCanvasClass(currentGroupings.map(canvas => canvas.index))]),
)}
>
{currentGroupings.map((canvas, i) => (
<IIIFThumbnail
key={canvas.id}
resource={canvas}
labelled
maxHeight={(position === 'far-right') ? style.height - (1.5 * SPACING) : height - (1.5 * SPACING)}
variant="inside"
/>
))}
</StyledCanvas>
</div>
);
}
}
ThumbnailCanvasGrouping.propTypes = {
currentCanvasId: PropTypes.string.isRequired,
data: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
index: PropTypes.number.isRequired,
setCanvas: PropTypes.func.isRequired,
style: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
};