mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Conflicts: - `.prettierignore`: Upstream removed it, replaced by `.oxfmtrc.json`. We had glitch-specific files in there. Updated `.oxfmtrc.json` accordingly and removed `.prettierignore`. - `config/formatjs-formatter.js`: Upstream switched to `oxfmt` from `prettier`, and some rules are slightly different. Glitch-soc had extra code in there. Reformatted appropriately. - `eslint.config.mjs`: Upstream moved some configuration from `eslint.config.mjs` to `.oxfmtrc.json` where glitch-soc had slightly different configuration. Removed it from `eslint.config.mjs` as well and updated `.oxfmtrc.json` accordingly. - `package.json`: Upstream changed script definitions textually adjacent to one that we have modified. Applied upstream's change, keeping the textually adjacent modified script intact.
79 lines
2.0 KiB
TypeScript
79 lines
2.0 KiB
TypeScript
import { useState, useCallback, useRef, useId } from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import type {
|
|
OffsetValue,
|
|
UsePopperOptions,
|
|
} from 'react-overlays/esm/usePopper';
|
|
import Overlay from 'react-overlays/Overlay';
|
|
|
|
import { useSelectableClick } from 'flavours/glitch/hooks/useSelectableClick';
|
|
|
|
const offset = [0, 4] as OffsetValue;
|
|
const popperConfig = { strategy: 'fixed' } as UsePopperOptions;
|
|
|
|
export const AltTextBadge: React.FC<{ description: string }> = ({
|
|
description,
|
|
}) => {
|
|
const accessibilityId = useId();
|
|
const anchorRef = useRef<HTMLButtonElement>(null);
|
|
const [open, setOpen] = useState(false);
|
|
|
|
const handleClick = useCallback(() => {
|
|
setOpen((v) => !v);
|
|
}, [setOpen]);
|
|
|
|
const handleClose = useCallback(() => {
|
|
setOpen(false);
|
|
}, [setOpen]);
|
|
|
|
const [handleMouseDown, handleMouseUp] = useSelectableClick(handleClose);
|
|
|
|
return (
|
|
<>
|
|
<button
|
|
type='button'
|
|
ref={anchorRef}
|
|
className='media-gallery__alt__label'
|
|
onClick={handleClick}
|
|
aria-expanded={open}
|
|
aria-controls={accessibilityId}
|
|
>
|
|
ALT
|
|
</button>
|
|
|
|
<Overlay
|
|
rootClose
|
|
onHide={handleClose}
|
|
show={open}
|
|
target={anchorRef}
|
|
placement='top-end'
|
|
flip
|
|
offset={offset}
|
|
popperConfig={popperConfig}
|
|
>
|
|
{({ props }) => (
|
|
<div {...props} className='hover-card-controller'>
|
|
<div // eslint-disable-line jsx-a11y/no-noninteractive-element-interactions
|
|
className='info-tooltip dropdown-animation'
|
|
role='region'
|
|
id={accessibilityId}
|
|
onMouseDown={handleMouseDown}
|
|
onMouseUp={handleMouseUp}
|
|
>
|
|
<h4>
|
|
<FormattedMessage
|
|
id='alt_text_badge.title'
|
|
defaultMessage='Alt text'
|
|
/>
|
|
</h4>
|
|
<p>{description}</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</Overlay>
|
|
</>
|
|
);
|
|
};
|