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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ngx-custom-controls

v1.0.2

Published

Angular library which provides a powerful base directive (`BaseCvaImplementationDirective<T>`) that implements both `ControlValueAccessor` and `Validator` interfaces, making it easy to create custom form controls with built-in validation support. Every cu

Downloads

9

Readme

NGX Custom Controls

Angular library which provides a powerful base directive (BaseCvaImplementationDirective<T>) that implements both ControlValueAccessor and Validator interfaces, making it easy to create custom form controls with built-in validation support. Every custom control implemented by extending the base directive will support both template-driven and reactive forms. Library also provides basic control components created using base directive and bootstrap css.

If you find this library helpful, please consider giving it a ⭐ on GitHub!

Why Use This Library?

  • Simplified Custom Control Creation: Create your own form controls by extending the base directive, eliminating the need to implement complex form control interfaces manually
  • Type-Safe: Fully generic implementation allows you to specify the type of value your control will handle
  • Framework Agnostic: Works seamlessly with both template-driven and reactive forms
  • Validation Made Easy: We can use
  • DRY Principle: The base directive handles all the boilerplate code for form integration

Features

  • 🎯 Framework agnostic form controls
  • ✅ Built-in validation support with custom messages
  • 🔄 Two-way binding support
  • 🎨 Customizable styling
  • 📦 Lightweight and tree-shakeable
  • 🛡️ Written in TypeScript with strict type checking
  • 🔧 Extensible base directive for custom controls
  • 📝 Built-in form state tracking (touched, dirty, etc.)

Installation

npm install ngx-custom-controls

Basic Usage

Import the desired components in your module or standalone component:

import { CustomInputComponent } from 'ngx-custom-controls';

@Component({
  // ...
  imports: [CustomInputComponent]
})

Template Usage Example

@Component({
  template: `
    <ngcc-custom-input
      name="email"
      controlId="emailField"
      [(ngModel)]="email"
      [validators]="emailValidators">
    </ngcc-custom-input>
  `
})
export class ExampleComponent {
  email = '';
  
  emailValidators = [
    {
      validator: Validators.required,
      message: 'Email is required'
    },
    {
      validator: Validators.email,
      message: 'Please enter a valid email'
    }
  ];
}

We just need to write all applicable validators and provide it to the control and everything else will be handled by the directive.

Creating Custom Controls

You can create your own form controls by extending the BaseCvaImplementationDirective:

import { Component, input } from '@angular/core';
import { NgClass } from '@angular/common';
import { cvaProviders } from '../../shared/providers/cva-providers';
import { BaseCvaImplementationDirective } from '../../shared/directives/base-cva-implementation.directive';
import { ValidationMessagesComponent } from '../../shared/components/validation-messages/validation-messages.component';

@Component({
  selector: 'ngcc-custom-input',
  imports: [NgClass, ValidationMessagesComponent],
  standalone: true,
  templateUrl: './custom-input.component.html',
  providers: [...cvaProviders(CustomInputComponent)]  
})
export class CustomInputComponent extends BaseCvaImplementationDirective<string> {
  styleClass = input('form-control');
  placeholder = input('Enter');
  type = input('text');
  ngOnInit() {
    this.value = '';
  }
}

In most cases you need not to write any code in your control it's only when you need to override something.

Usage in parent component

It's time to use your component now

Reactive form example

  <form [formGroup]="ageForm">
    <ngcc-custom-input controlId="age" placeholder="21" formControlName="age" [validators]="ageValidators"
      [type]="'number'">
      <label for="age">Age</label>
    </ngcc-custom-input>
  </form>
ageForm = new FormGroup({
    age: new FormControl(22)
  });
  ageValidators = [
    {
      validator: Validators.required,
      message: 'Age is required'
    },
    {
      validator: Validators.min(18),
      message: 'Must be at least 18 years old'
    },
    {
      validator: Validators.max(100),
      message: 'Must be less than 100 years old'
    }
  ];

You se we have just added applicable validators which can also be shared using shared validator class.

This example demonstrates:

  • Creating a custom input component supporting dynamic "type", placeholder and css class
  • Number type input to create age input box.
  • Integration with reactive forms using formControlName
  • Custom value parsing
  • Bootstrap validation styling
  • Multiple validators with custom messages

Template driven form example

  <ngcc-custom-input controlId="tage" placeholder="22" [(ngModel)]="age" [validators]="ageValidators" [type]="'number'">
    <label for="tage">Age</label>
  </ngcc-custom-input>
age:number;
//Same validators used for reactive form control
ageValidators = [
    {
      validator: Validators.required,
      message: 'Age is required'
    },
    {
      validator: Validators.min(18),
      message: 'Must be at least 18 years old'
    },
    {
      validator: Validators.max(100),
      message: 'Must be less than 100 years old'
    }
  ];

Base Directive Properties

The BaseCvaImplementationDirective provides:

Inputs

  • validators: Array of ValidatorWithMessage[]
  • name: Control name
  • controlId: Unique identifier

Properties

  • value: Current control value
  • validationErrors: Current validation errors
  • errorMessages: Array of error messages
  • isTouched: Touch state
  • isDirty: Dirty state

Methods

  • onInputChange(value: T): Handle value changes
  • markAsTouched(): Mark control as touched
  • runValidators(): Execute validation

Validation

Define validators with custom messages:

const validators = [
  {
    validator: Validators.required,
    message: 'This field is required'
  },
  {
    validator: Validators.minLength(3),
    message: 'Minimum length is 3 characters'
  }
];

Components included in library created with Bootstrap css

  • Custom input component
  • Custom select component
  • Custom range component
  • Custom Date picker components
  • Custom Checkbox
  • Custom Radio

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.