-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add information about alt text to alt text modal in web UI (#33702)
- Loading branch information
Showing
7 changed files
with
142 additions
and
6 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
app/javascript/mastodon/features/alt_text_modal/components/info_button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { useState, useRef, useCallback, useId } from 'react'; | ||
|
||
import { FormattedMessage, useIntl, defineMessages } from 'react-intl'; | ||
|
||
import classNames from 'classnames'; | ||
|
||
import Overlay from 'react-overlays/Overlay'; | ||
|
||
import QuestionMarkIcon from '@/material-icons/400-24px/question_mark.svg?react'; | ||
import { Icon } from 'mastodon/components/icon'; | ||
|
||
const messages = defineMessages({ | ||
help: { id: 'info_button.label', defaultMessage: 'Help' }, | ||
}); | ||
|
||
export const InfoButton: React.FC = () => { | ||
const intl = useIntl(); | ||
const [open, setOpen] = useState(false); | ||
const triggerRef = useRef<HTMLButtonElement>(null); | ||
const accessibilityId = useId(); | ||
|
||
const handleClick = useCallback(() => { | ||
setOpen(!open); | ||
}, [open, setOpen]); | ||
|
||
return ( | ||
<> | ||
<button | ||
type='button' | ||
className={classNames('help-button', { active: open })} | ||
ref={triggerRef} | ||
onClick={handleClick} | ||
aria-expanded={open} | ||
aria-controls={accessibilityId} | ||
aria-label={intl.formatMessage(messages.help)} | ||
> | ||
<Icon id='' icon={QuestionMarkIcon} /> | ||
</button> | ||
|
||
<Overlay | ||
show={open} | ||
rootClose | ||
placement='top' | ||
onHide={handleClick} | ||
offset={[5, 5]} | ||
target={triggerRef} | ||
> | ||
{({ props }) => ( | ||
<div | ||
{...props} | ||
className='dialog-modal__popout prose dropdown-animation' | ||
id={accessibilityId} | ||
> | ||
<FormattedMessage | ||
id='info_button.what_is_alt_text' | ||
defaultMessage='<h1>What is alt text?</h1> | ||
<p>Alt text provides image descriptions for people with vision impairments, low-bandwidth connections, or those seeking extra context.</p> | ||
<p>You can improve accessibility and understanding for everyone by writing clear, concise, and objective alt text.</p> | ||
<ul> | ||
<li>Capture important elements</li> | ||
<li>Summarize text in images</li> | ||
<li>Use regular sentence structure</li> | ||
<li>Avoid redundant information</li> | ||
<li>Focus on trends and key findings in complex visuals (like diagrams or maps)</li> | ||
</ul>' | ||
values={{ | ||
h1: (node) => <h1>{node}</h1>, | ||
p: (node) => <p>{node}</p>, | ||
ul: (node) => <ul>{node}</ul>, | ||
li: (node) => <li>{node}</li>, | ||
}} | ||
/> | ||
</div> | ||
)} | ||
</Overlay> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters