3.0.1 • Published 5 years ago

typescript-components v3.0.1

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

typescript-components

A TypeScript Framework for non-pwa pages

Installation

npm install typescript-components --save

Node

import "typescript-components";

Why not Angular, React, Vue.js etc?

Have you ever had to develop a project that you could not develop as a singe-page project?

I have encountered this problem many times already. Every time I wanted to use one of the above frameworks, but could not, because these are based on client-side rendering.

This framework is based on simple components, which can be set to an element via data attribute and thus extend this to various functionalities.

Usage

First, the component must be declared. Here we declare a simple "scroll to top" button.

// scroll-top.component.ts
import {AbstractComponent, Component, ElementAttribute, EventListener, smoothScroll} from "typescript-components";

/**
 * Decorate the declared component class with the @Component decorator (the magic happens here)
 */
@Component({
	/**
	 * define the data- selector which should be used to identify the element
	 * (matches scroll-top and data-scroll-top)
	 */
	selector: 'scroll-top'
})
export class ScrollTopComponent extends AbstractComponent {

	/**
	 * Declare a class property and decorate it via the @ElementAttribute decorator which automatically retrieves the attribute value of the element on page load.
	 * (800 if the element would look like this <button scroll-top duration="800">To top!</button>)
	 *
	 * If the attribute is not specified, the default value (in this case 500) is used
	 */
	@ElementAttribute()
	protected duration = 500;

	/**
	 * Attach a simple click listener to the element.
	 *
	 * You can also define multiple listeners of the same kind if you specify the listener name as first argument for the @EventListener decorator like:
	 *
	 * @EventListener('click')
	 * public clickOne() {
	 * }
	 *
	 * @EventListener('click')
	 * public clickTwo() {
	 * }
	 *
	 */
	@EventListener()
	public click() {
		smoothScroll(0, +this.duration);
	}
}

Then we need to register the created component for bootstrapping.

// main.ts
import {ComponentFactory} from "typescript-components";
import {ScrollTopComponent} from "./scroll-top.component";

ComponentFactory.registerComponents([
	ScrollTopComponent
]);

Now we just have to define the html and call the page (after building the javascript of cause).

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"/>
    <title>TypeScript Components</title>
  </head>
<body>
	<button scroll-top duration="1000">To Top 1000ms</button>
  <script src="build.js"></script>
</body>
</html>

Take a look at the examples if you want to see more advanced component configurations.

A documentation will follow soon to show you all programming possibilities.

3.0.1

5 years ago

3.0.0

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3-1

5 years ago

2.0.3

5 years ago

2.0.2-1

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.11

5 years ago

1.2.10

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago