|
@@ -2,7 +2,10 @@ import { z } from 'zod'
|
|
|
import { useForm } from 'react-hook-form'
|
|
import { useForm } from 'react-hook-form'
|
|
|
import { ChevronDownIcon } from '@radix-ui/react-icons'
|
|
import { ChevronDownIcon } from '@radix-ui/react-icons'
|
|
|
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { zodResolver } from '@hookform/resolvers/zod'
|
|
|
|
|
+import { fonts } from '@/config/fonts'
|
|
|
import { cn } from '@/lib/utils'
|
|
import { cn } from '@/lib/utils'
|
|
|
|
|
+import { useFont } from '@/context/font-context'
|
|
|
|
|
+import { useTheme } from '@/context/theme-context'
|
|
|
import { toast } from '@/hooks/use-toast'
|
|
import { toast } from '@/hooks/use-toast'
|
|
|
import { Button, buttonVariants } from '@/components/ui/button'
|
|
import { Button, buttonVariants } from '@/components/ui/button'
|
|
|
import {
|
|
import {
|
|
@@ -20,7 +23,7 @@ const appearanceFormSchema = z.object({
|
|
|
theme: z.enum(['light', 'dark'], {
|
|
theme: z.enum(['light', 'dark'], {
|
|
|
required_error: 'Please select a theme.',
|
|
required_error: 'Please select a theme.',
|
|
|
}),
|
|
}),
|
|
|
- font: z.enum(['inter', 'manrope', 'system'], {
|
|
|
|
|
|
|
+ font: z.enum(fonts, {
|
|
|
invalid_type_error: 'Select a font',
|
|
invalid_type_error: 'Select a font',
|
|
|
required_error: 'Please select a font.',
|
|
required_error: 'Please select a font.',
|
|
|
}),
|
|
}),
|
|
@@ -28,18 +31,25 @@ const appearanceFormSchema = z.object({
|
|
|
|
|
|
|
|
type AppearanceFormValues = z.infer<typeof appearanceFormSchema>
|
|
type AppearanceFormValues = z.infer<typeof appearanceFormSchema>
|
|
|
|
|
|
|
|
-// This can come from your database or API.
|
|
|
|
|
-const defaultValues: Partial<AppearanceFormValues> = {
|
|
|
|
|
- theme: 'light',
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
export function AppearanceForm() {
|
|
export function AppearanceForm() {
|
|
|
|
|
+ const { font, setFont } = useFont()
|
|
|
|
|
+ const { theme, setTheme } = useTheme()
|
|
|
|
|
+
|
|
|
|
|
+ // This can come from your database or API.
|
|
|
|
|
+ const defaultValues: Partial<AppearanceFormValues> = {
|
|
|
|
|
+ theme: theme as 'light' | 'dark',
|
|
|
|
|
+ font,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const form = useForm<AppearanceFormValues>({
|
|
const form = useForm<AppearanceFormValues>({
|
|
|
resolver: zodResolver(appearanceFormSchema),
|
|
resolver: zodResolver(appearanceFormSchema),
|
|
|
defaultValues,
|
|
defaultValues,
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
function onSubmit(data: AppearanceFormValues) {
|
|
function onSubmit(data: AppearanceFormValues) {
|
|
|
|
|
+ if (data.font != font) setFont(data.font)
|
|
|
|
|
+ if (data.theme != theme) setTheme(data.theme)
|
|
|
|
|
+
|
|
|
toast({
|
|
toast({
|
|
|
title: 'You submitted the following values:',
|
|
title: 'You submitted the following values:',
|
|
|
description: (
|
|
description: (
|
|
@@ -64,18 +74,20 @@ export function AppearanceForm() {
|
|
|
<select
|
|
<select
|
|
|
className={cn(
|
|
className={cn(
|
|
|
buttonVariants({ variant: 'outline' }),
|
|
buttonVariants({ variant: 'outline' }),
|
|
|
- 'w-[200px] appearance-none font-normal'
|
|
|
|
|
|
|
+ 'w-[200px] appearance-none font-normal capitalize'
|
|
|
)}
|
|
)}
|
|
|
{...field}
|
|
{...field}
|
|
|
>
|
|
>
|
|
|
- <option value='inter'>Inter</option>
|
|
|
|
|
- <option value='manrope'>Manrope</option>
|
|
|
|
|
- <option value='system'>System</option>
|
|
|
|
|
|
|
+ {fonts.map((font) => (
|
|
|
|
|
+ <option key={font} value={font}>
|
|
|
|
|
+ {font}
|
|
|
|
|
+ </option>
|
|
|
|
|
+ ))}
|
|
|
</select>
|
|
</select>
|
|
|
</FormControl>
|
|
</FormControl>
|
|
|
<ChevronDownIcon className='absolute right-3 top-2.5 h-4 w-4 opacity-50' />
|
|
<ChevronDownIcon className='absolute right-3 top-2.5 h-4 w-4 opacity-50' />
|
|
|
</div>
|
|
</div>
|
|
|
- <FormDescription>
|
|
|
|
|
|
|
+ <FormDescription className='font-manrope'>
|
|
|
Set the font you want to use in the dashboard.
|
|
Set the font you want to use in the dashboard.
|
|
|
</FormDescription>
|
|
</FormDescription>
|
|
|
<FormMessage />
|
|
<FormMessage />
|