Hero-admin: foto klikbaar voor de uitsnede, direct voorbeeld na Toepassen, Opslaan uitgegrijsd zonder wijzigingen
- De thumbnail is de knop 'Uitsnede aanpassen' (hint bij hover/focus, kleine crop-icoon altijd zichtbaar voor touch); losse focusknop vervalt - Na Toepassen toont de thumbnail direct de nieuwe uitsnede (zelfde rekenlogica als de host) met 'Focus gewijzigd, nog niet opgeslagen' - Opslaan is uitgeschakeld (aria-disabled) zolang er niets te bewaren is, bezig-indicator tijdens opslaan, weer uit na opslaan - Test van de keten: Toepassen, Opslaan (imageFocus in de PUT), 'Nieuwe uitsnede wordt gemaakt', 'Verwerking afgerond'; backend: PUT-body bindt, status direct pending, renderer klaar - Logregel 'recut superseded' als een nieuwere focus de lopende uitsnede overneemt Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import { Crop } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { WIDE, cropFor } from '../lib/focusMath';
|
||||
import { mediaUrl } from '../lib/media';
|
||||
import type { HeroFocusRequest, HeroImageDto } from '../services/types';
|
||||
|
||||
interface CropThumbnailProps {
|
||||
image: HeroImageDto;
|
||||
/** The small picture of the published (saved) crop. */
|
||||
savedSrc: string;
|
||||
/** A focus change that was applied in the dialog and is not saved yet: the thumbnail then shows that crop already. */
|
||||
edit?: HeroFocusRequest;
|
||||
onClick: () => void;
|
||||
testId: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The picture of a slide, and at the same time the way to change its crop: a real button (so keyboard and screen reader
|
||||
* users have it too). A hint with a crop icon and "Adjust crop" shows on hover and on keyboard focus, and a small crop
|
||||
* icon is always there, so it can be found on a touch screen as well. After "Apply" in the dialog the thumbnail shows
|
||||
* the new crop right away (the same calculation as the host) with a clear "not saved yet" note.
|
||||
*/
|
||||
export function CropThumbnail({ image, savedSrc, edit, onClick, testId }: CropThumbnailProps) {
|
||||
const { t } = useTranslation();
|
||||
const local = edit && image.previewSrc ? localCrop(image, edit) : null;
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
aria-label={t('hero.slides.cropEdit')}
|
||||
className={`group relative block aspect-[3/2] w-28 shrink-0 cursor-pointer overflow-hidden rounded bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${edit ? 'ring-2 ring-amber-500' : ''}`}
|
||||
data-testid={testId}
|
||||
>
|
||||
{local && image.previewSrc ? (
|
||||
<img src={mediaUrl(image.previewSrc)} alt="" draggable={false} className="absolute max-w-none" style={local} data-testid={`${testId}-local`} />
|
||||
) : (
|
||||
<img src={savedSrc} alt="" draggable={false} className="h-full w-full object-cover" />
|
||||
)}
|
||||
{/* Always there, so it is found without hovering (touch screens). */}
|
||||
<span className="pointer-events-none absolute right-1 top-1 rounded bg-black/55 p-1 text-white" aria-hidden="true">
|
||||
<Crop className="size-3" />
|
||||
</span>
|
||||
{/* The explanation on hover and keyboard focus. */}
|
||||
<span
|
||||
className="pointer-events-none absolute inset-0 flex items-center justify-center gap-1 bg-black/55 px-1 text-center text-[11px] font-medium leading-tight text-white opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100 motion-reduce:transition-none"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<Crop className="size-4 shrink-0" />
|
||||
{t('hero.slides.cropEdit')}
|
||||
</span>
|
||||
{edit && (
|
||||
<span
|
||||
className="pointer-events-none absolute inset-x-0 bottom-0 bg-amber-500 px-1 py-0.5 text-center text-[10px] font-medium leading-tight text-black"
|
||||
data-testid={`${testId}-pending`}
|
||||
>
|
||||
{t('hero.slides.focusPending')}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
/** Places the whole picture in the box so exactly the crop of the host shows (the same calculation as the dialog). */
|
||||
function localCrop(image: HeroImageDto, edit: HeroFocusRequest) {
|
||||
const focus = edit.wide ?? edit.focus;
|
||||
const crop = cropFor(image.width, image.height, WIDE, focus);
|
||||
return {
|
||||
width: `${(image.width / crop.width) * 100}%`,
|
||||
left: `${(-crop.x / crop.width) * 100}%`,
|
||||
// top is a percentage of the box height: the box width times denominator over numerator.
|
||||
top: `${(-crop.y / crop.width) * (WIDE.numerator / WIDE.denominator) * 100}%`,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user