diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/client/accessibility/components/AuditProgressOverlay.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
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 | 92 |
1 files changed, 92 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..3c16998bcf --- /dev/null +++ b/devtools/client/accessibility/components/AuditProgressOverlay.js @@ -0,0 +1,92 @@ +/* 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("resource://devtools/client/shared/vendor/react.js"); +const ReactDOM = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); +const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.js"); +const { + connect, +} = require("resource://devtools/client/shared/vendor/react-redux.js"); + +const FluentReact = require("resource://devtools/client/shared/vendor/fluent-react.js"); +const Localized = React.createFactory(FluentReact.Localized); + +/** + * Helper functional component to render an accessible text progressbar. + * @param {Object} props + * - id for the progressbar element + * - fluentId: localized string id + */ +function TextProgressBar({ id, fluentId }) { + return Localized( + { + id: fluentId, + attrs: { "aria-valuetext": true }, + }, + ReactDOM.span({ + id, + key: id, + role: "progressbar", + }) + ); +} + +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, + fluentId: "accessibility-progress-initializing", + }); + } + + if (percentage === 100) { + return TextProgressBar({ + id, + fluentId: "accessibility-progress-finishing", + }); + } + + return ReactDOM.span( + { + id, + key: id, + }, + Localized({ + id: "accessibility-progress-progressbar", + $nodeCount: 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); |