-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of SlotFill for DimensionControls
This will allow for ad hoc controls to be injected by blocks into the dimensions block support panel.
- Loading branch information
1 parent
65b18b9
commit ab8a037
Showing
7 changed files
with
129 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/block-editor/src/components/dimension-controls/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# DimensionControls | ||
|
||
Dimension controls appear under the dimensions block support panel in post | ||
settings sidebar when a block is being edited. `DimensionControls` allow for | ||
blocks to group their own dimensions related controls along side those provided | ||
via block supports. | ||
|
||
The dimensions panel is built via the `ToolsPanel` component. Block's can also | ||
add their controls to the `ToolsPanel` menu by wrapping them in a | ||
`ToolsPanelItem` component and providing the required callbacks. | ||
|
||
## Usage | ||
|
||
```js | ||
import { DimensionsControls } from '@wordpress/block-editor'; | ||
import { | ||
TextControl, | ||
__experimentalToolsPanelItem as ToolsPanelItem, | ||
} from '@wordpress/components'; | ||
|
||
function MyBlockEdit( props ) { | ||
const { attributes, setAttributes } = props; | ||
|
||
return ( | ||
<DimensionControls> | ||
<ToolsPanelItem | ||
hasValue={ () => !! attributes.myValue } | ||
label={ __( 'My dimension control' ) } | ||
onDeselect={ () => setAttributes( { myValue: undefined } ) } | ||
resetAllFilter={ ( newAttributes ) => ( { | ||
...newAttributes, | ||
myValue: undefined, | ||
} ) } | ||
isShownByDefault={ true } | ||
> | ||
<TextControl | ||
label="My dimension" | ||
value={ attributes.myValue } | ||
onChange={ ( next ) => setAttributes( { myValue: next } ) ) } | ||
/> | ||
</ToolsPanelItem> | ||
</DimensionControls> | ||
); | ||
} | ||
``` |
18 changes: 18 additions & 0 deletions
18
packages/block-editor/src/components/dimension-controls/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createSlotFill } from '@wordpress/components'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import useDisplayBlockControls from '../use-display-block-controls'; | ||
|
||
const { Fill, Slot } = createSlotFill( 'DimensionControls' ); | ||
|
||
function DimensionControls( { children } ) { | ||
return useDisplayBlockControls() ? <Fill>{ children }</Fill> : null; | ||
} | ||
|
||
DimensionControls.Slot = Slot; | ||
|
||
export default DimensionControls; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters