svelte icon indicating copy to clipboard operation
svelte copied to clipboard

implement svelte's actions for Components

Open TheHadiAhmadi opened this issue 3 years ago • 0 comments

one useful thing that only DOM elements supports is: actions sometimes we need to use actions for components (for example forwardEvents).

SMUI supports this using use prop.

we can write a preprocessor which change:

<Button use:action1 use:anotherAction use:forwardEvents color="red">
  Red Button
</Button>

to:

<Button use={[action1,anotherAction,forwardEvents]} color="red">
  Red Button
</Button>

then in Base component (Button.svelte) we can have use prop and pass to DOM element. ui/blob/master/packages/common/src/internal/useActions.ts)

<script>
  export let use: ActionArray[] = []

</script>
<button use:useActions(use) {color}>
  <slot/>
</button>
  • useActions is something like this

@pournasserian What do you think about this?

TheHadiAhmadi avatar Sep 23 '22 18:09 TheHadiAhmadi