Improve logic of selection inside table

This commit is contained in:
Marcos Moura 2016-10-26 21:59:51 -02:00
parent 0bcca87f08
commit aa4135fc71
8 changed files with 53 additions and 16 deletions

View file

@ -26,7 +26,8 @@
}, },
"globals": { "globals": {
"arguments": true, "arguments": true,
"window": true "window": true,
"Promise": true
}, },
"root": true, "root": true,
"parserOptions": { "parserOptions": {

View file

@ -25,7 +25,7 @@
</thead> </thead>
<tbody> <tbody>
<md-table-row v-for="test in 10"> <md-table-row v-for="test in 100">
<td>Cell 1</td> <td>Cell 1</td>
<td>Cell 2</td> <td>Cell 2</td>
<td>Cell 3</td> <td>Cell 3</td>

View file

@ -42,7 +42,9 @@
}, },
"dependencies": { "dependencies": {
"autosize": "^3.0.17", "autosize": "^3.0.17",
"chokidar": "^1.6.1",
"element.scrollintoviewifneeded-polyfill": "^1.0.1", "element.scrollintoviewifneeded-polyfill": "^1.0.1",
"node-sass": "3.10.1",
"scopedQuerySelectorShim": "github:lazd/scopedQuerySelectorShim", "scopedQuerySelectorShim": "github:lazd/scopedQuerySelectorShim",
"vue": "^2.0.2" "vue": "^2.0.2"
}, },

View file

@ -8,7 +8,6 @@ $checkbox-ripple-size: 48px;
margin: 16px 8px 16px 0; margin: 16px 8px 16px 0;
display: inline-flex; display: inline-flex;
position: relative; position: relative;
transform: translate3D(0, 0, 0);
.md-checkbox-container { .md-checkbox-container {
width: $checkbox-size; width: $checkbox-size;
@ -17,6 +16,7 @@ $checkbox-ripple-size: 48px;
border-radius: 2px; border-radius: 2px;
border: 2px solid rgba(#000, .54); border: 2px solid rgba(#000, .54);
transition: $swift-ease-out; transition: $swift-ease-out;
transform: translate3D(0, 0, 0);
&:after { &:after {
width: 6px; width: 6px;

View file

@ -4,6 +4,14 @@
display: flex; display: flex;
flex-flow: column wrap; flex-flow: column wrap;
&.md-transition-off {
tr,
.md-checkbox .md-checkbox-container,
.md-checkbox .md-checkbox-container:after {
transition: none !important;
}
}
table { table {
width: 100%; width: 100%;
border-spacing: 0; border-spacing: 0;
@ -40,7 +48,6 @@
height: 56px; height: 56px;
position: relative; position: relative;
overflow: hidden; overflow: hidden;
transition: $swift-ease-out;
color: rgba(#000, .54); color: rgba(#000, .54);
font-size: 12px; font-size: 12px;
line-height: 16px; line-height: 16px;

View file

@ -16,7 +16,8 @@
data() { data() {
return { return {
numberOfRows: 0, numberOfRows: 0,
selectedRows: [] numberOfSelected: 0,
selectedRows: {}
}; };
}, },
computed: { computed: {

View file

@ -9,6 +9,8 @@
</template> </template>
<script> <script>
const transitionClass = 'md-transition-off';
export default { export default {
data() { data() {
return { return {
@ -25,25 +27,34 @@
}, },
methods: { methods: {
setSelectedRow(value, index) { setSelectedRow(value, index) {
let arrayIndex = this.$parent.selectedRows.indexOf(index);
if (arrayIndex >= 0) {
this.$parent.selectedRows.splice(arrayIndex, 1);
}
if (value) { if (value) {
this.$parent.selectedRows.push(index); this.$parent.selectedRows[index] = value;
++this.$parent.numberOfSelected;
} else {
delete this.$parent.selectedRows[index];
--this.$parent.numberOfSelected;
} }
}, },
handleSingleSelection(value) { handleSingleSelection(value) {
this.setSelectedRow(value, this.index); this.setSelectedRow(value, this.index);
this.$parent.$children[0].checkbox = this.$parent.selectedRows.length >= this.$parent.numberOfRows; this.$parent.$children[0].checkbox = this.$parent.numberOfSelected >= this.$parent.numberOfRows;
}, },
handleMultipleSelection(value) { handleMultipleSelection(value) {
this.$parent.$children.forEach((row, index) => { this.$parent.$el.classList.add(transitionClass);
this.$parent.$children.forEach((row) => {
row.checkbox = value; row.checkbox = value;
this.setSelectedRow(value, index + 1);
}); });
if (value) {
/*this.$parent.selectedRows = {}; //and so on, this can be lazly created the first time or on component boot*/
this.$parent.numberOfSelected = this.$parent.numberOfRows;
} else {
/*this.$parent.selectedRows = {};*/
this.$parent.numberOfSelected = 0;
}
window.setTimeout(() => this.$parent.$el.classList.remove(transitionClass));
}, },
select(value) { select(value) {
if (this.$parent.mdRowSelection) { if (this.$parent.mdRowSelection) {

View file

@ -1123,6 +1123,21 @@ change-case@3.0.x:
upper-case "^1.1.1" upper-case "^1.1.1"
upper-case-first "^1.1.0" upper-case-first "^1.1.0"
chokidar:
version "1.6.1"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.6.1.tgz#2f4447ab5e96e50fb3d789fd90d4c72e0e4c70c2"
dependencies:
anymatch "^1.3.0"
async-each "^1.0.0"
glob-parent "^2.0.0"
inherits "^2.0.1"
is-binary-path "^1.0.0"
is-glob "^2.0.0"
path-is-absolute "^1.0.0"
readdirp "^2.0.0"
optionalDependencies:
fsevents "^1.0.0"
chokidar@^1.0.0: chokidar@^1.0.0:
version "1.6.0" version "1.6.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.6.0.tgz#90c32ad4802901d7713de532dc284e96a63ad058" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.6.0.tgz#90c32ad4802901d7713de532dc284e96a63ad058"
@ -3221,7 +3236,7 @@ node-pre-gyp@^0.6.29:
tar "~2.2.0" tar "~2.2.0"
tar-pack "~3.1.0" tar-pack "~3.1.0"
node-sass@^3.10.1: node-sass@3.10.1:
version "3.10.1" version "3.10.1"
resolved "https://registry.yarnpkg.com/node-sass/-/node-sass-3.10.1.tgz#c535b2e1a5439240591e06d7308cb663820d616c" resolved "https://registry.yarnpkg.com/node-sass/-/node-sass-3.10.1.tgz#c535b2e1a5439240591e06d7308cb663820d616c"
dependencies: dependencies: