Code Monkey home page Code Monkey logo

phoenix-active-link's Introduction

phoenix-active-link

Build Status

Elixir/Phoenix helper to create links with "active" state.

Installation

Add phoenix_active_link to your list of dependencies in mix.exs:

def deps do
  [{:phoenix_active_link, "~> 0.2.1"}]
end

Usage

First, add

import PhoenixActiveLink

to the quote of the view function in your web.ex.

You can then use the functions as follow:

<header>
  <ul>
    <%= 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 %>
      <img src="foo.png">
    <% end %>
  </ul>
</header>

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:

<%= 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

Documentation

For more information, take a look at the documentation

Credits

This library is inspired by/ported from active_link_to.

phoenix-active-link's People

Contributors

artemgordinskiy avatar cdesch avatar danhper avatar jsteiner avatar lustrousgorilla avatar maennchen avatar matsa59 avatar mdlkxzmcp avatar robinvdvleuten avatar zwippie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

phoenix-active-link's Issues

It doesn't work like the README says

If I use active_link by it's own I get undefined function active_link/3.
However it works if I specify the mondule name PhoenixActiveLink.active_link.
Is there any missing step?

Add ability to set different tags for wrapper vs link

Bootstrap expects active links like this

<li class="nav-item active">
  <a class="nav-link" href="/about">About</a>
</li>

But when you set the active tag like this

<%= active_link(@conn, "About", to: page_path(@conn, :about), wrap_tag: :li, class_active: "active nav-item", class_inactive: "nav-item") %>

The output isn't correct. I want apply nav-link to the inner link and no other classes.

<li class="active nav-item">
  <a class="active nav-item" href="/about">About</a>
</li>

Pass options forward to link

I have a use case where I need to set some attributes on an active_link.

At the moment, phoenix-active-link doesn't pass these options forward to link.

Cannot deps.get

Trying to install, but getting this error:

Failed to use "phoenix_html" (version 3.2.0) because
phoenix_active_link (version 0.2.1) requires ~> 2.10
phoenix_ecto (version 4.4.0) requires ~> 2.14.2 or ~> 3.0
phoenix_live_view (version 0.17.9) requires ~> 3.1
mix.lock specifies 3.2.0

running phoenix 1.6.7

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.