one-click-accessibility/modules/scanner/assets/js/layouts/alt-text-layout.js
VasylD 43f1b2cb5a
[APP-1741][APP-1742][APP-1743] add components, calc contrast ratio, a… (#346)
* [APP-1741][APP-1742][APP-1743] add components, calc contrast ratio, add logic for lightness

* Update modules/scanner/assets/js/components/color-contrast-form/color-set.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* update

* update

* Remove shadow dom, add color picker

* Remove shadow dom, add color picker

* Remove shadow dom, add color picker

* Update modules/scanner/assets/js/layouts/color-contrast-layout.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Update modules/scanner/assets/js/components/color-contrast-form/color-set.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Update modules/scanner/assets/js/components/color-contrast-form/color-set.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Update modules/scanner/assets/js/layouts/color-contrast-layout.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Update modules/scanner/assets/js/utils/calc-color-ratio.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Remove shadow dom, add color picker

* Remove shadow dom, add color picker

* Revert shadow dom, include styles for color picker

* Revert shadow dom, include styles for color picker

---------

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>
2025-07-25 16:03:12 +02:00

57 lines
1.7 KiB
JavaScript

import { mixpanelEvents, mixpanelService } from '@ea11y-apps/global/services';
import { AltTextForm } from '@ea11y-apps/scanner/components/alt-text-form';
import { FormNavigation } from '@ea11y-apps/scanner/components/form-navigation';
import { BLOCKS } from '@ea11y-apps/scanner/constants';
import { useScannerWizardContext } from '@ea11y-apps/scanner/context/scanner-wizard-context';
import { StyledContent } from '@ea11y-apps/scanner/styles/app.styles';
import {
focusOnElement,
removeExistingFocus,
} from '@ea11y-apps/scanner/utils/focus-on-element';
import { useEffect, useState } from '@wordpress/element';
export const AltTextLayout = () => {
const { sortedViolations, isResolved } = useScannerWizardContext();
const [current, setCurrent] = useState(0);
const resolved = isResolved(BLOCKS.altText);
useEffect(() => {
const item = sortedViolations.altText[current];
if (!resolved && sortedViolations.altText.length) {
focusOnElement(item.node);
} else {
removeExistingFocus();
}
mixpanelService.sendEvent(mixpanelEvents.issueSelected, {
issue_type: item.message,
rule_id: item.ruleId,
wcag_level: item.reasonCategory.match(/\((AAA?|AA?|A)\)/)?.[1] || '',
category_name: BLOCKS.altText,
});
}, [current]);
const changeNavigation = (index) => {
if (index > sortedViolations.altText.length - 1) {
setCurrent(0);
} else {
setCurrent(index);
}
};
return (
<StyledContent>
<AltTextForm
items={sortedViolations.altText}
current={current}
setCurrent={changeNavigation}
/>
<FormNavigation
total={sortedViolations.altText.length}
current={current}
setCurrent={changeNavigation}
/>
</StyledContent>
);
};