This repository was archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheditable-table-sort.html
More file actions
147 lines (136 loc) · 3.95 KB
/
editable-table-sort.html
File metadata and controls
147 lines (136 loc) · 3.95 KB
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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="editable-table-iconset.html">
<!--
`editable-table-sort`
A column header that functions as a three-state sort button
(no sort, sort ascending, sort descending) for the
table-editor-display mode (table-editor-display.html).
@demo demo/index.html
@microcopy - the mental model for this element
<editable-table-sort
sort-mode="asc" //The column's sort mode, can be "asc", "desc", or "none". Default is "none".
sort-column="3" //The column number of current sort column.
column-number="2" //The column number of this button. If this matches the sort-column number, sorting will be turned on.
text=""> //The text of the column header
</editable-table-sort>
-->
<dom-module id="editable-table-sort">
<template>
<style is="custom-style">
:host paper-button {
padding: 0;
margin: 0;
width: 100%;
min-width: unset;
display: inline-flex;
justify-content: space-between;
align-items:center;
align-content: stretch;
text-transform: unset;
}
:host paper-button > div {
flex-grow: 1;
}
:host .sr-only {
position: absolute;
left: -9999px;
font-size: 0;
height: 0;
width: 0;
overflow: hidden;
}
:host:not([sort-mode="asc"]) .asc,
:host:not([sort-mode="desc"]) .desc,
:host:not([sort-mode="none"]) .none,
:host #asc,
:host #desc,
:host[sorting]:not([sort-mode="none"]) #none {
display: none;
}
:host[sorting][sort-mode="asc"] #asc,
:host[sorting][sort-mode="desc"] #desc {
display: flex;
}
</style>
<paper-button id="button" class="container">
[[text]]
<span class="sr-only asc">(ascending)</span>
<span class="sr-only desc">(descending)</span>
<span class="sr-only"> Toggle sort mode.</span>
<iron-icon id="asc" icon="arrow-drop-up"></iron-icon>
<iron-icon id="desc" icon="arrow-drop-down"></iron-icon>
<iron-icon id="none" icon="editable-table:sortable"></iron-icon>
</paper-button>
</template>
<script>
Polymer({
is: 'editable-table-sort',
listeners: {
"tap": "_onSortTapped"
},
properties: {
/**
* sort ascending, descending or none
*/
columnNumber: {
type: Number,
value: null,
reflectToAttribute: true
},
/**
* Sort mode: ascending, descending or none
*/
sortMode: {
type: String,
value: "none",
reflectToAttribute: true
},
/**
* The index of the current sort column
*/
sortColumn: {
type: Number,
value: -1,
reflectToAttribute: true
},
/**
* If this is the sort column, sorting is on
*/
sorting: {
type: Boolean,
computed: '_isSorting(columnNumber,sortColumn)',
reflectToAttribute: true
},
/**
* the column header text
*/
text: {
type: String,
value: ""
},
},
/**
* listen for button tap
*/
_onSortTapped: function(){
let root = this;
root.fire('change-sort-mode',root);
},
/**
* changes the sort mode
*/
setSortMode: function(mode){
this.sortMode = mode;
this.__checked = mode === 'asc' ? true : mode === 'desc' ? mode : false;
},
/**
* Is the column number is the same as the current sort column?
*/
_isSorting: function(columnNumber,sortColumn){
return columnNumber === sortColumn;
}
});
</script>
</dom-module>