Skip to content

Instantly share code, notes, and snippets.

@andyjessop
Last active January 26, 2024 22:46
Show Gist options
  • Save andyjessop/8568b6a85e24deea15f98fabddc0e8c4 to your computer and use it in GitHub Desktop.
Save andyjessop/8568b6a85e24deea15f98fabddc0e8c4 to your computer and use it in GitHub Desktop.
Link custom element to handle route changes in thepassle/app-tools router
import { RouterLink } from './RouterLink';
// After router is setup...
RouterLink.setRouter(() => router);
import { css, html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { Item } from './types';
@customElement('my-links')
export class Links extends LitElement {
@property({ type: Array })
items: Item[] = [];
static styles = [
css`
cx-link::part(link):hover {
background-color: var(--color-gray-100);
}
cx-link::part(link active) {
background-color: var(--color-primary-500);
color: white;
}
cx-link::part(link active):hover {
background-color: var(--color-primary-500);
cursor: default;
}
`,
];
render() {
return html`
<ul>
${this.items.map(
(item) => html`
<li>
<cx-link to="${item.path}">${item.title}</cx-link>
</li>
`,
)}
</ul>
`;
}
}
@andyjessop
Copy link
Author

I've updated the gist and tested locally, and it looks good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment