Skip to content

muneerzargar/stencil-form-example

Repository files navigation

Built With Stencil

Stencil Component Starter

This is a starter project for building a standalone Web Component using Stencil.

Stencil is also great for building entire apps. For that, use the stencil-app-starter instead.

Stencil

Stencil is a compiler for building fast web apps using Web Components.

Stencil combines the best concepts of the most popular frontend frameworks into a compile-time rather than run-time tool. Stencil takes TypeScript, JSX, a tiny virtual DOM layer, efficient one-way data binding, an asynchronous rendering pipeline (similar to React Fiber), and lazy-loading out of the box, and generates 100% standards-based Web Components that run in any browser supporting the Custom Elements v1 spec.

Stencil components are just Web Components, so they work in any major framework or with no framework at all.

Getting Started

To start building a new web component using Stencil, clone this repo to a new directory:

git clone https://github.com/ionic-team/stencil-component-starter.git my-component
cd my-component
git remote rm origin

and run:

npm install
npm start

To build the component for production, run:

npm run build

To run the unit tests for the components, run:

npm test

Component Description

The component is developed using Html, Css, Stenciljs. The structure is divided into multiple components listed as sjs-form-component, sjs-input-component and sjs-input-sign-component where SJS stands for stencil js.

  • sjs-form-component renders the form and dspatchs an event on the click of the button. The button is enabled only on the successful validation of the input fields. The form is valid when the input is greater than '0.00'. This can be further extended with the inclusion of the multiple components. Alternative - Form to support slots, such that the end user of the component is able to pass child elements in the component.

  • sjs-input-sign is an attempt to create an functional component. Such components can be used to render the markup, component does not cater to lifecycle hooks for more information Functional components with Stencil

  • sjs-input-component renders multiple user input fields and is responsible for the validation of the input fields such that it accepts only numeric values (this is based on the passed property allowOnlyNumbers). The Values are combined in this component and an event "computedInputValue" is dispatched from the component which is listened at the parent component in this case form component within JSX template.

Further Additions

  • Fixing the errors/warnings given by tsx/ts.