question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Theming support via classes?

See original GitHub issue

It doesn’t seem like <Link/> class tag is working? If not, are there other ways to theme <Link/>?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
EmilTholincommented, May 19, 2020

Hi @kamiyaa!

Like @ronvdberkmortel pointed out the getProps prop function is used to give the underlying anchor tag custom attributes, but I will have to consider if all the extra props on the Link should be spread on the anchor tag as well for simplicity’s sake. I’m not quite sure if there are any drawbacks to that at the moment, but I will look into it.

1reaction
ronvdberkmortelcommented, Apr 29, 2020

I had the same problem and ended up using a NavLink component to add the relevant classes. Props to Emil for the package and the example that provided the base code. Since I am using Bootstrap 4 in combination with svelte-routing, I wanted to add the base nav-link class and conditionally add the active class.

components/NavLink.svelte

<script>
  import { Link } from "svelte-routing";

  export let to = "";

  function getProps({ location, href, isPartiallyCurrent, isCurrent }) {
    const isActive = href === "/" ? isCurrent : isPartiallyCurrent || isCurrent;

    // The object returned here is spread on the anchor element's attributes
    if (isActive) {
      return { class: "nav-link active" };
    }
    return { class: "nav-link" };
  }
</script>

<Link {to} {getProps}>
  <slot />
</Link>

App.svelte

  import NavLink from "./components/NavLink.svelte";
  ...
          <li class="nav-item">
            <NavLink to="/">Home</NavLink>
          </li
  ...

Hopefully this is useful to you and other users of the package.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A guide to theming in CSS - LogRocket Blog
This tutorial shows you how to create apps that are theme-aware using CSS variables and JavaScript to enable a better presentation.
Read more >
Best Practices - Using Classes within X Theme? - Support
We would like to define classes that specify the basic typography of our text; the color and weight; and the behavior (including responsive...
Read more >
Creating a Custom Theme Class | Styling and Themes - Vaadin
Create Theme Class​​ You can integrate a custom component theme to be used with the built-in Vaadin components. To do this, you need...
Read more >
Understanding Responsive Support Classes - RocketTheme
Your guide to using responsive support classes in RocketTheme themes. ... Another useful feature available, via Bootstrap, is the collection of responsive utility ......
Read more >
Theme Introduction - Classes - FuelPHP Documentation
The Theme class provides theming to your application. A theme will group theme templates (views) and assets, and allows you to change the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found