{"id":27880529,"url":"https://github.com/kapilkumar0037/ngx-custom-controls","last_synced_at":"2025-05-05T04:03:13.728Z","repository":{"id":272623262,"uuid":"915359731","full_name":"kapilkumar0037/ngx-custom-controls","owner":"kapilkumar0037","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-03T10:52:49.000Z","size":439,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-03T11:33:01.442Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kapilkumar0037.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-11T16:38:02.000Z","updated_at":"2025-05-03T10:52:52.000Z","dependencies_parsed_at":"2025-05-03T11:28:12.674Z","dependency_job_id":"a0f88911-445f-4cb9-b753-973ebaa41cda","html_url":"https://github.com/kapilkumar0037/ngx-custom-controls","commit_stats":null,"previous_names":["kapilkumar0037/ngx-custom-controls"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapilkumar0037%2Fngx-custom-controls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapilkumar0037%2Fngx-custom-controls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapilkumar0037%2Fngx-custom-controls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapilkumar0037%2Fngx-custom-controls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kapilkumar0037","download_url":"https://codeload.github.com/kapilkumar0037/ngx-custom-controls/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252436291,"owners_count":21747470,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-05T04:02:23.797Z","updated_at":"2025-05-05T04:03:13.664Z","avatar_url":"https://github.com/kapilkumar0037.png","language":"TypeScript","funding_links":[],"categories":["Recently Updated","Third Party Components"],"sub_categories":["[May 04, 2025](/content/2025/05/04/README.md)","Forms"],"readme":"# NGX Custom Controls\n\nAngular library which provides a powerful base directive (`BaseCvaImplementationDirective\u003cT\u003e`) 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. \n\nIf you find this library helpful, please consider giving it a ⭐ on [GitHub](https://github.com/kapilkumar0037/ngx-custom-controls)!\n\n## Why Use This Library?\n\n- **Simplified Custom Control Creation**: Create your own form controls by extending the base directive, eliminating the need to implement complex form control interfaces manually\n- **Type-Safe**: Fully generic implementation allows you to specify the type of value your control will handle\n- **Framework Agnostic**: Works seamlessly with both template-driven and reactive forms\n- **Validation Made Easy**: We can use\n- **DRY Principle**: The base directive handles all the boilerplate code for form integration\n\n## Features\n\n- 🎯 Framework agnostic form controls\n- ✅ Built-in validation support with custom messages\n- 🔄 Two-way binding support\n- 🎨 Customizable styling\n- 📦 Lightweight and tree-shakeable\n- 🛡️ Written in TypeScript with strict type checking\n- 🔧 Extensible base directive for custom controls\n- 📝 Built-in form state tracking (touched, dirty, etc.)\n\n\n\n## Installation\n\n```bash\nnpm install ngx-custom-controls\n```\n\n## Basic Usage\n\nImport the desired components in your module or standalone component:\n\n```typescript\nimport { CustomInputComponent } from 'ngx-custom-controls';\n\n@Component({\n  // ...\n  imports: [CustomInputComponent]\n})\n```\n\n### Template Usage Example\n\n```typescript\n@Component({\n  template: `\n    \u003cngcc-custom-input\n      name=\"email\"\n      controlId=\"emailField\"\n      [(ngModel)]=\"email\"\n      [validators]=\"emailValidators\"\u003e\n    \u003c/ngcc-custom-input\u003e\n  `\n})\nexport class ExampleComponent {\n  email = '';\n  \n  emailValidators = [\n    {\n      validator: Validators.required,\n      message: 'Email is required'\n    },\n    {\n      validator: Validators.email,\n      message: 'Please enter a valid email'\n    }\n  ];\n}\n```\nWe just need to write all applicable validators and provide it to the control and everything else will be handled by the directive.\n\n## Creating Custom Controls\n\nYou can create your own form controls by extending the `BaseCvaImplementationDirective`:\n\n```typescript\nimport { Component, input } from '@angular/core';\nimport { NgClass } from '@angular/common';\nimport { cvaProviders } from '../../shared/providers/cva-providers';\nimport { BaseCvaImplementationDirective } from '../../shared/directives/base-cva-implementation.directive';\nimport { ValidationMessagesComponent } from '../../shared/components/validation-messages/validation-messages.component';\n\n@Component({\n  selector: 'ngcc-custom-input',\n  imports: [NgClass, ValidationMessagesComponent],\n  standalone: true,\n  templateUrl: './custom-input.component.html',\n  providers: [...cvaProviders(CustomInputComponent)]  \n})\nexport class CustomInputComponent extends BaseCvaImplementationDirective\u003cstring\u003e {\n  styleClass = input('form-control');\n  placeholder = input('Enter');\n  type = input('text');\n  ngOnInit() {\n    this.value = '';\n  }\n}\n\n```\nIn most cases you need not to write any code in your control it's only when you need to override something.\n\n## Usage in parent component\nIt's time to use your component now\n### Reactive form example\n```html\n  \u003cform [formGroup]=\"ageForm\"\u003e\n    \u003cngcc-custom-input controlId=\"age\" placeholder=\"21\" formControlName=\"age\" [validators]=\"ageValidators\"\n      [type]=\"'number'\"\u003e\n      \u003clabel for=\"age\"\u003eAge\u003c/label\u003e\n    \u003c/ngcc-custom-input\u003e\n  \u003c/form\u003e\n```\n```typescript\nageForm = new FormGroup({\n    age: new FormControl(22)\n  });\n  ageValidators = [\n    {\n      validator: Validators.required,\n      message: 'Age is required'\n    },\n    {\n      validator: Validators.min(18),\n      message: 'Must be at least 18 years old'\n    },\n    {\n      validator: Validators.max(100),\n      message: 'Must be less than 100 years old'\n    }\n  ];\n```\nYou se we have just added applicable validators which can also be shared using shared validator class.\n\nThis example demonstrates:\n- Creating a custom input component supporting dynamic \"type\", placeholder and css class\n- Number type input to create age input box.\n- Integration with reactive forms using `formControlName`\n- Custom value parsing\n- Bootstrap validation styling\n- Multiple validators with custom messages\n\n### Template driven form example\n```html\n  \u003cngcc-custom-input controlId=\"tage\" placeholder=\"22\" [(ngModel)]=\"age\" [validators]=\"ageValidators\" [type]=\"'number'\"\u003e\n    \u003clabel for=\"tage\"\u003eAge\u003c/label\u003e\n  \u003c/ngcc-custom-input\u003e\n```\n```typescript\nage:number;\n//Same validators used for reactive form control\nageValidators = [\n    {\n      validator: Validators.required,\n      message: 'Age is required'\n    },\n    {\n      validator: Validators.min(18),\n      message: 'Must be at least 18 years old'\n    },\n    {\n      validator: Validators.max(100),\n      message: 'Must be less than 100 years old'\n    }\n  ];\n```\n\n## Base Directive Properties\n\nThe `BaseCvaImplementationDirective` provides:\n\n### Inputs\n- `validators`: Array of `ValidatorWithMessage[]`\n- `name`: Control name\n- `controlId`: Unique identifier\n\n### Properties\n- `value`: Current control value\n- `validationErrors`: Current validation errors\n- `errorMessages`: Array of error messages\n- `isTouched`: Touch state\n- `isDirty`: Dirty state\n\n### Methods\n- `onInputChange(value: T)`: Handle value changes\n- `markAsTouched()`: Mark control as touched\n- `runValidators()`: Execute validation\n\n## Validation\n\nDefine validators with custom messages:\n\n```typescript\nconst validators = [\n  {\n    validator: Validators.required,\n    message: 'This field is required'\n  },\n  {\n    validator: Validators.minLength(3),\n    message: 'Minimum length is 3 characters'\n  }\n];\n```\n## Components included in library created with Bootstrap css\n- Custom input component\n- Custom select component\n- Custom range component\n- Custom Date picker components\n- Custom Checkbox\n- Custom Radio\n\n## Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkapilkumar0037%2Fngx-custom-controls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkapilkumar0037%2Fngx-custom-controls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkapilkumar0037%2Fngx-custom-controls/lists"}