forked from predixdesignsystem/px-data-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpx-data-table-highlight.html
146 lines (135 loc) · 4.52 KB
/
px-data-table-highlight.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
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
<!--
Relative paths assume component is being run from inside an app or another component, where dependencies are flat
siblings. When this component is run from its own repo (e.g. ui tests, examples), we assume the server is started with
'grunt depserve' (or similar server setup) to enable correct finding of bower dependencies for local runs.
-->
<link rel="import" href="../polymer/polymer.html" />
<!--
Element to define and configure highlighting behaviour for a given column (and hence cell or row).
##### Usage
<px-data-table-highlight highlight-type="row" highlight-method="isLongString" import="px-example-highlight.html"></px-data-table-highlight>
@element px-data-table-highlight
@blurb Element to define and configure highlighting behaviour for a given column (and hence cell or row).
@homepage index.html
@demo demo.html
-->
<link rel="import" href="css/px-data-table-highlight-styles.html">
<dom-module id="px-data-table-highlight">
<template>
<style include="px-data-table-styles"></style>
<span></span>
<content></content>
</template>
</dom-module>
<script>
Polymer({
is: 'px-data-table-highlight',
/**
* Properties block, expose attribute values to the DOM via 'notify'
*
* @property properties
* @type Object
*/
properties: {
/**
* A url that points to a file containing the JavaScript methods to be used for determining the highlighting behavior.
*
* @property import
* @default ""
*/
import: {
type: String,
value: ''
},
/**
* An object that holds the highlighting methods and attaches them to the window of the application.
*
* @property import
* @default "{}"
*/
highlight: {
type: Object,
value: function(){
return new Function();
}
},
/**
* A JavaScript method name from the file located at the import url.
*
* @property highlightMethod
* @default ""
*/
highlightMethod: {
type: String,
value: ''
},
/**
* Property to set the custom highlight colour style - supports any CSS color value e.g. 'rgb(67,100,221,0.25)', 'lightblue', '#0000FF' etc.
*
* <px-data-table-highlight highlight-color="rgb(67,100,221,0.25)" highlight-type="row" highlight-method="isLongString" import="px-data-table-highlight-example.html"></px-data-table-highlight>
*
* @property highlightColor
* @default ""
*/
highlightColor: {
type: String,
value: ''
},
/**
* Property for what actually gets highlighted - either 'cell' or 'row'
*
* <px-data-table-highlight highlight-color="rgb(67,100,221,0.25)" highlight-type="row" highlight-method="isLongString" import="px-data-table-highlight-example.html"></px-data-table-highlight>
*
* @property highlightType
* @default "cell"
*/
highlightType: {
type: String,
value: 'cell'
},
/**
* Property to set the pre-defined style of a highlight based on severity. One of 'high', 'medium' or 'low'
*
* <px-data-table-highlight highlight-value="low" highlight-type="row" highlight-method="isLongString" import="px-data-table-highlight-example.html"></px-data-table-highlight>
*
* @property highlightValue
* @default "low"
*/
highlightValue: {
type: String,
value: 'low'
}
},
/**
* Loads the imported highlight function.
*
* @method ready
*/
ready: function() {
this.importHref(this.import, function(e) {
if (this.highlightMethod && window.PxHighlight[this.highlightMethod]){
this.highlight = window.PxHighlight[this.highlightMethod];
this.fire('px-data-table-highlight-loaded');
}
}, function(e) {
// loading error
}, false);
},
/**
* Returns the appropriate highlight color according to what is configured via highlight-color or highlight-value.
*
* @method calculateHighLightColor
*/
calculateHighlightColor: function(){
var highlightColorValue;
this.updateStyles();
if(this.highlightColor){
highlightColorValue = this.highlightColor;
} else {
var cssVarName = '--cell--value__highlight--' + this.highlightValue + '--color';
highlightColorValue = this.getComputedStyleValue(cssVarName);
}
return highlightColorValue;
}
});
</script>