Giter Site home page Giter Site logo

active-link's Introduction

Active Link

A Svelte Action that lets you style links. Use it on a wrapping element. It targets all <a>-tags inside it and add data-attributes to links inside the wrapping element.

Why it's awesome:

  • Does not think /carbon is a descendant of /car
  • Let's you style both the active link, it's descendants and it's ancestors.

Installation

pnpm add --save-dev npm i @fabianmossberg/active-link

Usage

Import the action and it on an element wrapping the links.

<script lang="ts">
    import { activeLink } from '@fabianmossberg/active-link';
</script>

<ul use:activeLink>
	<li><a href="/">Home</a></li>
	<li>
		<a href="/a">A</a>
		<ul>
			<li><a href="/a/aa">AA</a></li>
		</ul>
	</li>
	<li><a href="/b">B</a></li>
	<li><a href="/car">Car</a></li>
	<li><a href="/car/tesla">Tesla</a></li>
	<li><a href="/carbon">Carbon</a></li>
	<li><a href="/b" data-never-active>B</a></li>
</ul>

Style it with css

/* Will be applied the active link as well as it's descendant and ancestors */
[data-active] {
    background-color: yellow;
}

/* Will be applied to the active link */
[data-active="active"] {
    color: black;
	border:2px solid red;
    font-weight: 900;
}

/* Will be applied to links that are ancestors of the active link. */
[data-active="ancestor"] {
    color: rgb(172, 86, 52);
}

/* Will be applied to links that are decendants of the active link. */
[data-active="descendant"] {
    color: rgb(55, 84, 211);
}

active-link's People

Contributors

fabianmossberg avatar

Watchers

James Cloos avatar  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.