Giter Site home page Giter Site logo

bugsplat-git / ngb-filterable-dropdown Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 1.0 3.6 MB

⚑️πŸ₯ΎπŸ”Œ Powerful ng-bootstrap dropdown control for complicated filtering.

Home Page: https://bugsplat-git.github.io/ngb-filterable-dropdown-example

License: MIT License

JavaScript 3.85% TypeScript 79.32% HTML 12.38% SCSS 4.33% Shell 0.13%
angular filter dropdown bootstrap ng-bootstrap bugsplat

ngb-filterable-dropdown's Introduction

bugsplat-github-banner-basic-outline

BugSplat

Crash and error reporting built for busy developers.

πŸ‘‹ Introduction

BugSplat's @bugsplat/ngb-filterable-dropdown package provides a powerful dropdown control for complicated filtering. Take a peek our example that demonstrates how to filter and select various items in a collection.

πŸ— Installation

Install @bugsplat/ngb-filterable-dropdown and the associated peer dependencies @ng-bootstrap/ng-bootstrap and Bootstrap:

npm i @bugsplat/ngb-filterable-dropdown @ng-boostrap/ng-bootstrap bootstrap

πŸƒ Usage

Add NgbFilterableDropdownModule to your NgModule imports for each module where you plan to use the filterable dropdown:

import { NgbFilterableDropdownModule } from '@bugsplat/ngb-filterable-dropdown'

@NgModule({
  ...
  imports: [
    NgbFilterableDropdownModule
  ],
  ...
})

Add ngb-filterable-dropdown to your component's template:

<ngb-filterable-dropdown
  [allowCreateItem]="allowCreateItem"
  [autoClose]="autoClose"
  [items]="items"
  [disabled]="disabled"
  [placeholder]="placeholder"
  [searchInputPlaceholder]="searchInputPlaceholder"
  [selection]="selection"
  [selectionMode]="selectionMode"
  (itemCreated)="onItemCreated($event)"
  (openChanged)="onOpenChanged($event)"
  (selectionChanged)="onSelectionChanged($event)"
>
</ngb-filterable-dropdown>

🧩 API

Customize your dropdown by leveraging the inputs and outputs of @bugsplat/ngb-filterable-dropdown as described below.

Selection

The component takes two main inputs, a list of strings that are selectable and a sub-list of strings that are already selected.

items: Array<string> = ['Beetle', 'Ant', 'Moth', 'Fire Ant', 'Dung Beetle', 'Grass Ant'];
selection: Array<string> = ['Moth'];

Selection Modes

You can also specify whether or not to allow multiple items to be selected. By default, the component allows one item to be selected.

selectionMode: NgbFilterableDropdownSelectionMode =
  NgbFilterableDropdownSelectionMode.SingleSelect;

Create New Items

You can specify whether or not to allow new items to be created. By default, the component does not allow new items to be created.

allowCreateItem: boolean = false;

Opening and Closing

The open/close behavior of the dialog can be changed by setting autoClose to true or false. Alternatively you can specify whether to close on an outside or inside click.

autoClose: boolean | 'inside' | 'outside' = false;

Disabling

Dropdowns can be disabled at any time by setting disabled to true.

disabled: boolean = false;

Loading

You can also display a loading placeholder by setting loading to true.

loading: boolean = false;

Placeholders

If you'd like to specify the placeholder in the search input you can set the value of searchInputPlaceholder to a string of your choosing.

placeholder: string = 'No Items Selected';
searchInputPlaceholder: string = 'Search';

Outputs

The component provides the selected data back to the parent through the selectionChanged event.

onSelectionChanged(event: SelectionChangedEvent) {
  const selection = event.selection;
}

When an item is created the component outputs an event with the properties created, items, and selection.

onItemCreated(event: ItemCreatedEvent) {
  const created = event.created;
  const selection = event.selection;
  const items = event.items;
}

The component also provides an event when the dropdown is opened or closed through the openChanged event.

onOpenChanged(event: OpenChangedEvent) {
  const open = event.open;
}

πŸ› About

@bugsplat/ngb-filterable-dropdown is an open source library developed by BugSplat! BugSplat is a crash and error reporting tool used by developers to find, fix, and track errors in their applications.

If you're interested in error reporting, check out our Angular integration.

With ❀️
BugSplat

ngb-filterable-dropdown's People

Contributors

bobbyg603 avatar dependabot[bot] avatar semantic-release-bot avatar zmrl010 avatar zoolouie avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

zmrl010

ngb-filterable-dropdown's Issues

Fix icon styles

Ok I think I have a good fix for this - see the end result below

Screen Shot 2020-10-05 at 5 01 49 PM
image

Fix:
Change left and right padding to match that of the other dropdown items with

padding-left: .5rem!important;
padding-right: .5rem!important;

Then put some padding the right side of the svg

icon-all {
padding-right: 7px;
}

And locally add an element style to the svg to give it 4px of bottom margin

**

Add support for creating a new item if one does not exist

If the user types something that doesn't exist in the filter we should emit some sort of event that requests its creation by the consumer. This would support the enter key and have a button in the list that would both function the same. This functionality should probably be turned on or off by an input. There might be some funny cases we need to handle to make sure it plays nice with allowMultiSelect for instance.

Migrate to ESLint

TSLint's support is discontinued and we're deprecating its support in Angular CLI.
To opt-in using the community driven ESLint builder, see: https://github.com/angular-eslint/angular-eslint#migrating-an-angular-cli-project-from-codelyzer-and-tslint.

Should display items after opening dropdown

  1. Add ngb-filterable-dropdown to a component and provide it with a list of items
  2. Click button to show dropdown with items and search input
  3. Notice dropdown shows 'No items to display' however there are in fact several items and they are revealed upon searching

Switch to templates for providing buttons

I tried to use the official FontAwesome icons package for Angular today but hit a blocker where I couldn't use the component inside of ngb-custom-filterable-dropdown. I can only assume this is because of transclusion because doing the same thing in ngx-datatable via ng-template has no such problems.

Updated Docs

We made some changes for 6.0.0 and need to update the documentation to reflect this.

Search input should be autofocused

  1. Click the dropdown toggle to review the list of items and search input
  2. Notice that the search input is not focused

Search input should be focused so user can start typing immediately

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.