Skip to content

Commit

Permalink
available font faces: adding animation when removing or restoring fon…
Browse files Browse the repository at this point in the history
…t faces
  • Loading branch information
matiasbenedetto committed Dec 28, 2022
1 parent 9b5644c commit 0a13f52
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 29 deletions.
1 change: 1 addition & 0 deletions packages/edit-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"react-native": "src/index",
"dependencies": {
"@babel/runtime": "^7.16.0",
"@react-spring/web": "^9.4.5",
"@wordpress/a11y": "file:../a11y",
"@wordpress/api-fetch": "file:../api-fetch",
"@wordpress/block-editor": "file:../block-editor",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { useSpring, animated } from '@react-spring/web';

/**
* WordPress dependencies
*/
Expand All @@ -18,18 +23,59 @@ import Subtitle from './subtitle';
import { useFontFamilies } from './hooks';
import FontFaceItem from './font-face-item';

function RemovableFontFace( { fontFace } ) {
const { handleRemoveFontFace } = useFontFamilies();
const [ springs, api ] = useSpring( () => ( {
from: { y: 0, opacity: 1 },
} ) );

useEffect( () => {
if ( ! fontFace.shouldBeRemoved ) {
api.start( { y: 0, opacity: 1 } );
}
}, [ fontFace ] );

const handleRemove = () => {
api.start( { y: -20, opacity: 0 } );
const timer = setTimeout( () => {
handleRemoveFontFace(
fontFace.fontFamily,
fontFace.fontWeight,
fontFace.fontStyle
);
return () => clearTimeout( timer );
}, 200 );
};

if ( fontFace.shouldBeRemoved ) {
return null;
}

return (
<animated.div style={ springs }>
<FontFaceItem
fontFace={ fontFace }
actionTrigger={
<Tooltip text={ __( 'Remove Font Face' ) } delay={ 0 }>
<Button
style={ { padding: '0 8px' } }
onClick={ handleRemove }
>
<Icon icon={ check } size={ 20 } />
</Button>
</Tooltip>
}
/>
</animated.div>
);
}

function ScreenThemeFontFacesList( { themeFontSelected } ) {
const { goBack } = useNavigator();
const { fontFamilies, handleRemoveFontFace, sortFontFaces } =
useFontFamilies();
const { fontFamilies, sortFontFaces } = useFontFamilies();
const font = fontFamilies[ themeFontSelected ];
const getFontFaces = ( fontFamily ) => {
if ( ! fontFamily || ! Array.isArray( fontFamily.fontFace ) ) {
return [];
}
return sortFontFaces(
font.fontFace.filter( ( fontFace ) => ! fontFace.shouldBeRemoved )
);
return sortFontFaces( fontFamily.fontFace || [] );
};
const fontFaces = useMemo( () => getFontFaces( font ), [ fontFamilies ] );

Expand Down Expand Up @@ -68,28 +114,9 @@ function ScreenThemeFontFacesList( { themeFontSelected } ) {
{ ! font && <p>{ __( 'No font faces available' ) }</p> }

{ fontFaces.map( ( fontFace, i ) => (
<FontFaceItem
<RemovableFontFace
fontFace={ fontFace }
key={ `font-face-${ i }` }
actionTrigger={
<Tooltip
text={ __( 'Remove Font Face' ) }
delay={ 0 }
>
<Button
style={ { padding: '0 8px' } }
onClick={ () =>
handleRemoveFontFace(
fontFace.fontFamily,
fontFace.fontWeight,
fontFace.fontStyle
)
}
>
<Icon icon={ check } size={ 20 } />
</Button>
</Tooltip>
}
key={ `fontface-${ i }` }
/>
) ) }
</div>
Expand Down

1 comment on commit 0a13f52

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3796056642
📝 Reported issues:

Please sign in to comment.