-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Add featured image settings to the Latest Posts block (#39257
) This change adds featured image settings to the native Latest Posts block. This is a step towards bringing the available block settings on the native side in alignment with the web.
- Loading branch information
Siobhan Bamber
authored
Apr 27, 2022
1 parent
422933d
commit 48e2e83
Showing
6 changed files
with
260 additions
and
110 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
packages/block-editor/src/components/block-alignment-control/constants.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,45 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, _x } from '@wordpress/i18n'; | ||
import { | ||
alignNone, | ||
positionCenter, | ||
positionLeft, | ||
positionRight, | ||
stretchFullWidth, | ||
stretchWide, | ||
} from '@wordpress/icons'; | ||
|
||
export const BLOCK_ALIGNMENTS_CONTROLS = { | ||
none: { | ||
icon: alignNone, | ||
title: _x( 'None', 'Alignment option' ), | ||
}, | ||
left: { | ||
icon: positionLeft, | ||
title: __( 'Align left' ), | ||
}, | ||
center: { | ||
icon: positionCenter, | ||
title: __( 'Align center' ), | ||
}, | ||
right: { | ||
icon: positionRight, | ||
title: __( 'Align right' ), | ||
}, | ||
wide: { | ||
icon: stretchWide, | ||
title: __( 'Wide width' ), | ||
}, | ||
full: { | ||
icon: stretchFullWidth, | ||
title: __( 'Full width' ), | ||
}, | ||
}; | ||
|
||
export const DEFAULT_CONTROL = 'none'; | ||
|
||
export const POPOVER_PROPS = { | ||
isAlternate: true, | ||
}; |
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
86 changes: 86 additions & 0 deletions
86
packages/block-editor/src/components/block-alignment-control/ui.native.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,86 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
ToolbarDropdownMenu, | ||
ToolbarGroup, | ||
BottomSheetSelectControl, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useAvailableAlignments from './use-available-alignments'; | ||
import { | ||
BLOCK_ALIGNMENTS_CONTROLS, | ||
DEFAULT_CONTROL, | ||
POPOVER_PROPS, | ||
} from './constants'; | ||
|
||
function BlockAlignmentUI( { | ||
value, | ||
onChange, | ||
controls, | ||
isToolbar, | ||
isCollapsed = true, | ||
isBottomSheetControl = false, | ||
} ) { | ||
const enabledControls = useAvailableAlignments( controls ); | ||
const hasEnabledControls = !! enabledControls.length; | ||
|
||
if ( ! hasEnabledControls ) { | ||
return null; | ||
} | ||
|
||
function onChangeAlignment( align ) { | ||
onChange( [ value, 'none' ].includes( align ) ? undefined : align ); | ||
} | ||
|
||
const activeAlignmentControl = BLOCK_ALIGNMENTS_CONTROLS[ value ]; | ||
const defaultAlignmentControl = | ||
BLOCK_ALIGNMENTS_CONTROLS[ DEFAULT_CONTROL ]; | ||
|
||
const toolbarUIComponent = isToolbar ? ToolbarGroup : ToolbarDropdownMenu; | ||
const UIComponent = isBottomSheetControl | ||
? BottomSheetSelectControl | ||
: toolbarUIComponent; | ||
|
||
const commonProps = { | ||
label: __( 'Align' ), | ||
}; | ||
const extraProps = isBottomSheetControl | ||
? { | ||
options: enabledControls.map( ( { name: controlName } ) => { | ||
const control = BLOCK_ALIGNMENTS_CONTROLS[ controlName ]; | ||
return { | ||
value: controlName, | ||
label: control.title, | ||
icon: control.icon, | ||
}; | ||
} ), | ||
value: activeAlignmentControl ? value : 'none', | ||
onChange: ( align ) => onChangeAlignment( align ), | ||
} | ||
: { | ||
icon: activeAlignmentControl | ||
? activeAlignmentControl.icon | ||
: defaultAlignmentControl.icon, | ||
isCollapsed: isToolbar ? isCollapsed : undefined, | ||
controls: enabledControls.map( ( { name: controlName } ) => { | ||
return { | ||
...BLOCK_ALIGNMENTS_CONTROLS[ controlName ], | ||
isActive: | ||
value === controlName || | ||
( ! value && controlName === 'none' ), | ||
onClick: () => onChangeAlignment( controlName ), | ||
}; | ||
} ), | ||
popoverProps: POPOVER_PROPS, | ||
toggleProps: { describedBy: __( 'Change alignment' ) }, | ||
}; | ||
|
||
return <UIComponent { ...commonProps } { ...extraProps } />; | ||
} | ||
|
||
export default BlockAlignmentUI; |
Oops, something went wrong.