/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/block-editor/src/components/url-input/button.js
76 строк
2 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import { __ } from '@wordpress/i18n'; import { useReducer } from '@wordpress/element'; import { Button, __experimentalInputControlSuffixWrapper as InputControlSuffixWrapper, } from '@wordpress/components'; import { link, keyboardReturn, arrowLeft } from '@wordpress/icons'; import URLInput from './'; /** * A button that toggles a URL input field for inserting or editing links. * * @param {Object} props Component properties. * @param {string} props.url The current URL value. * @param {Function} props.onChange Callback function to handle URL changes. * @return {React.JSX.Element} The URL input button component. */ function URLInputButton( { url, onChange } ) { const [ expanded, toggleExpanded ] = useReducer( ( isExpanded ) => ! isExpanded, false ); const submitLink = ( event ) => { event.preventDefault(); toggleExpanded(); }; return ( <div className="block-editor-url-input__button"> <Button size="compact" icon={ link } label={ url ? __( 'Edit link' ) : __( 'Insert link' ) } onClick={ toggleExpanded } className="components-toolbar__control" isPressed={ !! url } /> { expanded && ( <form className="block-editor-url-input__button-modal" onSubmit={ submitLink } > <div className="block-editor-url-input__button-modal-line"> <Button __next40pxDefaultSize className="block-editor-url-input__back" icon={ arrowLeft } label={ __( 'Close' ) } onClick={ toggleExpanded } /> <URLInput value={ url || '' } onChange={ onChange } suffix={ <InputControlSuffixWrapper variant="control"> <Button size="small" icon={ keyboardReturn } label={ __( 'Submit' ) } type="submit" /> </InputControlSuffixWrapper> } /> </div> </form> ) } </div> ); } /** * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/url-input/README.md */ export default URLInputButton;