-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathAltTextControls.jsx
More file actions
73 lines (69 loc) · 2.18 KB
/
AltTextControls.jsx
File metadata and controls
73 lines (69 loc) · 2.18 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
import React from 'react';
import PropTypes from 'prop-types';
import { Form } from '@openedx/paragon';
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
import * as hooks from './hooks';
import messages from './messages';
/**
* Wrapper for alt-text input and isDecorative checkbox control
* @param {obj} errorProps - props for error handling
* {bool} isValid - are alt-text fields valid for saving?
* @param {bool} isDecorative - is the image decorative?
* @param {func} setIsDecorative - handle isDecorative change event
* @param {func} setValue - update alt-text value
* @param {string} value - current alt-text value
*/
const AltTextControls = ({
isDecorative,
setIsDecorative,
setValue,
validation,
value,
}) => {
const intl = useIntl();
return (
<Form.Group className="mt-4.5">
<Form.Label as="h4">
<FormattedMessage {...messages.accessibilityLabel} />
</Form.Label>
<Form.Control
className="mt-4.5"
disabled={isDecorative}
floatingLabel={intl.formatMessage(messages.altTextFloatingLabel)}
isInvalid={validation.show}
onChange={hooks.onInputChange(setValue)}
type="input"
value={value}
/>
{validation.show
&& (
<Form.Control.Feedback type="invalid">
<FormattedMessage {...messages.altTextLocalFeedback} />
</Form.Control.Feedback>
)}
<Form.Checkbox
checked={isDecorative}
className="mt-4.5 decorative-control-label"
onChange={hooks.onCheckboxChange(setIsDecorative)}
>
<Form.Label>
<FormattedMessage {...messages.decorativeAltTextCheckboxLabel} />
</Form.Label>
</Form.Checkbox>
</Form.Group>
);
};
AltTextControls.propTypes = {
error: PropTypes.shape({
show: PropTypes.bool,
}).isRequired,
isDecorative: PropTypes.bool.isRequired,
setValue: PropTypes.func.isRequired,
setIsDecorative: PropTypes.func.isRequired,
validation: PropTypes.shape({
show: PropTypes.bool,
}).isRequired,
value: PropTypes.string.isRequired,
};
export const AltTextControlsInternal = AltTextControls; // For testing only
export default AltTextControls;