InputTime
Usage
Use the v-model directive to control the selected time.
<script setup lang="ts">
import { Time } from '@internationalized/date'
const value = shallowRef(new Time(12, 30, 0))
</script>
<template>
<PInputTime v-model="value" />
</template><script setup lang="ts">
import { shallowRef } from 'vue'
import { Time } from '@internationalized/date'
const value = shallowRef(new Time(12, 30, 0))
</script>
<template>
<PInputTime v-model="value" />
</template>Use the default-value prop to set the initial value when you do not need to control its state.
<script setup lang="ts">
import { Time } from '@internationalized/date'
const defaultValue = shallowRef(new Time(9, 45, 0))
</script>
<template>
<PInputTime :default-value="defaultValue" />
</template><script setup lang="ts">
import { shallowRef } from 'vue'
import { Time } from '@internationalized/date'
const defaultValue = shallowRef(new Time(9, 45, 0))
</script>
<template>
<PInputTime :default-value="defaultValue" />
</template>@internationalized/date package for locale-aware formatting. The time format is determined by the locale prop of the App component.@internationalized/date package for locale-aware formatting. The time format is determined by the locale prop of the App component.Range
Use the range prop to enable time range selection with start and end times.
<script setup lang="ts">
import { Time } from '@internationalized/date'
const value = shallowRef({ start: new Time(9, 0, 0), end: new Time(17, 30, 0) })
</script>
<template>
<PInputTime range v-model="value" />
</template><script setup lang="ts">
import { shallowRef } from 'vue'
import { Time } from '@internationalized/date'
const value = shallowRef({ start: new Time(9, 0, 0), end: new Time(17, 30, 0) })
</script>
<template>
<PInputTime range v-model="value" />
</template>Hour Cycle
Use the hour-cycle prop to change the hour cycle of the InputTime. Defaults to 12.
<script setup lang="ts">
import { Time } from '@internationalized/date'
const defaultValue = shallowRef(new Time(16, 30, 0))
</script>
<template>
<PInputTime :hour-cycle="24" :default-value="defaultValue" />
</template><script setup lang="ts">
import { shallowRef } from 'vue'
import { Time } from '@internationalized/date'
const defaultValue = shallowRef(new Time(16, 30, 0))
</script>
<template>
<PInputTime :hour-cycle="24" :default-value="defaultValue" />
</template>Color
Use the color prop to change the color of the InputTime.
<template>
<PInputTime color="neutral" highlight />
</template>highlight prop is used here to show the focus state. It's used internally when a validation error occurs.Variant
Use the variant prop to change the variant of the InputTime.
<template>
<PInputTime variant="subtle" />
</template>Size
Use the size prop to change the size of the InputTime.
<template>
<PInputTime size="xl" />
</template>Icon
Use the icon prop to show an Icon inside the InputTime.
<template>
<PInputTime icon="i-lucide-clock" />
</template>leading and trailing props to set the icon position or the leading-icon and trailing-icon props to set a different icon for each position.Separator Icon
Use the separator-icon prop to change the Icon of the range separator. Defaults to i-lucide-minus.
<template>
<PInputTime range separator-icon="i-lucide-arrow-right" />
</template>Avatar
Use the avatar prop to show an Avatar inside the InputTime.
<template>
<PInputTime
:avatar="{
src: 'https://github.com/vuejs.png',
loading: 'lazy'
}"
size="md"
variant="outline"
/>
</template>Disabled
Use the disabled prop to disable the InputTime.
<template>
<PInputTime disabled />
</template>Examples
Within a FormField
You can use the InputTime within a FormField component to display a label, help text, required indicator, etc.
<script setup lang="ts">
import { Time } from '@internationalized/date';
const time = shallowRef(new Time(12, 30, 0));
</script>
<template>
<PFormField
label="Time"
help="Specify the time"
required
>
<PInputTime v-model="time" />
</PFormField>
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import { Time } from '@internationalized/date';
const time = shallowRef(new Time(12, 30, 0));
</script>
<template>
<PFormField
label="Time"
help="Specify the time"
required
>
<PInputTime v-model="time" />
</PFormField>
</template>
API
Props
| Prop | Default | Type |
|---|
Slots
| Slot | Type |
|---|
Emits
| Event | Type |
|---|
Theme
export default defineAppConfig({
ui: {
inputTime: {
slots: {
base: [
'group relative inline-flex items-center rounded-md select-none',
'transition-colors'
],
leading: 'absolute inset-y-0 start-0 flex items-center',
leadingIcon: 'shrink-0 color-text-dimmed',
leadingAvatar: 'shrink-0',
leadingAvatarSize: '',
trailing: 'absolute inset-y-0 end-0 flex items-center',
trailingIcon: 'shrink-0 color-text-dimmed',
segment: [
'rounded-sm text-center outline-hidden data-[placeholder]:color-text-dimmed data-[segment=literal]:color-text-muted data-[invalid]:color-error data-[disabled]:cursor-not-allowed data-[disabled]:opacity-75',
'transition-colors'
],
separatorIcon: 'shrink-0 size-4 color-text-muted'
},
variants: {
fieldGroup: {
horizontal: 'first:not-[*:only-child]:rounded-e-none last:not-[*:only-child]:rounded-s-none not-last:not-first:rounded-none focus-visible:z-1',
vertical: 'first:not-[*:only-child]:rounded-b-none last:not-[*:only-child]:rounded-t-none not-last:not-first:rounded-none focus-visible:z-1'
},
size: {
xs: {
base: [
'px-2 py-1 text-sm/4 gap-1',
'pohon:gap-0.25'
],
leading: 'ps-2',
trailing: 'pe-2',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4',
segment: 'not-data-[segment=literal]:w-8'
},
sm: {
base: [
'px-2.5 py-1.5 text-sm/4 gap-1.5',
'pohon:gap-0.5'
],
leading: 'ps-2.5',
trailing: 'pe-2.5',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4',
segment: 'not-data-[segment=literal]:w-8'
},
md: {
base: [
'px-2.5 py-1.5 text-base/5 gap-1.5',
'pohon:gap-0.5'
],
leading: 'ps-2.5',
trailing: 'pe-2.5',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5',
segment: 'not-data-[segment=literal]:w-9'
},
lg: {
base: [
'px-3 py-2 text-base/5 gap-2',
'pohon:gap-0.75'
],
leading: 'ps-3',
trailing: 'pe-3',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5',
segment: 'not-data-[segment=literal]:w-9'
},
xl: {
base: [
'px-3 py-2 text-base gap-2',
'pohon:gap-0.75'
],
leading: 'ps-3',
trailing: 'pe-3',
leadingIcon: 'size-6',
leadingAvatarSize: 'xs',
trailingIcon: 'size-6',
segment: 'not-data-[segment=literal]:w-10'
}
},
variant: {
outline: 'color-text-highlighted bg-background ring ring-inset ring-border-accented',
soft: 'color-text-highlighted bg-background-elevated/50 hover:bg-background-elevated has-focus:bg-background-elevated disabled:bg-background-elevated/50',
subtle: 'color-text-highlighted bg-background-elevated ring ring-inset ring-border-accented',
ghost: 'color-text-highlighted bg-transparent hover:bg-background-elevated has-focus:bg-background-elevated disabled:bg-transparent dark:disabled:bg-transparent',
none: 'color-text-highlighted bg-transparent has-focus:outline-none'
},
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
leading: {
true: ''
},
trailing: {
true: ''
},
loading: {
true: ''
},
highlight: {
true: ''
},
fixed: {
false: ''
},
type: {
file: 'file:me-1.5 file:font-500 file:color-text-muted file:outline-none'
}
},
compoundVariants: [
{
color: 'primary',
variant: [
'outline',
'subtle'
],
class: 'outline-primary/25 has-focus-visible:outline-3 has-focus-visible:ring-primary'
},
{
color: 'primary',
variant: [
'soft',
'ghost'
],
class: 'outline-primary/25 has-focus-visible:outline-3'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset pohon:ring-primary'
},
{
color: 'neutral',
variant: [
'outline',
'subtle'
],
class: 'outline-border-inverted/25 has-focus-visible:outline-3 has-focus-visible:ring-border-inverted'
},
{
color: 'neutral',
variant: [
'soft',
'ghost'
],
class: 'outline-border-inverted/25 has-focus-visible:outline-3'
},
{
color: 'neutral',
highlight: true,
class: 'ring ring-inset ring-border-inverted'
},
{
leading: true,
size: 'xs',
class: 'ps-7'
},
{
leading: true,
size: 'sm',
class: 'ps-8'
},
{
leading: true,
size: 'md',
class: 'ps-9'
},
{
leading: true,
size: 'lg',
class: 'ps-10'
},
{
leading: true,
size: 'xl',
class: 'ps-11'
},
{
trailing: true,
size: 'xs',
class: 'pe-7'
},
{
trailing: true,
size: 'sm',
class: 'pe-8'
},
{
trailing: true,
size: 'md',
class: 'pe-9'
},
{
trailing: true,
size: 'lg',
class: 'pe-10'
},
{
trailing: true,
size: 'xl',
class: 'pe-11'
},
{
loading: true,
leading: true,
class: {
leadingIcon: 'animate-spin'
}
},
{
loading: true,
leading: false,
trailing: true,
class: {
trailingIcon: 'animate-spin'
}
},
{
fixed: false,
size: 'xs',
class: 'md:text-xs'
},
{
fixed: false,
size: 'sm',
class: 'md:text-xs'
},
{
fixed: false,
size: 'md',
class: 'md:text-sm'
},
{
fixed: false,
size: 'lg',
class: 'md:text-sm'
},
{
variant: 'outline',
class: {
segment: 'focus:bg-background-elevated'
}
},
{
variant: 'soft',
class: {
segment: 'focus:bg-background-accented/50 group-hover:focus:bg-background-accented'
}
},
{
variant: 'subtle',
class: {
segment: 'focus:bg-background-accented'
}
},
{
variant: 'ghost',
class: {
segment: 'focus:bg-background-elevated group-hover:focus:bg-background-accented'
}
},
{
variant: 'none',
class: {
segment: 'focus:bg-background-elevated'
}
}
],
defaultVariants: {
size: 'md',
color: 'primary',
variant: 'outline'
}
}
}
})import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from 'pohon-ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
inputTime: {
slots: {
base: [
'group relative inline-flex items-center rounded-md select-none',
'transition-colors'
],
leading: 'absolute inset-y-0 start-0 flex items-center',
leadingIcon: 'shrink-0 color-text-dimmed',
leadingAvatar: 'shrink-0',
leadingAvatarSize: '',
trailing: 'absolute inset-y-0 end-0 flex items-center',
trailingIcon: 'shrink-0 color-text-dimmed',
segment: [
'rounded-sm text-center outline-hidden data-[placeholder]:color-text-dimmed data-[segment=literal]:color-text-muted data-[invalid]:color-error data-[disabled]:cursor-not-allowed data-[disabled]:opacity-75',
'transition-colors'
],
separatorIcon: 'shrink-0 size-4 color-text-muted'
},
variants: {
fieldGroup: {
horizontal: 'first:not-[*:only-child]:rounded-e-none last:not-[*:only-child]:rounded-s-none not-last:not-first:rounded-none focus-visible:z-1',
vertical: 'first:not-[*:only-child]:rounded-b-none last:not-[*:only-child]:rounded-t-none not-last:not-first:rounded-none focus-visible:z-1'
},
size: {
xs: {
base: [
'px-2 py-1 text-sm/4 gap-1',
'pohon:gap-0.25'
],
leading: 'ps-2',
trailing: 'pe-2',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4',
segment: 'not-data-[segment=literal]:w-8'
},
sm: {
base: [
'px-2.5 py-1.5 text-sm/4 gap-1.5',
'pohon:gap-0.5'
],
leading: 'ps-2.5',
trailing: 'pe-2.5',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4',
segment: 'not-data-[segment=literal]:w-8'
},
md: {
base: [
'px-2.5 py-1.5 text-base/5 gap-1.5',
'pohon:gap-0.5'
],
leading: 'ps-2.5',
trailing: 'pe-2.5',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5',
segment: 'not-data-[segment=literal]:w-9'
},
lg: {
base: [
'px-3 py-2 text-base/5 gap-2',
'pohon:gap-0.75'
],
leading: 'ps-3',
trailing: 'pe-3',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5',
segment: 'not-data-[segment=literal]:w-9'
},
xl: {
base: [
'px-3 py-2 text-base gap-2',
'pohon:gap-0.75'
],
leading: 'ps-3',
trailing: 'pe-3',
leadingIcon: 'size-6',
leadingAvatarSize: 'xs',
trailingIcon: 'size-6',
segment: 'not-data-[segment=literal]:w-10'
}
},
variant: {
outline: 'color-text-highlighted bg-background ring ring-inset ring-border-accented',
soft: 'color-text-highlighted bg-background-elevated/50 hover:bg-background-elevated has-focus:bg-background-elevated disabled:bg-background-elevated/50',
subtle: 'color-text-highlighted bg-background-elevated ring ring-inset ring-border-accented',
ghost: 'color-text-highlighted bg-transparent hover:bg-background-elevated has-focus:bg-background-elevated disabled:bg-transparent dark:disabled:bg-transparent',
none: 'color-text-highlighted bg-transparent has-focus:outline-none'
},
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
leading: {
true: ''
},
trailing: {
true: ''
},
loading: {
true: ''
},
highlight: {
true: ''
},
fixed: {
false: ''
},
type: {
file: 'file:me-1.5 file:font-500 file:color-text-muted file:outline-none'
}
},
compoundVariants: [
{
color: 'primary',
variant: [
'outline',
'subtle'
],
class: 'outline-primary/25 has-focus-visible:outline-3 has-focus-visible:ring-primary'
},
{
color: 'primary',
variant: [
'soft',
'ghost'
],
class: 'outline-primary/25 has-focus-visible:outline-3'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset pohon:ring-primary'
},
{
color: 'neutral',
variant: [
'outline',
'subtle'
],
class: 'outline-border-inverted/25 has-focus-visible:outline-3 has-focus-visible:ring-border-inverted'
},
{
color: 'neutral',
variant: [
'soft',
'ghost'
],
class: 'outline-border-inverted/25 has-focus-visible:outline-3'
},
{
color: 'neutral',
highlight: true,
class: 'ring ring-inset ring-border-inverted'
},
{
leading: true,
size: 'xs',
class: 'ps-7'
},
{
leading: true,
size: 'sm',
class: 'ps-8'
},
{
leading: true,
size: 'md',
class: 'ps-9'
},
{
leading: true,
size: 'lg',
class: 'ps-10'
},
{
leading: true,
size: 'xl',
class: 'ps-11'
},
{
trailing: true,
size: 'xs',
class: 'pe-7'
},
{
trailing: true,
size: 'sm',
class: 'pe-8'
},
{
trailing: true,
size: 'md',
class: 'pe-9'
},
{
trailing: true,
size: 'lg',
class: 'pe-10'
},
{
trailing: true,
size: 'xl',
class: 'pe-11'
},
{
loading: true,
leading: true,
class: {
leadingIcon: 'animate-spin'
}
},
{
loading: true,
leading: false,
trailing: true,
class: {
trailingIcon: 'animate-spin'
}
},
{
fixed: false,
size: 'xs',
class: 'md:text-xs'
},
{
fixed: false,
size: 'sm',
class: 'md:text-xs'
},
{
fixed: false,
size: 'md',
class: 'md:text-sm'
},
{
fixed: false,
size: 'lg',
class: 'md:text-sm'
},
{
variant: 'outline',
class: {
segment: 'focus:bg-background-elevated'
}
},
{
variant: 'soft',
class: {
segment: 'focus:bg-background-accented/50 group-hover:focus:bg-background-accented'
}
},
{
variant: 'subtle',
class: {
segment: 'focus:bg-background-accented'
}
},
{
variant: 'ghost',
class: {
segment: 'focus:bg-background-elevated group-hover:focus:bg-background-accented'
}
},
{
variant: 'none',
class: {
segment: 'focus:bg-background-elevated'
}
}
],
defaultVariants: {
size: 'md',
color: 'primary',
variant: 'outline'
}
}
}
})
]
})