# ngx-cva-base

> This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.1.0.

Latest version **1.0.1-rc.4** (published 2022-08-09) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install ngx-cva-base
pnpm add ngx-cva-base
yarn add ngx-cva-base
bun add ngx-cva-base
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1-rc.4 |
| Published | 2022-08-09 |
| First published | 2022-08-09 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 164.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | gerandon |
| Keywords | angular, cva, control_value_accessor, widget |

## Links

- npm: https://www.npmjs.com/package/ngx-cva-base
- Repository: https://github.com/Gerandon/cva-base-workspace
- Homepage: https://github.com/Gerandon/cva-base-workspace#readme
- Issues: https://github.com/Gerandon/cva-base-workspace/issues
- npm.io page: https://npm.io/package/ngx-cva-base

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.1-rc.4 (latest) — 2022-08-09
- 1.0.1-rc.3 — 2022-08-09
- 1.0.1-rc.2 — 2022-08-09
- 1.0.1-rc.1 — 2022-08-09

## README

# NgxCvaBase

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.1.0.

## Short Description
This is basically a utility-widget Angular library, for creating `ControlValueAccessors` in an easier way, by implementing and extending
the `Core` classes.

Instead of creating `ControlValueAccessor` implementations in each of our project, this library provides already defined classes for that functionality.

##Core Classes

<table>
    <thead>
        <tr>
            <th>File name</th>
            <th>Class name</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>base-value-accessor.ts</td>
            <td>BaseValueAccessor</td>
            <td>The main "core" class of the library. It contains the CVA interface implementations and handles the built-in "overridable" and redundant functionalities.</td>
        </tr>
        <tr>
            <td>base.input.ts</td>
            <td>BaseInput</td>
            <td>Simple class that extends the BaseCVA class. It has multiple attributes inside of it, the most common ones such as: "name", "label", "appearance", etc. Extending this class in our component, makes our component to act like a custom control input.</td>
        </tr>
        <tr>
            <td>base-text.input.ts</td>
            <td>BaseTextInput</td>
            <td>This class extends the BaseInput one. It has multiple attributes that are being used in case of "plain" text inputs, such as: "type (text or passwd)", "maxLength", etc.</td>
        </tr>
    </tbody>
</table>

##Widgets (built-in examples)
There are a few custom components, just to present how the core functionality and implementation works and makes
the development easier (especially in case of a newly created project)

In the following example you can see a custom CVA implementation built into the library (as widget)

As you can see, instead of defining what our CVA will look like, we could use the Base implementation from the core of the library. That way (as seen) our component will have significantly less code on its TS side and we also reduced redundancy as well.
###BasicInput (component)
```typescript
@Component({
    selector: 'basic-input',
    templateUrl: './basic-input.component.html',
    styleUrls: ['./basic-input.component.scss'],
    encapsulation: ViewEncapsulation.None,
    providers: [
        {provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => BasicInputComponent), multi: true},
        {provide: NG_ASYNC_VALIDATORS, useExisting: forwardRef(() => BasicInputComponent), multi: true},
    ],
})
export class BasicInputComponent extends BaseTextInput<string> implements OnInit {

    constructor(protected injector: Injector, protected cdr: ChangeDetectorRef) {
        super(cdr, injector);
    }

    ngOnInit() {
        super.ngOnInit();
    }
}
```

```angular2html
<mat-form-field [floatLabel]="floatLabel && 'always'" [appearance]="appearance">
    <mat-label *ngIf="label && floatLabel !== 'never'">{{ label | translate: translateParams }}</mat-label>
    <input
        #inputElement
        #input="ngForm"
        matInput
        label=""
        [type]="type"
        [attr.disabled]="disabled"
        [readonly]="disabled"
        [placeholder]="placeholder | translate: translateParams"
        [formControl]="control"
        [maxLength]="maxLength"
        [name]="name"
        [required]="required"/>
    <mat-icon *ngIf="icon" matPrefix color="primary">{{icon}}</mat-icon>
    <span *ngIf="suffix" matSuffix>{{suffix}}</span>
    <mat-error *ngIf="hasError('required')">{{ 'COMMON.REQUIRED' | translate: translateParams }}</mat-error>
    <mat-error *ngIf="hasError('max')">{{ 'ERROR.NUMERIC.MAX' | translate }}</mat-error>
    <mat-error *ngIf="hasError('min')">{{ 'ERROR.NUMERIC.MIN' | translate }}</mat-error>
</mat-form-field>

```

---
_Source: https://npm.io/package/ngx-cva-base · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
