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

@cagov/ds-back-to-top

v2.0.3

Published

The back to top button lets people go back to the top of a page without scrolling. This can be helpful on long pages. When selected, the back to top button takes you to the top of the page.

Downloads

276

Readme

Back to top button

The back to top button lets people go back to the top of a page without scrolling. This can be helpful on long pages. When selected, the back to top button takes you to the top of the page.

This can help people with mobility issues navigate the page more easily. It also helps people save time.

The back to top button is especially helpful for people using mobile devices. It decreases the swiping they have to do to get back to the top of a page.

The button appears when the user has scrolled past the first screen and begins to scroll back up. It disappears after 7 seconds by default. If someone scrolls again, it will reappear. If the user reaches the top of the page at any point, the button will disappear right away.

When and how to use it

We recommend installing the back to top button by default. If a page is not long enough to require scrolling, the back to top button will not appear.

How not to use it

This component has no extra guidance. Use the component as specified.

Demo and sample markup

The back to top component is integrated into this site and appears at the bottom right of the screen during a pause in scroll activity if you have scrolled down past the first screen and have begun to scroll back up.

<cagov-back-to-top data-hide-after="7000" data-label="Back to top">
</cagov-back-to-top>

Specs

| Property | Value | | ------------ | ---------------- | | Machine name | ds-back-to-top | | JavaScript | yes | | SCSS | ./src/index.scss |

Project installation

The instructions assume familiarity with npm package management tool, modern JavaScript techniques, and Sass.

  1. npm i @cagov/ds-back-to-top
  2. Use import¹ or require to include the component’s JavaScript in your page or compiler.
  3. Add the sample markup to your HTML.
  4. Refer to the Content model section for notes on mapping your data to the sample markup.

CDN installation

We recommend using a build system and bundling your JavaScript for faster performance. If you do not use a build system, you can include the code from our CDN with a script tag.

<script type="module" src="https://cdn.designsystem.webstandards.ca.gov/components/ds-back-to-top/v2.0.3/dist/index.js"></script>

CSS variables

The following CSS variables are used in this component:

  • --primary-700
  • --primary-900
  • --accent2-500
  • --font-size-2
  • --font-size-1

All CSS variables define their own fallback value so you do not have to use additional CSS unless you want to change them. You may define your own value for the variable by adding your own style rules. Here is an example defining the global hex value for a CSS variable named “--primary-700”:

:root {
  --primary-700: #165ac2;
}

Accessibility

Component-specific accessibility review

  • Make sure that arrow span has aria-hidden=”true” attribute.
  • When button is not visible, make sure it has aria-hidden=”true” and tabindex=”-1” attributes. When button is visible, make sure those attribute are no longer there.
  • Make sure that button has solid, 2px outline that uses --accent2-500 variable on focused state.

Standard accessibility review

As a component in Alpha status, this component must pass the following accessibility reviews every time a new version is published:

  • Tested with the [axe](https://www.deque.com/axe/) accessibility tool and passes all automated WCAG Level AA checks
  • Reviewed with the VoiceOver screen reader on desktop
  • Verified keyboard navigation and that all actionable elements of the component are reachable via keyboard commands only
  • Reviewed component layout on a variety of screen sizes

Progressive enhancement

This component uses a custom element defined in JavaScript in addition to HTML and CSS. Edge, Firefox, Safari, and Chrome support custom elements. If the JavaScript for this component is not delivered or supported, the component will not display. This is the desired behavior because this component is not critical for site interaction. It uses CSS variables to inherit design token values. Token definitions are not required because these style rules provide fallback values.

Content model

This component uses the following data attributes. We provide this information to help with integrating the component into backend publishing systems or identifying content that may require translation.

| Name | Attribute name | Data type | Field type | | ---------- | --------------- | --------- | --------------------------------------- | | Label | data-label | string | Plain text (default is “Back to top”) | | Hide after | data-hide-after | string | Integer (milliseconds, default is 7000) |

Contributor/developer documentation