Fl4m3Ph03n1x
Background
I have app.html.heex with a top bar that I got from TailwinUI : Tailwind CSS Stacked Layouts - Official Tailwind UI Components
However, I see in the notes and comments that I need JS for this:
<!--
Dropdown menu, show/hide based on menu state.
Entering: "transition ease-out duration-100"
From: "transform opacity-0 scale-95"
To: "transform opacity-100 scale-100"
Leaving: "transition ease-in duration-75"
From: "transform opacity-100 scale-100"
To: "transform opacity-0 scale-95"
-->
<div class="absolute right-0 z-10 mt-2 w-48 origin-top-right rounded-md bg-white py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none" role="menu" aria-orientation="vertical" aria-labelledby="user-menu-button" tabindex="-1">
<!-- Active: "bg-gray-100", Not Active: "" -->
<a href="#" class="block px-4 py-2 text-sm text-gray-700" role="menuitem" tabindex="-1" id="user-menu-item-0">Your Profile</a>
<a href="#" class="block px-4 py-2 text-sm text-gray-700" role="menuitem" tabindex="-1" id="user-menu-item-2">Sign out</a>
</div>
I though I didn’t need to use JS directly on Phoenix 1.7.
- Is there a way to have the menu drop and lift when clicked without using JS?
- If I do have to use JS directly, where would I put it?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
polypush135
Have a look at the LiveView JS module.
Here’s an example where there is a show/hide modal.
https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/components/core_components.ex#L338-L353
Edit: Also as to the “I thought I don’t need JS in Liveview”
While you can do a great deal without JS I would not recommend trying to avoid JS.
That said, the way you interface with JS is much different if you choose to use the Liveview JS module.
But by no means are you limited to just using the Liveview JS modules.
I would spend a little time reading this JavaScript interoperability — Phoenix LiveView v1.2.5
Fl4m3Ph03n1x
Given this code is in
app.html.heexwhere would I put theshow_hide_modalfunction? In which module?polypush135
I would read how they do it in that example I show for live beats.
They also have the modal in the main layout too.
They even did a good job describing the fact this was in the layout and they use send_update as a way to talk with said component.
Honestly just spend a good amount of time just reading and trying to understand how they got the modal to work and it will answer your question.
Fl4m3Ph03n1x
I apologize but reading code I can barely understand is not productive for me when learning a new technology.
This is mainly why I mostly focus on tutorials, guides and the community to ask guidance.
I understand you are not like me, I am happy for you. I would really appreciate if you could point me in another direction.
polypush135
My apologizes,
I realize I’m asking you to do the hard longer path.
I will only say it will be just that much more rewarding if you keep with it.
I believe that while it maybe hard to understand at first, I too took a long time and many re readings of this code before I understood it too.
I just would hate to think what you will be missing out on if you don’t try to push past the hard part.
And honestly try and get as far as you can, then come back with more questions. I will be waiting and willing to help and so are others here.
In other words you can’t rush this stuff. There is no easy ticket to learning this.
My best advice, read the Liveview documentation on top of using the LiveBeats as a starting point.
Or even just generate a basic scaffold app, it too has many great and closely resembling examples.
So all that said.
#1 you are trying to access a liveview component at the layout level.
You need to take this into consideration as most liveview components are children of a main liveview component. Thus the send_update function maybe a needed thing to learn.
#2 Look at how the LiveView JS module works. It has the transformation options you are looking for.
#3 Embrace vanilla JS and ES6 standards you will still need these and the more you learn the easier it will be to understand what benefits LiveView is giving you.
Fl4m3Ph03n1x
I see in the documentation examples we have
JS.hideandJS.show, but I was not able to find aJS.toggleoption or similar.Given the sample:
Will hide the item if it is visible and do nothing if its not (makes sense given the function’s name). Is there a function/way that I am missing that shows/hides the components?
I take from LiveBeats that when showing a dropdown I must add a class that tells me it is expanded:
But I wonder if there is a another way of doing it.
Fl4m3Ph03n1x
After further studying LiveBeats and docs, I was able to come up with something that works:
This will show the item when the button is clicked and hide it when you click away. If you click the button while the item is visible, nothing happens.
I understand that if I want more custom behaviour I can add it in
components/core_componentslike in the Project @polypush135 suggested.polypush135