da-ui-input
v1.0.28
Published
> **Angular UI Components Library** > Author: CuongLe > License: MIT
Readme
da-theme
Angular UI Components Library
Author: CuongLe
License: MIT
Overview
da-theme is an Angular UI component library providing customizable, easy-to-use input components for building modern forms. It supports both Reactive Forms and Template-driven Forms, and includes:
- Text input
- Number input
- Textarea
- Checkbox
- Radio button
- Select dropdown
- Tags input
Installation
npm install da-ui-inputRequired Dependencies
Install Bootstrap and Bootstrap Datepicker:
npm install bootstrap@^5.3.8 bootstrap-datepicker@^1.10.1 jqueryUsage
Import the module in your app:
import { DaThemeModule } from 'da-ui-input';
@NgModule({
imports: [DaThemeModule]
})
export class AppModule {}Or import standalone components:
import { DaInputText } from 'da-ui-input';Add global styles
To apply library styles globally, add the library stylesheet to your Angular project's angular.json. Edit the build options for your application and include the stylesheet path in the styles array (use the relative path starting with ./node_modules as shown):
Example (angular.json snippet):
{
"projects": {
"<your-app-name>": {
"architect": {
"build": {
"options": {
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css",
"node_modules/da-ui-input/assets/styles/styles.scss"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/bootstrap/dist/js/bootstrap.bundle.min.js",
"node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"
]
}
}
}
}
}
}Important notes:
- Bootstrap is required for basic styling and components
- Bootstrap Datepicker is required for date picker functionality
- jQuery is required by Bootstrap Datepicker
- The order of scripts is important - jQuery must be loaded before Bootstrap
- Restart
ng serveafter modifying angular.json
Global Configuration
You can provide a global configuration for all da-theme components using Angular's dependency injection.
Create a config object and provide it in your app module:
import { DA_CONFIG, DaConfig } from 'da-ui-input';
const daThemeConfig: DaConfig = {
customClass: 'my-custom-theme', // Optional: global custom CSS class
theme: 'pink' // Optional: 'default' | 'pink'
};
@NgModule({
providers: [
{ provide: DA_CONFIG, useValue: daThemeConfig }
]
})
export class AppModule {}Or use forRoot:
import { DaThemeModule } from 'da-ui-input';
@NgModule({
imports: [
DaThemeModule.forRoot({
customClass: 'my-custom-theme',
theme: 'pink'
})
]
})
export class AppModule {}Config options:
| Option | Type | Description |
|---------------|----------------------------|---------------------------------------------|
| customClass | string (optional) | Custom CSS class applied to all components |
| theme | 'default' | 'pink' | Theme style for all components |
Example
<form [formGroup]="form">
<da-input-text formControlName="fullname" label="Full Name" placeholder="Enter full name"></da-input-text>
<da-input-number formControlName="age" label="Age" placeholder="Enter age" [readonly]="true"></da-input-number>
<da-textarea formControlName="description" label="Description" [rows]="3"></da-textarea>
<da-checkbox formControlName="redHair" label="Red Hair"></da-checkbox>
<da-radio formControlName="sex" label="Male" inputValue="male"></da-radio>
<da-radio formControlName="sex" label="Female" inputValue="female"></da-radio>
<da-select
[options]="[
{ label: 'New York', value: 'NY' },
{ label: 'San Francisco', value: 'SF' },
{ label: 'Los Angeles', value: 'LA' }
]"
formControlName="city"
label="City"
placeholder="Select city"
(valueChange)="onCityChange($event)">
</da-select>
<da-tags
formControlName="tags"
label="Tags"
placeholder="Add tag"
[readonly]="false"
[maxTags]="5"
[removable]="true"
(tagsChange)="onTagsChange($event)">
</da-tags>
<da-daterangepicker
formControlName="dateRange"
label="Date Range"
placeholder="Select dates"
[multiPicker]="true"
[showActionBtns]="true"
applyText="Apply"
cancelText="Cancel">
</da-daterangepicker>
<da-datepicker
formControlName="date"
label="Date"
placeholder="Select date">
</da-datepicker>
</form>Using with UntypedFormGroup (example)
Initialize an UntypedFormGroup with clear, English default values:
import { Component } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
@Component({ selector: 'app-root', templateUrl: './app.component.html' })
export class AppComponent {
isReadonly = false;
form: UntypedFormGroup = this.formBuilder.group({
age: [{ value: 30, disabled: false }, [Validators.required, Validators.min(18)]],
fullname: ['Jane Doe', [Validators.required]],
address: [{ value: '123 Main St, Springfield', disabled: true }, []],
height: [{ value: 170, disabled: false }, [Validators.min(0)]],
phonenumber: [{ value: '+1-555-0100', disabled: false }, []],
description: [{ value: 'This is a sample description', disabled: false }, []],
note: [{ value: 'Sample note', disabled: false }, []],
married: [{ value: false, disabled: false }, []],
redHair: [{ value: false, disabled: false }, []],
sex: [{ value: 'female', disabled: false }, []],
city: [{ value: 'NY', disabled: false }, []],
tags: [{ value: ['travel'], disabled: false }, []] // tags control holds array of strings
dateRange: [[new Date(), new Date()]], // For date range picker
date: [new Date()], // For single date picker
});
constructor(private formBuilder: UntypedFormBuilder) {}
}Notes:
- The
phonenumbervalue shown is a placeholder sample number; replace with your real contact if needed. tagscontrol stores an array of strings (e.g. ['travel', 'work']).- When components emit events like
valueChangeortagsChange, keep the form control synced if the component does not update the control automatically.
Component Options
<da-input-text>
| Input | Type | Default | Description |
|---------------|-----------|-----------|-----------------------------------|
| label | string | | Label for the input |
| class | string | | Custom class for the input |
| placeholder | string | | Placeholder text |
| readonly | boolean | false | Set input as readonly |
| id | string | | Custom input id |
| Output | Type | Description |
|---------------|---------------------|-------------------------------------------|
| valueChange | EventEmitter | Emits when value changes |
<da-input-number>
| Input | Type | Default | Description |
|---------------|-----------|-----------|-----------------------------------|
| label | string | | Label for the input |
| class | string | | Custom class for the input |
| placeholder | string | | Placeholder text |
| readonly | boolean | false | Set input as readonly |
| id | string | | Custom input id |
| min | number | | Minimum value |
| max | number | | Maximum value |
| step | number | 1 | Step value |
| Output | Type | Description |
|---------------|---------------------|-------------------------------------------|
| valueChange | EventEmitter | Emits when value changes |
<da-textarea>
| Input | Type | Default | Description |
|---------------|-----------|-----------|-----------------------------------|
| label | string | | Label for the textarea |
| class | string | | Custom class for the input |
| placeholder | string | | Placeholder text |
| readonly | boolean | false | Set textarea as readonly |
| rows | number | 3 | Number of rows |
| id | string | | Custom textarea id |
| Output | Type | Description |
|---------------|---------------------|-------------------------------------------|
| valueChange | EventEmitter | Emits when value changes |
<da-checkbox>
| Input | Type | Default | Description |
|---------------|-----------|-----------|-----------------------------------|
| label | string | | Label for the checkbox |
| class | string | | Custom class for the input |
| readonly | boolean | false | Set checkbox as readonly |
| labelIsRight| boolean | false | Set label position |
| trueText | string | | Text when checked |
| falseText | string | | Text when unchecked |
| Output | Type | Description |
|---------------|---------------------|-------------------------------------------|
| valueChange | EventEmitter | Emits when value changes |
<da-radio>
| Input | Type | Default | Description |
|---------------|-----------|-----------|-----------------------------------|
| label | string | | Label for the radio button |
| class | string | | Custom class for the input |
| inputValue | any | | Value of the radio button |
| readonly | boolean | false | Set radio as readonly |
| Output | Type | Description |
|---------------|---------------------|-------------------------------------------|
| valueChange | EventEmitter | Emits when value changes |
<da-select>
| Input | Type | Default | Description |
|---------------|-----------|-----------|-----------------------------------|
| options | Array<{label: string, value: any}> | | List of options |
| class | string | | Custom class for the input |
| label | string | | Label for the select |
| placeholder | string | | Placeholder text |
| readonly | boolean | false | Set select as readonly |
| id | string | | Custom select id |
| Output | Type | Description |
|---------------|-----------|-------------------------------------------|
| valueChange | EventEmitter | Emits when value changes |
<da-tags>
| Input | Type | Default | Description |
|------------------|-----------|-----------|-----------------------------------------------------|
| options | Array<{label: string, value: any}> | | List of options (if supported) |
| label | string | | Label for the tags input |
| class | string | | Custom class for the input |
| placeholder | string | | Placeholder for new tag |
| readonly | boolean | false | Set tags input as readonly |
| id | string | | Custom tags input id |
| maxTags | number | | Maximum number of tags allowed |
| removable | boolean | true | Allow removing tags |
| Output | Type | Description |
|---------------|---------------------|-------------------------------------------|
| tagsChange | EventEmitter<string[]> | Emits when tags change |
| valueChange | EventEmitter | Emits when value changes (if provided) |
<da-daterangepicker>
| Input | Type | Default | Description |
|------------------|-----------|-----------|-----------------------------------------------|
| label | string | | Label for the date range picker |
| placeholder | string | | Placeholder text |
| readonly | boolean | false | Set date range picker as readonly |
| class | string | | Custom class for the input |
| multiPicker | boolean | true | Show two month pickers side by side |
| showActionBtns | boolean | true | Show Apply/Cancel buttons |
| applyText | string | 'Apply' | Text for apply button |
| cancelText | string | 'Cancel' | Text for cancel button |
| Output | Type | Description |
|---------------|----------------------|-------------------------------------|
| valueChange | EventEmitter<Date[]> | Emits when date range changes |
<da-datepicker>
| Input | Type | Default | Description |
|---------------|-----------|-----------|-----------------------------------|
| label | string | | Label for the datepicker |
| placeholder | string | | Placeholder text |
| readonly | boolean | false | Set datepicker as readonly |
| class | string | | Custom class for the input |
| Output | Type | Description |
|---------------|---------------------|-------------------------------------|
| valueChange | EventEmitter | Emits when date changes |
Contribution
Pull requests and issues are welcome!
