chore: update AppearanceForm.vue

update pnpm and some deps -_-
This commit is contained in:
Sadegh Barati 2023-09-27 19:32:07 +03:30
parent 6be33b10fd
commit 1dcb74f0d6
5 changed files with 404 additions and 335 deletions

View File

@ -14,7 +14,7 @@
"dependencies": {
"@morev/vue-transitions": "^2.3.6",
"@radix-icons/vue": "^1.0.0",
"@tanstack/vue-table": "^8.10.1",
"@tanstack/vue-table": "^8.10.3",
"@unovis/ts": "^1.2.1",
"@unovis/vue": "1.3.0-alpha.3",
"@vee-validate/zod": "^4.11.7",
@ -51,7 +51,7 @@
"typescript": "^5.2.2",
"unplugin-icons": "^0.17.0",
"vite": "^4.4.9",
"vitepress": "^1.0.0-rc.13",
"vue-tsc": "^1.8.13"
"vitepress": "^1.0.0-rc.20",
"vue-tsc": "^1.8.15"
}
}

View File

@ -1,9 +1,11 @@
<script setup lang="ts">
import { ref } from 'vue'
import { useForm } from 'vee-validate'
import { toTypedSchema } from '@vee-validate/zod'
import * as z from 'zod'
import { cn } from '@/lib/utils'
import { Label } from '@/lib/registry/new-york/ui/label'
import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/lib/registry/default/ui/form'
import { Separator } from '@/lib/registry/new-york/ui/separator'
import { RadioGroup, RadioGroupItem } from '@/lib/registry/default/ui/radio-group'
import {
@ -16,12 +18,7 @@ import {
} from '@/lib/registry/new-york/ui/select'
import { Button } from '@/lib/registry/new-york/ui/button'
const appearenceForm = ref({
theme: 'light',
font: '',
})
const appearanceFormSchema = z.object({
const appearanceFormSchema = toTypedSchema(z.object({
theme: z.enum(['light', 'dark'], {
required_error: 'Please select a theme.',
}),
@ -29,21 +26,19 @@ const appearanceFormSchema = z.object({
invalid_type_error: 'Select a font',
required_error: 'Please select a font.',
}),
}))
const { handleSubmit, resetForm } = useForm({
validationSchema: appearanceFormSchema,
initialValues: {
theme: 'dark',
font: 'inter',
},
})
type AppearanceFormValues = z.infer<typeof appearanceFormSchema>
const errors = ref<z.ZodFormattedError<AppearanceFormValues> | null>(null)
async function handleSubmit() {
const result = appearanceFormSchema.safeParse(appearenceForm.value)
if (!result.success) {
errors.value = result.error.format()
console.log(errors.value)
return
}
console.log('Form submitted!', appearenceForm.value)
}
const onSubmit = handleSubmit((values, { resetForm }) => {
console.log(values)
})
</script>
<template>
@ -56,109 +51,107 @@ async function handleSubmit() {
</p>
</div>
<Separator />
<form class="space-y-8" @submit.prevent="handleSubmit">
<div class="grid gap-2">
<Label for="font" :class="cn('text-sm', errors?.font && 'text-destructive')">
Font
</Label>
<Select id="font" v-model="appearenceForm.font">
<SelectTrigger class="w-[200px]">
<SelectValue placeholder="Select a font" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem value="inter">
Inter
</SelectItem>
<SelectItem value="manrope">
Manrope
</SelectItem>
<SelectItem value="system">
System
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
<span class="text-muted-foreground text-xs">
Set the font you want to use in the dashboard.
</span>
<div v-if="errors?.font" class="text-sm text-destructive">
<span v-for="error in errors.font._errors" :key="error">{{ error }}</span>
</div>
</div>
<form class="space-y-8" @submit="onSubmit">
<FormField v-slot="{ componentField }" name="font">
<FormItem>
<FormLabel>Email</FormLabel>
<div class="relative w-[200px]">
<FormControl>
<Select v-bind="componentField">
<SelectTrigger>
<SelectValue placeholder="Select a font" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem value="inter">
Inter
</SelectItem>
<SelectItem value="manrope">
Manrope
</SelectItem>
<SelectItem value="system">
System
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
</FormControl>
</div>
<FormDescription>
Set the font you want to use in the dashboard.
</FormDescription>
<FormMessage />
</FormItem>
</FormField>
<div class="grid gap-2">
<Label for="theme" :class="cn('text-sm', errors?.theme && 'text-destructive')">
Theme
</Label>
<span class="text-muted-foreground text-xs">
Select the theme for the dashboard.
</span>
<RadioGroup
v-model="appearenceForm.theme"
default-value="light"
class="grid max-w-md grid-cols-2 gap-8 pt-2"
>
<div class="grid gap-2">
<Label class="[&:has([data-state=checked])>div]:border-primary">
<div>
<RadioGroupItem value="light" class="sr-only" />
</div>
<div class="items-center rounded-md border-2 border-muted p-1 hover:border-accent">
<div class="space-y-2 rounded-sm bg-[#ecedef] p-2">
<div class="space-y-2 rounded-md bg-white p-2 shadow-sm">
<div class="h-2 w-[80px] rounded-lg bg-[#ecedef]" />
<div class="h-2 w-[100px] rounded-lg bg-[#ecedef]" />
</div>
<div class="flex items-center space-x-2 rounded-md bg-white p-2 shadow-sm">
<div class="h-4 w-4 rounded-full bg-[#ecedef]" />
<div class="h-2 w-[100px] rounded-lg bg-[#ecedef]" />
</div>
<div class="flex items-center space-x-2 rounded-md bg-white p-2 shadow-sm">
<div class="h-4 w-4 rounded-full bg-[#ecedef]" />
<div class="h-2 w-[100px] rounded-lg bg-[#ecedef]" />
<FormField v-slot="{ componentField, value }" type="radio" name="theme">
<FormItem class-name="space-y-1">
<FormLabel>Theme</FormLabel>
<FormDescription>
Select the theme for the dashboard.
</FormDescription>
<FormMessage />
<RadioGroup
class="grid max-w-md grid-cols-2 gap-8 pt-2"
v-bind="componentField"
:default-value="value"
>
<FormItem>
<FormLabel class="[&:has([data-state=checked])>div]:border-primary">
<FormControl>
<RadioGroupItem value="light" class="sr-only" />
</FormControl>
<div class="items-center rounded-md border-2 border-muted p-1 hover:border-accent">
<div class="space-y-2 rounded-sm bg-[#ecedef] p-2">
<div class="space-y-2 rounded-md bg-white p-2 shadow-sm">
<div class="h-2 w-[80px] rounded-lg bg-[#ecedef]" />
<div class="h-2 w-[100px] rounded-lg bg-[#ecedef]" />
</div>
<div class="flex items-center space-x-2 rounded-md bg-white p-2 shadow-sm">
<div class="h-4 w-4 rounded-full bg-[#ecedef]" />
<div class="h-2 w-[100px] rounded-lg bg-[#ecedef]" />
</div>
<div class="flex items-center space-x-2 rounded-md bg-white p-2 shadow-sm">
<div class="h-4 w-4 rounded-full bg-[#ecedef]" />
<div class="h-2 w-[100px] rounded-lg bg-[#ecedef]" />
</div>
</div>
</div>
</div>
<span class="block w-full p-2 text-center font-normal">
Light
</span>
</Label>
</div>
<div>
<Label class="[&:has([data-state=checked])>div]:border-primary">
<div>
<RadioGroupItem value="dark" class="sr-only" />
</div>
<div class="items-center rounded-md border-2 border-muted bg-popover p-1 hover:bg-accent hover:text-accent-foreground">
<div class="space-y-2 rounded-sm bg-slate-950 p-2">
<div class="space-y-2 rounded-md bg-slate-800 p-2 shadow-sm">
<div class="h-2 w-[80px] rounded-lg bg-slate-400" />
<div class="h-2 w-[100px] rounded-lg bg-slate-400" />
</div>
<div class="flex items-center space-x-2 rounded-md bg-slate-800 p-2 shadow-sm">
<div class="h-4 w-4 rounded-full bg-slate-400" />
<div class="h-2 w-[100px] rounded-lg bg-slate-400" />
</div>
<div class="flex items-center space-x-2 rounded-md bg-slate-800 p-2 shadow-sm">
<div class="h-4 w-4 rounded-full bg-slate-400" />
<div class="h-2 w-[100px] rounded-lg bg-slate-400" />
<span class="block w-full p-2 text-center font-normal">
Light
</span>
</FormLabel>
</FormItem>
<FormItem>
<FormLabel class="[&:has([data-state=checked])>div]:border-primary">
<FormControl>
<RadioGroupItem value="dark" class="sr-only" />
</FormControl>
<div class="items-center rounded-md border-2 border-muted bg-popover p-1 hover:bg-accent hover:text-accent-foreground">
<div class="space-y-2 rounded-sm bg-slate-950 p-2">
<div class="space-y-2 rounded-md bg-slate-800 p-2 shadow-sm">
<div class="h-2 w-[80px] rounded-lg bg-slate-400" />
<div class="h-2 w-[100px] rounded-lg bg-slate-400" />
</div>
<div class="flex items-center space-x-2 rounded-md bg-slate-800 p-2 shadow-sm">
<div class="h-4 w-4 rounded-full bg-slate-400" />
<div class="h-2 w-[100px] rounded-lg bg-slate-400" />
</div>
<div class="flex items-center space-x-2 rounded-md bg-slate-800 p-2 shadow-sm">
<div class="h-4 w-4 rounded-full bg-slate-400" />
<div class="h-2 w-[100px] rounded-lg bg-slate-400" />
</div>
</div>
</div>
</div>
<span class="block w-full p-2 text-center font-normal">
Dark
</span>
</Label>
</div>
<div class="col-span-2">
<span v-if="errors?.theme" class="text-sm text-destructive">
<span v-for="error in errors.theme._errors" :key="error">{{ error }}</span>
</span>
</div>
</RadioGroup>
</div>
<span class="block w-full p-2 text-center font-normal">
Dark
</span>
</FormLabel>
</FormItem>
</RadioGroup>
</FormItem>
</FormField>
<div class="flex justify-start">
<Button type="submit">

View File

@ -3,6 +3,7 @@ import { ref } from 'vue'
import { FieldArray, useForm } from 'vee-validate'
import { toTypedSchema } from '@vee-validate/zod'
import * as z from 'zod'
import { Cross1Icon } from '@radix-icons/vue'
import { cn } from '@/lib/utils'
import { Input } from '@/lib/registry/new-york/ui/input'
@ -123,12 +124,8 @@ const onSubmit = handleSubmit((values, { resetForm }) => {
</FormField>
<div>
<FieldArray v-slot="{ fields, push }" name="urls">
<div v-for="(fieldq, index) in fields" :key="`urls-${fieldq.key}`">
<!-- <button type="button" @click="remove(index)">
Remove
</button> -->
<FieldArray v-slot="{ fields, push, remove }" name="urls">
<div v-for="(field, index) in fields" :key="`urls-${field.key}`">
<FormField v-slot="{ componentField }" :name="`urls[${index}].value`">
<FormItem>
<FormLabel :class="cn(index !== 0 && 'sr-only')">
@ -137,9 +134,14 @@ const onSubmit = handleSubmit((values, { resetForm }) => {
<FormDescription :class="cn(index !== 0 && 'sr-only')">
Add links to your website, blog, or social media profiles.
</FormDescription>
<FormControl>
<Input type="url" v-bind="componentField" />
</FormControl>
<div class="relative flex items-center">
<FormControl>
<Input type="url" v-bind="componentField" />
</FormControl>
<button class="absolute py-2 pe-3 end-0 text-muted-foreground" @click="remove(index)">
<Cross1Icon class="w-3" />
</button>
</div>
<FormMessage />
</FormItem>
</FormField>

View File

@ -2,7 +2,7 @@
"name": "shadcn-vue",
"version": "0.2.0",
"private": true,
"packageManager": "pnpm@8.7.6",
"packageManager": "pnpm@8.8.0",
"license": "MIT",
"repository": "radix-vue/shadcn-vue",
"workspaces": [
@ -34,9 +34,9 @@
"@commitlint/config-conventional": "^17.7.0",
"eslint": "^8.50.0",
"lint-staged": "^14.0.1",
"pnpm": "^8.7.6",
"pnpm": "^8.8.0",
"simple-git-hooks": "^2.9.0",
"taze": "^0.11.2",
"taze": "^0.11.3",
"typescript": "^5.2.2",
"vitest": "^0.34.4"
},

File diff suppressed because it is too large Load Diff