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

@studyportals/content-switcher

v1.1.6

Published

The content switcher is responsible for displaying multiple large modules inside a switchable container. It will generate a menu based on the content so you can easily switch between the content.

Downloads

96

Readme

Content-Switcher

The content switcher is responsible for displaying multiple large modules inside a switchable container. It will generate a menu based on the content so you can easily switch between the content.

How to use Content-Switcher

In order for content switcher to work you need to have a wrapper element which contains your content. Inside this container there should be a container element with the classname: "SwitchableContent". Inside the "SwitchableContent" element you will place you individual pieces of content with the classname: "SwitchableGroup".

On the wrapperElement you pass a data-id attribute, this id will be broadcasted allong the content change event.

<div class="WrapperElement" data-id="id_of_content_switcher">
  <div class="SwitchableContent">
    <div class="SwitchableGroup">
      content 1
    </div>
    <div class="SwitchableGroup">
      content 2
    </div>
    <div class="SwitchableGroup">
      content 3
    </div>
  </div>
</div>

Generate content switcher

Before generating the content switcher you need to add some data attributes to the module elements

| data attribute | usages | |-----------------|-------------------------------------------------------------------------------| | data-id | used as a identifier during broadcast and targeting of the module | | data-label | max 2 words (no numbers). Used as text inside the buttons to switch the content |

<div class="WrapperElement" data-id="id_of_content_switcher">
  <div class="SwitchableContent">
    <div class="SwitchableGroup" data-id="content_1" data-label="content one">
      content 1
    </div>
    <div class="SwitchableGroup"  data-id="content_2" data-label="content two">
      content 2
    </div>
    <div class="SwitchableGroup"  data-id="content_3" data-label="content three">
      content 3
    </div>
  </div>
</div>

To generate the content switcher you create an instance of the ContentSwitcher class with the refference to the wrapper element. After this you call the init() function.

const wrapperElement = document.querySelector('.WrapperElement');
const contentSwitcher = new ContentSwitcher(wrapperElement);
contentSwitcher.init();

This will generate the content switcher and hides all the modules apart from the first module. If you want to show a different module on init you can pass in a second argument in the constructor to show the corresponding module.

const contentSwitcher = new ContentSwitcher(wrapperElement, 'content_2');

Events

The content switcher will dispatch an event everytime the content is switched. the event will pass the id of the switched content & the id of the content switcher

document.addEventListener('contentChanged', (event) => {

  const activatedGroupId = event.detail.to;
  const deactivatedGroupId = event.detail.from;
  const id = event.detail.id;
});

You can change the active module by calling setActiveModule()


const contentSwitcher = new ContentSwitcher(wrapperElement);
contentSwitcher.setActiveModule('content_2');

Flowchart

For more detailed information you can refer to the flowchart