1.0.4 • Published 4 years ago

@skhye05/multi-select v1.0.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 years ago

Nativescript Multi Select apple android

npm npm

Overview

Nativescript Multi Select is a popup dialog which provides multi selection, search through list and return the selected items.

Installation

tns plugin add @skhye05/multi-select

Usage

TypeScript

import { MultiSelect, AShowType } from '@skhye05/multi-select';
import { MSOption } from '@skhye05/multi-select';

let MSelect = new MultiSelect();
let selectedItems = ["moi-a", "moi-b"];

const options: MSOption = {
  title: "Please Select",
  selectedItems: this._selectedItems,
  items: [
    { name: "A", value: "moi-a" },
    { name: "B", value: "moi-b" },
    { name: "C", value: "moi-c" },
    { name: "D", value: "moi-d" },
  ],
  bindValue: 'value',
  displayLabel: 'name',
  onConfirm: selectedItems => {
    selectedItems = selectedItems;
    console.log("SELECTED ITEMS => ", selectedItems);
  },
  onItemSelected: selectedItem => {
    console.log("SELECTED ITEM => ", selectedItem);
  },
  onCancel: () => {
    console.log('CANCEL');
  },
  android: {
    titleSize: 25,
    cancelButtonTextColor: "#252323",
    confirmButtonTextColor: "#70798C",
  },
  ios: {
    cancelButtonBgColor: "#252323",
    confirmButtonBgColor: "#70798C",
    cancelButtonTextColor: "#ffffff",
    confirmButtonTextColor: "#ffffff",
    showType: AShowType.TypeBounceIn
  }
};

MSelect.show(options);

Angular

import { Component, OnInit, NgZone } from "@angular/core";
import { MultiSelect, AShowType } from '@skhye05/multi-select';
import { MSOption } from '@skhye05/multi-select';

@Component({
 // ...
})
export class SomeComponent implements OnInit {

  private _MSelect: MultiSelect;
  private predefinedItems: Array<any>;
  public selectedItems: Array<any>;

  constructor(private zone: NgZone) {
    this._MSelect = new MultiSelect();
    this.predefinedItems = ["moi-a", "moi-b"];
  }

  ngOnInit(): void {
  }


  public onSelectTapped(): void {
    const options: MSOption = {
      title: "Please Select",
      selectedItems: this.predefinedItems,
      items: [
        { name: "A", value: "moi-a" },
        { name: "B", value: "moi-b" },
        { name: "C", value: "moi-c" },
        { name: "D", value: "moi-d" },
      ],
      bindValue: 'value',
      displayLabel: 'name',
      onConfirm: selectedItems => {
        this.zone.run(() => {
          this.selectedItems = selectedItems;
          this.predefinedItems = selectedItems;
          console.log("SELECTED ITEMS => ", selectedItems);
        })
      },
      onItemSelected: selectedItem => {
        console.log("SELECTED ITEM => ", selectedItem);
      },
      onCancel: () => {
        console.log('CANCEL');
      },
      android: {
        titleSize: 25,
        cancelButtonTextColor: "#252323",
        confirmButtonTextColor: "#70798C",
      },
      ios: {
        cancelButtonBgColor: "#252323",
        confirmButtonBgColor: "#70798C",
        cancelButtonTextColor: "#ffffff",
        confirmButtonTextColor: "#ffffff",
        showType: AShowType.TypeBounceIn
      }
    };

    this._MSelect.show(options);
  }
}

Vue

<script>
  import {
    MultiSelect,
    AShowType
  } from "@skhye05/multi-select";
  const MSelect = new MultiSelect();
  let predefinedItems = ["moi-a", "moi-b"];
  
  export default {
    data() {
    },
    methods: {
      onSelectTapped() {
        const that = this;
        const options = {
          title: "Please Select",
          selectedItems: predefinedItems,
          items: [{
              name: "A",
              value: "moi-a"
            },
            {
              name: "B",
              value: "moi-b"
            },
            {
              name: "C",
              value: "moi-c"
            },
            {
              name: "D",
              value: "moi-d"
            }
          ],
          bindValue: "value",
          displayLabel: "name",
          onConfirm: _selectedItems => {
            that.selectedItems = _selectedItems;
            console.log("SELECTED ITEMS => ", _selectedItems);
          },
          onItemSelected: selectedItem => {
            console.log("SELECTED ITEM => ", selectedItem);
          },
          onCancel: () => {
            console.log("CANCEL");
          },
          android: {
            titleSize: 25,
            cancelButtonTextColor: "#252323",
            confirmButtonTextColor: "#70798C"
          },
          ios: {
            cancelButtonBgColor: "#252323",
            confirmButtonBgColor: "#70798C",
            cancelButtonTextColor: "#ffffff",
            confirmButtonTextColor: "#ffffff",
            showType: AShowType.TypeBounceIn
          }
        };
  
        MSelect.show(options);
      }
    }
  };
</script>

API

MultiSelect

PropertyTypeDescription
show(options: MSOption)() : voidShow Multi Select Dialog

MSOption

PropertyTypeDescription
titlestringDialog Title
confirmButtonTextstringconfirm button text optional
cancelButtonTextstringcancel button text optional
selectedItemsArray<any>predefined items optional
itemsArray<any>items/list that will be display
bindValuestringthe value that will determine the property which will be return when an item is selected optional
displayLabelstringthe value that will determine the property which will be display in the list optional
iosMSiOSOptionios options optional
androidMSAndroidOptionandroid options optional
onConfirm: (selectedItems: Array<any>) => voidFunction Callbackcallback which fires when the selection has been confirm/done
onItemSelected: (selectedItem: any) => voidFunction Callbackcallback which fires when an item has been selected optional
onCancel: () => voidFunction Callbackcallback which fires when the cancel button is tapped optional

MSAndroidOption (for android)

PropertyTypeDescription
titleSizenumberoptional
confirmButtonTextColorstringoptional
cancelButtonTextColorstringoptional

MSiOSOption (for ios)

PropertyTypeDescription
cancelButtonBgColorstringoptional
confirmButtonBgColorstringoptional
confirmButtonTextColorstringoptional
cancelButtonTextColorstringoptional
showTypenumberpopup view show type, default by AAPopupViewShowTypeFadeIn optional
dismissTypenumberpopup view dismiss type, default by AAPopupViewDismissTypeFadeOut optional
itemColorstringitem text color optional

iOS Popup: Animation AShowType ENUM

PropertyValue
TypeNone0
TypeFadeIn1
TypeGrowIn2
TypeShrinkIn3
TypeSlideInFromTop4
TypeSlideInFromBottom5
TypeSlideInFromLeft6
TypeSlideInFromRight7
TypeBounceIn8
TypeBounceInFromTop9
TypeBounceInFromBottom10
TypeBounceInFromLeft11
TypeBounceInFromRight12

iOS Popup: Animation ADismissType ENUM

PropertyValue
TypeNone0
TypeFadeOut1
TypeGrowOut2
TypeShrinkOut3
TypeSlideOutToTop4
TypeSlideOutToBottom5
TypeSlideOutToLeft6
TypeSlideOutToRight7
TypeBounceOut8
TypeBounceOutToTop9
TypeBounceOutToBottom10
TypeBounceOutToLeft11
TypeBounceOutToRight12

Author

Jonathan Mayunga, mayunga.j@gmail.com

Credits

License

Apache License Version 2.0, January 2004