Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/pages/components/InputOTP.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script setup lang="ts">
import {
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
} from '@/components/input-otp'
</script>

<template>
<InputOTP :maxlength="6">
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot :index="3" />
<InputOTPSlot :index="4" />
<InputOTPSlot :index="5" />
</InputOTPGroup>
</InputOTP>
</template>
1 change: 1 addition & 0 deletions app/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export { default as Empty } from "./components/Empty.vue"
export { default as Flasher } from "./components/Flasher.vue"
export { default as Heading } from "./components/Heading.vue"
export { default as Input } from "./components/Input.vue"
export { default as InputOTP } from "./components/InputOTP.vue"
export { default as Label } from "./components/Label.vue"
export { default as Pagination } from "./components/Pagination.vue"
export { default as Popover } from "./components/Popover.vue"
Expand Down
7 changes: 7 additions & 0 deletions app/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
Flasher,
Heading,
Input,
InputOTP,
Label,
Pagination,
Popover,
Expand Down Expand Up @@ -198,6 +199,12 @@ const routes = [
component: Input,
meta: { layout: ComponentLayout, shadcn: true },
},
{
name: "Input OTP",
path: "/components/input-otp",
component: InputOTP,
meta: { layout: ComponentLayout, shadcn: true },
},
{
name: "Label",
path: "/components/label",
Expand Down
64 changes: 60 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"reka-ui": "^2.5.0",
"tailwind-merge": "^2.6.0",
"tailwindcss-animate": "^1.0.7",
"vaul-vue": "^0.4.1"
"vaul-vue": "^0.4.1",
"vue-input-otp": "^0.3.2"
},
"devDependencies": {
"@inertiajs/vue3": "^1.0.0",
Expand Down
28 changes: 28 additions & 0 deletions src/components/input-otp/InputOTP.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script setup lang="ts">
import type { HTMLAttributes } from "vue"
import type { OTPInputEmits, OTPInputProps } from "vue-input-otp"
import { reactiveOmit } from "@vueuse/core"
import { useForwardPropsEmits } from "reka-ui"
import { OTPInput } from "vue-input-otp"
import { cn } from "@/lib/utils"

const props = defineProps<OTPInputProps & { class?: HTMLAttributes["class"] }>()

const emits = defineEmits<OTPInputEmits>()

const delegatedProps = reactiveOmit(props, "class")

const forwarded = useForwardPropsEmits(delegatedProps, emits)
</script>

<template>
<OTPInput
v-slot="slotProps"
v-bind="forwarded"
:container-class="cn('flex items-center gap-2 has-disabled:opacity-50', props.class)"
data-slot="input-otp"
class="disabled:cursor-not-allowed"
>
<slot v-bind="slotProps" />
</OTPInput>
</template>
22 changes: 22 additions & 0 deletions src/components/input-otp/InputOTPGroup.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { reactiveOmit } from "@vueuse/core"
import { useForwardProps } from "reka-ui"
import { cn } from "@/lib/utils"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()

const delegatedProps = reactiveOmit(props, "class")

const forwarded = useForwardProps(delegatedProps)
</script>

<template>
<div
data-slot="input-otp-group"
v-bind="forwarded"
:class="cn('flex items-center', props.class)"
>
<slot />
</div>
</template>
21 changes: 21 additions & 0 deletions src/components/input-otp/InputOTPSeparator.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { MinusIcon } from "lucide-vue-next"
import { useForwardProps } from "reka-ui"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()

const forwarded = useForwardProps(props)
</script>

<template>
<div
data-slot="input-otp-separator"
role="separator"
v-bind="forwarded"
>
<slot>
<MinusIcon />
</slot>
</div>
</template>
32 changes: 32 additions & 0 deletions src/components/input-otp/InputOTPSlot.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { reactiveOmit } from "@vueuse/core"
import { useForwardProps } from "reka-ui"
import { computed } from "vue"
import { useVueOTPContext } from "vue-input-otp"
import { cn } from "@/lib/utils"

const props = defineProps<{ index: number, class?: HTMLAttributes["class"] }>()

const delegatedProps = reactiveOmit(props, "class")

const forwarded = useForwardProps(delegatedProps)

const context = useVueOTPContext()

const slot = computed(() => context?.value.slots[props.index])
</script>

<template>
<div
v-bind="forwarded"
data-slot="input-otp-slot"
:data-active="slot?.isActive"
:class="cn('data-[active=true]:border-ring data-[active=true]:ring-ring/50 data-[active=true]:aria-invalid:ring-destructive/20 dark:data-[active=true]:aria-invalid:ring-destructive/40 aria-invalid:border-destructive data-[active=true]:aria-invalid:border-destructive dark:bg-input/30 border-input relative flex h-9 w-9 items-center justify-center border-y border-r text-sm shadow-xs transition-all outline-none first:rounded-l-md first:border-l last:rounded-r-md data-[active=true]:z-10 data-[active=true]:ring-[3px]', props.class)"
>
{{ slot?.char }}
<div v-if="slot?.hasFakeCaret" class="pointer-events-none absolute inset-0 flex items-center justify-center">
<div class="animate-caret-blink bg-foreground h-4 w-px duration-1000" />
</div>
</div>
</template>
4 changes: 4 additions & 0 deletions src/components/input-otp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { default as InputOTP } from "./InputOTP.vue"
export { default as InputOTPGroup } from "./InputOTPGroup.vue"
export { default as InputOTPSeparator } from "./InputOTPSeparator.vue"
export { default as InputOTPSlot } from "./InputOTPSlot.vue"
5 changes: 5 additions & 0 deletions src/components/input-otp/input-otp.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("template spec", () => {
it("passes", () => {
cy.visit("/components/input-otp")
})
})
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export * from "@/components/drawer"
export * from "@/components/dropdown-menu"
export * from "@/components/empty"
export * from "@/components/input"
export * from "@/components/input-otp"
export * from "@/components/label"
export * from "@/components/pagination"
export * from "@/components/popover"
Expand Down