Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a00b7a4
Add initial visualizer popover, sized to the full-width
talldan Oct 18, 2022
fa9c580
Make snapping more magnetic, requiring a longer dwell time from the u…
talldan Mar 15, 2023
94a401f
Show a tooltip above the snapped alignment
talldan Mar 28, 2023
96f47a3
Avoid horizontal scrollbar when resizing
talldan Mar 28, 2023
f556dbb
Ensure block assumes the correct height when snapping
talldan Mar 28, 2023
cb24c0b
Fix typo
talldan Mar 28, 2023
ccefece
Remove unused CSS
talldan Mar 28, 2023
97e30c5
Remove unused code
talldan Mar 29, 2023
7bef33f
Fix image not inheriting correct size
talldan Apr 3, 2023
975bbeb
Prevent image layout animation unless alignment visualizer is visible
talldan Apr 3, 2023
8671b30
Remove duplicate code
talldan Apr 3, 2023
dc6471f
Fix label wrapping
talldan Apr 4, 2023
e2e478b
Make ResizableAlignmentControls a private api
talldan Apr 4, 2023
25dd8bd
Use an experiment toggle
talldan Apr 4, 2023
1342830
Remove popover usage
talldan Apr 4, 2023
c19f072
Revert changes to Popover
talldan Apr 4, 2023
c18891c
Nest entire visualizer in shadow dom container
talldan Apr 4, 2023
8bcef22
Fix merge conflict issue
talldan Apr 18, 2023
7290e20
Fix aspect ratio calculation
talldan Apr 18, 2023
af59e3b
Fix docs. Not sure how this is related to this branch, so :shrug:
talldan Apr 18, 2023
816f517
Remove restrictions that hide resize tools when at wide or full align…
talldan Apr 18, 2023
be71e52
Increase max width buffer for wide or full alignments
talldan Apr 18, 2023
0bf7c33
Try an undefined maxWidth and maxHeight
talldan Apr 18, 2023
89f4521
Fix maintaining height when resizing
talldan Apr 20, 2023
b189af4
Unset the alignment when starting a drag
talldan Apr 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Show a tooltip above the snapped alignment
  • Loading branch information
talldan committed Apr 18, 2023
commit 94a401f9e9fdb059240b14226022d91f78254faf
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default function BlockAlignmentVisualizer( {
contentSize={ layout.contentSize }
wideSize={ layout.wideSize }
justification={ layout.justifyContent }
highlightedAlignment={ highlightedAlignment }
/>
<Guides
alignments={ availableAlignments }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,34 @@
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { Fragment } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

const ALIGNMENT_LABELS = {
content: __( 'Content width' ),
wide: __( 'Wide width' ),
full: __( 'Full width' ),
};

/**
* Renders a visualization of block alignments.
*
* @param {Object} props
* @param {string} props.contentSize The CSS value for content size (e.g. 600px).
* @param {string} props.wideSize The CSS value for wide size (e.g. 80%).
* @param {'none'|'wide'|'full'[]} props.alignments An array of the alignments to render.
* @param {'left'|'right'|'center'} props.justification The justification.
* @param {string} props.contentSize The CSS value for content size (e.g. 600px).
* @param {string} props.wideSize The CSS value for wide size (e.g. 80%).
* @param {'none'|'wide'|'full'[]} props.alignments An array of the alignments to render.
* @param {'left'|'right'|'center'} props.justification The justification.
* @param {string} props.highlightedAlignment The name of the highlighted alignment.
*/
export default function Visualization( {
contentSize,
wideSize,
alignments,
justification,
highlightedAlignment,
} ) {
return (
<>
Expand Down Expand Up @@ -45,9 +59,31 @@ export default function Visualization( {
}

.block-editor-alignment-visualizer__visualization-segment {
background: #3d5af2;
opacity: 0.2;
position: relative;
background: rgba(61, 90, 242, 0.2);
border-radius: 2px;
}

.block-editor-alignment-visualizer__visualization-segment-label {
position: absolute;
top: -32px;
right: 0px;
background: rgba( 0, 0, 0, 0.8 );
border-radius: 2px;
color: white;
font-size: 12px;
min-width: 32px;
opacity: 0;
padding: 4px 8px;
pointer-events: none;
text-align: center;
transition: opacity 120ms ease;
user-select: none;
line-height: 1.4;
}

.block-editor-alignment-visualizer__visualization-segment-label.is-highlighted {
opacity: 1;
}

/* Hide wide width alignments when the container is smaller than wide size */
Expand Down Expand Up @@ -116,14 +152,20 @@ export default function Visualization( {
/>
)
) }
<VisualizationSegment alignment="content" />
<VisualizationSegment
alignment="content"
isHighlighted={ highlightedAlignment === 'none' }
/>
{ alignments.map(
( { name } ) =>
( name === 'full' || name === 'wide' ) && (
<VisualizationSegment
key={ `${ name }-right` }
alignment={ name }
side="right"
isHighlighted={
highlightedAlignment === name
}
/>
)
) }
Expand All @@ -133,14 +175,29 @@ export default function Visualization( {
);
}

function VisualizationSegment( { side, alignment } ) {
function VisualizationSegment( { side, alignment, isHighlighted } ) {
const label = ALIGNMENT_LABELS[ alignment ];

return (
<div
className={ classnames(
'block-editor-alignment-visualizer__visualization-segment',
`${ alignment }-width`,
{ [ `${ side }-side` ]: side }
) }
/>
>
{ !! label && (
<div
className={ classnames(
'block-editor-alignment-visualizer__visualization-segment-label',
{
'is-highlighted': isHighlighted,
}
) }
>
{ label }
</div>
) }
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function ResizableAlignmentControls( {
layoutClientId={ rootClientId }
focusedClientId={ clientId }
allowedAlignments={ allowedAlignments }
highlightedAlignment={ snappedAlignment }
highlightedAlignment={ snappedAlignment?.name }
/>
</motion.div>
) }
Expand Down