diff --git a/packages/block-library/src/search/button-position-dropdown.native.js b/packages/block-library/src/search/button-position-dropdown.native.js new file mode 100644 index 00000000000000..b6e4537e290438 --- /dev/null +++ b/packages/block-library/src/search/button-position-dropdown.native.js @@ -0,0 +1,82 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { DropdownMenu } from '@wordpress/components'; + +/** + * Internal dependencies + */ +import { buttonOutside, buttonInside, noButton } from './icons'; + +const BUTTON_OPTIONS = [ + 'button-inside', + 'button-outside', + 'no-button', + 'button-only', +]; + +/** + * Creates a custom dropdown menu for the button position options. + * + * @param {Object} Component Component properties. + * @param {string} Component.selectedOption The selected option. + * @param {Function} Component.onChange Function to handle a change + * in the selected option. + * + * @return {DropdownMenu} Dropdown menu for use inside {ToolbarGroup} + */ +export default function ButtonPositionDropdown( { selectedOption, onChange } ) { + const getButtonIcon = ( option ) => { + switch ( option ) { + case 'button-inside': + return buttonInside; + case 'button-outside': + return buttonOutside; + case 'no-button': + return noButton; + } + }; + + const getButtonTitle = ( option ) => { + switch ( option ) { + case 'button-inside': + return __( 'Button Inside' ); + case 'button-outside': + return __( 'Button Outside' ); + case 'no-button': + return __( 'No Button' ); + } + }; + + const createOptionControl = ( + targetOption, + activeOption, + title, + onChangeCallback + ) => { + const isActive = targetOption === activeOption; + + return { + icon: getButtonIcon( targetOption ), + title, + isActive, + onClick: () => onChangeCallback( targetOption ), + }; + }; + + return ( + + createOptionControl( + option, + selectedOption, + getButtonTitle( option ), + onChange + ) + ) } + label={ __( 'Change button position' ) } + /> + ); +} diff --git a/packages/block-library/src/search/edit.native.js b/packages/block-library/src/search/edit.native.js index 45f0969ce0787b..3ea7844278a4e8 100644 --- a/packages/block-library/src/search/edit.native.js +++ b/packages/block-library/src/search/edit.native.js @@ -1,19 +1,81 @@ /** * External dependencies */ -import { View } from 'react-native'; +import { View, Alert } from 'react-native'; /** * WordPress dependencies */ -import { RichText } from '@wordpress/block-editor'; +import { RichText, BlockControls } from '@wordpress/block-editor'; +import { ToolbarGroup, ToolbarButton } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; +/** + * Internal dependencies + */ +import { buttonWithIcon, toggleLabel } from './icons'; +import ButtonPositionDropdown from './button-position-dropdown.native'; + export default function SearchEdit( { attributes, setAttributes } ) { - const { label, showLabel } = attributes; + const { label, showLabel, buttonPosition, buttonUseIcon } = attributes; + + // Temporary. Will be removed when styling is implemented + // in a future PR. + const alert = ( message ) => { + Alert.alert( '', message, [ { text: 'OK' } ], { cancelable: true } ); + }; + + const controls = ( + + + { + setAttributes( { + showLabel: ! showLabel, + } ); + } } + isActive={ showLabel } + /> + + { + setAttributes( { + buttonPosition: position, + } ); + + // Temporary. Will be removed when styling is implemented + // in a future PR. + alert( `Button position: ${ position }` ); + } } + /> + + { 'no-button' !== buttonPosition && ( + { + setAttributes( { + buttonUseIcon: ! buttonUseIcon, + } ); + + // Temporary. Will be removed when styling is implemented + // in a future PR. + alert( `Icon only button: ${ ! buttonUseIcon }` ); + } } + isActive={ buttonUseIcon } + /> + ) } + + + ); return ( + { controls } + { showLabel && (