Skip to content

Commit

Permalink
remove custom fonts form
Browse files Browse the repository at this point in the history
  • Loading branch information
Cenadros committed Dec 19, 2024
1 parent 570aeee commit 42ec8d8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 75 deletions.
2 changes: 1 addition & 1 deletion plugin-src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ figma.ui.onmessage = message => {
}

if (message.type === 'export') {
handleExportMessage(message.data as Record<string, string>);
handleExportMessage();
}

if (message.type === 'cancel') {
Expand Down
7 changes: 1 addition & 6 deletions plugin-src/handleExportMessage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
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({
type: 'PENPOT_DOCUMENT',
data: await transformDocumentNode(figma.root)
Expand Down
9 changes: 0 additions & 9 deletions plugin-src/translators/text/font/custom/customFontIds.ts

This file was deleted.

1 change: 0 additions & 1 deletion plugin-src/translators/text/font/custom/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './customFontIds';
export * from './translateCustomFont';
export * from './translateFontVariantId';
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
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';

export const translateCustomFont = (
fontName: FontName,
fontWeight: string
): Pick<TextTypography, 'fontId' | 'fontVariantId' | 'fontWeight'> | undefined => {
const customFontId = getCustomFontId(fontName);

return {
fontId: customFontId ? `custom-${customFontId}` : '',
fontId: '',
fontVariantId: translateFontVariantId(fontName, fontWeight),
fontWeight
};
Expand Down
65 changes: 13 additions & 52 deletions ui-src/components/MissingFontsSection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Banner, IconInfo32, Link, Textbox } from '@create-figma-plugin/ui';
import { Controller, useFormContext } from 'react-hook-form';
import { Banner, IconInfo32, Link } from '@create-figma-plugin/ui';

import { useFigmaContext } from '@ui/context';

Expand All @@ -14,58 +13,20 @@ export const MissingFontsSection = () => {
<Stack space="small">
<Stack space="xsmall">
<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>
<span>To export your file with custom fonts, please follow these steps:</span>
<Stack as="ol" space="xsmall" style={{ paddingLeft: '1rem' }}>
<li>
Before exporting the file, upload your custom local fonts in Penpot.
<br />
<Link href="https://help.penpot.app/user-guide/custom-fonts/" target="_blank">
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>
<span>
To export your file with custom fonts, first upload them in Penpot.{' '}
<Link href="https://help.penpot.app/user-guide/custom-fonts/" target="_blank">
Learn how to upload fonts.
</Link>
</span>
</Stack>
{missingFonts.map(font => (
<Stack space="2xsmall" key={font}>
<ControlledTextbox name={font} placeholder="Paste font ID from Penpot" />
<span>{font}</span>
</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"
/>
)}
/>
);
};
4 changes: 2 additions & 2 deletions ui-src/context/useFigma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ export const useFigma = (): UseFigmaHook => {
postMessage('cancel');
};

const exportPenpot = (data: FormValues) => {
const exportPenpot = () => {
setExporting(true);
setStep('processing');
setProcessedItems(0);

postMessage('export', data);
postMessage('export');
};

useEffect(() => {
Expand Down

0 comments on commit 42ec8d8

Please sign in to comment.