-
Notifications
You must be signed in to change notification settings - Fork 0
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
25 changed files
with
517 additions
and
1 deletion.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 @@ | ||
<script lang="ts" setup> | ||
import { Slot } from 'radix-vue' | ||
import { useFormField } from './useFormField' | ||
const { error, formItemId, formDescriptionId, formMessageId } = useFormField() | ||
</script> | ||
|
||
<template> | ||
<Slot | ||
:id="formItemId" | ||
:aria-describedby="!error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`" | ||
:aria-invalid="!!error" | ||
> | ||
<slot /> | ||
</Slot> | ||
</template> |
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,20 @@ | ||
<script lang="ts" setup> | ||
import type { HTMLAttributes } from 'vue' | ||
import { useFormField } from './useFormField' | ||
import { cn } from '@/lib/utils' | ||
const props = defineProps<{ | ||
class?: HTMLAttributes['class'] | ||
}>() | ||
const { formDescriptionId } = useFormField() | ||
</script> | ||
|
||
<template> | ||
<p | ||
:id="formDescriptionId" | ||
:class="cn('text-sm text-muted-foreground', props.class)" | ||
> | ||
<slot /> | ||
</p> | ||
</template> |
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,25 @@ | ||
<script lang="ts"> | ||
import type { HTMLAttributes, InjectionKey } from 'vue' | ||
export const FORM_ITEM_INJECTION_KEY | ||
= Symbol() as InjectionKey<string> | ||
</script> | ||
|
||
<script lang="ts" setup> | ||
import { provide } from 'vue' | ||
import { useId } from 'radix-vue' | ||
import { cn } from '@/lib/utils' | ||
const props = defineProps<{ | ||
class?: HTMLAttributes['class'] | ||
}>() | ||
const id = useId() | ||
provide(FORM_ITEM_INJECTION_KEY, id) | ||
</script> | ||
|
||
<template> | ||
<div :class="cn('space-y-2', props.class)"> | ||
<slot /> | ||
</div> | ||
</template> |
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,23 @@ | ||
<script lang="ts" setup> | ||
import type { HTMLAttributes } from 'vue' | ||
import type { LabelProps } from 'radix-vue' | ||
import { useFormField } from './useFormField' | ||
import { cn } from '@/lib/utils' | ||
import { Label } from '@/components/ui/label' | ||
const props = defineProps<LabelProps & { class?: HTMLAttributes['class'] }>() | ||
const { error, formItemId } = useFormField() | ||
</script> | ||
|
||
<template> | ||
<Label | ||
:class="cn( | ||
error && 'text-destructive', | ||
props.class, | ||
)" | ||
:for="formItemId" | ||
> | ||
<slot /> | ||
</Label> | ||
</template> |
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,16 @@ | ||
<script lang="ts" setup> | ||
import { ErrorMessage } from 'vee-validate' | ||
import { toValue } from 'vue' | ||
import { useFormField } from './useFormField' | ||
const { name, formMessageId } = useFormField() | ||
</script> | ||
|
||
<template> | ||
<ErrorMessage | ||
:id="formMessageId" | ||
as="p" | ||
:name="toValue(name)" | ||
class="text-sm font-medium text-destructive" | ||
/> | ||
</template> |
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,6 @@ | ||
export { Form, Field as FormField } from 'vee-validate' | ||
export { default as FormItem } from './FormItem.vue' | ||
export { default as FormLabel } from './FormLabel.vue' | ||
export { default as FormControl } from './FormControl.vue' | ||
export { default as FormMessage } from './FormMessage.vue' | ||
export { default as FormDescription } from './FormDescription.vue' |
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,30 @@ | ||
import { FieldContextKey, useFieldError, useIsFieldDirty, useIsFieldTouched, useIsFieldValid } from 'vee-validate' | ||
import { inject } from 'vue' | ||
import { FORM_ITEM_INJECTION_KEY } from './FormItem.vue' | ||
|
||
export function useFormField() { | ||
const fieldContext = inject(FieldContextKey) | ||
const fieldItemContext = inject(FORM_ITEM_INJECTION_KEY) | ||
|
||
const fieldState = { | ||
valid: useIsFieldValid(), | ||
isDirty: useIsFieldDirty(), | ||
isTouched: useIsFieldTouched(), | ||
error: useFieldError(), | ||
} | ||
|
||
if (!fieldContext) | ||
throw new Error('useFormField should be used within <FormField>') | ||
|
||
const { name } = fieldContext | ||
const id = fieldItemContext | ||
|
||
return { | ||
id, | ||
name, | ||
formItemId: `${id}-form-item`, | ||
formDescriptionId: `${id}-form-item-description`, | ||
formMessageId: `${id}-form-item-message`, | ||
...fieldState, | ||
} | ||
} |
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,24 @@ | ||
<script setup lang="ts"> | ||
import type { HTMLAttributes } from 'vue' | ||
import { useVModel } from '@vueuse/core' | ||
import { cn } from '@/lib/utils' | ||
const props = defineProps<{ | ||
defaultValue?: string | number | ||
modelValue?: string | number | ||
class?: HTMLAttributes['class'] | ||
}>() | ||
const emits = defineEmits<{ | ||
(e: 'update:modelValue', payload: string | number): void | ||
}>() | ||
const modelValue = useVModel(props, 'modelValue', emits, { | ||
passive: true, | ||
defaultValue: props.defaultValue, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<input v-model="modelValue" :class="cn('flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50', props.class)"> | ||
</template> |
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 { default as Input } from './Input.vue' |
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,27 @@ | ||
<script setup lang="ts"> | ||
import { type HTMLAttributes, computed } from 'vue' | ||
import { Label, type LabelProps } from 'radix-vue' | ||
import { cn } from '@/lib/utils' | ||
const props = defineProps<LabelProps & { class?: HTMLAttributes['class'] }>() | ||
const delegatedProps = computed(() => { | ||
const { class: _, ...delegated } = props | ||
return delegated | ||
}) | ||
</script> | ||
|
||
<template> | ||
<Label | ||
v-bind="delegatedProps" | ||
:class=" | ||
cn( | ||
'text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70', | ||
props.class, | ||
) | ||
" | ||
> | ||
<slot /> | ||
</Label> | ||
</template> |
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 { default as Label } from './Label.vue' |
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,15 @@ | ||
<script setup lang="ts"> | ||
import type { SelectRootEmits, SelectRootProps } from 'radix-vue' | ||
import { SelectRoot, useForwardPropsEmits } from 'radix-vue' | ||
const props = defineProps<SelectRootProps>() | ||
const emits = defineEmits<SelectRootEmits>() | ||
const forwarded = useForwardPropsEmits(props, emits) | ||
</script> | ||
|
||
<template> | ||
<SelectRoot v-bind="forwarded"> | ||
<slot /> | ||
</SelectRoot> | ||
</template> |
Oops, something went wrong.