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

angular-custom-dropdown

v1.1.1

Published

Angular2+ Dropdown. Simple dropdowns without relying on CSS frameworks.

Downloads

129

Readme

Angular Custom Dropdown

npm Version Build Status

Create simple Angular2+ dropdowns without relying on CSS frameworks.

Demo

https://zurfyx.github.io/angular-custom-dropdown

Features

  • Light and simple
  • No CSS framework tied
  • Compatible with Bootstrap

Install

npm install angular-custom-dropdown

Getting started

my-module.module.ts

import { DropdownModule } from 'angular-custom-dropdown';

@NgModule({
  imports: [
    ...
    DropdownModule,
  ],

my-module.component.ts

my-module.component.html

<div class="dropdown" dropdown>
  <h1 class="dropdown-toggle" dropdownToggle>Angular Custom Dropdown ▼</h1>
  <ul class="dropdown-menu" dropdownMenu>
    <li><a class="neat" href="https://github.com/zurfyx/angular-custom-modal" rel="noopener" target="_blank">Check it out @ GitHub</a></li>
    <li><a class="neat" href="#">...</a></li>
  </ul>
</div>

my-module.component.css [Optional]

Styles are optional and up to you. Below are the ones that the demo page uses, but you can also use Bootstrap styles for that, or any other compatible library or framework. For most cases you'll just need to adapt the class names of the HTML snippet above.

If you want to read more about styling see the next section.

.dropdown  {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  display: block;
  align-self: center;
  width: 80%;
  opacity: 0;
  margin: -.25rem 0 0 10%; // -.25rem top (animation).
  padding: 0.25rem;
  list-style-type: none;
  background-color: #fff;
  border-radius: 4px;
  transition: .2s all ease-in;
}

.dropdown-menu li {
  padding: .5rem .5rem;
}

.dropdown-menu li + li {
  border-top: 1px solid #e1e1e1;
  padding-top: .5rem;
}

.dropdown-menu li > a {
  display: block;
  border-radius: 4px;
  padding: 1rem 1.5rem;
  transition: .2s background-color ease-in;
}

.dropdown-menu li > a:hover {
  background-color: #e9e9e9;
}

.dropdown.open .dropdown-menu {
  opacity: 1;
  margin-top: 0;
}

a.neat {
  color: inherit;
  text-decoration: none;
}

About styling

This library carries no predefined styles, which prevents clashing with your own set of styles or CSS frameworks. You can find the demo copy-paste dropdown styles above.

A minimal version (purely dropdown functionality) would look like the following:

.dropdown  {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  display: block;
  opacity: 0;
}

.dropdown.open .dropdown-menu {
  opacity: 1;
}

You can then add your own set of styles to make it look beautiful, or use a CSS framework. Note that the classes naming matches Bootstrap (and it is actually compatible with it!).

Aligning

Our demo example is centered with the parent container, and we do so through CSS. You can easy move the .dropdown-menu wherever you need it.

Left

By default.

Center

.dropdown-menu {
  left: 50%;
  transform: translateX(-50%);
}

Right

.dropdown-menu {
  right: 0;
}

Advanced

All directives are exported using the same selector names, which allows you to access inner methods on your own templates or components.

Accessing the dropdown reference in your own template

<span (click)="myDropdown.toggle()">While the toggle element is outside the dropdown, it has a reference to dropdown.</span>
<div #myDropdown=dropdown dropdown>
  ...
</div>

Accessing the dropdown reference in your own component

All the examples below require the HTML to have a reference such as the following:

<div #myDropdown=dropdown dropdown>...</div>

Toggle dropdown:

import { DropdownDirective } from 'angular-custom-dropdown';
...
@ViewChild('myDropdown') myDropdown: DropdownDirective;

openNow() {
  this.myDropdown.open();
}

Subscribing to dropdown status changes:

import { DropdownDirective, TOGGLE_STATUS } from 'angular-custom-dropdown';
...
@ViewChild('myDropdown') myDropdown: DropdownDirective;

ngOnInit() {
  this.myDropdown.statusChange()
    .subscribe((status: TOGGLE_STATUS) => {
      let statusValue: String;
      if (status === TOGGLE_STATUS.OPEN) {
        statusValue = 'Opened';
      } else if (status === TOGGLE_STATUS.CLOSE) {
        statusValue = 'Closed';
      }
      console.info(`Dropdown status changed to "${statusValue}".`);
    });
}

Warning! This example has been shortened for the sake of readability. Subscriptions should always be cleaned up on destroy (see the full source code here).

Special thanks

To pleerock for ngx-dropdown, of which I took some design ideas.

License

MIT © Gerard Rovira Sánchez