Skip to content

Commit

Permalink
Move functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
apeatling committed May 17, 2021
1 parent 9d55454 commit ee5e7e4
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions packages/block-library/src/search/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,6 @@ export default function SearchEdit( {
}
}, [ buttonPosition ] );

const hideSearchField = () => {
searchFieldRef.current.style.width = `${ searchFieldRef.current.offsetWidth }px`;
searchFieldRef.current.style.flexGrow = '0';
searchFieldRef.current.style.transitionDuration = `${ SEARCHFIELD_ANIMATION_DURATION }ms`;
searchFieldRef.current.style.transitionProperty = 'margin-left';

const offset =
searchFieldRef.current.offsetWidth +
parseInt(
window.getComputedStyle( searchFieldRef.current ).marginRight
) +
parseInt( window.getComputedStyle( buttonRef.current ).marginLeft );

searchFieldRef.current.style.marginLeft = `-${ offset }px`;
};

const showSearchField = ( animate = true ) => {
const duration = animate ? SEARCHFIELD_ANIMATION_DURATION : 0;

searchFieldRef.current.style.marginLeft = 0;
searchFieldRef.current.style.transitionDuration = `${ duration }ms`;

const resetWidth = setTimeout( () => {
searchFieldRef.current.style.flexGrow = '1';
searchFieldRef.current.style.width = `${ width }${ widthUnit }`;
clearTimeout( resetWidth );
}, duration );
};

const getBlockClassNames = () => {
return classnames(
className,
Expand Down Expand Up @@ -187,6 +158,35 @@ export default function SearchEdit( {
};
};

const hideSearchField = () => {
searchFieldRef.current.style.width = `${ searchFieldRef.current.offsetWidth }px`;
searchFieldRef.current.style.flexGrow = '0';
searchFieldRef.current.style.transitionDuration = `${ SEARCHFIELD_ANIMATION_DURATION }ms`;
searchFieldRef.current.style.transitionProperty = 'margin-left';

const offset =
searchFieldRef.current.offsetWidth +
parseInt(
window.getComputedStyle( searchFieldRef.current ).marginRight
) +
parseInt( window.getComputedStyle( buttonRef.current ).marginLeft );

searchFieldRef.current.style.marginLeft = `-${ offset }px`;
};

const showSearchField = ( animate = true ) => {
const duration = animate ? SEARCHFIELD_ANIMATION_DURATION : 0;

searchFieldRef.current.style.marginLeft = 0;
searchFieldRef.current.style.transitionDuration = `${ duration }ms`;

const resetWidth = setTimeout( () => {
searchFieldRef.current.style.flexGrow = '1';
searchFieldRef.current.style.width = `${ width }${ widthUnit }`;
clearTimeout( resetWidth );
}, duration );
};

const renderTextField = () => {
return (
<input
Expand Down

0 comments on commit ee5e7e4

Please sign in to comment.