Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputControl: Use less Emotion styled API #58948

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
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
Add back SuffixItem
  • Loading branch information
mirka committed Feb 13, 2024
commit 396d61c4bccb4f595e7b8cc5abe5c5e33905b438
50 changes: 39 additions & 11 deletions packages/components/src/search-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,45 @@ import classnames from 'classnames';
*/
import { useInstanceId, useMergeRefs } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { Icon, search, closeSmall } from '@wordpress/icons';
import { forwardRef, useMemo, useRef } from '@wordpress/element';

/**
* Internal dependencies
*/
import Button from '../button';
import type { WordPressComponentProps } from '../context/wordpress-component';
import type { SearchControlProps } from './types';
import type { SearchControlProps, SuffixItemProps } from './types';
import type { ForwardedRef } from 'react';
import { ContextSystemProvider } from '../context';
import { SuffixItemWrapper } from './styles';
import InputControl from '../input-control';

function SuffixItem( {
searchRef,
value,
onChange,
onClose,
}: SuffixItemProps ) {
if ( ! onClose && ! value ) {
return <Icon icon={ search } />;
}

const onReset = () => {
onChange( '' );
searchRef.current?.focus();
};

return (
<Button
size="small"
icon={ closeSmall }
label={ onClose ? __( 'Close search' ) : __( 'Reset search' ) }
onClick={ onClose ?? onReset }
/>
);
}

function UnforwardedSearchControl(
{
__nextHasNoMarginBottom = false,
Expand Down Expand Up @@ -80,16 +108,16 @@ function UnforwardedSearchControl(
autoComplete="off"
placeholder={ placeholder }
value={ value ?? '' }
// suffix={
// <SuffixItemWrapper size={ size }>
// <SuffixItem
// searchRef={ searchRef }
// value={ value }
// onChange={ onChange }
// onClose={ onClose }
// />
// </SuffixItemWrapper>
// }
suffix={
<SuffixItemWrapper size={ size }>
<SuffixItem
searchRef={ searchRef }
value={ value }
onChange={ onChange }
onClose={ onClose }
/>
</SuffixItemWrapper>
}
{ ...restProps }
/>
</ContextSystemProvider>
Expand Down
Loading