Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/radiofrance/svelte-component-actions

A svelte action to facilitate the use of actions and action parameters on components.
https://github.com/radiofrance/svelte-component-actions

action actions component components svelte useactions

Last synced: 24 days ago
JSON representation

A svelte action to facilitate the use of actions and action parameters on components.

Awesome Lists containing this project

README

        

# svelte-component-actions

This package provides a [svelte action](https://svelte.dev/docs/svelte-action) that facilitates the use of actions and action parameters on components. It is based on what [svelte-material-ui](https://github.com/hperrin/svelte-material-ui) uses internaly for its own components.

## Install
```bash
npm install svelte-component-actions
```

## Usage

In the component you want to pass actions to :

- Expose a `use` props
- Import `useActions` from `svelte-component-actions` and add the `use` directive to the desired element as follows : `use:useActions={use}`

```html

import { useActions, type ActionArray } from "svelte-component-actions";

export let use: ActionArray = [];


Hello from MyComponent !

```

When using your component, give the `use` prop an array. Each array element can either be an action, or an array containing an action followed by its parameters.

```html

import MyComponent from "./Mycomponent.svelte"
import { myAction, myActionWithParams }

```

> ⚠️ **When updating action parameters, do not change the actions array length**