@ngspot/ng-superclass-material
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

ng-superclass-material

This package features class FormComponentMaterialSuperclass. Extend from this class to make it easy to write custom form controls compatible with Material Form Field.

MIT commitizen PRs styled with prettier

Installation

NPM

npm install @ngspot/ng-superclass-material

Yarn

yarn add @ngspot/ng-superclass-material

Overview

Writing a custom control can be quite a bit work. Writing a custom control compatible with Material Form Field is even more work.

The work associated with writing a custom control is simplified via FormComponentSuperclass class from @ngspot/ng-superclass package. You are welcome.

@ngspot/ng-superclass-material package presents a layer on top of it. It features FormComponentMaterialSuperclass that extends from FormComponentSuperclass and makes it much easier to author form components compatible with Material Form Field.

Take a look at the exactly the same component built by hand vs when FormComponentMaterialSuperclass was used:

code comparison

See the full code for this example in the Demo

Usage:

  • Extend your component class from the FormComponentMaterialSuperclass
  • Implement MatFormFieldControl
  • Make sure to add MatFormFieldControl to providers
  • The rest is the same as for the FormComponentSuperclass. See docs here.
@Component({
  // ...
  providers: [{ provide: MatFormFieldControl, useExisting: MyComponent }],
})
class MyComponent
  extends FormComponentMaterialSuperclass<ValueType>
  implements MatFormFieldControl<ValueType> {
  // ...
}

License

MIT © Dmitry Efimenko

Package Sidebar

Install

npm i @ngspot/ng-superclass-material

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

107 kB

Total Files

27

Last publish

Collaborators

  • dmitryefimenko