--- title: About description: Powered by amazing open source projects. --- ## About is a port of for Svelte/SvelteKit. It's maintained by and and has received countless contributions from the community. ## Credits - - The brilliant mind behind the designs, methodology, and implementation of the original . - - The headless components that power this project. - - The form components that power this project. - - The resizable components that power this project. - - The drawer components that power this project. - - The command menu components that power this project. - - The headless primitive component builders that power this project. - - The headless components and examples that the original was built on. - - The typography style is adapted from his work on Nextra. - - Where shad copied the styles for the first component: the `Button`. ## License MIT © & --- title: Changelog description: Latest updates and announcements. --- ## March 2024 ### Introducing Blocks are ready-made components that you can use to build your apps. They are fully responsive, accessible, and composable, meaning they are built using the same principles as the rest of the components in shadcn-svelte. only supports React at the moment, so you can't customize them like you can the original from . However, if having support for Svelte interests you, I'm sure the v0 team would love to hear about it. :) ### New Component: Breadcrumb We've added a new component to the project, .
### New Component: Scroll Area We've added a new component to the project, , which is built on top of the component from Bits UI. It supports both vertical and horizontal scrolling, and is designed to provide a consistent experience across all browsers and platforms. #### Examples
## February 2024 ### New Component: Resizable We've added a new component to the project, , which is built on top of . PaneForge is still in an early stage, so be sure to raise any issues you find with the library on the .
### Updated Icon Imports After some feedback about dev server performance, we've updated the way we import icons. With this change, we've decided to move away from the unmaintained `radix-icons-svelte` package to for the `new-york` style. Instead of importing icons like so: We now import them directly: With deep imports, we're preventing Vite from optimizing the entire icon collections, and instead only optimizing the icons that are actually used in your project. From what we've seen, this has a massive impact on dev server performance. Enjoy! 🚀 ### Major Forms Update Formsnap has been completely rewritten to be more flexible, easier to use, and less opinionated. This means we've had to make some changes to the way we use it in `shadcn-svelte`, but once you get the hang of it, you'll find it's much more powerful and less restrictive than the previous iteration. Since the changes are so significant, there isn't a direct migration path from the old version to the new version. You'll need to update your components to use the new API, as well as ensure you're using the latest version of `formsnap` and `sveltekit-superforms`. All of the `Form` components have been updated to use the new API, and you can see live examples of them on the page. Visit the documentation to learn more about the new API and how its used. ## January 2024 We've added four new components to the project, , , , & . ### New Component: Carousel We've added a new component to the project, .
### New Component: Drawer The Drawer is built on top of and is a port of , originally created by for React.
### New Component: Sonner The Sonner component is provided by , which is a Svelte port of , originally created by for React.
### New Component: Pagination Pagination leverages the component from Bits UI.
## December 2023 We've added three new components to the project, , , & . ### New Component: Calendar
### New Component: Range Calendar
### New Component: Date Picker
## November 2023 ### New Component: Toggle Group We've added a new component to the library, .
## October 2023 We've added two new components to the library, & . We've also made some updates to the `
` component that you'll want to be aware of. ### New Component: Command Command is a component that allows you to create a command palette. It's built on top of , which is a Svelte port of . The library is still in its infancy, but we're excited to see where it goes. If you notice any issues, please with the library.
Be sure to check out the docs for more information. ### New Component: Combobox Combobox is a combination of the ` ` & ` ` components. It allows you to create a searchable dropdown menu.
Be sure to check out the docs for more information. ### Updates to Form #### Form.Label Changes Since we had to make some internal changes to formsnap to fix outstanding issues, there is a slight modification we have to make to the ` ` component. The `ids` returned from `getFormField` is now a store, so we need to prefix it with `$` when we use it. ### Form.Control Formsnap introduced a new component ` ` which wraps non-traditional form elements. This allows us to ensure the components are accessible, and work well with the rest of the form components. You'll need to define & export that control in your `form/index.ts` file. ## August 2023 - Transitions & More ### Transitions To support both enter and exit transitions, we've had to move from `tailwindcss-animate` to . You can still use the `tailwindcss-animate` if you'd like, but you won't have exit transitions on most components. To get the updated transition support, be sure to upgrade to the latest version of `bits-ui`, which at the time of this writing is `0.5.0`. We now provide a custom transition `flyAndScale` ) which most components use. It's added to the `utils.ts` file when you `init` a new project. #### Migration If you're using `tailwindcss-animate` and want to migrate to the new transition system, you'll need to do the following: Update your `utils.ts` file to include the `flyAndScale` transition: Inside the components that use transitions/animations, you'll need to remove the animation classes and add the transition. Here's an example of the `AlertDialog.Content` component: If you're unsure which specific classes should be removed, you can reference the components in the to see the changes. ### Events Previous, we were using the same syntax as for events, as we were simply forwarding them. So you'd have to do `on:m-click` or `on:m-keydown`. While this isn't a huge deal, since we're using components, we decided we wanted to use the same syntax as you would for any other Svelte component. So now you can just do `on:click` or `on:keydown`. Behind the scenes, we're redispatching the event, so the contents of the event are the same, but the syntax is a bit more familiar. #### Migration To migrate to the new event syntax, you'll need to update your components that are forwarding the `m-` events. Ensure you're on the latest version of `bits-ui` before doing so. --- title: CLI description: Use the CLI to add components to your project. --- ## init Use the `init` command to initialize dependencies for a new project. The `init` command installs dependencies, adds the `cn` util, configures `tailwind.config.cjs`, and creates CSS variables for the project. You will be asked a few questions to configure `components.json`: ### Options ## add Use the `add` command to add components and dependencies to your project. You will be presented with a list of components to choose from: ### Options ## update Use the `update` command to update components in your project. This will overwrite any modifications you've made to the components, so be sure to commit your changes before running this command. ### Options ## Outgoing Requests ### Proxy This enables the use of a proxy when sending out requests to fetch from the `shadcn` registry. If the `HTTP_PROXY` or `http_proxy` environment variables have been set, the request library underneath will respect the proxy settings. --- title: components.json description: Configuration for your project. --- The `components.json` file holds configuration for your project. We use it to understand how your project is set up and how to generate components customized for your project. Note: The components.json
file is optional and **only required if you're using the CLI** to add components to your project. If you're using the copy and paste method, you don't need this file. You can create a `components.json` file in your project by running the following command: See the for more information. ## $schema You can see the JSON Schema for `components.json` . ## style The style for your components. **This cannot be changed after initialization.**
## tailwind Configuration to help the CLI understand how Tailwind CSS is set up in your project. See the for how to set up Tailwind CSS. ### tailwind.config Path to where your `tailwind.config.js` file is located. ### tailwind.css Path to the CSS file that imports Tailwind CSS into your project. ### tailwind.baseColor This is used to generate the default color palette for your components. **This cannot be changed after initialization.** ## aliases The CLI uses these values and the `alias` config from your `svelte.config.js` file to place generated components in the correct location. Path aliases have to be set up in your `svelte.config.js` file. ### aliases.utils Import alias for your utility functions. ### aliases.components Import alias for your components. ## Typescript --- title: Accordion description: A vertically stacked set of interactive headings that each reveal a section of content. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/accordion bits: https://www.bits-ui.com/docs/components/accordion ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Alert Dialog description: A modal dialog that interrupts the user with important content and expects a response. featured: true component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/alert-dialog bits: https://www.bits-ui.com/docs/components/alert-dialog ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Alert description: Displays a callout for user attention. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/alert ---
## Installation 1. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Default
### Destructive
--- title: Aspect Ratio description: Displays content within a desired ratio. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/aspect-ratio bits: https://www.bits-ui.com/docs/components/aspect-ratio ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Avatar description: An image element with a fallback for representing the user. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/avatar bits: https://www.bits-ui.com/docs/components/avatar ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Badge description: Displays a badge or a component that looks like a badge. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/badge ---
## Installation 1. Copy and paste the component source files linked at the top of this page into your project. ## Usage ### Link You can use the `badgeVariants` helper to create a link that looks like a badge. ## Examples ### Default
--- ### Secondary
--- ### Outline
--- ### Destructive
--- title: Breadcrumb description: Displays the path to the current resource using a hierarchy of links. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/breadcrumb ---
## Installation 1. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Custom separator Use a custom component in the `` of ` ` to create a custom separator.
--- ### Dropdown You can compose ` ` with a ` ` to create a dropdown in the breadcrumb.
--- ### Collapsed We provide a ` ` component to show a collapsed state when the breadcrumb is too long.
--- ### Link component To use a custom link component from your routing library, you can use the `asChild` prop on ` `.
--- ### Responsive Here's an example of a responsive breadcrumb that composes ` ` with ` `, ` `, and ` `. It displays a dropdown on desktop and a drawer on mobile.
--- title: Button description: Displays a button or a component that looks like a button. featured: true component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/button bits: https://www.bits-ui.com/docs/components/button ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ### Link You can convert the `` into an `` element by simply passing an `href` as a prop. Alternatively, you can use the `buttonVariants` helper to create a link that looks like a button. ## Examples ### Primary
--- ### Secondary
--- ### Destructive
--- ### Outline
--- ### Ghost
--- ### Link
--- ### With Icon
--- ### Icon
--- ### Loading
--- title: Calendar description: A calendar component that allows users to select dates. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/calendar bits: https://www.bits-ui.com/docs/components/calendar ---
## About The ` ` component is built on top of the component, which uses the package to handle dates. If you're looking for a range calendar, check out the component. ## Installation 1. Install `bits-ui` and `@internationalized/date`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Date Picker You can use the ` ` component to build a date picker. See the page for more information. ## Examples ### Form
## Advanced Customization The ` ` component can be combined with other components to create a more complex calendar. By default, we export the combined Calendar component as Calendar
as there are quite a few pieces that need to be combined to create it. We're modifying that component in the examples below. ### Month & Year Selects Here's an example of how you could create a calendar with month and year select dropdowns instead of the previous and next buttons.
--- title: Card description: Displays a card with header, content, and footer. featured: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/card ---
## Installation 1. Copy and paste the component source files linked at the top of this page into your project. ## Usage ### Modify the heading level By default, the `` component renders an `` element. You can change this by passing a `tag` prop to the component. For example: ... ## Examples
--- title: Carousel description: A carousel with motion and swipe built using Embla. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/carousel bits: https://www.embla-carousel.com/get-started/svelte/ ---
## About The carousel component is built using the library. ## Installation 1. Install `embla-carousel-svelte`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Sizes To set the size of the items, you can use the `basis` utility class on the ` `.
### Spacing To set the spacing between the items, we use a `pl-` utility on the ` ` and a negative `-ml-` on the ` `.
### Orientation Use the `orientation` prop to set the orientation of the carousel.
## Options You can pass options to the carousel using the `opts` prop. See the for more information. ## API Use reactive state and the `bind:api` directive to get an instance of the carousel API.
## Events You can listen to events using the api instance from `bind:api`. ## Plugins You can use the `plugins` prop to add plugins to the carousel.
See the for more information on using plugins. --- title: Checkbox description: A control that allows the user to toggle between checked and not checked. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/checkbox bits: https://www.bits-ui.com/docs/components/checkbox ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### With Text
### Disabled
### Form
--- title: Collapsible description: An interactive component which expands/collapses a panel. component: true featured: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/collapsible bits: https://www.bits-ui.com/docs/components/collapsible ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Combobox description: Autocomplete input and command palette with a list of suggestions. component: true ---
## Installation The Combobox is built using a composition of the ` ` and the ` ` components. See installation instructions for the and the components. ## Usage ## Examples ### Combobox
### Popover
### Dropdown menu
### Form Since the Combobox is built using the ` ` and the ` ` components, we need to use the ` ` component. ` ` enables us to apply the right `aria-*` attributes to non-standard form elements, and adds a hidden input to ensure the form is submitted with the correct value. Note: You must be on version `0.5.0` or higher of `formsnap` for this to work correctly.
--- title: Command description: Fast, composable, unstyled command menu for Svelte. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/command bits: https://github.com/huntabyte/cmdk-sv ---
## About The ` ` component uses the library to provide a fast, composable, unstyled command menu for Svelte. **Note:** `cmdk-sv` is a new library and is still in alpha. While I don't anticipate a ton of breaking changes, as the API aligns with the original, I want to bring this to your awareness. If you find any bugs, please with the library, rather than this project. ## Installation 1. Install `cmdk-sv` and `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Dialog
To show the command menu in a dialog, use the ` ` component instead of ` `. It accepts props for both the ` ` and ` ` components. --- title: Context Menu description: Displays a menu to the user — such as a set of actions or functions — triggered by right click. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/context-menu bits: https://www.bits-ui.com/docs/components/context-menu ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Data Table description: Powerful table and datagrids built using Svelte Headless Table. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/example/data-table-demo.svelte ---
## Introduction Data tables are difficult to componentize because of the wide variety of features they support, and the uniqueness of every data set. So instead of trying to create a one-size-fits-all solution, we've created a guide to help you build your own data tables. We'll start with the basic `` component, and work our way up to a fully-featured data table. Tip: If you find yourself using the same table in multiple places, you can always extract it into a reusable component. ## Table of Contents This guide will show you how to use and the `` component to build your own custom data table. We'll cover the following topics: - Basic Table - Row Actions - Pagination - Sorting - Filtering - Visibility - Row Selection - Reusable Components ## Installation 1. Add the `` component to your project: 2. Add `svelte-headless-table` as a dependency: ## Prerequisites We're going to build a table to show recent payments. Here's what our data looks like: ## Project Structure Start by creating a route where your data table will live , along with the following files: - `data-table.svelte` will contain the `` component all of our data table logic. - `data-table-actions.svelte` will contain the actions menu for each row. - `data-table-checkbox.svelte` will contain the checkbox for each row. - `+page.svelte` is where we'll render and access ` ` component. ## Basic Table Let's start by building a basic table. ### Get/Add Data Before we can initialize a table, we need to get our data. You can retrieve your data from anywhere, but for this example we'll use a `payments` array. ### Initialize Table Next, we'll initialize a new table using `svelte-headless-table`. ### Create Columns Now that we have a table, we can define our columns. The last column is where we'll render a menu of actions for each row. ### Create View Model & Render Table Finally, we'll create a view model which we'll use to build our table. ### Render the table Finally, we'll render our table in our `+page.svelte` file. ## Cell Formatting Now that we have a basic table, let's format the `amount` cell to display the dollar amount. We'll also align the cell to the right. ### Update columns definition First, we'll update our columns definition for the `amount` column to return a formatted string. ### Update styles Now that we're returning a formatted string, let's now align the `amount` header and cell to the right. We'll also capitalize our `status` cell values. You can use this approach to customize the styles of any cell in your table. In the following sections, we'll demonstrate how you can use a component to render a cell as well. ## Row Actions Let's now add row actions to our table. We'll use a ` ` and ` ` component for this. ### Create actions component We'll start by creating a new component called `data-table-actions.svelte` which will contain our actions menu. It's going to receive an `id` prop, which we'll use to identify and perform specific actions on the row. ### Update columns definition Now that we've defined our actions component, let's update our `actions` column definition to use it. We're just passing the `id` to our actions component, but you could pass whatever information you need to perform actions on the row. In this example, we could use the `id` to make a DELETE request to our API to delete the payment. ## Pagination Next, we'll add pagination to our table ### Enable the `addPagination` plugin ### Add pagination controls We can add pagination controls to our table using the ` ` component and the `hasNextPage`, `hasPreviousPage`, and `pageIndex` variables. See the for more information on how to customize the pagination behavior. ## Sorting Let's make the email column sortable. ### Enable the `addSortBy` plugin Let's enable the `addSortBy` plugin and import the ` ` icon which we'll use to indicate the sort option for the column. ### Make header cell sortable We can now update the `email` header cell to add sorting controls. See the for more information on how to customize the sort behavior. ## Filtering Let's add a search input to filter emails in our table. ### Enable the `addTableFilter` plugin We'll start by enabling the `addTableFilter` plugin and importing the ` ` component we'll use for the search input. We're excluding all columns except for `email` from the filter plugin, and we're using a case-insensitive filter function to match the email value. ### Add search input Now that our table is configured to filter by email, let's add a search input on top of our table. Since `filterValue` is a store, we can bind it to the input value and it will automatically update as the user types. See the for more information on how to customize the filtering behavior. ## Visibility Let's add the ability to control which columns are visible in our table. ### Enable `addHiddenColumns` plugin We'll start by enabling the `addHiddenColumns` plugin. We'll also need a ` ` icon and the ` ` component in the next step. We're setting the `hiddenColumnIds` store from the plugin whenever `hideForId` changes to reflect our newly chosen hidden/shown columns. ### Add column visibility controls Now we'll use the icon and ` ` we imported in the previous step to render a menu of columns that can be hidden. See the for more information. ## Row Selection Next, we're going to add row selection to our table. ### Create checkbox component We'll start by creating a new component called `data-table-checkbox.svelte` which will be used to render a checkbox for each row. ### Enable `addSelectedRows` plugin Next, we'll enable the `addSelectedRows` plugin and import the ` ` component we just created. ### Update styles & show selected rows To accommodate the checkbox, we'll need to update our table styles. We'll also add a message to show how many rows are selected. See the for more information on how to customize the selection behavior. --- title: Date Picker description: A date picker component with range and presets. component: true source: https://github.com/huntabyte/shadcn-svelte/blob/main/sites/docs/src/lib/registry/default/example/date-picker-demo.svelte ---
## Installation The Date Picker is built using a composition of the ` ` and either the ` ` or ` ` components. See installations instructions for the , , and components. ## Usage ## Examples ### Date Picker
### Date Range Picker
### With Presets
### Form
--- title: Dialog description: A window overlaid on either the primary window or another dialog window, rendering the content underneath inert. component: true featured: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/dialog bits: https://www.bits-ui.com/docs/components/dialog ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Drawer description: A drawer component for Svelte. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/drawer bits: https://www.vaul-svelte.com ---
## About Drawer is built on top of , which is a Svelte port of by . ## Installation 1. Install `vaul-svelte`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Responsive Dialog You can combine the `Dialog` and `Drawer` components to create a responsive dialog. This renders a `Dialog` on desktop and a `Drawer` on mobile.
--- title: Dropdown Menu description: Displays a menu to the user — such as a set of actions or functions — triggered by a button. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/dropdown-menu bits: https://www.bits-ui.com/docs/components/dropdown-menu ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Checkboxes
### Radio Group
--- title: Formsnap & Superforms description: Building forms with Formsnap, Superforms, & Zod. --- Forms are tricky. They are one of the most common things you'll build in a web application, but also one of the most complex. Well-designed HTML forms are: - Well-structured and semantically correct. - Easy to use and navigate . - Accessible with ARIA attributes and proper labels. - Has support for client and server side validation. - Well-styled and consistent with the rest of the application. In this guide, we will take a look at building forms with , and . ## Features The `Form` components offered by `shadcn-svelte` are wrappers around `formsnap` & `sveltekit-superforms` which provide a few things: - Composable components for building forms. - Form field components for scoping form state. - Form validation using or any other validation library supported by . - Applies the correct `aria` attributes to form fields based on states. - Enables you to easily use various components like , , , and other form components with forms. If you aren't familiar with & , you should check out their documentation first, as this guide assumes you have a basic understanding of how they work together. ## Anatomy ## Example ## Installation ## Usage ### Create a form schema Define the shape of your form using a Zod schema. You can read more about using Zod in the . We're going to define it in a file called `schema.ts` in the same directory as our page component, but you can put it anywhere you like. ### Return the form from the route's load function ### Create a form component For this example, we'll be passing the `form` returned from the load function as a prop to this component. To ensure it's typed properly, we'll use the `SuperValidated` type from `sveltekit-superforms`, and pass in the type of our form schema. The `name`, `id`, and all accessibility attributes are applied to the input by spreading the `attrs` object from the `Form.Control` component. The `Form.Label` will automatically be associated with the input using the `for` attribute, so you don't have to worry about that. ### Create a page component that uses the form We'll pass the `form` from the data returned from the load function to the form component we created above. ### Create an Action that handles the form submission ### Done That's it. You now have a fully accessible form that is type-safe and has client & server side validation. ## Next Steps Be sure to check out the and documentation for more information on how to use them. ## Examples See the following links for more examples on how to use the other `Form` components: - - - - - - - --- title: Hover Card description: For sighted users to preview content available behind a link. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/hover-card bits: https://www.bits-ui.com/docs/components/link-preview ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Input description: Displays a form input field or a component that looks like an input field. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/input ---
## Installation 1. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Default
### Disabled
### With Label
### With Text
### With Button
### File
### Form
--- title: Label description: Renders an accessible label associated with controls. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/label bits: https://www.bits-ui.com/docs/components/label ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Menubar description: A visually persistent menu common in desktop applications that provides quick access to a consistent set of commands. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/menubar bits: https://www.bits-ui.com/docs/components/menubar --- ## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Pagination description: Pagination with page navigation, next and previous links. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/pagination bits: https://www.bits-ui.com/docs/components/pagination ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Popover description: Displays rich content in a portal, triggered by a button. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/popover bits: https://www.bits-ui.com/docs/components/popover ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Progress description: Displays an indicator showing the completion progress of a task, typically displayed as a progress bar. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/progress bits: https://www.bits-ui.com/docs/components/progress ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Radio Group description: A set of checkable buttons—known as radio buttons—where no more than one of the buttons can be checked at a time. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/radio-group bits: https://www.bits-ui.com/docs/components/radio-group ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Form
--- title: Range Calendar description: A calendar component that allows users to select a range of dates. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/range-calendar bits: https://www.bits-ui.com/docs/components/range-calendar ---
## About The ` ` component is built on top of the component, which uses the package to handle dates. ## Installation 1. Install `bits-ui` and `@internationalized/date`: 2. Copy and paste the component source files linked at the top of this page into your project. --- title: Resizable description: Accessible resizable panel groups and layouts with keyboard support. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/resizable bits: https://paneforge.com ---
## About The `Resizable` component is built on top of by . Visit the for all the available props and abilities of the `Resizable` component. ## Installation 1. Install `paneforge`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Vertical Use the `direction` prop to set the direction of the resizable panels.
### Handle You can set or hide the handle by using the `withHandle` prop on the `ResizableHandle` component.
--- title: Scroll Area description: Augments native scroll functionality for custom, cross-browser styling. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/scroll-area bits: https://bits-ui.com/docs/components/scroll-area ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Horizontal Scrolling Set the `orientation` prop to `"horizontal"` to enable horizontal scrolling.
### Horizontal and Vertical Scrolling Set the `orientation` prop to `"both"` to enable both horizontal and vertical scrolling.
--- title: Select description: Displays a list of options for the user to pick from—triggered by a button. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/select bits: https://www.bits-ui.com/docs/components/select ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Form For more advanced usage and to learn how to implement `multiple` Select components in a form, check out the on Formsnap.
--- title: Separator description: Visually or semantically separates content. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/separator bits: https://www.bits-ui.com/docs/components/separator ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Sheet description: Extends the Dialog component to display content that complements the main content of the screen. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/sheet bits: https://www.bits-ui.com/docs/components/dialog ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Side Pass the `side` property to ` ` to indicate the edge of the screen where the component will appear. The values can be `top`, `right`, `bottom` or `left`.
--- title: Skeleton description: Use to show a placeholder while content is loading. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/skeleton ---
## Installation 1. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Slider description: An input where the user selects a value from within a given range. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/slider bits: https://www.bits-ui.com/docs/components/slider ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Sonner description: An opinionated toast component for Svelte. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/sonner ---
## About The Sonner component is provided by , which is a Svelte port of , originally created by for React. ## Installation Setup theme support By default, Sonner will use the user's system preferences to determine whether to show the light or dark theme. To get around this, you can either pass in a custom `theme` prop to the component, or simply use which you can hardcode to `dark` or `light` mode should you wish. You can learn more about setting up Dark Mode support . If you wish to opt out of Dark Mode support, you can uninstall `mode-watcher` and remove the `theme` prop from the component after installing via CLI, or manually install the component and don't include `mode-watcher` Run the following command: Add the Toaster component Note: Make sure you are adding the import from the path `"$lib/components/ui/sonner"` not `"svelte-sonner"`. 1. Install `svelte-sonner`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Switch description: A control that allows the user to toggle between checked and not checked. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/switch bits: https://www.bits-ui.com/docs/components/switch ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Form
--- title: Table description: A responsive table component. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/table ---
## Installation 1. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Tabs description: A set of layered sections of content—known as tab panels—that are displayed one at a time. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/tabs bits: https://www.bits-ui.com/docs/components/tabs ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Textarea description: Displays a form textarea or a component that looks like a textarea. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/textarea ---
## Installation 1. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Default
### Disabled
### With Label
### With Text
### With Button
### Form
--- title: Toggle Group description: A set of two-state buttons that can be toggled on or off. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/toggle-group bits: https://www.bits-ui.com/docs/components/toggle-group ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Default
### Outline
### Single
### Small
### Large
### Disabled
--- title: Toggle description: A two-state button that can be either on or off. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/toggle bits: https://www.bits-ui.com/docs/components/toggle ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage ## Examples ### Default
### Outline
### With Text
### Small
### Large
### Disabled
--- title: Tooltip description: A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it. component: true source: https://github.com/huntabyte/shadcn-svelte/tree/main/sites/docs/src/lib/registry/default/ui/tooltip bits: https://www.bits-ui.com/docs/components/tooltip ---
## Installation 1. Install `bits-ui`: 2. Copy and paste the component source files linked at the top of this page into your project. ## Usage --- title: Dark mode on Astro description: Adding dark mode to your Astro site. --- Just like in regular Svelte, we use the `class` strategy from Tailwind CSS to support dark mode toggling. See the for more information. How you add the `dark` class to the `html` element is up to you. In this guide, we'll take a look at enabling dark mode toggling with . ## Usage ### Create an inline theme script This script will, in part, keep and track the dark mode value in `localStorage` and prevent . ### Install mode-watcher ### Add the ModeWatcher component Import the `ModeWatcher` component and use it in your page with the `client:load` directive: ### Create a mode toggle Create a mode toggle on your site to toggle between light and dark mode: #### Light switch
#### Dropdown menu
### Add mode toggle to page Add the mode toggle to the page : --- title: Dark mode description: Adding dark mode to your site. --- --- title: Dark mode description: Adding dark mode to your Svelte site. --- We use the `class` strategy from Tailwind CSS to support dark mode toggling. See the for more information. How you add the ` dark` class to the `html` element is up to you. In this guide, we will take a look at enabling dark mode toggling with . ## Usage ### Install mode-watcher Start by installing `mode-watcher`: ### Add the ModeWatcher component Import the `ModeWatcher` component and use it in your root layout: ### Add a mode toggle Place a mode toggle on your site to toggle between light and dark mode. #### Light switch
#### Dropdown menu
--- title: Figma description: Every component recreated in Figma. With customizable props, typography and icons. --- The Figma UI Kit is open sourced by . ## Grab a copy https://www.figma.com/community/file/1203061493325953101 --- title: Introduction description: Re-usable components built with Bits UI, Melt UI, and Tailwind CSS. --- An unofficial, community-led port of . We are not affiliated with , but we did get his blessing before creating a Svelte version of his work. This project was born out of the need for a similar project for the Svelte ecosystem. This is **NOT** a component library. It's a collection of re-usable components that you can copy and paste or use the CLI to add to your apps. **What do you mean not a component library?** It means you do not install it as a dependency. It is not available or distributed via npm, with no plans to publish it. Pick the components you need. Use the CLI to automatically add the components, or copy and paste the code into your project and customize to your needs. The code is yours. _Use this as a reference to build your own component libraries._ ## FAQ Why not packaged as a dependency? The idea behind this is to give you ownership and control over the code, allowing you to decide how the components are built and styled. Start with some sensible defaults, then customize the components to your needs. One of the drawback of packaging the components in an npm package is that the style is coupled with the implementation. _The design of your components should be separate from their implementation._ Which frameworks are supported? This port is built to be used with Svelte/SvelteKit. Can I use this in my project? Yes. Free to use for personal and commercial projects. No attribution required. But let us know if you do use it. We'd love to see what you build with it. --- title: Astro description: How to setup shadcn-svelte in an Astro project. --- ## Setup your project ### Create project Start by creating a new Astro project: ### Configure your Astro project You will be asked a few questions to configure your project: ### Add Svelte to your project Install Svelte using the Astro CLI: Answer `Yes` to all the question prompted by the CLI when installing Svelte. ### Add TailwindCSS to your project Add Tailwind CSS using the Astro CLI: Answer `Yes` to all the question prompted by the CLI when installing Svelte. ### Setup path aliases Add the following code to the `tsconfig.json` file to resolve paths: If needed, adapt the path aliases to your specific needs ). ### Create a global CSS file Create the global stylesheet in `src/styles/app.css`: ### Import the global CSS file Import the `app.css` file in the `src/pages/index.astro` file: ### Run the CLI Run the `shadcn-svelte` init command to setup your project: ### Configure components.json You will be asked a few questions to configure `components.json`: ### Update Astro's Tailwind config To prevent serving the Tailwind base styles twice, we need to tell Astro not to apply the base styles, since we already include them in our own `app.css` file. To do this, set the `applyBaseStyles` config option for the tailwind plugin in `astro.config.mjs` to `false`. ### Update tailwind.config.mjs When running `shadcn-svelte@latest init`, your Tailwind config for content will be overwritten. To fix this, add `astro` as one of the options inside of `content`: ### That's it You can now start adding components to your project. The command above will add the `Button` component to your project. You can then import it like this: Remember to use the `client` directives inside `.astro` files when dealing with interactive components ). --- title: Installation description: How to install dependencies and structure your app. --- ## Guides SvelteKit
Astro
Vite
Manual
## Imports Unlike the original for React, where the full components can exist in a single file, components in this port are split into multiple files. This is because Svelte doesn't support defining multiple components in a single file, so utilizing the CLI to add components will be the optimal approach. The CLI will create a folder for _each_ component, which will sometimes just contain a single Svelte file, and in other times, multiple files. Within each folder, there will be an `index.ts` file that exports the component, so you can import them from a single file. For example, the Accordion component is split into four `.svelte` files: - `Accordion.svelte` - `AccordionContent.svelte` - `AccordionItem.svelte` - `AccordionTrigger.svelte` They can then be imported from the `accordion/index.ts` file like so: Regardless of the import approach you take, the components will be tree-shaken by Rollup, so you don't have to worry about unused components being bundled into your app. ## TypeScript This project and the components are written in TypeScript. We recommend using TypeScript for your project as well. However, we provide a JavaScript version of the components as well. The JavaScript version is _only_ available via the . ### Opt-out of TypeScript To opt out of TypeScript, set the `typescript` flag to `false` in your `components.json` file. To configure import aliases, create a `jsconfig.json` file: ## ESLint configuration If you are using ESLint, some components may trigger false positives depending on your ESLint configuration. For example, you could end up with lint errors when components define `$$Props` to specify the type for `$$restProps` as `$$Props` is not directly used in the rest of the component. To ignore these linting errors, you can modify your ESLint configuration. One option is to add a `.eslintrc` file in the directory where you define your components, `$lib/components/ui` for example: The main benefit of adding an additional `.eslintrc` file just to `$lib/components/ui` is that you will not affect how ESLint functions for the rest of your project. Only your `shadcn-svelte` components will ignore these false positives. If this is not important to you, then another option is to use a similar rule override in your global ESLint configuration file, usually `.eslintrc.cjs`. For inspiration, please refer to . If your global ESLint configuration is using the or you would like to migrate to the flat config format you could add another rule block in your `eslint.config.js` for example: ## VSCode extension Install the shadcn-svelte by in Visual Studio Code to easily add Shadcn Svelte components to your project. This extension offers a range of features: - Ability to initialize the shadcn-svelte CLI - Add components to your project - Navigate to a specific component's documentation page directly from your IDE - Handy snippets for quick component imports and markup ## JetBrains IDEs extension Install the shadcn/ui Components Manager by in any JetBrains IDE to easily manage shadcn components within your project. This extension offers a range of features, including: - Automatically detect shadcn/ui components in your project - Instantly add, remove, and update them with a single click - Supports all shadcn/ui implementations: Svelte, React, Vue, and Solid - Easily search for remote or existing components --- title: Manual Installation description: How to setup shadcn-svelte manually. --- ## Setup your project ### Add Tailwind Use the Svelte CLI to add Tailwind CSS to your project. ### Add dependencies Add the following dependencies to your project: ### Add icon library If you're using the `default` style, install `lucide-svelte`: If you're using the `new-york` style, install `svelte-radix`: ### Configure path aliases If you are using SvelteKit and are not using the default alias `$lib`, you'll need to update your `svelte.config.js` file to include those aliases. If you are _not_ using SvelteKit, then you'll need to update your path aliases in your `tsconfig.json` and `vite.config.ts`. ### Configure tailwind.config.js This is what this project's `tailwind.config.js` file looks like: Feel free to add or modify as needed to suit your project. ### Configure styles Add the following to your `src/app.pcss` file. You can learn more about using CSS variables for theming in the . ### Configure utils You'll want to create a `cn` helper to make it easier to conditionally add Tailwind CSS classes. Additionally, you'll want to add the custom transition that is used by various components. ### Import styles to your app Create `src/routes/+layout.svelte` and import the styles: ### That's it You can now start adding components to your project. --- title: SvelteKit description: How to setup shadcn-svelte in a SvelteKit project. --- ## Setup your project ### Create project Use the SvelteKit CLI to create a new project. ### Add TailwindCSS Use the Svelte CLI to add Tailwind CSS to your project. ### Setup path aliases If you are not using the default alias `$lib`, you'll need to update your `svelte.config.js` file to include those aliases. ### Run the CLI ### Configure components.json You will be asked a few questions to configure `components.json`: ### That's it You can now start adding components to your project. The command above will add the `Button` component to your project. You can then import it like this: --- title: Vite description: How to setup shadcn-svelte in a Vite project. --- ## Setup your project ### Add TailwindCSS Use the Svelte CLI to add Tailwind CSS to your project. ### Setup path aliases Update your path aliases in your `tsconfig.json` and `vite.config.ts`. ### Run the CLI ### Configure components.json You will be asked a few questions to configure `components.json`: ### That's it You can now start adding components to your project. The command above will add the `Button` component to your project. You can then import it like this: --- title: Theming description: Use CSS Variables to customize the look and feel of your application. --- We use CSS variables for styling. This allows you to easily change the colors of components without having to update class names. **CSS variables must be defined without the color space function**. See the for more information. ## Hex -> Color Channel You can use this tool to convert your HEX color to HSL without the color space function. Simply add your color in hex format, copy one of the generated values, then add them to the CSS variable. ## Convention We use a simple `background` and `foreground` convention for colors. The `background` variable is used for the background color of the component and the `foreground` variable is used for the text color. The `background` suffix can be omitted if the variable is used for the background color of the component. Given the following CSS variables: The `background` color of the following component will be `hsl / )` and the `foreground` color will be `hsl / )`. ## CSS Variables Here's the list of variables available for customization: ## Default The following is the default color palette used by the components. --- title: Typography description: Styles for headings, paragraphs, lists...etc component: true ---
## h1
## h2
## h3
## h4
## p
## blockquote
## table
## list
## Inline code
## Lead
## Large
## Small
## Muted