import React, { useCallback, useState } from 'react' /** * Retrieves the translation of text. * * @see https://developer.wordpress.org/block-editor/packages/packages-i18n/ */ import { __ } from '@wordpress/i18n'; import { PanelBody, RangeControl, TextControl, Button, BaseControl, SelectControl, ToggleControl } from '@wordpress/components' import { InstantSearchEditComponent } from '../block.interfaces'; const { useInstanceId } = require('@wordpress/compose') const IndexName: InstantSearchEditComponent = ({attributes: {indexName}, setAttributes}) => { const [tmpIndexName, changeIndexName] = useState(indexName) const handleChangeIndexName = useCallback(() => { setAttributes({indexName: tmpIndexName}) }, [setAttributes, tmpIndexName]) const instanceId = useInstanceId( TextControl ); const id = `inspector-text-control-${ instanceId }`; const onChangeValue = useCallback(( event ) => changeIndexName( event.target.value ), [changeIndexName]) return (
{ if (e.key !== 'Enter') return; handleChangeIndexName() }} />
) } export const SearchOption: InstantSearchEditComponent = (props) => { const { attributes:{ hitsItems, searchFormStyle, autoFocus, }, setAttributes } = props const handleUpdateHitItems = useCallback((value) => { setAttributes({hitsItems: value}) }, [setAttributes]) console.log({autoFocus}) return ( setAttributes({searchFormStyle: value})} /> { setAttributes({ autoFocus: !autoFocus }) }} /> ) }