npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

raven-sticky-sidebar

v0.2.0

Published

An Angular component for making sidebars that stick in place while content around them scrolls as usual.

Downloads

21

Readme

Raven Sticky Sidebar for Angular

An Angular component for making sidebars that stick in place while content around them scrolls as usual.

Features

  • Uses position:sticky for better performance
  • Gracefully handles sidebars larger than the viewport
  • Support for float, flexbox, and grid layouts

Installation

Install into your Angular project using NPM.

npm install raven-sticky-sidebar --save

Import the StickySidebarModule into your module.

import { StickySidebarModule } from 'raven-sticky-sidebar';

@NgModule({
  imports: [
    StickySidebarModule,
    // ...
  ],
  // ...
})
export class AppModule { }

Usage

Add a <raven-sticky-sidebar> element to your template, and use floats, flexbox, or grid to position the sidebar.

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
    <style>
      .wrapper {
        display: grid;
        grid-template-columns: 1fr 3fr;
        grid-gap: 1rem;
      }
    </style>

    <div class="wrapper">
      <raven-sticky-sidebar>
        <aside>Sidebar content...</aside>
      </raven-sticky-sidebar>

      <article>
        Main content that scrolls...
      </article>
    </div>
  `,
  styles: []
})
export class AppComponent { }

Options

| Option | Type | Description | Default Value | :-------- | :----- | :------------------------------------------------------- | :------------ | topOffset | number | Space to add to the top while sidebar is stuck (px). | 0 | container | string | A CSS selector string that points to the parent element. | ""

Only add the container attribute if the sidebar is expected to stick within a parent element that has a limited height with its own scroll bars.

FAQ

How do I add a bottom offset?

The primary reason for needing a bottom offset is when the sidebar is larger than the viewport, causing the bottom of the sidebar content to butt up against the bottom of the viewport.

This can be easily fixed by adding some bottom padding to the last element in the sidebar. You may also need to adjust how you add your background to prevent the background from showing below the last element (adding padding to a wrapper element can help in those cases).

The sidebar is not working correctly. How can I fix it?

Try creating a new Angular project with the bare minimum code necessary to make use of raven-sticky-sidebar. Gradually make changes to reproduce your issue in the bare environment.

The sidebar is still not working correctly. What else can I do?

Sometimes, when content in a sidebar is changed, it can cause problems with the initial calculations that were made. However, you can recalculate using the sidebar component’s reset() method.

import { Component, ViewChild } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
    <style>/* ... */</style>

    <raven-sticky-sidebar #sidebar>
      <!-- ... -->
    </raven-sticky-sidebar>
  `
})
export class AppComponent {
  @ViewChild('sidebar')
  sidebar: StickySidebarComponent;

  someFuncThatUpdatesContent() {
    // Update content in sidebar
    // ...

    // Reset sidebar
    this.sidebar.reset()
  }
}

Browser Compatibility

Internet Explorer does not support position:sticky and is not compatible with raven-sticky-sidebar. Most other major browsers have support (including Edge).

Development

To contribute to the development of this component, clone its repository and run npm install. Then run ng serve -o to start a development server and to open a sample page in your browser.

License.

MIT license.