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

@tft/crispr-forms

v17.0.0

Published

<a href="https://www.npmjs.com/package/@tft/interact"> <img alt="npm latest version" src="https://img.shields.io/npm/v/@tft/interact/latest.svg"> </a>

Downloads

263

Readme

CRISPR Forms

Build forms like DNA builds life

Interactive docs

Description

Web development tends to involve building a lot of forms, and even though it can be repetitive it's not necessarily easy. Connecting templates to FormGroups takes time and there are a lot of opportunities to make mistakes along the way that can difficult to debug. Large form are difficult to keep organized, and long form templates are cumbersome to update.

Luckily, we've abstracted out the template work entirely, allowing the end developer to simply pass a config object to the tft-crispr-forms component and it will use these instructions to build out the form. This allows the end developer to focus on the business logic and not the template details.

We currently only support styling for Material Design, but support for other design systems is on our roadmap.

Supported Angular Material fields:

  • Autocomplete
  • Autocomplete Chiplist
  • Checkbox
  • Input
  • Select
  • Textarea
  • Slider
  • Datepicker
  • Button
  • Heading
  • Divider

More fields coming soon!

Super sweet features:

  • computed values: field values based on one or many other field values (fieldC === fieldA * fieldB)
  • dynamically disabled fields: disable a field reactively based on other field(s) values
  • configurations to handle all the features of each Angular Material field

Installation

CRISPR Forms has a few dependencies. First you'll need Angular Material. Usually you can just run ng add @angular/material. Find installation docs here.

The datepicker field require date-fns and @angular/material-date-fns-adapter to be installed. npm i date-fns @angular/material-date-fns-adapter

You will have also have to provide value for MAT_DATE_LOCALE in your root module.

import { MAT_DATE_LOCALE } from '@angular/material/core';
import { enUS } from 'date-fns/locale';


@NgModule({
  ...
  providers: [
    {
        provide: MAT_DATE_LOCALE,
        useValue: enUS,
    },
  ],
});

There are default messages for all the built in Angular validators, but they can easily overwritten by setting the errorDictionary field on the config input. Custom messages can also be created for custom validators.

Usage

With CRISPR Forms we've abstracted out form template entirely allowing you to generate your form by simply passing a configuration object to the tft-crispr-form component.

Interactive documentation can be found on Stackblitz here, with editable examples for most features.

In some-component.html we pass the configuration to the component and handleSubmit function to the submitted event.

<crispr-form
  [config]="config"
  (submitted)="handleSubmit($event)">
</crispr-form>

In some-component.ts we define the config and handleSubmit function.

export class DemoComponent implements OnInit {

  config: FormConfig = {
    fields: [
      // a basic input field in the form with the following configuration
      {
        controlType: ControlType.INPUT,
        label: 'I am a label on a text input',
        controlName: 'textInput',
        placeholder: 'I am a placeholder in a text input',
        validators: [Validators.required, Validators.minLength(5)],
      },
      {
        controlType: ControlType.SELECT,
        label: 'I am a label on a text input',
        controlName: 'textInput',
        options: [
          {label: 'option a', value: 'optionA'}
          {label: 'option a', value: 'optionA'}
        ],
        placeholder: 'I am a placeholder in a text input',
        validators: [Validators.required, Validators.minLength(5)],
      },
    ]
  }
}

Buttons can reset form or take custom events

See example here.

Datepicker can take a callback function to pass a class to specified fields

See example here. Be sure to check out the corresponding .scss file to see how we pass styles down to the cell class.

Pass Custom Components to CRISPR

Simply create a component and pass it as an argument to the component property.

export class CustomComponentComponent {

  customComponentConfig: FormConfig<CustomInputConfig> = {
    autocomplete: 'off',
    fields: [
      {
        component: CustomInputComponent,
        controlType: ControlType.CUSTOM,
        controlName: 'customComponent',
      },

Examples of how to extend current field behavior available here

Breaking Changest v13 => v14

Switch from MomentDateAdaptor to FnsDateAdapter

With momentjs shifting into maintenance mode, it no longer makes sense to use the MomentDateAdaptor, so we've switched to the FnsDateAdapter. This means that for DatepickerFieldConfigs the datepickerFilter, cellClassFunction, dateClass properties, instances of Moment will need to be replaced with Date.

v13

  datepickerFilter?: (date: Moment) => boolean;
  cellClassFunction?: MatCalendarCellClassFunction<Moment>;
  dateClass?: (parentGroup: FormGroup) => Observable<MatCalendarCellClassFunction<Moment>>;

v14

  datepickerFilter?: (date: Date) => boolean;
  cellClassFunction?: MatCalendarCellClassFunction<Date>;
  dateClass?: (parentGroup: FormGroup) => Observable<MatCalendarCellClassFunction<Date>>;

You'll also have to set up a date locale in your root module. See installation for details on how to set up the new adaptor.

Upcoming / In Progress

  • Creating modules for each component so that you can avoid importing unused components

  • Framework agnostic with Angular Elements

  • More examples of how to change field layout

  • The rest of the Angular Material fields:

    • Radio button
    • Slide toggle
    • Button toggle