-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Block bindings: UI for connecting bindings #62880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ae6afbc
5efa047
0a1b636
1f9900e
8128c0f
4eac7dc
db906bd
e357882
1a18fb6
39b2efa
8484002
88759d3
aa626fe
be20d24
5343678
58054eb
8e8a122
683abfb
d3ba547
3b703f7
f0cd95a
3bc6072
da6845e
28ceffe
a90d9da
2df3ef3
6be1849
0380ee8
fe88757
41691df
4f097d0
6e04036
51904df
28ba254
25051fc
981367a
b1aaa7a
3d9182e
ff7c393
f2469c9
26b5988
8798953
27639ba
f0a0680
42693a4
b7efec2
11b2a4b
58eb28c
d17b593
dfeba8b
9e67785
b19d01e
fb4a51b
6439308
9f277b3
0beff34
8e6ad14
c9ea7c7
436c97f
9896dbf
752d7e0
feb890d
8bb9136
22e1020
cabd3d8
b814725
591bd72
8ffc7f4
13cd09e
3a086ab
12c9088
bc05788
a9b347f
839b37a
01fcf7d
d14d50f
2dff252
50f6f1e
3bf117c
6fb7d89
d091c34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
DropdownMenuV2
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,10 @@ import { privateApis as blocksPrivateApis } from '@wordpress/blocks'; | |
| import { | ||
| __experimentalItemGroup as ItemGroup, | ||
| __experimentalItem as Item, | ||
| __experimentalVStack as VStack, | ||
| __experimentalText as Text, | ||
| __experimentalToolsPanel as ToolsPanel, | ||
| __experimentalToolsPanelItem as ToolsPanelItem, | ||
| __experimentalTruncate as Truncate, | ||
| __experimentalDropdownContentWrapper as DropdownContentWrapper, | ||
| Dropdown, | ||
| privateApis as componentsPrivateApis, | ||
| } from '@wordpress/components'; | ||
| import { useSelect, useDispatch, useRegistry } from '@wordpress/data'; | ||
| import { useContext } from '@wordpress/element'; | ||
|
|
@@ -30,11 +27,13 @@ import { unlock } from '../lock-unlock'; | |
| import InspectorControls from '../components/inspector-controls'; | ||
| import BlockContext from '../components/block-context'; | ||
|
|
||
| const popoverProps = { | ||
| placement: 'left-start', | ||
| offset: 36, | ||
| shift: true, | ||
| }; | ||
| const { | ||
| DropdownMenuV2: DropdownMenu, | ||
| DropdownMenuGroupV2: DropdownMenuGroup, | ||
| DropdownMenuCheckboxItemV2: DropdownMenuCheckboxItem, | ||
| DropdownMenuItemLabelV2: DropdownMenuItemLabel, | ||
| DropdownMenuItemHelpTextV2: DropdownMenuItemHelpText, | ||
| } = unlock( componentsPrivateApis ); | ||
|
|
||
| const useToolsPanelDropdownMenuProps = () => { | ||
| const isMobile = useViewportMatch( 'medium', '<' ); | ||
|
|
@@ -53,53 +52,73 @@ function BlockBindingsPanelDropdown( { | |
| fieldsList, | ||
| addConnection, | ||
| attribute, | ||
| binding, | ||
| } ) { | ||
| const currentKey = binding?.args?.key; | ||
| return ( | ||
| <DropdownContentWrapper | ||
| paddingSize="small" | ||
| className="block-editor-bindings__popover" | ||
| > | ||
| <> | ||
| { Object.entries( fieldsList ).map( ( [ label, fields ] ) => ( | ||
| <ItemGroup | ||
| <DropdownMenuGroup | ||
| key={ label } | ||
| label={ | ||
| Object.keys( fieldsList ).length > 1 ? label : null | ||
| } | ||
| > | ||
| { Object.entries( fields ).map( ( [ key, value ] ) => ( | ||
| <Item | ||
| <DropdownMenuCheckboxItem | ||
| key={ key } | ||
| onClick={ () => addConnection( key, attribute ) } | ||
|
artemiomorales marked this conversation as resolved.
Outdated
|
||
| name={ attribute + '-binding' } | ||
| value={ key } | ||
| checked={ key === currentKey } | ||
| hideOnClick | ||
| > | ||
| <VStack spacing={ 0 }> | ||
| <Truncate>{ key }</Truncate> | ||
| <Truncate className="block-editor-bindings__item-explanation"> | ||
| { value } | ||
| </Truncate> | ||
| </VStack> | ||
| </Item> | ||
| <DropdownMenuItemLabel> | ||
| { key } | ||
| </DropdownMenuItemLabel> | ||
| <DropdownMenuItemHelpText> | ||
| { value } | ||
| </DropdownMenuItemHelpText> | ||
| </DropdownMenuCheckboxItem> | ||
| ) ) } | ||
| </ItemGroup> | ||
| </DropdownMenuGroup> | ||
| ) ) } | ||
| </DropdownContentWrapper> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| function BlockBindingsAttribute( { toggleProps, attribute, binding } ) { | ||
| function BlockBindingsAttribute( { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This name feels a bit confusing to me. What about something like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BlockBindingItem maybe? I find your option quite verbose. It is true that is each block attribute that can be connected but... 🤔 It's not a strong opinion, feel free to update it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about Alternative names:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say it is not exactly the component that creates the binding. It just shows the attribute and where it is connected to. It is reused in "read-only" mode as well. I would say the one controlling the creation is the Dropdown. |
||
| fieldsList, | ||
| addConnection, | ||
| attribute, | ||
| binding, | ||
| } ) { | ||
| const { source: sourceName, args } = binding || {}; | ||
| const sourceProps = | ||
| unlock( blocksPrivateApis ).getBlockBindingsSource( sourceName ); | ||
| return ( | ||
| <Item { ...toggleProps }> | ||
| <VStack spacing={ 0 }> | ||
| <Truncate>{ attribute }</Truncate> | ||
| { !! binding && ( | ||
| <Truncate className="block-editor-bindings__item-explanation"> | ||
| { args?.key || sourceProps?.label || sourceName } | ||
| </Truncate> | ||
| ) } | ||
| </VStack> | ||
| </Item> | ||
| <DropdownMenu | ||
| placement="left-start" | ||
| gutter={ 36 } | ||
| style={ { width: '360px' } } | ||
| trigger={ | ||
| <Item> | ||
| <DropdownMenuItemLabel>{ attribute }</DropdownMenuItemLabel> | ||
| { !! binding && ( | ||
| <DropdownMenuItemHelpText className="block-editor-bindings__item-explanation"> | ||
| { args?.key || sourceProps?.label || sourceName } | ||
| </DropdownMenuItemHelpText> | ||
| ) } | ||
| </Item> | ||
| } | ||
| > | ||
| <BlockBindingsPanelDropdown | ||
| fieldsList={ fieldsList } | ||
| addConnection={ addConnection } | ||
| attribute={ attribute } | ||
| binding={ binding } | ||
| /> | ||
| </DropdownMenu> | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -227,32 +246,11 @@ export const BlockBindingsPanel = ( { name, metadata } ) => { | |
| removeConnection( attribute ); | ||
| } } | ||
| > | ||
| <Dropdown | ||
| popoverProps={ popoverProps } | ||
| className="block-editor-bindings__dropdown" | ||
| renderToggle={ ( { onToggle, isOpen } ) => { | ||
| const toggleProps = { | ||
| onClick: onToggle, | ||
| className: isOpen ? 'is-open' : '', | ||
| 'aria-expanded': isOpen, | ||
| }; | ||
| return ( | ||
| <BlockBindingsAttribute | ||
| toggleProps={ toggleProps } | ||
| attribute={ attribute } | ||
| binding={ | ||
| filteredBindings[ attribute ] | ||
| } | ||
| /> | ||
| ); | ||
| } } | ||
| renderContent={ () => ( | ||
| <BlockBindingsPanelDropdown | ||
| fieldsList={ fieldsList } | ||
| addConnection={ addConnection } | ||
| attribute={ attribute } | ||
| /> | ||
| ) } | ||
| <BlockBindingsAttribute | ||
| fieldsList={ fieldsList } | ||
| addConnection={ addConnection } | ||
| attribute={ attribute } | ||
| binding={ filteredBindings[ attribute ] } | ||
| /> | ||
| </ToolsPanelItem> | ||
| ) ) } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.