From 7c64005871a04049994c77002c913a5b87b2f4b8 Mon Sep 17 00:00:00 2001 From: Bruno Alves de Faria Date: Wed, 17 Aug 2016 10:21:38 -0300 Subject: [PATCH] LT-275: Creating 'Add description' button action --- Packages/design/styles/common/keyframes.styl | 32 ++++++++--------- .../design/styles/imports/animations.styl | 12 ++++--- .../components/measureFlow/measureFlow.html | 15 +++++++- .../components/measureFlow/measureFlow.js | 36 +++++++++++++++++++ .../components/measureFlow/measureFlow.styl | 33 +++++++++++++++-- 5 files changed, 104 insertions(+), 24 deletions(-) diff --git a/Packages/design/styles/common/keyframes.styl b/Packages/design/styles/common/keyframes.styl index f829b6af6..0c406e221 100644 --- a/Packages/design/styles/common/keyframes.styl +++ b/Packages/design/styles/common/keyframes.styl @@ -1,19 +1,19 @@ @import "{design}/app.styl" -@keyframes zoomInOut { - from { - transform(scale(0)) - } - to { - transform(scale(1)) - } -} +@keyframes zoomIn + from + transform(scale(0)) + to + transform(scale(1)) -@keyframes fadeInOut { - from { - opacity: 0 - } - to { - opacity: 1 - } -} +@keyframes fadeIn + from + opacity: 0 + to + opacity: 1 + +@keyframes fadeOut + from + opacity: 1 + to + opacity: 0 diff --git a/Packages/design/styles/imports/animations.styl b/Packages/design/styles/imports/animations.styl index eed97dc9c..5f8951ab1 100644 --- a/Packages/design/styles/imports/animations.styl +++ b/Packages/design/styles/imports/animations.styl @@ -1,15 +1,17 @@ animationDefaults() animation-duration: 0.3s - animation-iteration-count: 1 animation-direction: alternate animation-timing-function: ease-out + animation-fill-mode: forwards animateZoomIn() animationDefaults() - animation-name: zoomInOut - animation-fill-mode: forwards + animation-name: zoomIn animateFadeIn() animationDefaults() - animation-name: fadeInOut - animation-fill-mode: forwards + animation-name: fadeIn + +animateFadeOut() + animationDefaults() + animation-name: fadeOut diff --git a/Packages/lesiontracker/client/components/measureFlow/measureFlow.html b/Packages/lesiontracker/client/components/measureFlow/measureFlow.html index 45871e8e4..964454710 100644 --- a/Packages/lesiontracker/client/components/measureFlow/measureFlow.html +++ b/Packages/lesiontracker/client/components/measureFlow/measureFlow.html @@ -4,9 +4,22 @@ {{#if eq instance.state.get 'selected'}}
{{instance.value.label}} + {{#if instance.descriptionEdit.get}} +
+ +
+ {{else}} + {{#if instance.description.get}} +
{{instance.description.get}}
+ {{/if}} + {{/if}}
- +
{{/if}} diff --git a/Packages/lesiontracker/client/components/measureFlow/measureFlow.js b/Packages/lesiontracker/client/components/measureFlow/measureFlow.js index 32b878111..b200e2532 100644 --- a/Packages/lesiontracker/client/components/measureFlow/measureFlow.js +++ b/Packages/lesiontracker/client/components/measureFlow/measureFlow.js @@ -9,6 +9,8 @@ Template.measureFlow.onCreated(() => { const instance = Template.instance(); instance.state = new ReactiveVar('closed'); + instance.description = new ReactiveVar(''); + instance.descriptionEdit = new ReactiveVar(false); instance.items = [{ label: 'Category 1', @@ -120,6 +122,40 @@ Template.measureFlow.events({ instance.selectTreeView = Blaze.renderWithData(Template.selectTree, data, parentElement); }); }, + 'click .measure-flow .btn-description'(event, instance) { + // Fade out the action buttons + instance.$('.measure-flow .actions').addClass('fadeOut'); + + // Set the description edit mode + instance.descriptionEdit.set(true); + + // Wait for DOM rerendering, resize and focus the description textarea + Tracker.afterFlush(() => { + const $textarea = instance.$('textarea'); + $textarea.trigger('input').focus(); + }); + }, + 'input textarea, change textarea'(event, instance) { + const element = event.currentTarget; + const $element = $(element); + + // Resize the textarea based on its content length + $element.css('max-height', 0); + $element.height(element.scrollHeight); + $element.css('max-height', ''); + }, + 'keydown textarea'(event, instance) { + // Unset the description edit mode if ENTER or ESC was pressed + if (event.which === 13 || event.which === 27) { + instance.$('.measure-flow .actions').removeClass('fadeOut'); + instance.descriptionEdit.set(false); + } + + // Keep the current description if ENTER was pressed + if (event.which === 13) { + instance.description.set($(event.currentTarget).val()); + } + }, 'click .select-tree-common label'(event, instance) { instance.commonClicked = true; }, diff --git a/Packages/lesiontracker/client/components/measureFlow/measureFlow.styl b/Packages/lesiontracker/client/components/measureFlow/measureFlow.styl index a5cd20585..5fbe75f6b 100644 --- a/Packages/lesiontracker/client/components/measureFlow/measureFlow.styl +++ b/Packages/lesiontracker/client/components/measureFlow/measureFlow.styl @@ -73,8 +73,13 @@ .actions margin-top: 16px opacity: 0 - animateFadeIn() - animation-delay: 0.3s + + &:not(.fadeOut) + animateFadeIn() + animation-delay: 0.3s + + &.fadeOut + animateFadeOut() button background-color: transparent @@ -87,6 +92,30 @@ padding: 0 12px text-align: center + .description + margin-top: -10px + margin-bottom: 26px + + textarea + background-color: white + box-shadow: 0 10px white + border: 0 + line-height: 20px + outline: none + overflow: hidden + padding: 0 12px + resize: none + transition(height 0.3s ease) + width: 100% + + .descriptionText + background-color: white + box-shadow: 0 10px white + line-height: 20px + margin-bottom: 26px + margin-top: -10px + padding: 0 12px + &.selected>.tree-leaf span