-
Notifications
You must be signed in to change notification settings - Fork 20
/
px-data-grid-string-renderer.html
104 lines (87 loc) · 3.89 KB
/
px-data-grid-string-renderer.html
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
<!--
Copyright (c) 2018, General Electric
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../px-tooltip/px-tooltip.html">
<link rel="import" href="px-data-grid-renderer-mixin.html">
<link rel="import" href="px-data-grid-theme.html">
<link rel="import" href="css/px-data-grid-string-renderer-styles.html">
<!--
### Styling
The following custom properties are available for styling of the string-renderer content.
Custom property | Description
'--px-data-grid-cell-string-column-overflow' | controls the overflow behavior, visible, hidden
'--px-data-grid-cell-string-column-white-space' | controls how white-spaces are handled, normal, nowrap
'--px-data-grid-cell-string-column-word-wrap' | controls how word-wrapping is handled normal, break-word
'--px-data-grid-cell-string-column-text-overflow' | controls how text-overflow is handled, clip, ellipsis
'--px-data-grid-cell-string-column-editor-align-items | control editor alignment when in edit mode, center, flex-end, flex-start'
Examples:
Make string-renderer columns wrap the content:
--px-data-grid-cell-string-column-overflow: hidden;
--px-data-grid-cell-string-column-word-wrap: break-word;
Make string-renderer columns use ellipsis overflow:
--px-data-grid-cell-string-column-text-overflow: ellipsis;
--px-data-grid-cell-string-column-white-space: nowrap;
--px-data-grid-cell-string-column-overflow: hidden;
-->
<dom-module id="px-data-grid-string-renderer">
<template>
<style include="px-data-grid-string-renderer-styles"></style>
<template is="dom-if" if="[[!_editing]]">[[value]]</template>
<template is="dom-if" if="[[_editing]]" restamp>
<div class="input-container">
<input id="editingTemplateInput" class$="{{getClasses(validationResult)}}" type="text" value="{{value::change}}">
<px-tooltip
for="editingTemplateInput"
orientation="top"
tooltip-message="[[validationResult.message]]"
opened="[[_showValidationError]]"
ignore-target-events>
</div>
</template>
</template>
<script>
{
/**
* A `<px-data-grid-string-renderer>` is standard renderer for string cell content.
* This element shows how to implement custom renderer in order to display uncommon data.
* Each renderer that is needed for displaying content should have element with id="value",
* which is rendered in non-editable state of the cell.
* You may also provide element with id="editingTemplate", which will display when the cell is editing.
*
* @memberof Predix
* @extends Polymer.Element
* @mixes Predix.DataGridRendererMixin
*/
class DataGridStringRenderer extends Predix.DataGridRendererMixin(Polymer.Element) {
static get is() {
return 'px-data-grid-string-renderer';
}
validate() {
return {
valid: !this.column.required || this.value.length > 0,
message: this.localize('Value is required')
};
}
getClasses(result) {
return !result || result.valid ? 'text-input' : 'text-input validation-error';
}
}
customElements.define(DataGridStringRenderer.is, DataGridStringRenderer);
/**
* @namespace Predix
*/
window.Predix = window.Predix || {};
Predix.DataGridStringRenderer = DataGridStringRenderer;
}
</script>
</dom-module>