Git Product home page Git Product logo

hotwire-cookbook's Introduction

changes:

  • turbo-drive-confirm: custom confirm dialog with tailwind. One thing missing is modal closing when user clicks elsewhere. Cancel/Confirm no js needed. Esc close works also. Result: image
  • turbo-frame-modals: deleted unnecessary code in new/edit views. Moved the modal into a layout. Wrapped client/new in <dialog> element. Added close button that uses stimulus.

how it works:

  • turbo-drive-disable-on-submit: on submitting the form submit button is disabled, it's content changes (here it shows "Submitting..." text). Create action sleeps for 1 second.
  • turbo-frame-modals: empty turbo frame rendered in application.html.erb. Links that open the modal have data: { turbo_frame: 'modal' }. New and edit are turbo frames with forms inside. To achieve modal look styles are applied on #modal. Turbo streams are used in create and update actions for updating employees list (in create) and replacing specific employee data (in update). In the same streams files modal frame is updated with nil.

notes:

  • turbo-frame-modals: Implementation is very clear. What's missing is closing the modal with a button and ideally with clicking Esc and outside the modal. Could be added with stimulus for sure, but maybe an option to use <dialog> element and with it 2/3 above would be achieved without stimulus. Another potential thing to be improved - instead of putting <%= turbo_frame_tag "modal" %> maybe creating a layout for it would be better as it doesn't clutter application.html.erb. Maybe will try this out. Should be easily adaptable to Tailwind, but transitions could be tougher - but that's not the problem of this implementation, just overall. One additional neat thing: in controllers there's a redirect if the request isn't a turbo request, so for example /new and /edit paths put in URL just redirect to main page.

hotwire-cookbook's People

Contributors

hebiscus avatar yshmarov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.