All Projects → zurfyx → angular-custom-dropdown

zurfyx / angular-custom-dropdown

Licence: MIT license
Angular2+ Dropdown. Simple dropdowns without relying on CSS frameworks.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to angular-custom-dropdown

PopupFilterMenu
仿猫眼电影多条件搜索菜单弹框
Stars: ✭ 16 (+0%)
Mutual labels:  dropdown, dropdown-menus
Ng Select
⭐ Native angular select component
Stars: ✭ 2,781 (+17281.25%)
Mutual labels:  dropdown, angular5
ContextMenuSwift
A better version of iOS 13 Context Menu
Stars: ✭ 162 (+912.5%)
Mutual labels:  dropdown, dropdown-menus
toggle term
A simple script to transform your boring terminal into A DROP DOWN boring terminal
Stars: ✭ 19 (+18.75%)
Mutual labels:  dropdown
react-native-picker-box
Simple and configurable component picker for react native
Stars: ✭ 0 (-100%)
Mutual labels:  dropdown
ng-pdf-highlighter
PDF annotation with angular7
Stars: ✭ 15 (-6.25%)
Mutual labels:  angular5
SBDropDown
Simple DropDown framework ...
Stars: ✭ 21 (+31.25%)
Mutual labels:  dropdown
angular5-social-login
Social authentication module for Angular 5. Includes Facebook and Google login with AOT compatibility.
Stars: ✭ 40 (+150%)
Mutual labels:  angular5
Menu
The most customizable menu for macOS apps.
Stars: ✭ 84 (+425%)
Mutual labels:  dropdown
ng-toggle
Bootstrap-styled Angular Toggle Component
Stars: ✭ 14 (-12.5%)
Mutual labels:  angular5
ngx-notify
一个无须依赖HTML模板、极简Angular通知组件。
Stars: ✭ 81 (+406.25%)
Mutual labels:  angular5
spring-websocket-angular6
Example for using Spring Websocket and Angular with Stomp Messaging
Stars: ✭ 18 (+12.5%)
Mutual labels:  angular5
react-functional-select
Micro-sized & micro-optimized select component for React.js
Stars: ✭ 165 (+931.25%)
Mutual labels:  dropdown
react-native-select-pro
React Native dropdown (select) component developed by Mobile Reality
Stars: ✭ 79 (+393.75%)
Mutual labels:  dropdown
react-native-panel
A Customizable React Native Panel for Android and iOS
Stars: ✭ 35 (+118.75%)
Mutual labels:  dropdown
EvalAI-ngx
Revamped codebase of EvalAI Frontend
Stars: ✭ 34 (+112.5%)
Mutual labels:  angular5
ngx-print
🖨️ A plug n' play Angular (2++) library to print your stuff
Stars: ✭ 124 (+675%)
Mutual labels:  angular5
Accordion
Silky-smooth accordion widgets with no external dependencies.
Stars: ✭ 32 (+100%)
Mutual labels:  dropdown
PygameWidgets
A module for use with Pygame. Includes fully customisable buttons, textboxes, sliders and many more, as well as the ability to create and run animations on these widgets.
Stars: ✭ 34 (+112.5%)
Mutual labels:  dropdown
acronym-decoder
Acronym Decoder
Stars: ✭ 39 (+143.75%)
Mutual labels:  angular5

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" >...</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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].