LT-275: Making common animation labels act as normal labels when clicked

This commit is contained in:
Bruno Alves de Faria authored and Erik Ziegler committed 2016-11-15 08:25:09 +01:00
1 parent 5a9379e6c3
commit cc8f486204
6 files changed
+40 -19

No files matched your search

@@ -177,7 +177,7 @@ Template.measureFlow.events({
'click .select-tree-common label'(event, instance) {
// Set the common section clicked flag
instance.commonClicked = true;
instance.commonClicked = event.currentTarget;
},
'change .select-tree-root'(event, instance) {
@@ -193,39 +193,44 @@ Template.measureFlow.events({
'click .tree-leaf input'(event, instance) {
const $target = $(event.currentTarget);
const $label = $target.closest('label');
let $label = $target.closest('label');
const $treeRoot = $label.closest('.select-tree-root');
const $container = $treeRoot.find('.tree-options:first');
let labelOffset;
// Check if the targe click was a label inside common section
// Check if the clicked target was a label inside common section
if (instance.commonClicked) {
const labelTop = $label.position().top;
const containerCenter = Math.round($container.height() / 2);
const labelCenter = Math.round($label.height() / 2);
// Scroll the options container to make the target input visible
$container.scrollTop(labelTop - containerCenter + labelCenter);
$label = $(instance.commonClicked);
labelOffset = $label.data('offset');
} else {
labelOffset = $label.offset();
}
// Change the measure flow state to selected
instance.state.set('selected');
// Get the clicked label window offset
const labelOffset = $label.offset();
// Wait for the DOM re-rendering
Tracker.afterFlush(() => {
// Get the measure flow div
const $measureFlow = instance.$('.measure-flow');
// Subtract the label box shadow height from the label's position
labelOffset.top -= 10;
// Adjust the label position
if (instance.commonClicked) {
labelOffset.top -= 10;
labelOffset.left -= 12;
} else {
labelOffset.top -= 10;
}
// Reposition the measure flow based on the clicked label position
$measureFlow.css(labelOffset);
// Resize the copied label with same width of the clicked one
$measureFlow.children('.tree-leaf').width($label.outerWidth());
// $measureFlow.children('.tree-leaf').width($label.outerWidth());
$measureFlow.children('.tree-leaf').width(212);
// Reset the flag to avoid wrong positioning when clicking normal labels again
instance.commonClicked = false;
});
// Wait the fade-out transition and remove the selectTree component
@@ -1,6 +1,7 @@
import './mixin.js';
import './selectTree.html';
import './selectTree.styl';
import './selectTree.js';
import './selectTreeCommon.html';
import './selectTreeCommon.js';
@@ -0,0 +1,284 @@
@import "{design}/app"
// TODO: [design] can't we use colors that are already in common pallete?
$gray1 = #A3A3A3
$gray2 = #A0A0A0
$gray3 = #C4C4C4
$gray4 = #C0C0C0
$gray5 = #9B9B9B
$gray6 = #303030
.select-tree-root
.tree-content
background-color: white
position: relative
transition(transform 0.3s ease\, background-color 0.3s ease\, border-color 0.3s ease\, border-radius 0.3s ease)
.tree-search
a.tree-back
.tree-breadcrumb span
.tree-node
.tree-leaf
transition(all 0.3s ease)
&.selected
label.tree-leaf.active
box-shadow: 0 0 0 10px white, inset 0 0 0 200px white
.tree-content
background-color: transparent
&>.tree-content
border-color: transparent
border-radius: 0
.tree-search
background-color: transparent
border-color: transparent
color: transparent
&, .select-tree
&:not(.open)>.tree-content
&>.tree-inputs
&>.tree-breadcrumb
display: none
&>.tree-content>.tree-options
&>.tree-inputs>label:not(.active)
&>.tree-breadcrumb a
&>.tree-breadcrumb span
color: transparent
&>.tree-inputs>label.tree-node:not(.active)
border-color: transparent
&.common-clicked .tree-leaf.active
background-color: transparent
box-shadow: none
color: transparent
.select-tree-root
display: inline-block
position: relative
z-index: 0
&>.tree-content
border: 1px solid $gray3
border-radius: 5px
overflow: hidden
&>.tree-content>.tree-options
transform(scale(1))
transition(height 0.3s ease)
.tree-search
background-color: $gray4
border-bottom: 1px solid $gray3
color: $gray6
display: block
margin: 0
padding: 5px
position: relative
text-align: center
span
font-weight: bold
line-height: 24px
input
border-color: $gray5
font-weight: normal
padding-left: 34px
& ~ i
color: $gray1
font-size: 18px
left: 16px
position: absolute
top: 37px
.tree-breadcrumb
line-height: 32px
padding: 5px 12px
.path-link, .tree-current-node
display: inline-block
font-weight: normal
float: left
overflow: hidden
text-overflow: ellipsis
white-space: nowrap
i
margin-right: 5px
.select-tree-node
left: 0
overflow: hidden
position: fixed
width: 100%
z-index: 2
&
.tree-content
.tree-inputs
height: 100%
.tree-options
overflow: hidden
position: relative
z-index: 2
.tree-node, .tree-leaf
cursor: pointer
display: block
font-weight: normal
margin-bottom: 0
padding: 0 12px
position: relative
z-index: 1
&>input
display: none
.tree-node
height: 41px
border-bottom: 1px solid $gray3
border-top: 1px solid $gray3
line-height: 41px
margin-top: -1px
&:last-child
border-bottom: 0
.tree-leaf
box-shadow: 0 0 0 200px transparent, inset 0 0 0 200px transparent
line-height: 26px
&.active
box-shadow: 0 0 0 200px white, inset 0 0 0 200px white
transition(box-shadow 0.3s ease)
z-index: 0
&:last-child:after
display: block
content: ''
height: 10px
&.collapsed
z-index: 1
.select-tree-common
height: 100%
padding-left: 6px
position: absolute
right: 0
top: 0
width: 50%
.content
background-color: $gray6
border: 1px solid $gray5
border-radius: 5px
color: white
opacity: 0.9
padding: 0 15px 12px
position: absolute
top: 50%
transform(translateY(-50%))
width: calc(100% - 6px)
h5.title
color: $gray5
font-weight: normal
line-height: 20px
margin: 12px 0 16px
div.labels
position: relative
label
cursor: pointer
display: block
font-weight: 300
line-height: 26px
margin: 0
padding-left: 3px
transition(padding 0.3s ease)
&:hover
padding-left: 0
.select-tree-root
&>.tree-content
transform(scale(0))
transform-origin(100% 50%)
.select-tree-common
overflow: hidden
z-index: -1
.content
margin-left: calc(-100% - 6px)
transition(all 0.3s ease 0.3s)
&.started
&>.tree-content
transform(scale(1))
.select-tree-common
animation-name: selectTreeCommonOverflow
animation-delay: 0.3s
animation-duration: 0.3s
animation-iteration-count: 1
animation-direction: alternate
animation-fill-mode: forwards
.content
margin-left: 0
&.interacted, &.selected
.select-tree-common
z-index: 1
.content
animation-name: selectTreeCommonCloseLeft
animation-duration: 0.3s
animation-iteration-count: 1
animation-direction: alternate
animation-timing-function: ease-out
animation-fill-mode: forwards
@keyframes selectTreeCommonOverflow {
from {
overflow: hidden
}
to {
overflow: visible
}
}
@keyframes selectTreeCommonCloseLeft {
from {
height: 37px
display: table
margin-left: 0
opacity: 1
visibility: visible
}
to {
height: 100%
margin-left: calc(-100% - 6px)
opacity: 0
visibility: hidden
width: calc(100% - 6px)
}
}
@@ -2,9 +2,11 @@
<div class="select-tree-common">
<div class="content">
<h5 class="title">Common</h5>
{{#each item in items}}
<label for="{{this.storageKey}}_{{encodeId item.value}}">{{item.label}}</label>
{{/each}}
<div class="labels">
{{#each item in items}}
<label for="{{this.storageKey}}_{{encodeId item.value}}">{{item.label}}</label>
{{/each}}
</div>
</div>
</div>
</template>
@@ -9,6 +9,9 @@ Template.selectTreeCommon.events({
// Get the clicked label
const $target = $(event.currentTarget);
// Store the offset position for further use
$target.data('offset', $target.offset());
// Build the input selector based on the label target
const inputSelector = '#' + $target.attr('for');
@@ -23,6 +26,9 @@ Template.selectTreeCommon.events({
// Wait for options rerendering
Tracker.afterFlush(() => {
const $treeRoot = treeInstance.$('.select-tree-root:first').first();
$treeRoot.addClass('common-clicked');
// Wait for components initialization
Meteor.defer(() => $(inputSelector).click());
});