Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jfdelarosa/VanillaJS-components

Web components using vanilla JS only
https://github.com/jfdelarosa/VanillaJS-components

javascript js vanilla webcomponents

Last synced: about 2 months ago
JSON representation

Web components using vanilla JS only

Awesome Lists containing this project

README

        

# VanillaJS Components

A set of cross-browser web componens made using only vanilla js

[Demo](http://jfdelarosa.me/VanillaJS-components/)

### Installation

```
$ npm install jfdelarosa/vanillajs-components
```
Alternatively, you can [download](https://github.com/jfdelarosa/vanillajs-components/archive/master.zip) the repo.

### Run server

```
$ npm start
```

## Basic usage

**index.html**
```HTML


VanillaJS components

Hello



loadComponent('path/to/my-hello');

```
**my-hello.js**
```JAVASCRIPT
registerComponent('my-hello', {
template: function(){
return `

Hello ${this.myText}!
`;
},
stylesheet: 'path/to/component-stylesheet.css',
attributes: ['my-text', 'debug'],
functions: {
'debug': function(value, template){
console.log(value);
console.log(template);
}
}
});
```

## Methods
```JAVASCRIPT
loadComponent(path);
```

**path**

A string wich contains the path of the component script.

```JAVASCRIPT
registerComponent(componentTag, options);
```

**componentTag**

The tag of the component.

**options**

An object containing the configuration of the component, the options are listed below.

## Options
**template** (required)

> A **function** that returns the template, you can pass any component attribute using ES6 template literals `${this.attribute}`.

> Also, you can use external variables if the `this` keyword is omitted `$(globalVar)`.

> Parameters containing hyphens are converted to camel case.

> You can use the `` tag to use the text inside the component tags in the template, as seen on the example above.

**stylesheet** (optional)

> A **string** containing the path to the component stylesheet.

> Stylesheets are NOT component specific, and can affect other the layout of the page or other components as well.

**attributes** (optional)

> An **array** containing the names of the atributes of the component.

**functions** (optional)

> An **object** containing component parameters as keys and functions as values, each of this functions has the value of the specified component parameter and the component template as parameters.

## Browser Support

| | IE | Chrome | Firefox | Safari | Chrome Android | Safari iOS |
| :--------------------: | :---: | :----: | :-----: | :-------: | :------------: | :-----------: |
| Version | x | x | x | x | x | x |

## TODO
- [ ] Check Browser support
- [ ] Attatch events to the component
- [x] Component ``
- [ ] Refactor code
- [ ] Better documentation