Giter Club home page Giter Club logo

nb-choices's Introduction

๐Ÿ“ข Angular Choices

Angular wrapper for choices.js - vanilla, lightweight, configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency.

Live Demo - https://stackblitz.com/edit/nb-choices

๐Ÿญ Features

  • Angular forms support
  • Custom Angular templates
  • Placeholder support out of the box
  • Works with observables and the async pipe
  • Custom checkbox in multiple dropdowns
  • Escaping your HTML out of the box
  • Modern styling

Demo

Installation

npm install nb-choices
yarn add nb-choices

Style

@import '~nb-choices/nb-choices.scss'

Examples

Single Select

<choices [formControl]="control"
         [choices]="options"
         placeholder="Choose..."></choices>

Single Select - Combo box

 <choices [formControl]="control"
          [isCombo]="true"
          [choices]="options"
          placeholder="Choose..."></choices>

Single Select - Group

this.options = [{
  label: 'Group one',
  id: 1,
  choices: [
    { value: 'Child One', label: 'Child One' },
    { value: 'Child Two', label: 'Child Two' },
  ]
 },
 {
   label: 'Group two',
   id: 2,
   choices: [
     { value: 'Child Four', label: 'Child Three' },
     { value: 'Child Five', label: 'Child Four' },
   ]
}];
<choices [formControl]="control"
         [choices]="options"
         placeholder="Choose..."></choices>

With Custom Template

this.options = [{
      value: 'chrome',
      label: 'Chrome',
      customProperties: {
        icon: 'chrome'
      }
    },
    {
      value: 'explorer',
      label: 'Explorer',
      customProperties: {
        icon: 'internet-explorer'
    }
 }];
<ng-template #tpl let-data>
 <i class="fa fa-{{data.customProperties?.icon}}"></i> {{data.label}}
</ng-template>

<choices [formControl]="control"
         [isCombo]="true"
         [choiceTemplate]="tpl"
         [choices]="options"
         placeholder="Choose..."></choices>

With Observables

ngOnInit() {
  this.loading = true;
  this.options$ = timer(500).mapTo(this.options).do(() => {
    this.loading = false
  });
}
<choices [formControl]="control"
         [isCombo]="true"
         [loading]="loading"
         [choices]="options$ | async"
         placeholder="Choose..."></choices>

Multiple Select

<choices [isMultiple]="true"
         [choices]="options"
         [isCombo]="true"
         [formControl]="control"
         placeholder="Choose skills..."></choices>

Multiple Select - With Checkbox

<choices [isMultiple]="true"
         [choices]="options"
         [withCheckbox]="true"
         [isCombo]="true"
         [formControl]="control"
         placeholder="Choose skills..."></choices>

Controls

<choices [formControl]="control"
         [isCombo]="true"
         #choices="choices"
         [choices]="options"
         placeholder="Choose..."></choices>

<button (click)="choices.toggleDropdown(true)">Show</button>
<button (click)="choices.toggleDropdown()">Hide</button>
<button (click)="choices.disable()">Disable</button>
<button (click)="choices.enable()">Enable</button>
<button (click)="choices.clear()">Reset</button>
<button (click)="choicesMultiple.clearMultiple()">Reset multiple select</button>

Text

<choices [text]="true" [items]="textOptions" [formControl]="controText" #choicesText="choices"></choices>

<button (click)="choicesText.clearMultiple()">Reset</button>

Configuration

The default configurations of nb-choices for selects are:

{
  placeholderValue: context.placeholder,
  searchEnabled: context.isCombo,
  searchPlaceholderValue: context.searchPlaceholder,
  silent: true,
  removeItems: true,
  removeItemButton: true,
  duplicateItems: false,
  resetScrollPosition: false,
  searchResultLimit: 10000,
  fuseOptions: {
    threshold: 0.2,
  },
  shouldSort: false,
  shouldSortItems: false,
  renderSelectedChoices: 'always',
  loadingText: 'Loading...',
  noResultsText: 'No results found',
  noChoicesText: 'No choices to choose from',
  itemSelectText: '',
}

The default configurations of nb-choices for texts are:

{
  duplicateItems: false,
  removeItemButton: true,
}

You can extend the configurations by providing the CHOICES_CONFIG provider for selects or the CHOICES_TEXT_CONFIG for texts.

For example:

providers: [{provide: CHOICES_CONFIG, useValue: { removeItems: false }}]

Options

@Inputs() Description Default
isMultiple Whether the select should be multiple false
placeholder The value to show when the control is empty Choose..
isCombo Whether to show the search box true
text Whether is a text type false
searchPlaceholder The value to show on the search input Search..
labelKey The label which bound to the option text label
valueKey The value which bound to the option value value
choices The list of choices []
items The list of items (relevant for text) []
choiceTemplate TemplateRef that will replace the default view null
loadingText The loading text Loading..
textConfig The text config {}
withCheckbox Whether to show a checkbox in multiple dropdown false
loading Whether to show the loading text false
@Outputs() Description
onSearch Triggered when a user types into an input to search choices

Custom Styling

You can customize the style by modifying the nb-choices.scss and include it in your application.

TODO

  • Add Tests

nb-choices's People

Contributors

netanelbasal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nb-choices's Issues

Compile issues - Namespace 'Choices' has no exported member 'ClassNames'

Are you in the right place?

  • For issues or feature requests related to the choices library go to Choices.js
  • For general technical questions, post a question on StackOverflow tagged appropriately.

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

