/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/interface/src/components/complementary-area-toggle/index.js
68 строк
2 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import { Button } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import { usePluginContext } from '@wordpress/plugins'; import { store as interfaceStore } from '../../store'; /** * Whether the role supports checked state. * * @see https://www.w3.org/TR/wai-aria-1.1/#aria-checked * @param {React.AriaRole} role Role. * @return {boolean} Whether the role supports checked state. */ function roleSupportsCheckedState( role ) { return [ 'checkbox', 'option', 'radio', 'switch', 'menuitemcheckbox', 'menuitemradio', 'treeitem', ].includes( role ); } export default function ComplementaryAreaToggle( { as = Button, scope, identifier: identifierProp, icon: iconProp, selectedIcon, name, shortcut, ...props } ) { const ComponentToUse = as; const context = usePluginContext(); const icon = iconProp || context.icon; const identifier = identifierProp || `${ context.name }/${ name }`; const isSelected = useSelect( ( select ) => select( interfaceStore ).getActiveComplementaryArea( scope ) === identifier, [ identifier, scope ] ); const { enableComplementaryArea, disableComplementaryArea } = useDispatch( interfaceStore ); return ( <ComponentToUse icon={ selectedIcon && isSelected ? selectedIcon : icon } aria-controls={ identifier.replace( '/', ':' ) } // Make sure aria-checked matches spec https://www.w3.org/TR/wai-aria-1.1/#aria-checked aria-checked={ roleSupportsCheckedState( props.role ) ? isSelected : undefined } onClick={ () => { if ( isSelected ) { disableComplementaryArea( scope ); } else { enableComplementaryArea( scope, identifier ); } } } shortcut={ shortcut } { ...props } /> ); }