Tip
Now time picker works with Svelte 4 and Svelte 5 as shadcn or headless!
This project is a Svelte adaptation of the TimePickerInput component, originally built with React and Shadcn UI. The Svelte version utilizes svelte-shadcn components to provide a customizable and accessible time picker for your applications.
- Keyboard Navigation: Supports arrow key navigation for time selection.
- Date Formatting: Formats date values for display.
- Mobile Optimization: Enhances mobile keyboard interactions for time input.
Note: This component currently works only with SvelteKit projects. Attempting to set up shadcn-svelte on a Svelte project without SvelteKit may result in issues. (But you can use it as headless)
Tip
Time picker can be used without shadcn, but you should a little change code (few lines)
Before integrating the time picker component, ensure your project includes the following dependencies:
Additionally, install the necessary svelte-shadcn components:
- Input (required)
- Label (optional, for time-picker.svelte)
- Select (optional, for period selection)
- Calendar (optional, for date and time selection)
- Popover (optional, for date and time selection)
- Button (optional, for date and time selection)
-
Initialize shadcn-svelte in your SvelteKit project:
npx shadcn-svelte@latest init
Follow the prompts to configure your project. Ensure you have TypeScript and Tailwind CSS set up, as the command assumes a SvelteKit project with these configurations.
-
Add the required components:
npx shadcn-svelte@latest add input # Optional npx shadcn-svelte@latest add select label calendar popover
This command will add the specified components to your project.
-
Install additional dependencies:
npm install @internationalized/date
Ensure these packages are added to your
package.jsonand installed in your project. -
Copy main snippets
Copy
time-picker-input.svelteandtime-picker-utils.tsinto your project. (For example into$lib/components/ui/time-picker)
-
Install dependencies:
npm install @internationalized/date
Ensure these packages are added to your
package.jsonand installed in your project. -
Copy main snippets
Copy
time-picker-input.svelteandtime-picker-utils.tsinto your project. (For example into$lib/components/ui/time-picker)
After installation, you can copy snippets and use the time picker components in your Svelte files. (can be without shadcn)
Customize the component as needed to fit your application's requirements.
This component is inspired by the original TimePicker by OpenStatus and utilizes components from svelte-shadcn. Special thanks to the contributors of these projects for their excellent work.