https://github.com/danhper/phoenix-active-link
Elixir/Phoenix view helper to manage "active" state of a link
https://github.com/danhper/phoenix-active-link
Last synced: 3 months ago
JSON representation
Elixir/Phoenix view helper to manage "active" state of a link
- Host: GitHub
- URL: https://github.com/danhper/phoenix-active-link
- Owner: danhper
- License: mit
- Created: 2016-04-16T09:59:31.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-02-05T13:36:44.000Z (over 1 year ago)
- Last Synced: 2024-04-14T11:08:02.481Z (about 1 year ago)
- Language: Elixir
- Homepage: https://hex.pm/packages/phoenix_active_link
- Size: 43.9 KB
- Stars: 63
- Watchers: 1
- Forks: 25
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# phoenix-active-link
[](https://travis-ci.org/tuvistavie/phoenix-active-link)
Elixir/Phoenix helper to create links with "active" state.
## Installation
Add `phoenix_active_link` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:phoenix_active_link, "~> 0.2.1"}]
end
```## Usage
First, add
```elixir
import PhoenixActiveLink
```to the `quote` of the `view` function in your `web.ex`.
You can then use the functions as follow:
```erb
<%= active_link(@conn, "Dashboard", to: "/", active: [{Dashboard, :index}], wrap_tag: :li) %>
<%= active_link(@conn, "Users", to: "/users", wrap_tag: :li) %>
<%= active_link(@conn, to: "/users", wrap_tag: :li) do %>

<% end %>
```
If you prefer to write `PhoenixActiveLink.active_link` explicitly, you can skip
the first step.
### Example of Active Tags
To specify the active and inactive tags for the wrap tag, use `class_active` and `class_inactive`. Example:
```erb
<%= active_link(@conn, "Home", to: "/", wrap_tag: :li, class_active: "active nav-item", class_inactive: "nav-item") %>
```
*Defaults can be set in the `config.ex` as noted in the [documentation](https://hexdocs.pm/phoenix_active_link/PhoenixActiveLink.html)*
## Documentation
For more information, take a look at the [documentation](https://hexdocs.pm/phoenix_active_link/PhoenixActiveLink.html)
## Credits
This library is inspired by/ported from [active_link_to](https://github.com/comfy/active_link_to).