You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to implement a time picker and there was no component for it, the recently added number field wasn't what I was looking for so I did a little search and found
It's an open source implementation using shadcn/ui for react with a simple <Input/> component so I modify it for shadcn/vue.
I succeeded and here I'm sharing the component to see if it helps someone or maybe if it gets integrated with the library itself, specially at the calendar component.
To make it work we need to follow the same steps from the openstatus component, that is:
Install shadcn including the Input component (twelve-hour clocks also need the Select component)
The authors intented to have a single Input component that will work for both hours and minutes and if its hours it could be 12 or 24 hours with arrow controls cycling if you exceeded the maximum
Several changes were made, specially the part of [date, setDate] from react that is now a v-model:date.
And the emits for the onFocusRight and left. You can compare it with the original.
There's a lot of room for improvement so feel free to change anything
(Still following the time.openstatus.dev tutorial) Define your TimePicker component (e.g. time-picker-demo.tsx)
For this step I made a general component called time-picker.vue that you can consume as
<TimePickerwith-secondswith-periodwith-labelsv-model:date="date"
/>
const date = ref(new Date());
With those props, the default is 24 hours and minutes (no seconds nor period). I decided to make it opt-in since I considered the default to be that.
Describe the feature
Hello everyone,
I wanted to implement a time picker and there was no component for it, the recently added number field wasn't what I was looking for so I did a little search and found
https://time.openstatus.dev/
It's an open source implementation using shadcn/ui for react with a simple
<Input/>
component so I modify it for shadcn/vue.I succeeded and here I'm sharing the component to see if it helps someone or maybe if it gets integrated with the library itself, specially at the calendar component.
To make it work we need to follow the same steps from the openstatus component, that is:
Install shadcn including the
Input
component (twelve-hour clocks also need theSelect
component)Copy & paste
time-picker-utils.tsx
(inside@/components/ui/time-picker
)This step stays the same but you need to change the extension to
.ts
instead of.tsx
(its just a typescript file)time-picker-input.tsx
Alright so here's my edited component that I saved as
time-picker-input.vue
The authors intented to have a single Input component that will work for both hours and minutes and if its hours it could be 12 or 24 hours with arrow controls cycling if you exceeded the maximum
Several changes were made, specially the part of [date, setDate] from react that is now a v-model:date.
And the emits for the onFocusRight and left. You can compare it with the original.
There's a lot of room for improvement so feel free to change anything
time-picker-demo.tsx
)For this step I made a general component called
time-picker.vue
that you can consume asWith those props, the default is 24 hours and minutes (no seconds nor period). I decided to make it opt-in since I considered the default to be that.
Here's the component
Overall this is the folder structure I added to
@/components/ui
time-picker
├── index.ts
├── time-picker-input.vue
├── time-picker-utils.ts
└── time-picker.vue
Hope this helps someone
Additional information
The text was updated successfully, but these errors were encountered: