-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Tom Lienard <[email protected]>
- Loading branch information
Showing
14 changed files
with
330 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ db.sqlite* | |
.DS_Store | ||
*.log | ||
.env | ||
.env* | ||
*.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.vercel | ||
.env*.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { getFontData } from "../../../lib/fonts"; | ||
|
||
export const dynamic = "force-static"; | ||
|
||
export async function GET() { | ||
return Response.json(await getFontData()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Popover, Button, TextField, Flex, Badge } from "@radix-ui/themes"; | ||
import Fuse from "fuse.js"; | ||
import { useMemo, useState } from "react"; | ||
import { useFontsStore } from "../../stores/fontsStore"; | ||
import { useElementsStore } from "../../stores/elementsStore"; | ||
import { FontPreview } from "../FontPreview"; | ||
import type { OGElement } from "../../lib/types"; | ||
import { useDebounce } from "../../lib/hooks/useDebounce"; | ||
import { DEFAULT_FONTS } from "../../lib/fonts"; | ||
|
||
interface FontSelectorProps { | ||
selectedElement: OGElement & { tag: "p" | "span" }; | ||
} | ||
|
||
export function FontSelector({ selectedElement }: FontSelectorProps) { | ||
const { allFonts, installedFonts, installFont } = useFontsStore(); | ||
const updateElement = useElementsStore((state) => state.updateElement); | ||
const fuse = useMemo( | ||
() => new Fuse(allFonts, { keys: ["name"] }), | ||
[allFonts], | ||
); | ||
const [search, setSearch] = useState(""); | ||
const [isOpen, setIsOpen] = useState(false); | ||
const debouncedSearch = useDebounce(search, 200); | ||
|
||
const searchedFonts = fuse | ||
.search(debouncedSearch) | ||
.slice(0, 8) | ||
.map(({ item }) => item.name); | ||
|
||
return ( | ||
<Popover.Root open={isOpen} onOpenChange={setIsOpen}> | ||
<Popover.Trigger> | ||
<Button size="2" variant="soft" color="gray"> | ||
+ | ||
</Button> | ||
</Popover.Trigger> | ||
<Popover.Content width="300px"> | ||
<Flex gap="3" direction="column"> | ||
<TextField.Root | ||
placeholder="Search any fontsource font..." | ||
value={search} | ||
onChange={(event) => { | ||
setSearch(event.target.value); | ||
}} | ||
/> | ||
<Flex gap="1" direction="column"> | ||
{searchedFonts.map((font) => ( | ||
<Button | ||
variant="soft" | ||
color="gray" | ||
key={font} | ||
onClick={() => { | ||
installFont(font); | ||
const weights = allFonts.find( | ||
({ name }) => name === font, | ||
)?.weights; | ||
|
||
updateElement({ | ||
...selectedElement, | ||
fontFamily: font, | ||
fontWeight: weights?.includes(selectedElement.fontWeight) | ||
? selectedElement.fontWeight | ||
: 400, | ||
}); | ||
|
||
setIsOpen(false); | ||
}} | ||
> | ||
<FontPreview font={font} /> | ||
{DEFAULT_FONTS.includes(font) ? ( | ||
<Badge color="blue">Pre-installed</Badge> | ||
) : installedFonts.has(font) ? ( | ||
<Badge color="green">Installed</Badge> | ||
) : null} | ||
</Button> | ||
))} | ||
</Flex> | ||
</Flex> | ||
</Popover.Content> | ||
</Popover.Root> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.