-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
library-font-variant.js
66 lines (59 loc) · 1.57 KB
/
library-font-variant.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* WordPress dependencies
*/
import { useContext } from '@wordpress/element';
import {
CheckboxControl,
Flex,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
/**
* Internal dependencies
*/
import { getFontFaceVariantName } from './utils';
import { FontLibraryContext } from './context';
import FontFaceDemo from './font-demo';
import { unlock } from '../../../lock-unlock';
function LibraryFontVariant( { face, font } ) {
const { isFontActivated, toggleActivateFont } =
useContext( FontLibraryContext );
const isInstalled =
font?.fontFace?.length > 0
? isFontActivated(
font.slug,
face.fontStyle,
face.fontWeight,
font.source
)
: isFontActivated( font.slug, null, null, font.source );
const handleToggleActivation = () => {
if ( font?.fontFace?.length > 0 ) {
toggleActivateFont( font, face );
return;
}
toggleActivateFont( font );
};
const displayName = font.name + ' ' + getFontFaceVariantName( face );
const { kebabCase } = unlock( componentsPrivateApis );
const checkboxId = kebabCase(
`${ font.slug }-${ getFontFaceVariantName( face ) }`
);
return (
<label
className="font-library-modal__library-font-variant"
htmlFor={ checkboxId }
>
<Flex justify="flex-start" align="center" gap="1rem">
<CheckboxControl
checked={ isInstalled }
onChange={ handleToggleActivation }
__nextHasNoMarginBottom={ true }
id={ checkboxId }
label={ false }
/>
<FontFaceDemo fontFace={ face } text={ displayName } />
</Flex>
</label>
);
}
export default LibraryFontVariant;