Current behavior

When trying to compile I am recieing the following error:

ERROR in node_modules/nb-choices/dist/components/custom-choice.component.d.ts(7,25): error TS2694: Namespace 'Choices' has no exported member 'ClassNames'.
node_modules/nb-choices/dist/components/custom-choice.component.d.ts(8,19): error TS2694: Namespace 'Choices' has no exported member 'Choice'.

Expected behavior

Should compile without errors

Minimal reproduction of the problem with instructions

yarn add nb-choices
ng serve

Environment


Angular version: 6


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
Others:

Firefox not display svg background-image

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x ] Bug report  
[ ] Feature request
[ ] Documentation issue or request

Current behavior

background-image styles that use SVG are not displayed on Firefox.

Expected behavior

background-image styles that use SVG should be displayed on Firefox.

Minimal reproduction of the problem with instructions

Open:
https://stackblitz.com/edit/nb-choices
on Firefox.
Select some item in Multiple select or Multiple select with checkbox.
Selected items are not display remove icon.

Environment

Browser:

  • Chrome (desktop) version XX
  • Chrome (Android) version XX
  • Chrome (iOS) version XX
  • [ x] Firefox version 59.0.1 (64-bit) on Ubuntu, Window and Mac
  • Safari (desktop) version XX
  • Safari (iOS) version XX
  • IE version XX
  • Edge version XX

Others:
I think the issue reason is here:
https://stackoverflow.com/questions/30676125/svg-as-data-uri-triggers-xml-parsing-error-in-firefox

Property 'isMulti' does not exist on type 'CustomChoiceComponent'

Are you in the right place?

  • For issues or feature requests related to the choices library go to Choices.js
  • For general technical questions, post a question on StackOverflow tagged appropriately.

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x ] Bug report  
[ ] Feature request
[ ] Documentation issue or request

Current behavior

When I run ng build --prod on an Angular 4 application which uses nb-choices I receive the following error:

ERROR in ng:///C:/Users/558848/Documents/Projects/[my project]/node_modules/nb-choices/dist/components/custom-choice.component.d.ts.CustomChoiceCompo
nent.html (12,21): Property 'isMulti' does not exist on type 'CustomChoiceComponent'.

Expected behavior

I expect the build not to fail.

Minimal reproduction of the problem with instructions

Add this package to an Angular application and run ng build --prod

What is the motivation / use case for changing the behavior?

Environment


Angular version: 4.2.4


Browser:
- [x ] Chrome (desktop) version 63.0.3239.132
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
Others:

Property 'isMulti' does not exist on type 'CustomChoiceComponent' - prod build

Are you in the right place?

  • For issues or feature requests related to the choices library go to Choices.js
  • For general technical questions, post a question on StackOverflow tagged appropriately.

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

Current behavior

ng build --prod throws the below error:
ERROR in node_modules\nb-choices\dist\components\custom-choice.component.d.ts.CustomChoiceComponent.html(12,13): : Property 'isMulti' does not exist on type 'CustomChoiceComponent'.

Expected behavior

ng build --prod should work as expected

Minimal reproduction of the problem with instructions

build app with --prod

What is the motivation / use case for changing the behavior?

Environment


Angular version: 5.2.1


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
Others:

Issues when trying to serve via SSR

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

Current behavior

When building for your app to be rendered server side using Angular Universal nb-choices imports the choices.js lib into the built server.js file which causes an error since there are calls to the document (possibly window too) which aren't supported in node.

Expected behavior

Should only load choices.js client side as needed

Minimal reproduction of the problem with instructions

ng add @nguniversal/express-engine --clientProject your-project
npm run build:ssr && npm run serve:ssr

What is the motivation / use case for changing the behavior?

So you can use this lib when rendering your app on the server

Environment


Angular version: 8.02


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
Others:

Could you provide an update to Angular 9?

Could you provide an update to Angular 9 - now with npm I am getting warnings about required peer dependencies of Angular common and core 4.0, I am also getting errors when trying to render the component in the upgraded components (worked fine for Angular 8).

Cannot find name 'CHOICES_CONFIG'"

Thank you for this module!

Everything works fine with Angular CLI, except the "providers: [{provide: CHOICES_CONFIG, useValue: { removeItems: false }}]" part.

I am getting the error "error: Cannot find name 'CHOICES_CONFIG'". Can you tell me what I am doing wrong?

THX

Is there an option for

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[x] Documentation issue or request

Current behavior

Could only find documentation for choice template

Expected behavior

Expected to find documentation for item template

Minimal reproduction of the problem with instructions

N/A

What is the motivation / use case for changing the behavior?

N/A

Environment

N/A

Browser:

  • Chrome (desktop) version XX
  • Chrome (Android) version XX
  • Chrome (iOS) version XX
  • Firefox version XX
  • Safari (desktop) version XX
  • Safari (iOS) version XX
  • IE version XX
  • Edge version XX

Others:
I was hoping to find some documentation for item templates as well.

removeItemButton is not adding a 'x' to single select

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

Current behavior

The removeItemButton option which is set to true by default does not add a 'x' to single selects. Works correctly for multi-selects and text.

Expected behavior

If the removeItemButton option is set to true, an option to clear the value in single select should be added.

Minimal reproduction of the problem with instructions

The demo has this problem.

What is the motivation / use case for changing the behavior?

This option works correctly in choices.js. This wrapper should replicate that behavior.

Environment


Angular version: 5.1.0


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
Others:

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.