Skip to content

Implementing Modal #444

Answered by MJPawluk
nlmf123 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi nlmf123!

I used bulma.io which has a modal component. To activate the component you have to add is-active to the class attribute of the modal.

For the .py file of the component I did something like this:

# modal.py
from django_unicorn.components import UnicornView


class ModalView(UnicornView):
    is_active = ""

    def toggle_modal(self):
        if self.is_active == "":
            self.is_active = "is-active"
        else:
            self.is_active = ""

And in the .html file for the component:

<!-- modal.html -->
<div>
  <button unicorn:click="toggle_modal()"></button>
    
  <div class="modal {{ is_active }}">
          <!-- Modal contents here -->
  </div>
</div>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by adamghill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants