1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# Vaadin Core Elements
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/vaadin/vaadin-core-elements?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Vaadin Core Elements is an evolving set of custom HTML elements, built using [Polymer](https://www.polymer-project.org), for building mobile and desktop web applications in modern browsers.
### Examples and Documentation
View live examples and source code side-by-side for individual custom elements.
| Element | Description | Version
| --- | --- | --- |
| [<**vaadin-grid**>](https://github.com/vaadin/vaadin-grid) · [Examples](https://cdn.vaadin.com/vaadin-core-elements/latest/vaadin-grid/demo/) · [API](https://cdn.vaadin.com/vaadin-core-elements/latest/vaadin-grid/) | Data grid for showing large amounts of tabular data. | ![Bower version](https://img.shields.io/bower/v/vaadin-grid.svg) |
| [<**vaadin-combo-box**>](https://github.com/vaadin/vaadin-combo-box) · [Examples](https://cdn.vaadin.com/vaadin-core-elements/master/vaadin-combo-box/demo/) · [API](https://cdn.vaadin.com/vaadin-core-elements/master/vaadin-combo-box/) | Filterable select element for a large set of items. | ![Bower version](https://img.shields.io/bower/v/vaadin-combo-box.svg) |
### Installation
We offer three ways to use Vaadin Core Elements in your project: Bower, CDN and ZIP archive. The only difference between the options is the URL you use to import the necessary files into your HTML page.
#### 1. Create a new folder for your project
```shell
$ mkdir my-project
$ cd my-project
```
#### 2. Install Vaadin Core Elements
- ##### Bower
We recommend using [Bower](http://bower.io) for managing your front-end dependencies. Follow the [Bower installation instructions](http://bower.io/#install-bower), then run the following command inside your project folder to install the most recent stable release.
```shell
$ bower install --save vaadin-core-elements
```
This will download Vaadin Core Elements bundle and its dependencies to the `bower_components` folder inside your project's folder.
If you wish to use the development snapshot version of some component, you can install/update that separately:
```shell
$ bower install --save vaadin-grid#master
```
- ##### CDN
You can use Vaadin Core Elements from CDN (see example below). This is especially convenient for services like JSFiddle, Codepen.io, etc.
For example, to import vaadin-grid, use the following URL:
`https://cdn.vaadin.com/vaadin-core-elements/latest/vaadin-grid/vaadin-grid.html`
To import all Vaadin Core Elements, use the following URL:
`https://cdn.vaadin.com/vaadin-core-elements/latest/vaadin-core-elements/vaadin-core-elements.html`
> You can also use the nightly snapshot versions of any component, e.g. https://cdn.vaadin.com/vaadin-core-elements/master/vaadin-grid/vaadin-grid.html
- ##### Download ZIP
1. Download the latest ZIP archive from [vaadin.com/download](https://vaadin.com/download#elements)
2. Extract the archive under your project folder, for example `deps`
#### 3. Create a HTML file
Create a new HTML file inside your project folder and copy the following code into it (choose one of the options how to import Vaadin Core Elements in the `<head>` section):
> **Serving the files during development**, when using Bower or the ZIP archive:
> Due to browser security restrictions, serving HTML imports from a `file:///` URL does not work. You need a web server to view pages where you use custom elements. One simple option is to use the [`serve`](https://www.npmjs.com/package/serve) NPM package.
```html
<!doctype html>
<html>
<head>
<!-- Import Web Component polyfills and all Vaadin Core Elements -->
<!-- CDN -->
<script src="https://cdn.vaadin.com/vaadin-core-elements/latest/webcomponentsjs/webcomponents-lite.min.js"></script>
<link href="https://cdn.vaadin.com/vaadin-core-elements/latest/vaadin-core-elements/vaadin-core-elements.html" rel="import">
<!-- Bower -->
<!-- <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link href="bower_components/vaadin-core-elements/vaadin-core-elements.html" rel="import"> -->
<!-- ZIP archive -->
<!-- <script src="deps/webcomponentsjs/webcomponents-lite.min.js"></script>
<link href="deps/vaadin-core-elements/vaadin-core-elements.html" rel="import"> -->
</head>
<body>
<!-- Use the elements, for instance vaadin-grid -->
<vaadin-grid selection-mode="multi">
<table>
<!-- Define the columns -->
<col name="index" width="48">
<col name="user.picture.thumbnail" width="54">
<col name="user.name.first">
<col name="user.name.last">
<col name="user.email" flex>
</table>
<!-- Define custom column headers -->
<thead>
<tr>
<th>#</th>
<th></th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
</vaadin-grid>
<script>
// The Web Components polyfill introduces a custom event we can
// use to determine when the custom elements are ready to be used
document.addEventListener("WebComponentsReady", function () {
// Configure vaadin-grid to show data
// Reference to the grid element
var grid = document.querySelector("vaadin-grid");
// Fetch some JSON data from a URL
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
if (xhr.status == 200) {
var json = JSON.parse(xhr.responseText);
// Use the returned data array directly as the data source
// (keeping all the data source items in the browser's memory)
grid.items = json.results;
}
}
}
xhr.open("GET", "http://api.randomuser.me/?results=100", true);
xhr.send();
// Add a renderer for the index column
grid.columns[0].renderer = function(cell) {
cell.element.innerHTML = cell.row.index;
}
// Add a renderer for the picture column
grid.columns[1].renderer = function(cell) {
cell.element.innerHTML = '<img src="' + cell.data + '" style="width: 24px;">';
}
});
</script>
</body>
</html>
```
|