mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-21 21:23:06 -05:00
Remove custom fonts form (#243)
* remove custom fonts form * changeset * changeset
This commit is contained in:
parent
570aeee7b0
commit
b44cbf2052
8 changed files with 24 additions and 75 deletions
5
.changeset/fair-boxes-laugh.md
Normal file
5
.changeset/fair-boxes-laugh.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'penpot-exporter': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Remove custom font form since penpot now matches the fonts by fontName and fontFamily
|
|
@ -16,7 +16,7 @@ figma.ui.onmessage = message => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'export') {
|
if (message.type === 'export') {
|
||||||
handleExportMessage(message.data as Record<string, string>);
|
handleExportMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'cancel') {
|
if (message.type === 'cancel') {
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
import { transformDocumentNode } from '@plugin/transformers';
|
import { transformDocumentNode } from '@plugin/transformers';
|
||||||
import { setCustomFontId } from '@plugin/translators/text/font/custom';
|
|
||||||
|
|
||||||
export const handleExportMessage = async (missingFontIds: Record<string, string>) => {
|
|
||||||
Object.entries(missingFontIds).forEach(([fontFamily, fontId]) => {
|
|
||||||
setCustomFontId(fontFamily, fontId);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
export const handleExportMessage = async () => {
|
||||||
figma.ui.postMessage({
|
figma.ui.postMessage({
|
||||||
type: 'PENPOT_DOCUMENT',
|
type: 'PENPOT_DOCUMENT',
|
||||||
data: await transformDocumentNode(figma.root)
|
data: await transformDocumentNode(figma.root)
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
const customFontIds = new Map<string, string>();
|
|
||||||
|
|
||||||
export const getCustomFontId = (fontName: FontName) => {
|
|
||||||
return customFontIds.get(fontName.family);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const setCustomFontId = (fontFamily: string, fontId: string) => {
|
|
||||||
customFontIds.set(fontFamily, fontId);
|
|
||||||
};
|
|
|
@ -1,3 +1,2 @@
|
||||||
export * from './customFontIds';
|
|
||||||
export * from './translateCustomFont';
|
export * from './translateCustomFont';
|
||||||
export * from './translateFontVariantId';
|
export * from './translateFontVariantId';
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { getCustomFontId, translateFontVariantId } from '@plugin/translators/text/font/custom';
|
import { translateFontVariantId } from '@plugin/translators/text/font/custom';
|
||||||
|
|
||||||
import { TextTypography } from '@ui/lib/types/shapes/textShape';
|
import { TextTypography } from '@ui/lib/types/shapes/textShape';
|
||||||
|
|
||||||
|
@ -6,10 +6,8 @@ export const translateCustomFont = (
|
||||||
fontName: FontName,
|
fontName: FontName,
|
||||||
fontWeight: string
|
fontWeight: string
|
||||||
): Pick<TextTypography, 'fontId' | 'fontVariantId' | 'fontWeight'> | undefined => {
|
): Pick<TextTypography, 'fontId' | 'fontVariantId' | 'fontWeight'> | undefined => {
|
||||||
const customFontId = getCustomFontId(fontName);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fontId: customFontId ? `custom-${customFontId}` : '',
|
fontId: '',
|
||||||
fontVariantId: translateFontVariantId(fontName, fontWeight),
|
fontVariantId: translateFontVariantId(fontName, fontWeight),
|
||||||
fontWeight
|
fontWeight
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { Banner, IconInfo32, Link, Textbox } from '@create-figma-plugin/ui';
|
import { Banner, IconInfo32, Link } from '@create-figma-plugin/ui';
|
||||||
import { Controller, useFormContext } from 'react-hook-form';
|
|
||||||
|
|
||||||
import { useFigmaContext } from '@ui/context';
|
import { useFigmaContext } from '@ui/context';
|
||||||
|
|
||||||
|
@ -14,58 +13,20 @@ export const MissingFontsSection = () => {
|
||||||
<Stack space="small">
|
<Stack space="small">
|
||||||
<Stack space="xsmall">
|
<Stack space="xsmall">
|
||||||
<Banner icon={<IconInfo32 />}>
|
<Banner icon={<IconInfo32 />}>
|
||||||
{missingFonts.length} custom font{missingFonts.length > 1 ? 's' : ''} detected
|
{missingFonts.length} custom font{missingFonts.length > 1 ? 's' : ''} detected:
|
||||||
|
<ul style={{ paddingLeft: 20 }}>
|
||||||
|
{missingFonts.map(font => (
|
||||||
|
<li key={font}>{font}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
</Banner>
|
</Banner>
|
||||||
<span>To export your file with custom fonts, please follow these steps:</span>
|
<span>
|
||||||
<Stack as="ol" space="xsmall" style={{ paddingLeft: '1rem' }}>
|
To export your file with custom fonts, first upload them in Penpot.{' '}
|
||||||
<li>
|
<Link href="https://help.penpot.app/user-guide/custom-fonts/" target="_blank">
|
||||||
Before exporting the file, upload your custom local fonts in Penpot.
|
Learn how to upload fonts.
|
||||||
<br />
|
</Link>
|
||||||
<Link href="https://help.penpot.app/user-guide/custom-fonts/" target="_blank">
|
</span>
|
||||||
Learn how to do it.
|
|
||||||
</Link>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
Follow this{' '}
|
|
||||||
<Link
|
|
||||||
href="https://github.com/penpot/penpot-exporter-figma-plugin/wiki/Step-by-Step-guide-to-finding-Font-Ids-in-Penpot"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
step-by-step guide
|
|
||||||
</Link>{' '}
|
|
||||||
to locate and copy the font IDs from Penpot
|
|
||||||
</li>
|
|
||||||
<li>Return here and paste the font IDs in the section below</li>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
{missingFonts.map(font => (
|
|
||||||
<Stack space="2xsmall" key={font}>
|
|
||||||
<ControlledTextbox name={font} placeholder="Paste font ID from Penpot" />
|
|
||||||
<span>{font}</span>
|
|
||||||
</Stack>
|
|
||||||
))}
|
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
type ControlledTextboxProps = { name: string; placeholder: string };
|
|
||||||
|
|
||||||
const ControlledTextbox = ({ name, placeholder }: ControlledTextboxProps) => {
|
|
||||||
const { control } = useFormContext();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name={name}
|
|
||||||
render={({ field: { onChange, onBlur, value } }) => (
|
|
||||||
<Textbox
|
|
||||||
onChange={onChange}
|
|
||||||
onBlur={onBlur}
|
|
||||||
value={value}
|
|
||||||
placeholder={placeholder}
|
|
||||||
variant="border"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
|
@ -147,12 +147,12 @@ export const useFigma = (): UseFigmaHook => {
|
||||||
postMessage('cancel');
|
postMessage('cancel');
|
||||||
};
|
};
|
||||||
|
|
||||||
const exportPenpot = (data: FormValues) => {
|
const exportPenpot = () => {
|
||||||
setExporting(true);
|
setExporting(true);
|
||||||
setStep('processing');
|
setStep('processing');
|
||||||
setProcessedItems(0);
|
setProcessedItems(0);
|
||||||
|
|
||||||
postMessage('export', data);
|
postMessage('export');
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
Loading…
Reference in a new issue