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

@banzaicloud/uniform

v4.0.0

Published

This library contains building blocks for generating dynamic Angular forms.

Downloads

21

Readme

Uniform npm version

This library contains building blocks for generating dynamic Angular forms.

Usage

Install dependency:

npm i @banzaicloud/uniform

Include the module import for your application:

import { UniformModule } from '@banzaicloud/uniform';

@NgModule({
  imports: [
    // ...
    UniformModule,
  ],
})
export class AppModule {}

Use the UniformService to generate groups with form field types from raw input:

import { Component, OnInit } from '@angular/core';
import { UniformService, IFormFieldGroup } from '@banzaicloud/uniform';

@Component({
  selector: 'app-root',
  template: `
    <bcu-form
      [groups]="groups"
      (valueChanges)="onValueChanges($event)"
      (save)="onSave($event)">
    </bcu-form>
  `,
})
export class AppComponent implements OnInit {
  // can be fetched from an API
  rawGroups = [
    {
      name: 'Uniform demo',
      fields: [
        {
          controlType: 'textarea',
          key: 'wishlist',
          label: 'Wish list',
          placeholder: 'What are your desires?',
        },
      ],
    },
  ];
  groups: IFormFieldGroup[];
  values: { [key: string]: any };

  ngOnInit() {
    this.groups = UniformService.factory(this.rawGroups);
  }

  onValueChanges(values) {
    this.values = values;
  }

  onSave(rawValues) {
    console.log('Raw form values:', rawValues);
  }
}

Alternatively, use the field classes to build a form:

import { Component } from '@angular/core';
import { UniformService, FormFieldTextarea, IFormFieldGroup } from '@banzaicloud/uniform';

@Component({
  selector: 'app-root',
  template: `
    <bcu-form
      [groups]="groups"
      (valueChanges)="onValueChanges($event)"
      (save)="onSave($event)">
    </bcu-form>
  `,
})
export class AppComponent {
  groups: IFormFieldGroup[] = [
    {
      name: 'Uniform demo',
      fields: [
        new FormFieldTextarea({
          key: 'wishlist',
          label: 'Wish list',
          placeholder: 'What are your desires?',
        }),
      ],
    },
  ];
  values: { [key: string]: any };

  onValueChanges(values) {
    this.values = values;
  }

  onSave(rawValues) {
    console.log('Raw form values:', rawValues);
  }
}

Control types

Each control can be specified with the following options:

| FIELD | TYPE | DEFAULT | DESCRIPTION | | ------------- | ----------------- | ------- | ----------------------------------------------------- | | controlType | string (required) | | Control type | | key | string (required) | | Unique key of the control | | label | string (required) | | Label of the control (user friendly name) | | default | any | | Default value | | required | bool | false | Required control | | hidden | bool | false | Always hidden control | | disabled | bool | false | Always disabled control (eg. use with default) | | placeholder | string | | Placeholder (for example or description) | | description | string | | Description or hint | | minLength | number | | Minimum length of value | | maxLength | number | | Maximum length of value | | pattern | string | | Regular expression to validate value (eg. fqdn) | | showIf | object | | JSON schema to conditionally show or hide the control |

checkbox | FormFieldCheckbox

select | FormFieldSelect

Additional options:

| FIELD | TYPE | DEFAULT | DESCRIPTION | | --------- | ----------------------------- | ------- | -------------- | | options | { label: string, value: any } | | Select options | | multiple | boolean | | Whether the user can select multiple options |

number | FormFieldNumber

text | FormFieldText

password | FormFieldPassword

Additional options:

| FIELD | TYPE | DEFAULT | DESCRIPTION | | --------- | ------ | ------- | ------------------------------------------------------------------------------------------------ | | passwordRevealButton | boolean | false | Enables a show/hide functionality on the password field

textarea | FormFieldTextarea

code | FormFieldCode

Additional options:

| FIELD | TYPE | DEFAULT | DESCRIPTION | | --------- | ------ | ------- | ------------------------------------------------------------------------------------------------ | | options | object | | Config options passed to the CodeMirror instance |

file | FormFieldFile

Additional options:

| FIELD | TYPE | DEFAULT | DESCRIPTION | | ---------- | ------ | ------- | ------------------------------------------------------------- | | fillForm | bool | true | Parse the file as JSON and set the form values | | accept | string | | Comma-separated list of accepted, unique file type specifiers |

For example, when the field has a key of google.json_key and fillForm is set to true, the key-value pairs in the JSON file will be parsed and applied to the form values under the key prefix google.* (google.service_account, google.project_id, ...).