0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 21:53:27 -05:00
penpot-exporter-figma-plugin/ui-src/components/MissingFontsSection.tsx
Jordi Sala Morales 3ee244db92
New UI for the plugin (#90)
* add figma-create-plugin ui

* first attempt

* more changes

* update packages

* fix stuff

* implement reload action

* simplify code

* create wrapper

* fix logo

* adjust sizes

* add changelog

* update design again

* temporary fix

---------

Co-authored-by: Alex Sánchez <sion333@gmail.com>
2024-05-09 12:56:45 +02:00

61 lines
1.7 KiB
TypeScript

import { Banner, IconInfo32, Link, Textbox } from '@create-figma-plugin/ui';
import { Controller, useFormContext } from 'react-hook-form';
import { Stack } from './Stack';
type MissingFontsSectionProps = {
fonts?: string[];
};
export const MissingFontsSection = ({ fonts }: MissingFontsSectionProps) => {
if (!fonts || !fonts.length) return null;
return (
<Stack space="small">
<Stack space="xsmall">
<Banner icon={<IconInfo32 />}>
{fonts.length} custom font{fonts.length > 1 ? 's' : ''} detected
</Banner>
<span>To export your file with custom fonts, please follow these steps:</span>
<Stack as="ol" space="xsmall" style={{ paddingLeft: '1rem' }}>
<li>
Upload your local fonts in Penpot.
<br />
<Link href="https://www.google.com" target="_blank" rel="noreferrer">
Learn how to do it.
</Link>
</li>
<li>Copy and paste the font IDs from Penpot below.</li>
</Stack>
</Stack>
{fonts.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"
/>
)}
/>
);
};