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

@ng-zi/extensions-form-field

v0.0.1

Published

Angular Material Extensions for form-field

Downloads

3

Readme

MtxFormField Component Overview

The MtxFormField component is a versatile and highly configurable form field component built with Angular and Angular Material. It allows developers to create input fields with enhanced features such as icons, buttons, character counts, and validation error messages. This component is designed to simplify the creation of form fields while providing extensive customization options.

Features

| Feature | Description | | ---------------------- | --------------------------------------------------------------------------- | | Input Types | Supports different input types such as text, password, email, etc. | | TextArea Support | Can be configured as a textarea. | | Icons | Allows adding icons at the start or end of the input field. | | Buttons | Supports icon buttons within the form field. | | Character Count | Displays the current character count and the maximum allowed characters. | | Error Messages | Customizable error messages based on form validation. | | Hints and Placeholders | Provides hint and placeholder text for better user guidance. | | Clear Button | Includes a clear button to reset the input field. | | Disabled State | Supports enabling and disabling of the form field. | | Appearance Styles | Configurable appearance styles such as fill, outline, standard, and legacy. |

Installation

  1. Import the MtxFormField component and its dependencies in your module:
import { Component } from '@angular/core';

import { MtxFormFieldModule } from '@ng-zi/extensions/form-field';

@Component({
	selector: 'from-field-example',
	templateUrl: './app.component.html',
	styleUrl: './app.component.scss',
	standalone: true,
	imports: [MtxFormFieldModule],
})
export class AppComponent {}

Usage

To use the MtxFormField component in your template, follow these steps:

  1. Add the component to your template:

    <mtx-form-field
    	[formFieldConfig]="formFieldConfig"
    	[control]="formControl"
    	(iconBtnClick)="onIconBtnClick($event)"
    	(clearClick)="onClearClick()"
    ></mtx-form-field>
  2. Configure the component in your TypeScript file:

    import { Component } from '@angular/core';
    import { FormControl } from '@angular/forms';
    import { MtxFormFieldConfig } from './path-to-your-component/form-field.config';
    
    @Component({
    	selector: 'app-your-component',
    	templateUrl: './your-component.html',
    	styleUrls: ['./your-component.scss'],
    	standalone: true,
    	imports: [MtxFormFieldModule],
    })
    export class YourComponent {
    	formControl = new FormControl('');
    
    	formFieldConfig: MtxFormFieldConfig = {
    		label: 'Your Label',
    		placeholder: 'Enter text',
    		type: 'text',
    		icon: 'search',
    		iconPosition: 'start',
    		clearValue: true,
    		maxlength: 100,
    		showCharacterCount: true,
    		hint: 'Hint text',
    		errorMessages: {
    			required: 'This field is required',
    		},
    	};
    
    	onIconBtnClick(event: Event) {
    		// Handle icon button click
    	}
    
    	onClearClick() {
    		// Handle clear button click
    	}
    }

Configuration Options

The MtxFormFieldConfig interface provides the following configuration options:

  • label (string):

    • The label of the form field.
    • Example: 'Name'
  • hintLabel (string):

    • The hint label displayed below the form field.
    • Example: 'Enter your full name'
  • placeholder (string):

    • The placeholder text for the input.
    • Example: 'John Doe'
  • control (FormControl):

    • The form control associated with the form field.
  • type (string):

    • The type of input.
    • Possible values: 'text', 'password', 'email', etc.
    • Default: 'text'
  • isTextArea (boolean):

    • Determines if the form field is a textarea.
    • Default: false
  • hint (string):

    • The hint text displayed below the input.
    • Example: 'This is a hint text'
  • hintAlign ('start' | 'end'):

    • The alignment of the hint text.
    • Default: 'end'
  • errorMessages ({ [key: string]: string }):

    • An object containing error messages for validation errors.
    • Example: { required: 'This field is required', minlength: 'Minimum length is 5' }
  • appearance (MatFormFieldAppearance):

    • The appearance style of the form field.
    • Possible values: 'fill', 'outline'
    • Default: 'fill'
  • icon (string):

    • The icon to be displayed in the form field.
    • Example: 'search'
  • iconPosition ('start' | 'end'):

    • The position of the icon.
    • Default: 'start'
  • value (string):

    • The initial value of the form field.
  • iconBtn (string):

    • The icon for the button.
    • Example: 'add'
  • iconBtnAriaLabel (string):

    • The aria-label for the button.
    • Example: 'Add item'
  • iconBtnAriaPressed (any):

    • The aria-pressed state for the button.
    • Example: true or false
  • disabled (boolean):

    • If true, the form field will be disabled.
    • Default: false
  • clearValue (boolean):

    • If true, a clear button will be displayed to reset the form field.
    • Default: false
  • maxlength (number):

    • The maximum length of the input.
    • Example: 100
  • showCharacterCount (boolean):

    • If true, the character count will be displayed.
    • Default: false
  • hidePlaceholderOnFocus (boolean):

    • If true, Placeholder will get hide.
    • Default: false
  • hidePlaceholderWithDynamicWidth (boolean):

    • If true, Placeholder will hide with dynamic Input width.
    • Default: false
  • dynamicWidth (boolean):

    • If true, It Will provide dynamic Input width.
    • Default: false

Default Configuration

The DEFULT_MTX_FORM_FIELD_CONFIG object provides the default configuration for the form field:

export const DEFULT_MTX_FORM_FIELD_CONFIG: MtxFormFieldConfig = {
	label: '',
	hintLabel: '',
	placeholder: '',
	type: 'text',
	isTextArea: false,
	hint: '',
	hintAlign: 'end',
	errorMessages: {},
	appearance: 'fill',
	icon: '',
	iconPosition: 'start',
	value: '',
	iconBtn: '',
	iconBtnAriaLabel: '',
	iconBtnAriaPressed: '',
	disabled: false,
	clearValue: false,
	maxlength: undefined,
	showCharacterCount: false,
	hidePlaceholderOnFocus: false,
	hidePlaceholderWithDynamicWidth: false,
	dynamicWidth: false,
};

Example

Here is an example of how to use the MtxFormField component with a configuration object:

import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { MtxFormFieldConfig } from '@ng-zi/extensions/form-field';

@Component({
	selector: 'app-example',
	template: `
		<mtx-form-field
			[formFieldConfig]="formFieldConfig"
			[control]="formControl"
			(iconBtnClick)="onIconBtnClick($event)"
			(clearClick)="onClearClick()"
		></mtx-form-field>
	`,
	styleUrls: ['./example.component.scss'],
})
export class ExampleComponent {
	formControl = new FormControl('');

	formFieldConfig: MtxFormFieldConfig = {
		label: 'Your Label',
		placeholder: 'Enter text',
		type: 'text',
		icon: 'search',
		iconPosition: 'start',
		clearValue: true,
		maxlength: 100,
		showCharacterCount: true,
		hint: 'Hint text',
		errorMessages: {
			required: 'This field is required',
		},
	};

	onIconBtnClick(event: Event) {
		// Handle icon button click
	}

	onClearClick() {
		// Handle clear button click
	}
}