diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /devtools/client/accessibility/components/AuditProgressOverlay.js | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/accessibility/components/AuditProgressOverlay.js')
-rw-r--r-- | devtools/client/accessibility/components/AuditProgressOverlay.js | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/devtools/client/accessibility/components/AuditProgressOverlay.js b/devtools/client/accessibility/components/AuditProgressOverlay.js new file mode 100644 index 0000000000..f9704a0dc6 --- /dev/null +++ b/devtools/client/accessibility/components/AuditProgressOverlay.js @@ -0,0 +1,91 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const React = require("devtools/client/shared/vendor/react"); +const ReactDOM = require("devtools/client/shared/vendor/react-dom-factories"); +const PropTypes = require("devtools/client/shared/vendor/react-prop-types"); +const { connect } = require("devtools/client/shared/vendor/react-redux"); +const { PluralForm } = require("devtools/shared/plural-form"); + +const { L10N } = require("devtools/client/accessibility/utils/l10n"); + +/** + * Helper functional component to render an accessible text progressbar. + * @param {Object} props + * - id for the progressbar element + * - valuetext for the progressbar element + */ +function TextProgressBar({ id, textStringKey }) { + const text = L10N.getStr(textStringKey); + return ReactDOM.span( + { + id, + key: id, + role: "progressbar", + "aria-valuetext": text, + }, + text + ); +} + +class AuditProgressOverlay extends React.Component { + static get propTypes() { + return { + auditing: PropTypes.array.isRequired, + total: PropTypes.number, + percentage: PropTypes.number, + }; + } + + render() { + const { auditing, percentage, total } = this.props; + if (auditing.length === 0) { + return null; + } + + const id = "audit-progress-container"; + + if (total == null) { + return TextProgressBar({ + id, + textStringKey: "accessibility.progress.initializing", + }); + } + + if (percentage === 100) { + return TextProgressBar({ + id, + textStringKey: "accessibility.progress.finishing", + }); + } + + const progressbarString = PluralForm.get( + total, + L10N.getStr("accessibility.progress.progressbar") + ); + + return ReactDOM.span( + { + id, + key: id, + }, + progressbarString.replace("#1", total), + ReactDOM.progress({ + max: 100, + value: percentage, + className: "audit-progress-progressbar", + "aria-labelledby": id, + }) + ); + } +} + +const mapStateToProps = ({ audit: { auditing, progress } }) => { + const { total, percentage } = progress || {}; + return { auditing, total, percentage }; +}; + +module.exports = connect(mapStateToProps)(AuditProgressOverlay); |