import { h } from 'preact';
import PropTypes from 'prop-types';
// Limit the number of suggestions shown so that the UI isn't overwhelmed
const MAX_SUGGESTIONS = 3;
const ExternalUrlSVG = () => (
);
const extractRelevantErrors = (lintErrors) => {
const imageErrors = [];
const otherErrors = [];
lintErrors.forEach((lintError) => {
if (
lintError.ruleNames.includes('no-default-alt-text') ||
lintError.ruleNames.includes('no-empty-alt-text')
) {
imageErrors.push({ ...lintError, errorType: 'image' });
} else {
otherErrors.push({ ...lintError, errorType: 'other' });
}
});
// Truncate the errors, favouring image errors (as these accessibility suggestions are more impactful)
if (imageErrors.length > MAX_SUGGESTIONS) {
imageErrors.length = MAX_SUGGESTIONS;
}
const remainingErrors = MAX_SUGGESTIONS - imageErrors.length;
if (otherErrors.length > remainingErrors) {
otherErrors.length = remainingErrors;
}
return [...imageErrors, ...otherErrors];
};
/**
* An information notice displayed to users in the Preview window when accessibility improvements could be made to their post.
* This component displays a maximum of 3 suggestions, favouring image-related suggestions (as these changes are more impactful).
*
* @param {Object} props
* @param {Object[]} props.markdownLintErrors The array of error objects returned from the markdownlint library
*
* @example
*