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

@zokelion/ngx-select

v1.0.5

Published

Angular recursive select tree

Downloads

90

Readme

NgxSelect

Angular recursive select tree

What is it ?

NgxSelect is a recursive select tree for Angular 2+. You can use the research field for find any item in the list. NgxSelect can be configured for changing button's label and css classes.

Installation

npm install @zokelion/ngx-select --save

Usage

Basic

NgxSelect generate a tree based on an list of items. the component should be declared in your html code like this :

<ngx-select
    [items]="items"
    (itemSelectedEvent)="itemSelected($event)"
    [defaultToggleButtonLabel]="'No Items Selected'"
    [placeholder]="'Search Items'"
    [toggleBtnClass]="'btn-primary w-75'"
    [toggleContentClass]="'w-100'"
    [parentSelectable]="false"
    [enableAnimations]="true"
></ngx-select>

This is a simple interface that describes any parameters for a select component.

| Name | Type | required | Description | Default | | ------------------------ | ----------------- | :------: | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | | (itemSelectedEvent) | ItemSelectedEvent | ✔️ | function who was called by the event for getting the list of selected items, in the example below the function was called itemSelected() | NO | | items | item[] | ❌ | parameter item list | [] | | defaultToggleButtonLabel | string | ❌ | label of toggle button in case of none items are selected | 'No Items Selected' | | placeholder | string | ❌ | placeholder of research input | 'Search Items' | | toggleBtnClass | string | ❌ | input for your custom css classes on the toggle button | 'btn-primary w-75' | | toggleContentClass | string | ❌ | input for your custom css classes on the content of the toggle | 'w-100' | | parentSelectable | boolean | ❌ | parameter who define if parent item are selectable | false | | enableAnimation | boolean | ❌ | enable or not the animation of the toggle content | true |

In order to use the event class import it in your component and declare a new function in your component like this :

    // import to be able to use the event
    import { ItemSelectedEvent } from '@zokelion/ngx-select/models/item-selected-event.model';
    // import this model for the type of your list
    import { Item } from '@zokelion/ngx-select/models/item.model';

    // function for getting and using the list
    public itemSelected(eventItem: ItemSelectedEvent): void {
        this.selectedItems = eventItem.selectedItems;
    }

For the generation of the tree the list must be composed of items based on this model :

export class Item {
    id?: number;
    name: string;
    isSelected: boolean;
    children: Item[];
}

Detail of Item property :

| Name | Type | required | Description | | ---------- | ----------------- | :------: | ----------------------------------------------------------- | | id | ItemSelectedEvent | ❌ | item.id is optionnal but it is usefull when you use an api. | | name | string | ✔️ | name of item | | isSelected | boolean | ✔️ | indicates weither or not this item is ticked. | | children | item[] | ✔️ | childrens of the item |

Example of items list:

// this list is an example
items: Item[] = [{
            id: 1,
            name: 'World',
            isSelected: false,
            children: [
                {
                    id: 2,
                    name: 'America',
                    isSelected: false,
                    children: [
                        {
                            id: 3,
                            name: 'Canada',
                            isSelected: false,
                            children: []
                        },
                        {
                            id: 4,
                            name: 'United-States',
                            isSelected: false,
                            children: [
                                {
                                    id: 14,
                                    name: 'Arizona',
                                    isSelected: false,
                                    children: []
                                },
                                {
                                    id: 15,
                                    name: 'Washington',
                                    isSelected: false,
                                    children: []
                                }
                            ]
                        },
                        {
                            id: 5,
                            name: 'Mexico',
                            isSelected: false,
                            children: []
                        }
                    ]
                },
                {
                    id: 6,
                    name: 'Europe',
                    isSelected: false,
                    children: [
                        {
                            id: 7,
                            name: 'France',
                            isSelected: false,
                            children: []
                        },
                        {
                            id: 8,
                            name: 'Deutschland',
                            isSelected: false,
                            children: []
                        }
                    ]
                },
                {
                    id: 9,
                    name: 'Asia',
                    isSelected: false,
                    children: [
                        {
                            id: 10,
                            name: 'China',
                            isSelected: false,
                            children: []
                        },
                        {
                            id: 11,
                            name: 'Japan',
                            isSelected: false,
                            children: []
                        }
                    ]
                },
                {
                    id: 12,
                    name: 'Oceania',
                    isSelected: false,
                    children: [
                        {
                            id: 13,
                            name: 'Australia',
                            isSelected: false,
                            children: []
                        }
                    ]
                }
            ]
        }];

If you need to reset the select tree with no selected value you can use @ViewChild and call the reset function in your component.

    // first declare your viewchild
    @ViewChild(NgxSelectComponent)
    ngxSelectComponent: NgxSelectComponent;

    // then call reset function in your component
    resetNgxSelect() {
      this.ngxSelectComponent.reset();
    }

Configuration

Labels can be customized depending on your language. We're using English by default. You can use your custom css classes on this component, by default we used the bootstrap's classes 'w-75' on the toggle button and 'w-100' on the toggled content. The params have default value but the following params can be customized :

<ngx-select
    [defaultToggleButtonLabel]="'No Items Selected'"
    [placeholder]="'Search Items'"
    [toggleBtnClass]="'btn-primary w-75'"
    [toggleContentClass]="'w-100'"
    [parentSelectable]="false"
    [enableAnimations]="true"
></ngx-select>