marcoroth / turbo-morph

Morph action for Turbo Streams
MIT License
96 stars 1 forks source link
hotwire hotwired morphdom turbo turbo-stream turbo-streams

Turbo Morph

NPM Version NPM Downloads NPM Bundle Size

## Getting Started `turbo-morph` is a [morphdom](https://github.com/patrick-steele-idem/morphdom) integration for [Turbo Streams](https://turbo.hotwired.dev/reference/streams). It provides a new Turbo Stream `morph` action. **Note:** Requires Turbo **7.2+** ```bash yarn add turbo-morph ``` ```diff // application.js import * as Turbo from '@hotwired/turbo' +import TurboMorph from 'turbo-morph' +TurboMorph.initialize(Turbo.StreamActions) ``` ## Example ```html ``` ### `children-only` option [`morphdom` exposes a `childrenOnly` option](https://github.com/patrick-steele-idem/morphdom#morphdomfromnode-tonode-options--node) that can be passed to a morph call. With Turbo Streams you can apply this option by adding the `[children-only]` attribute to your `` element. ```html ... ``` ## Usage with Rails The [`turbo_power-rails`](https://github.com/marcoroth/turbo_power-rails) gem ships a Rails helper for using `turbo_stream.morph` in your application. Check out the Getting Started section over there. ## Acknowledgments tubro-morph is [MIT-licensed](LICENSE) open-source software from [Marco Roth](https://github.com/marcoroth). Turbo is [MIT-licensed](https://github.com/hotwired/turbo/blob/main/MIT-LICENSE) open-source software from [Basecamp](https://basecamp.com/). morphdom is [MIT-licensed](https://github.com/patrick-steele-idem/morphdom/blob/master/LICENSE) open-source software from [Patrick Steele-Idem](https://github.com/patrick-steele-idem)