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

@adc/forms

v1.0.0

Published

A Web Component collection that helps you build and handle forms.

Downloads

11

Readme

@adc/forms

npm (scoped) npm GitHub

This is a collection of standalone Web Components that make it easier to work with forms, including generating them programmatically. You can use the components inside any modern JS framework or with no framework at all.

@adc/forms is part of the aide-de-camp Web Components collection.

How to install

You can either:

  • install the npm package with npm install @adc/forms
  • rely on unpkg.com and a good ol' <script> tag

How to use

Framework-less

<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://unpkg.com/@adc/forms/latest/dist/adc-forms.js"></script>
    <!-- or use the path to your node_modules folder if you are using npm -->
  </head>
  <body>
    <!-- The @adc/forms Web Components are now ready to be used. -->
    <!-- Please refer to the Component Catalog section below -->
  </body>
</html>

Alternatively, if you want to take advantage of ES Modules, you could include the components using an import statement.

<!DOCTYPE html>
<html lang="en">
  <head>
    <script type="module">
      import { defineCustomElements } from 'https://unpkg.com/adc/forms/latest/dist/esm/es2017/adc-forms.define.js';
      // or use the path to your node_modules folder if you are using npm
      defineCustomElements(window);
    </script>
  </head>
  <body>
    <!-- The @adc/forms Web Components are now ready to be used. -->
    <!-- Please refer to the Component Catalog section below -->
  </body>
</html>

Angular

Including the Custom Elements Schema

Including theCUSTOM_ELEMENTS_SCHEMA in the module allows the use of the web components in the HTML markup without the compiler producing errors. Here is an example of adding it to AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { SharedModule } from './shared/shared.module';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, FormsModule, SharedModule],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}

The CUSTOM_ELEMENTS_SCHEMA needs to be included in any module that uses custom elements.

Calling defineCustomElements

A component collection built with Stencil (such as this one) includes a main function that is used to load the components in the collection. That function is called defineCustomElements() and it needs to be called once during the bootstrapping of your application. One convenient place to do this is in main.ts as such:

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

import { defineCustomElements } from '@adc/forms/dist/loader';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic()
  .bootstrapModule(AppModule)
  .catch(err => console.log(err));
defineCustomElements(window);

React

With an application built using the create-react-app starter the easiest way to include the component library is to call defineCustomElements(window) from the index.js file.

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

import { defineCustomElements } from '@adc/forms/dist/loader';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
defineCustomElements(window);

Vue.js

In order to use the custom element library within the Vue app, the application must be modified to define the custom elements and to inform the Vue compiler which elements to ignore during compilation. This can all be done within the main.js file. For example (assuming you created your project with vue-cli):

import Vue from 'vue';
import App from './App.vue';
import { defineCustomElements } from '@adc/forms/dist/loader';

Vue.config.productionTip = false;
Vue.config.ignoredElements = [/adc-forms-\w*/];

defineCustomElements(window);

new Vue({
  render: h => h(App),
}).$mount('#app');

Component Catalog

Browser support

  • Chrome (and all Chromium based browsers)
  • Safari
  • Edge
  • Firefox (64+ only)

Web Components, specifically Custom Elements, are natively supported in Chrome and Safari and are coming to both Edge and Firefox. A dynamic polyfill loader is already included in order to only load the polyfills for the browsers that are missing specific features.