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

vanilla-dropdown-component

v1.0.1

Published

Reusable dropdown components with images and buttons.

Downloads

4

Readme

vanilla-dropdown-component

This document provides guidance on how to utilize the Dropdown component in web projects. The component is highly customizable and can be styled using CSS variables.

This package is distributed as ES Modules and is expected to be used in environments that support module syntax.

Installation

npm install vanilla-dropdown-component

Usage

import {
  DropdownButton,
  DropdownWithImg,
  DropdownWithSvg,
} from "vanilla-dropdown-component";

const dropdownBtn = new DropdownButton();
const dropdownImg = new DropdownWithImg();
const dropdownSvg = new DropdownWithSvg();

// Append the dropdowns to body or anywhere you want
document.body.appendChild(dropdownBtn);
document.body.appendChild(dropdownImg);
document.body.appendChild(dropdownSvg);

Examples

Basic Dropdown Button

This example shows how to create a dropdown button with default settings:

const dropdownButton = new DropdownButton();
document.body.appendChild(dropdownButton.dropdownOuterEl);

Custom Dropdown Button

This example demonstrates how to create a dropdown button with custom button text and link information:

const customLinkInfo = {
  "User Profile": "https://example.com/profile",
  "Log Out": "https://example.com/logout",
  "Settings & Config": "https://example.com/setting",
};
const customButton = new DropdownButton("My Profile", customLinkInfo);
document.body.appendChild(customButton);

Dropdown with Image

Create a dropdown component that includes an image, using a default set of links and a custom image URL:

const imageUrl =
  "https://images.pexels.com/photos/21945939/pexels-photo-21945939.jpeg?auto=compress&cs=tinysrgb&w=300&lazy=load";
const dropdown = new DropdownWithImg(undefined, imageUrl);
document.body.appendChild(dropdown);

Custom Links and Image URL Dropdown

This example configures a dropdown with custom link options and a specified image URL:

const linkInfo = {
  "Google Link": "https://www.google.com",
  "Stack Overflow": "https://stackoverflow.com/",
  "YouTube Link": "https://www.youtube.com/",
};
const imageUrl = "https://example.com/path/to/image.jpg";
const dropdown = new DropdownWithImg(linkInfo, imageUrl);
document.body.appendChild(dropdown);

Dropdown with Custom SVG

Create a dropdown component that utilizes an SVG image alongside customized links:

const linkInfo = {
  "Google Link": "https://www.google.com",
  "Stack Overflow": "https://stackoverflow.com/",
  "YouTube Link": "https://www.youtube.com/",
};
const customSvg = `<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 340 340">
  <path fill="#CDCDCD" d="M170,0..."/>
</svg>`;
const dropdown = new DropdownWithSvg(customSvg, linkInfo);
document.body.appendChild(dropdown);

Configuring styles

To configure styles, import the CSS directly or use the provided variables in your project's CSS:

@import url("vanilla-dropdown-component/dist/styles/variables.css");
@import url("vanilla-dropdown-component/dist/styles/style.css");

:root {
  --clr-link-bg: #fff;
  --clr-ft-white: #fff;
  --clr-base: #666;
  --clr-base-lt: #999;
  --clr-base-ltst: #ebebeb;
  --clr-base-dk: #333;
  --clr-btn: #5c7cfa;
  --clr-btn-lt: #748ffc;
  --clr-btn-dk: #4263eb;
  --clr-btn-dkst: #364fc7;
  --fs-link: 14px;
}