Skip to content

Commit 7eca021

Browse files
authored
Use children and avoid prop drilling (#50963)
1 parent 1100545 commit 7eca021

File tree

2 files changed

+25
-53
lines changed

2 files changed

+25
-53
lines changed

packages/block-editor/src/components/link-control/index.js

+23-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import classnames from 'classnames';
66
/**
77
* WordPress dependencies
88
*/
9-
import { Button, Spinner, Notice } from '@wordpress/components';
9+
import { Button, Spinner, Notice, TextControl } from '@wordpress/components';
1010
import { __ } from '@wordpress/i18n';
1111
import { useRef, useState, useEffect } from '@wordpress/element';
1212
import { focus } from '@wordpress/dom';
@@ -19,6 +19,7 @@ import { isShallowEqualObjects } from '@wordpress/is-shallow-equal';
1919
import LinkControlSettingsDrawer from './settings-drawer';
2020
import LinkControlSearchInput from './search-input';
2121
import LinkPreview from './link-preview';
22+
import LinkSettings from './settings';
2223
import useCreatePage from './use-create-page';
2324
import useInternalValue from './use-internal-value';
2425
import { ViewerFill } from './viewer-slot';
@@ -376,22 +377,28 @@ function LinkControl( {
376377
<LinkControlSettingsDrawer
377378
settingsOpen={ settingsOpen }
378379
setSettingsOpen={ setSettingsOpen }
379-
showTextControl={ showTextControl }
380-
showSettings={ showSettings }
381-
textInputRef={ textInputRef }
382-
internalTextInputValue={
383-
internalControlValue?.title
384-
}
385-
setInternalTextInputValue={
386-
setInternalTextInputValue
387-
}
388-
handleSubmitWithEnter={ handleSubmitWithEnter }
389-
value={ internalControlValue }
390-
settings={ settings }
391-
onChange={ createSetInternalSettingValueHandler(
392-
settingsKeys
380+
>
381+
{ showTextControl && (
382+
<TextControl
383+
__nextHasNoMarginBottom
384+
ref={ textInputRef }
385+
className="block-editor-link-control__setting block-editor-link-control__text-content"
386+
label="Text"
387+
value={ internalControlValue?.title }
388+
onChange={ setInternalTextInputValue }
389+
onKeyDown={ handleSubmitWithEnter }
390+
/>
393391
) }
394-
/>
392+
{ showSettings && (
393+
<LinkSettings
394+
value={ internalControlValue }
395+
settings={ settings }
396+
onChange={ createSetInternalSettingValueHandler(
397+
settingsKeys
398+
) }
399+
/>
400+
) }
401+
</LinkControlSettingsDrawer>
395402
) }
396403

397404
<div className="block-editor-link-control__search-actions">

packages/block-editor/src/components/link-control/settings-drawer.js

+2-37
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44
import {
55
Button,
6-
TextControl,
76
__unstableMotion as motion,
87
__unstableAnimatePresence as AnimatePresence,
98
} from '@wordpress/components';
@@ -12,24 +11,7 @@ import { useReducedMotion, useInstanceId } from '@wordpress/compose';
1211
import { __ } from '@wordpress/i18n';
1312
import { Fragment } from '@wordpress/element';
1413

15-
/**
16-
* Internal dependencies
17-
*/
18-
import Settings from './settings';
19-
20-
function LinkSettingsDrawer( {
21-
settingsOpen,
22-
setSettingsOpen,
23-
showTextControl,
24-
showSettings,
25-
textInputRef,
26-
internalTextInputValue,
27-
setInternalTextInputValue,
28-
handleSubmitWithEnter,
29-
value,
30-
settings,
31-
onChange,
32-
} ) {
14+
function LinkSettingsDrawer( { children, settingsOpen, setSettingsOpen } ) {
3315
const prefersReducedMotion = useReducedMotion();
3416
const MaybeAnimatePresence = prefersReducedMotion
3517
? Fragment
@@ -68,24 +50,7 @@ function LinkSettingsDrawer( {
6850
} }
6951
>
7052
<div className="block-editor-link-control__drawer-inner">
71-
{ showTextControl && (
72-
<TextControl
73-
__nextHasNoMarginBottom
74-
ref={ textInputRef }
75-
className="block-editor-link-control__setting block-editor-link-control__text-content"
76-
label="Text"
77-
value={ internalTextInputValue }
78-
onChange={ setInternalTextInputValue }
79-
onKeyDown={ handleSubmitWithEnter }
80-
/>
81-
) }
82-
{ showSettings && (
83-
<Settings
84-
value={ value }
85-
settings={ settings }
86-
onChange={ onChange }
87-
/>
88-
) }
53+
{ children }
8954
</div>
9055
</MaybeMotionDiv>
9156
) }

0 commit comments

Comments
 (0)