-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathDimensionControls.jsx
More file actions
90 lines (87 loc) · 2.48 KB
/
Copy pathDimensionControls.jsx
File metadata and controls
90 lines (87 loc) · 2.48 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
import React from 'react';
import PropTypes from 'prop-types';
import {
Form,
Icon,
IconButton,
} from '@openedx/paragon';
import {
Locked,
Unlocked,
} from '@openedx/paragon/icons';
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
import * as hooks from './hooks';
import messages from './messages';
/**
* Wrapper for image dimension inputs and the lock checkbox.
* @param {bool} isLocked - are dimensions locked
* @param {func} lock - lock dimensions
* @param {func} setHeight - updates dimensions based on new height
* @param {func} setWidth - updates dimensions based on new width
* @param {func} unlock - unlock dimensions
* @param {func} updateDimensions - update dimensions callback
* @param {obj} value - local dimension values { height, width }
*/
const DimensionControls = ({
isLocked,
lock,
setHeight,
setWidth,
unlock,
updateDimensions,
value,
}) => {
const intl = useIntl();
if (!value) { return null; }
return (
<Form.Group>
<Form.Label as="h4">
<FormattedMessage {...messages.imageDimensionsLabel} />
</Form.Label>
<div className="mt-4.5">
<Form.Control
className="dimension-input"
value={value.width}
onChange={hooks.onInputChange(setWidth)}
onBlur={updateDimensions}
floatingLabel={intl.formatMessage(messages.widthFloatingLabel)}
/>
<Form.Control
className="dimension-input"
value={value.height}
onChange={hooks.onInputChange(setHeight)}
onBlur={updateDimensions}
floatingLabel={intl.formatMessage(messages.heightFloatingLabel)}
/>
<IconButton
className="d-inline-block"
alt={isLocked
? intl.formatMessage(messages.unlockDimensionsLabel)
: intl.formatMessage(messages.lockDimensionsLabel)}
iconAs={Icon}
src={isLocked ? Locked : Unlocked}
onClick={isLocked ? unlock : lock}
/>
</div>
</Form.Group>
);
};
DimensionControls.defaultProps = {
value: {
height: '100',
width: '100',
},
};
DimensionControls.propTypes = {
value: PropTypes.shape({
height: PropTypes.string,
width: PropTypes.string,
}),
setHeight: PropTypes.func.isRequired,
setWidth: PropTypes.func.isRequired,
isLocked: PropTypes.bool.isRequired,
lock: PropTypes.func.isRequired,
unlock: PropTypes.func.isRequired,
updateDimensions: PropTypes.func.isRequired,
};
export default DimensionControls;