It only takes a few lines of code to get started building components with Melt UI.
Quickstart
Melt UI exposes a number of component builders. The following code snippet demonstrates a simple
collapsible component using Melt UI's Collapsible builder.
You'll see that createCollapsible returns an object with a couple of properties. Some of these are
stores, and others are stores that return functions. The stores are used to manage the state of the
component, and the functions are used to pass arguments to the element.
Each component is different, so be sure to check out the documentation before attempting to use one.
Styling
Melt UI leaves the styling up to you. Whether you prefer scoped or global CSS, a utility framework
like TailwindCSS , or third-party components, as long as you can pass in
Melt's props, it's all good.
Animations
By passing the builder's returned props to an element, certain data and aria attributes will
automatically be added and/or altered for you. These changes can then be used for animation
purposes, should you desire to do so.
Svelte transitions can also be utilized. However, it is important to note that this may interfere with default functionality in particular components, such as focus management, so proceed with caution.
When using Svelte transitions, it is recommended to set the `forceVisible` prop to `true` to prevent
the component from being hidden while the transition is in progress.
Componentization
Usually, you'll use Melt's builders to build components. You can use them in an uncontrolled
manner, where props don't reactively affect the builder's internal state.
Or you can use them in a controlled manner, where props do affect the builder's internal state.
To get a clearer picture of the contrast between uncontrolled and controlled behavior,
read more about it here .
Builder elements as props
You can also pass down builder elements as props to other components. e.g. let's say you have a
generic Button component. You may want to pass down a trigger element from a builder to it.
Need help?
If you run into any bugs, or would like to request a feature, please feel free to
open an issue on GitHub.
You can also reach out to us on Discord if you have any questions or
just want to chat.