-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
2,058 additions
and
69 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
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 |
---|---|---|
@@ -1,5 +1,31 @@ | ||
// "use client"; | ||
import React from "react"; | ||
|
||
// import { FontSelector } from "@/modules/themes/components/font-selector"; | ||
|
||
export default function Demo() { | ||
return <div>internal</div>; | ||
// const [font, setFont] = React.useState<string | null>(null); | ||
|
||
// const content = variableFonts | ||
// .filter((elem) => elem.subsets.includes("latin")) | ||
// .filter((elem) => elem.variants.includes("regular")) | ||
// .filter((elem) => elem.category === "handwriting") | ||
// .map((elem) => elem.family); | ||
|
||
// const rawContent = JSON.stringify(content, null, 2); | ||
|
||
// const allCategories = variableFonts.map((elem) => elem.category) | ||
// const uniqueCategories = [...new Set(allCategories)] | ||
// console.log(uniqueCategories) | ||
|
||
// React.useEffect(() => { | ||
// // copy to clipboard | ||
// navigator.clipboard.writeText(rawContent); | ||
// }, [rawContent]); | ||
|
||
return ( | ||
<div className="container max-w-xs py-40"> | ||
{/* <FontSelector label="Body" font={font} onFontChange={setFont} /> */} | ||
</div> | ||
); | ||
} |
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 @@ | ||
export * from "@/registry/core/command_basic"; |
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
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,11 @@ | ||
export function FontLoader({ font }: { font: string | null | undefined }) { | ||
if (!font) return null; | ||
const googleFontUrl = generateGoogleFontUrl(font); | ||
return <link href={googleFontUrl} rel="stylesheet" />; | ||
} | ||
|
||
function generateGoogleFontUrl(font: string) { | ||
const familyName = font.replace(/\s+/g, "+"); | ||
|
||
return `https://fonts.googleapis.com/css?family=${familyName}`; | ||
} |
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,134 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import { ChevronDownIcon } from "lucide-react"; | ||
import { useInView } from "motion/react"; | ||
import { | ||
UNSTABLE_Virtualizer as Virtualizer, | ||
UNSTABLE_ListLayout as ListLayout, | ||
useFilter, | ||
} from "react-aria-components"; | ||
import { cn } from "@/lib/utils"; | ||
import { Button } from "@/components/core/button"; | ||
import { CommandRoot } from "@/components/core/command"; | ||
import { DialogRoot, Dialog } from "@/components/core/dialog"; | ||
import { | ||
ListBox, | ||
ListBoxItem, | ||
ListBoxSection, | ||
} from "@/components/core/list-box"; | ||
import { SearchField } from "@/components/core/search-field"; | ||
import { Select, SelectItem } from "@/components/core/select"; | ||
import { FontLoader } from "@/modules/themes/components/font-loader"; | ||
import { | ||
sansSerifFonts, | ||
monoFonts, | ||
serifFonts, | ||
displayFonts, | ||
handwritingFonts, | ||
} from "@/modules/themes/lib/google-fonts"; | ||
|
||
export const FontSelector = ({ | ||
label, | ||
font, | ||
onFontChange, | ||
}: { | ||
label: string; | ||
font: string | null; | ||
onFontChange: (font: string | null) => void; | ||
}) => { | ||
const { contains } = useFilter({ sensitivity: "base" }); | ||
|
||
const layout = React.useMemo(() => { | ||
return new ListLayout({ rowHeight: 32, headingHeight: 20 }); | ||
}, []); | ||
|
||
return ( | ||
<div className="flex flex-col gap-1"> | ||
<p className="text-fg-muted text-sm">{label}</p> | ||
<DialogRoot> | ||
<Button variant="outline"> | ||
<span className={cn("flex-1 text-left", !font && "text-fg-muted")}> | ||
{font ?? "Select a font"} | ||
</span> | ||
<ChevronDownIcon /> | ||
</Button> | ||
<Dialog | ||
type="popover" | ||
popoverProps={{ placement: "bottom" }} | ||
className="p-0! space-y-2" | ||
> | ||
{({ close }) => ( | ||
<> | ||
<div className="p-2 pb-0"> | ||
<Select selectedKey="featured"> | ||
<SelectItem id="featured">Featured fonts</SelectItem> | ||
<SelectItem id="all">All google fonts</SelectItem> | ||
</Select> | ||
</div> | ||
<CommandRoot filter={contains} className="h-72"> | ||
<div className="p-2"> | ||
<SearchField | ||
placeholder="Search" | ||
autoFocus | ||
className="w-full" | ||
/> | ||
</div> | ||
<Virtualizer layout={layout}> | ||
<ListBox | ||
selectionMode="single" | ||
selectedKeys={font ? [font] : []} | ||
onSelectionChange={(keys) => { | ||
onFontChange(([...keys][0] as string | null) ?? null); | ||
close(); | ||
}} | ||
className="p-0! h-full w-full border-0" | ||
> | ||
{[ | ||
{ title: "Sans serif", items: sansSerifFonts }, | ||
{ title: "Serif", items: serifFonts }, | ||
{ title: "Mono", items: monoFonts }, | ||
{ title: "Display", items: displayFonts }, | ||
{ title: "Handwriting", items: handwritingFonts }, | ||
].map(({ title, items }) => ( | ||
<ListBoxSection key={title} title={title}> | ||
{items.map((font) => ( | ||
<ListBoxItem | ||
key={font} | ||
id={font.trim().toLowerCase()} | ||
textValue={font} | ||
className="font-body" | ||
style={ | ||
{ | ||
"--font-body": font, | ||
} as React.CSSProperties | ||
} | ||
> | ||
{font} | ||
<FontLoaderInView font={font} /> | ||
</ListBoxItem> | ||
))} | ||
</ListBoxSection> | ||
))} | ||
</ListBox> | ||
</Virtualizer> | ||
</CommandRoot> | ||
</> | ||
)} | ||
</Dialog> | ||
</DialogRoot> | ||
</div> | ||
); | ||
}; | ||
|
||
const FontLoaderInView = ({ font }: { font: string }) => { | ||
const ref = React.useRef(null); | ||
const inView = useInView(ref); | ||
|
||
return ( | ||
<> | ||
<span ref={ref} /> | ||
{inView && <FontLoader font={font} />} | ||
</> | ||
); | ||
}; |
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.