0.2.4 • Published 2 years ago

mx-custom-countdown v0.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

ACME Countdown

Goal: Create a Countdown timer for ACME Corp as a custom web component.

Stack: JavaScript, Stencil, HTML, CSS

Breakdown:

  1. Define requirements 1.1 - Web Component needs to recieve Countdown-Name and Countdown-Time in SECONDS. Adittional: Create a finish custom message. 1.2 - Seconds need to be translated to Hours/Minutes/Seconds. 1.3 - Timer needs a count-down logic. 1.4 - Give some style! UI is important. 1.5 - Give some pre-defined customization! Developers UX is also important.

  2. Create Stencil project.

  3. Create count-down logic.
  4. Give your code some styling love and final touches.
  5. Refactor.

Additional Info on 1.6

Available Tags: name="Launch Time" -> Title to be shown above Timer seconds="10000" -> Time of coutdown in Seconds final-message="Liftoff!" -> Message to be displayed once time is off custom-style="nasa" -> Custom Styles: Try "nasa" (white bkg), "spacex" (black bkg) or "acme" (red bkg) logo="nasa" -> predefined logo: Try "nasa", "spacex" or "acme" -> can be customized by importing a PNG file into the assets folder

Publish Package in NPM:

  1. Set account
  2. Build component
  3. Publish

In order to get the Package run: npm install mx-custom-countdown

In order to use the web-components:

React ->

  1. Install package
  2. Go to index.js and add the following imports: import {defineCustomElements} from "mx-custom-countdown/loader";

At the end of your file add:

defineCustomElements(window);

  1. Go to the file you want to use the component on and use it as you wish. Ex:

possible properties:

seconds="10" name="Launch" final-message="Lift off" custom-style="spacex" (possible combinations: nasa (white), spacex (black), acme(red)) logo="spacex" (possible: nasa, spacex, acme)

Angular:

  1. Install package
  2. Go to app.module.ts and add: import {CUSTOM_ELEMENTS_SCHEMA} from "@angular/core"

on ngModule:

@NgModule({ schemas: CUSTOM_ELEMENTS_SCHEMA })

Afterwards you need to register the elements like this (similar to React):

On main.ts:

import {defineCustomElements} from "mx-custom-countdown/loader";

defineCustomElements(window);


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

Need help? Check out our docs here.

Naming Components

When creating new component tags, we recommend not using stencil in the component name (ex: <stencil-datepicker>). This is because the generated component has little to nothing to do with Stencil; it's just a web component!

Instead, use a prefix that fits your company or any name for a group of related components. For example, all of the Ionic generated web components use the prefix ion.

Using this component

There are three strategies we recommend for using web components built with Stencil.

The first step for all three of these strategies is to publish to NPM.

Script tag
  • Put a script tag similar to this <script type='module' src='https://unpkg.com/my-component@0.0.1/dist/my-component.esm.js'></script> in the head of your index.html
  • Then you can use the element anywhere in your template, JSX, html etc
Node Modules
  • Run npm install my-component --save
  • Put a script tag similar to this <script type='module' src='node_modules/my-component/dist/my-component.esm.js'></script> in the head of your index.html
  • Then you can use the element anywhere in your template, JSX, html etc
In a stencil-starter app
  • Run npm install my-component --save
  • Add an import to the npm packages import my-component;
  • Then you can use the element anywhere in your template, JSX, html etc
0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.0.1

2 years ago