-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: pin input * chore: build registry * chore: build registry, add form example * chore: update demo abit --------- Co-authored-by: zernonia <zernonia@gmail.com>
- Loading branch information
1 parent
b0e1b55
commit 6ab704a
Showing
16 changed files
with
406 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
title: PIN Input | ||
description: Allows users to input a sequence of one-character alphanumeric inputs. | ||
source: apps/www/src/lib/registry/default/ui/pin-input | ||
primitive: https://www.radix-vue.com/components/pin-input.html | ||
--- | ||
|
||
<ComponentPreview name="PinInputDemo" /> | ||
|
||
|
||
## Installation | ||
|
||
```bash | ||
npx shadcn-vue@latest add pin-input | ||
``` | ||
|
||
## Usage | ||
|
||
### Form | ||
|
||
<ComponentPreview name="PinInputFormDemo" /> |
28 changes: 28 additions & 0 deletions
28
apps/www/src/lib/registry/default/example/PinInputDemo.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,28 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
import { | ||
PinInput, | ||
PinInputInput, | ||
} from '@/lib/registry/default/ui/pin-input' | ||
const value = ref<string[]>([]) | ||
const handleComplete = (e: string[]) => alert(e.join('')) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<PinInput | ||
id="pin-input" | ||
v-model="value" | ||
placeholder="○" | ||
class="flex gap-2 items-center mt-1" | ||
@complete="handleComplete" | ||
> | ||
<PinInputInput | ||
v-for="(id, index) in 5" | ||
:key="id" | ||
:index="index" | ||
/> | ||
</PinInput> | ||
</div> | ||
</template> |
78 changes: 78 additions & 0 deletions
78
apps/www/src/lib/registry/default/example/PinInputFormDemo.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,78 @@ | ||
<script setup lang="ts"> | ||
import { h } from 'vue' | ||
import { useForm } from 'vee-validate' | ||
import { toTypedSchema } from '@vee-validate/zod' | ||
import * as z from 'zod' | ||
import { | ||
PinInput, | ||
PinInputInput, | ||
} from '@/lib/registry/new-york/ui/pin-input' | ||
import { Button } from '@/lib/registry/default/ui/button' | ||
import { | ||
FormControl, | ||
FormDescription, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from '@/lib/registry/default/ui/form' | ||
import { toast } from '@/lib/registry/default/ui/toast' | ||
const formSchema = toTypedSchema(z.object({ | ||
pin: z.array(z.coerce.string()).length(5, { message: 'Invalid input' }), | ||
})) | ||
const { handleSubmit, setValues } = useForm({ | ||
validationSchema: formSchema, | ||
initialValues: { | ||
pin: [], | ||
}, | ||
}) | ||
const onSubmit = handleSubmit(({ pin }) => { | ||
toast({ | ||
title: 'You submitted the following values:', | ||
description: h('pre', { class: 'mt-2 w-[340px] rounded-md bg-slate-950 p-4' }, h('code', { class: 'text-white' }, JSON.stringify(pin.join(''), null, 2))), | ||
}) | ||
}) | ||
const handleComplete = (e: string[]) => console.log(e.join('')) | ||
</script> | ||
|
||
<template> | ||
<form class="w-2/3 space-y-6 mx-auto" @submit="onSubmit"> | ||
<FormField v-slot="{ componentField }" name="pin"> | ||
<FormItem> | ||
<FormLabel>OTP</FormLabel> | ||
<FormControl> | ||
<PinInput | ||
id="pin-input" | ||
placeholder="○" | ||
class="flex gap-2 items-center mt-1" | ||
otp | ||
type="number" | ||
:name="componentField.name" | ||
@complete="handleComplete" | ||
@update:model-value="(arrStr) => { | ||
setValues({ | ||
pin: arrStr.filter(Boolean), | ||
}) | ||
}" | ||
> | ||
<PinInputInput | ||
v-for="(id, index) in 5" | ||
:key="id" | ||
:index="index" | ||
/> | ||
</PinInput> | ||
</FormControl> | ||
<FormDescription> | ||
Allows users to input a sequence of one-character alphanumeric inputs. | ||
</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
</FormField> | ||
|
||
<Button>Submit</Button> | ||
</form> | ||
</template> |
21 changes: 21 additions & 0 deletions
21
apps/www/src/lib/registry/default/ui/pin-input/PinInput.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,21 @@ | ||
<script setup lang="ts"> | ||
import { type HTMLAttributes, computed } from 'vue' | ||
import { PinInputRoot, type PinInputRootEmits, type PinInputRootProps, useForwardPropsEmits } from 'radix-vue' | ||
import { cn } from '@/lib/utils' | ||
const props = defineProps<PinInputRootProps & { class?: HTMLAttributes['class'] }>() | ||
const emits = defineEmits<PinInputRootEmits>() | ||
const delegatedProps = computed(() => { | ||
const { class: _, ...delegated } = props | ||
return delegated | ||
}) | ||
const forwarded = useForwardPropsEmits(delegatedProps, emits) | ||
</script> | ||
|
||
<template> | ||
<PinInputRoot v-bind="forwarded" :class="cn('flex gap-2 items-center', props.class)"> | ||
<slot /> | ||
</PinInputRoot> | ||
</template> |
18 changes: 18 additions & 0 deletions
18
apps/www/src/lib/registry/default/ui/pin-input/PinInputInput.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,18 @@ | ||
<script setup lang="ts"> | ||
import { type HTMLAttributes, computed } from 'vue' | ||
import { PinInputInput, type PinInputInputProps, useForwardProps } from 'radix-vue' | ||
import { cn } from '@/lib/utils' | ||
const props = defineProps<PinInputInputProps & { class?: HTMLAttributes['class'] }>() | ||
const delegatedProps = computed(() => { | ||
const { class: _, ...delegated } = props | ||
return delegated | ||
}) | ||
const forwardedProps = useForwardProps(delegatedProps) | ||
</script> | ||
|
||
<template> | ||
<PinInputInput v-bind="forwardedProps" :class="cn('flex w-10 h-10 text-center rounded-md border border-input bg-background text-sm ring-offset-background 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,2 @@ | ||
export { default as PinInput } from './PinInput.vue' | ||
export { default as PinInputInput } from './PinInputInput.vue' |
28 changes: 28 additions & 0 deletions
28
apps/www/src/lib/registry/new-york/example/PinInputDemo.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,28 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
import { | ||
PinInput, | ||
PinInputInput, | ||
} from '@/lib/registry/new-york/ui/pin-input' | ||
const value = ref<string[]>([]) | ||
function handleComplete() { | ||
console.log('212121') | ||
} | ||
</script> | ||
|
||
<template> | ||
<PinInput | ||
id="pin-input" | ||
v-model="value" | ||
placeholder="○" | ||
class="flex gap-2 items-center mt-1" | ||
@complete="handleComplete" | ||
> | ||
<PinInputInput | ||
v-for="(id, index) in 5" | ||
:key="id" | ||
:index="index" | ||
/> | ||
</PinInput> | ||
</template> |
78 changes: 78 additions & 0 deletions
78
apps/www/src/lib/registry/new-york/example/PinInputFormDemo.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,78 @@ | ||
<script setup lang="ts"> | ||
import { h } from 'vue' | ||
import { useForm } from 'vee-validate' | ||
import { toTypedSchema } from '@vee-validate/zod' | ||
import * as z from 'zod' | ||
import { | ||
PinInput, | ||
PinInputInput, | ||
} from '@/lib/registry/new-york/ui/pin-input' | ||
import { Button } from '@/lib/registry/new-york/ui/button' | ||
import { | ||
FormControl, | ||
FormDescription, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from '@/lib/registry/new-york/ui/form' | ||
import { toast } from '@/lib/registry/new-york/ui/toast' | ||
const formSchema = toTypedSchema(z.object({ | ||
pin: z.array(z.coerce.string()).length(5, { message: 'Invalid input' }), | ||
})) | ||
const { handleSubmit, setValues } = useForm({ | ||
validationSchema: formSchema, | ||
initialValues: { | ||
pin: [], | ||
}, | ||
}) | ||
const onSubmit = handleSubmit(({ pin }) => { | ||
toast({ | ||
title: 'You submitted the following values:', | ||
description: h('pre', { class: 'mt-2 w-[340px] rounded-md bg-slate-950 p-4' }, h('code', { class: 'text-white' }, JSON.stringify(pin.join(''), null, 2))), | ||
}) | ||
}) | ||
const handleComplete = (e: string[]) => console.log(e.join('')) | ||
</script> | ||
|
||
<template> | ||
<form class="w-2/3 space-y-6 mx-auto" @submit="onSubmit"> | ||
<FormField v-slot="{ componentField }" name="pin"> | ||
<FormItem> | ||
<FormLabel>OTP</FormLabel> | ||
<FormControl> | ||
<PinInput | ||
id="pin-input" | ||
placeholder="○" | ||
class="flex gap-2 items-center mt-1" | ||
otp | ||
type="number" | ||
:name="componentField.name" | ||
@complete="handleComplete" | ||
@update:model-value="(arrStr) => { | ||
setValues({ | ||
pin: arrStr.filter(Boolean), | ||
}) | ||
}" | ||
> | ||
<PinInputInput | ||
v-for="(id, index) in 5" | ||
:key="id" | ||
:index="index" | ||
/> | ||
</PinInput> | ||
</FormControl> | ||
<FormDescription> | ||
Allows users to input a sequence of one-character alphanumeric inputs. | ||
</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
</FormField> | ||
|
||
<Button>Submit</Button> | ||
</form> | ||
</template> |
21 changes: 21 additions & 0 deletions
21
apps/www/src/lib/registry/new-york/ui/pin-input/PinInput.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,21 @@ | ||
<script setup lang="ts"> | ||
import { type HTMLAttributes, computed } from 'vue' | ||
import { PinInputRoot, type PinInputRootEmits, type PinInputRootProps, useForwardPropsEmits } from 'radix-vue' | ||
import { cn } from '@/lib/utils' | ||
const props = defineProps<PinInputRootProps & { class?: HTMLAttributes['class'] }>() | ||
const emits = defineEmits<PinInputRootEmits>() | ||
const delegatedProps = computed(() => { | ||
const { class: _, ...delegated } = props | ||
return delegated | ||
}) | ||
const forwarded = useForwardPropsEmits(delegatedProps, emits) | ||
</script> | ||
|
||
<template> | ||
<PinInputRoot v-bind="forwarded" :class="cn('flex gap-2 items-center', props.class)"> | ||
<slot /> | ||
</PinInputRoot> | ||
</template> |
18 changes: 18 additions & 0 deletions
18
apps/www/src/lib/registry/new-york/ui/pin-input/PinInputInput.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,18 @@ | ||
<script setup lang="ts"> | ||
import { type HTMLAttributes, computed } from 'vue' | ||
import { PinInputInput, type PinInputInputProps, useForwardProps } from 'radix-vue' | ||
import { cn } from '@/lib/utils' | ||
const props = defineProps<PinInputInputProps & { class?: HTMLAttributes['class'] }>() | ||
const delegatedProps = computed(() => { | ||
const { class: _, ...delegated } = props | ||
return delegated | ||
}) | ||
const forwardedProps = useForwardProps(delegatedProps) | ||
</script> | ||
|
||
<template> | ||
<PinInputInput v-bind="forwardedProps" :class="cn('flex w-10 h-10 text-center rounded-md border border-input bg-background text-sm ring-offset-background 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,2 @@ | ||
export { default as PinInput } from './PinInput.vue' | ||
export { default as PinInputInput } from './PinInputInput.vue' |
Oops, something went wrong.