-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathfont-family-item.js
44 lines (37 loc) · 1.09 KB
/
font-family-item.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* WordPress dependencies
*/
import { _n } from '@wordpress/i18n';
import {
__experimentalHStack as HStack,
__experimentalItem as Item,
FlexItem,
} from '@wordpress/components';
import { useContext } from '@wordpress/element';
/**
* Internal dependencies
*/
import { FontLibraryContext } from './font-library-modal/context';
import { getFamilyPreviewStyle } from './font-library-modal/utils/preview-styles';
function FontFamilyItem( { font } ) {
const { handleSetLibraryFontSelected, toggleModal } =
useContext( FontLibraryContext );
const variantsCount = font?.fontFace?.length || 1;
const handleClick = () => {
handleSetLibraryFontSelected( font );
toggleModal( 'installed-fonts' );
};
const previewStyle = getFamilyPreviewStyle( font );
return (
<Item onClick={ handleClick }>
<HStack justify="space-between">
<FlexItem style={ previewStyle }>{ font.name }</FlexItem>
<FlexItem style={ { color: '#9e9e9e' } }>
{ variantsCount }{ ' ' }
{ _n( 'variant', 'variants', variantsCount ) }
</FlexItem>
</HStack>
</Item>
);
}
export default FontFamilyItem;