-
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.
Try: Don't show a clone when dragging. (#23024)
* Try: Don't show a clone when dragging. This is an experiment. * Hide the block being moved. * Remove clone, add shadow, polish comments. * Add DraggableChip experience to block-draggable * Hide dragging block to emulate a "lift" effect * Only show the grab cursor when drag and drop is possible. * Remove dead JS. * Polish chip. * Polish DraggableChip * Leave clone logic Co-authored-by: Jon Q <hello@jonquach.com> Co-authored-by: Joen Asmussen <asmussen@gmail.com> Co-authored-by: Ella van Durpe <ella@vandurpe.com>
- Loading branch information
1 parent
81a010f
commit cc0128f
Showing
13 changed files
with
188 additions
and
53 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/block-editor/src/components/block-draggable/draggable-chip.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,50 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { getBlockType } from '@wordpress/blocks'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { Flex, FlexItem } from '@wordpress/components'; | ||
import { menu, handle } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockIcon from '../block-icon'; | ||
|
||
export default function BlockDraggableChip( { clientIds } ) { | ||
const icon = useSelect( | ||
( select ) => { | ||
const { getBlockName } = select( 'core/block-editor' ); | ||
const [ firstId ] = clientIds; | ||
const blockName = getBlockName( firstId ); | ||
const isOfSameType = clientIds.every( | ||
( id ) => getBlockName( id ) === blockName | ||
); | ||
|
||
if ( ! isOfSameType ) { | ||
return menu; | ||
} | ||
|
||
return getBlockType( blockName ).icon; | ||
}, | ||
[ clientIds ] | ||
); | ||
|
||
return ( | ||
<div className="block-editor-block-draggable-chip-wrapper"> | ||
<div className="block-editor-block-draggable-chip"> | ||
<Flex | ||
justify="center" | ||
className="block-editor-block-draggable-chip__content" | ||
> | ||
<FlexItem> | ||
<BlockIcon icon={ handle } /> | ||
</FlexItem> | ||
<FlexItem> | ||
<BlockIcon icon={ icon } /> | ||
</FlexItem> | ||
</Flex> | ||
</div> | ||
</div> | ||
); | ||
} |
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
15 changes: 15 additions & 0 deletions
15
packages/block-editor/src/components/block-draggable/stories/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,15 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { wordpress } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { BlockDraggableChip } from '../draggable-chip'; | ||
|
||
export default { title: 'BlockEditor/BlockDraggable' }; | ||
|
||
export const _default = () => { | ||
return <BlockDraggableChip icon={ wordpress } label="WordPress" />; | ||
}; |
33 changes: 33 additions & 0 deletions
33
packages/block-editor/src/components/block-draggable/style.scss
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,33 @@ | ||
.block-editor-block-draggable-chip-wrapper { | ||
position: absolute; | ||
top: -$block-toolbar-height - $grid-unit-15; | ||
} | ||
|
||
.block-editor-block-draggable-chip { | ||
background-color: $dark-gray-primary; | ||
border-radius: $radius-block-ui; | ||
border: $border-width solid $dark-gray-primary; | ||
box-shadow: $shadow-popover; | ||
color: $white; | ||
cursor: grabbing; | ||
display: inline-flex; | ||
height: $block-toolbar-height; | ||
min-width: $button-size * 2; | ||
padding: 0 $grid-unit-15; | ||
user-select: none; | ||
|
||
svg { | ||
fill: currentColor; | ||
} | ||
|
||
&__content { | ||
margin: auto; | ||
} | ||
} | ||
|
||
// This hides the block being dragged. | ||
// The effect is that the block being dragged appears to be "lifted". | ||
.is-dragging.is-selected { | ||
display: none !important; | ||
} | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Path, SVG } from '@wordpress/primitives'; | ||
|
||
const handle = ( | ||
<SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"> | ||
<Path d="M7 16.5h10V15H7v1.5zm0-9V9h10V7.5H7z" /> | ||
</SVG> | ||
); | ||
|
||
export default handle; |
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