Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/melt-ui/runes

Experimenting what Melt will look like with Runes
https://github.com/melt-ui/runes

Last synced: about 2 months ago
JSON representation

Experimenting what Melt will look like with Runes

Awesome Lists containing this project

README

        

# Melt UI Runes Experiment

## Introduction

This is an experiment that aims to migrate existing Melt UI builders to runes.

EDIT: After experimenting with Runes, we're fairly confident in a API to move forward. See the [Migration plan](MIGRATION.md) for more details.

### Credits

Most of the work has been done by [Abdelrahman](https://github.com/abdel-17)!

## New API

The new API relies on classes instead of stores for creating builders.

```svelte

export let open;

const {
elements: { trigger, content, arrow },
states,
} = createTooltip({
defaultOpen: open,
onOpenChange: ({ curr, next }) => {
open = next;
return next;
},
});

$: states.open.set(open);

Trigger

{#if open}



Hello world!



{/if}
```

```svelte

let { open } = $props();

const tooltip = new Tooltip({
open: {
get: () => open,
set: (v) => (open = v),
},
});

Trigger

{#if open}



Hello world!



{/if}
```

I hear you saying "Ugh, classes". Let me explain the reasoning behind this choice:

1. They are more performant, especially with runes. No need for getters and setters for every state.
2. Destructuring makes it hard to use multiple builders in the same page because you need to rename multiple variables. This is no longer the case with the new API.

## Usage

Try out the new API yourself by cloning this repo.

```bash
git clone https://github.com/melt-ui/runes-experiment.git
```

You'll find three builders have been migrated to runes.

1. Label
2. Toggle
3. Tooltip

```ts
import { Label, Toggle, Tooltip } from "$lib/index.js";
```

You'll also find an example for each builder under the `src/routes/playground` directory.