one-click-accessibility/modules/scanner/assets/js/components/bulk-alt-text/image-card/ai-generate-button.js
Nirbhay Singh 63ed290ba7
Feature/app 2261 bulk alt manager (#512) (#524)
* add: preview images for bulk-alt-text

* add: bulk alt text banner

* fix: padding

* add: bulk alt text banner component

* add: icons

* add: support for aborting the fetch request

* add: bulk alt text manager

* update: husky

* fix: optimized images

* update: memoize images

* fix: imports

* add: focustrap

* add: mixpanel events

* update: add logic to save alt text when editing manually

* fix: abort controller reference and cleanup

* fix: improve key stability in image grid rendering

* refactor: add PropTypes validation and memoization to ImageCard component

* feat: add error handling for ImageCard component using ErrorBoundary

* fix: auto selection logic for card with bulk generation

* add: loading and generation states

* refactor: restructure bulk alt text components and enhance progress handling and decentralized logic

* refactor: extract logic from progress bar to hook

* add: quota exceeded alert

* add: promotional banner for generate button

* update: Generate button for selection mode

* fix: button alignment

* update: hide banner for 2 or less images

* fix: box shadow

* add: mixpanel events

* update: rename variable

* add: bulk upgrade url

* update: link handling for upgrade

* fix: box shadow

* add: border radius to dialog

* update: improved accessibility notifications

* fix: height and padding for banner

* update: add more context to image card

* add: ARIA labels

* add: focus on card

* add: decode URI component

* fix: accessibility issues

* add: encoding for file names

* fix: styled components

* update: made progress bar sticky

* update: add logic to disable button on bulk generation

* fix: style

* fix: closing the dialog while generating

* add: error handling

* fix: mark prop as not required

* Fix: Prevent MUI from adding aria-hidden to dialog parent elements [APP-2261]

* add: error handling for quota api error

* fix: prop requirement

* add: close handler to dialog

* fix: ui

* fix: icons

* fix: width of dialog

* fix: width of bulk dialog

---------

Co-authored-by: Kniazevych <pavlok@elementor.red>
2026-02-18 21:52:36 +02:00

95 lines
2.4 KiB
JavaScript

import AIIcon from '@elementor/icons/AIIcon';
import IconButton from '@elementor/ui/IconButton';
import Infotip from '@elementor/ui/Infotip';
import InputAdornment from '@elementor/ui/InputAdornment';
import Tooltip from '@elementor/ui/Tooltip';
import PropTypes from 'prop-types';
import { mixpanelEvents } from '@ea11y-apps/global/services/mixpanel/mixpanel-events';
import { mixpanelService } from '@ea11y-apps/global/services/mixpanel/mixpanel-service';
import { UpgradeContent } from '@ea11y-apps/scanner/components/upgrade-info-tip/upgrade-content';
import { AI_QUOTA_LIMIT, IS_PRO_PLAN } from '@ea11y-apps/scanner/constants';
import { __ } from '@wordpress/i18n';
const AIGenerateButton = ({ onGenerate, disabled, isLoading }) => {
const onUpgradeHover = () => {
mixpanelService.sendEvent(mixpanelEvents.upgradeSuggestionViewed, {
current_plan: window.ea11yScannerData?.planData?.plan?.name,
component: 'bulk_wizard_single_image',
feature: 'bulk_alt_text',
});
};
return (
<InputAdornment
position="end"
sx={{
marginBlockStart: 2.5,
marginInlineEnd: 1,
alignSelf: 'flex-start',
}}
>
{IS_PRO_PLAN && AI_QUOTA_LIMIT ? (
<Tooltip
placement="top-end"
title={__(
'Generate an Alt text description with AI.',
'pojo-accessibility',
)}
PopperProps={{
disablePortal: true,
}}
slotProps={{
tooltip: {
sx: {
maxWidth: '101px',
whiteSpace: 'normal',
lineHeight: 1.4,
},
},
}}
>
<IconButton
size="small"
onClick={onGenerate}
disabled={disabled}
aria-label={
isLoading
? __('Generating alt text with AI', 'pojo-accessibility')
: __('Click to generate alt text with AI', 'pojo-accessibility')
}
>
<AIIcon color="info" fontSize="small" />
</IconButton>
</Tooltip>
) : (
<Infotip
placement="top-end"
slotProps={{
tooltip: {
id: 'ai-btn-description',
},
}}
PopperProps={{
disablePortal: true,
}}
content={<UpgradeContent isAlt isBulkAlt isBulkSingleImage />}
>
<IconButton
size="small"
aria-labelledby="ai-btn-description"
onHover={onUpgradeHover}
>
<AIIcon color="promotion" />
</IconButton>
</Infotip>
)}
</InputAdornment>
);
};
AIGenerateButton.propTypes = {
onGenerate: PropTypes.func.isRequired,
disabled: PropTypes.bool,
};
export default AIGenerateButton;