From 38a1a9e55098eb63da7cca4df6820d6712337076 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 25 May 2023 14:16:00 +0100 Subject: [PATCH] Use children and avoid prop drilling --- .../src/components/link-control/index.js | 39 +++++++++++-------- .../link-control/settings-drawer.js | 39 +------------------ 2 files changed, 25 insertions(+), 53 deletions(-) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index bbb56ab72db8de..b9fa3038cda2fa 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -6,7 +6,7 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { Button, Spinner, Notice } from '@wordpress/components'; +import { Button, Spinner, Notice, TextControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { useRef, useState, useEffect } from '@wordpress/element'; import { focus } from '@wordpress/dom'; @@ -19,6 +19,7 @@ import { isShallowEqualObjects } from '@wordpress/is-shallow-equal'; import LinkControlSettingsDrawer from './settings-drawer'; import LinkControlSearchInput from './search-input'; import LinkPreview from './link-preview'; +import LinkSettings from './settings'; import useCreatePage from './use-create-page'; import useInternalValue from './use-internal-value'; import { ViewerFill } from './viewer-slot'; @@ -376,22 +377,28 @@ function LinkControl( { + { showTextControl && ( + ) } - /> + { showSettings && ( + + ) } + ) }
diff --git a/packages/block-editor/src/components/link-control/settings-drawer.js b/packages/block-editor/src/components/link-control/settings-drawer.js index 0cb12f2c5904c6..12b1fb8075e3c6 100644 --- a/packages/block-editor/src/components/link-control/settings-drawer.js +++ b/packages/block-editor/src/components/link-control/settings-drawer.js @@ -3,7 +3,6 @@ */ import { Button, - TextControl, __unstableMotion as motion, __unstableAnimatePresence as AnimatePresence, } from '@wordpress/components'; @@ -12,24 +11,7 @@ import { useReducedMotion, useInstanceId } from '@wordpress/compose'; import { __ } from '@wordpress/i18n'; import { Fragment } from '@wordpress/element'; -/** - * Internal dependencies - */ -import Settings from './settings'; - -function LinkSettingsDrawer( { - settingsOpen, - setSettingsOpen, - showTextControl, - showSettings, - textInputRef, - internalTextInputValue, - setInternalTextInputValue, - handleSubmitWithEnter, - value, - settings, - onChange, -} ) { +function LinkSettingsDrawer( { children, settingsOpen, setSettingsOpen } ) { const prefersReducedMotion = useReducedMotion(); const MaybeAnimatePresence = prefersReducedMotion ? Fragment @@ -68,24 +50,7 @@ function LinkSettingsDrawer( { } } >
- { showTextControl && ( - - ) } - { showSettings && ( - - ) } + { children }
) }