-
- {{ messageTitle }} {{ message }}
+
+
+ {{ messageTitle }}
+ {{ message }}
+ {{_showBtnText}}
+
+
@@ -80,11 +85,11 @@
properties: {
/**
* Establishes the alert level
- * - 'important'
- * - 'warning'
- * - 'error'
- * - 'information'
- * - 'custom' - allows a developer to specify HTML incluing images in place of the icon.
+ * - 'important' - red triangle labeled 1
+ * - 'warning'- orange diamond labeled 2
+ * - 'error' - yellow square labeled 3
+ * - 'information' - blue circle labeled 4
+ * - 'custom' - allows a developer to specify HTML including images in place of the icon.
* - 'more' - allows for a message that shows that there are more messages.
*/
type: {
@@ -93,7 +98,7 @@
value: 'information'
},
/**
- * The title that is displayed in the message area of the alert box.
+ * The title that is displayed bold in the message area of the alert box.
*/
messageTitle: {
type: String,
@@ -103,8 +108,7 @@
* The message body that is displayed in the message area of the alert box.
*/
message: {
- type: String,
- reflect: true
+ type: String
},
/**
* A delay in MS before a message is dismissed automatically.
@@ -148,23 +152,35 @@
},
_isNotMore: {
computed: '_isNotMoreType(type)'
+ },
+ _showBtnText: {
+ type: String,
+ value: "Show More"
+ },
+ _expandText: {
+ type: Boolean,
+ value: false
}
},
attached: function () {
+
this.listen(this, 'animationend', '_hide');
- this.$.alert.addEventListener('animationend', this._hide, true);
- this.$.alert.addEventListener('mozAnimationEnd', this._hide, true);
- this.$.alert.addEventListener('webkitAnimationEnd', this._hide, true);
- this.$.alert.addEventListener('msAnimationEnd', this._hide, true);
if(this.autoDismiss && this.autoDismiss > 0) {
this.setAutoDismiss(this.autoDismiss);
}
+ //for IE10 only: the attach callback is still too early for all text styles to have been applied
+ //this workaround allows for those styles to get applied, and then calling the message truncation function
+ //but, dom-change is too early for other browsers?
+ this.listen(this,'dom-change','_checkMessageLength');
+ //for all browsers except ie10, attach callback is sufficient
+ this._checkMessageLength();
+ this.listen(this.$.showMoreButton,'tap','_isTextExpanded');
+
},
detached: function () {
- this.$.alert.removeEventListener('animationend', this._hide, true);
- this.$.alert.removeEventListener('mozAnimationEnd', this._hide, true);
- this.$.alert.removeEventListener('webkitAnimationEnd', this._hide, true);
- this.$.alert.removeEventListener('msAnimationEnd', this._hide, true);
+ this.unlisten(this, 'animationend', '_hide');
+ this.unlisten(this,'dom-change','_checkMessageLength');
+ this.unlisten(this.$.showMoreButton,'tap','_isTextExpanded');
},
setAutoDismiss: function (dismissAfter) {
var _this = this;
@@ -176,9 +192,8 @@
};
this._timeouts = [];
}
-
- // store ID value of timer to clear once later
- this._timeouts.push(
+ // store ID value of timer to clear once later
+ this._timeouts.push(
setTimeout( function () {
_this._dismiss();
}, dismissAfter));
@@ -201,7 +216,6 @@
return (type !== 'more');
},
_dismiss: function () {
- //this.$.alert.classList.add('hidden');
this.$.alert.classList.add('fade-out');
},
_hide: function (event) {
@@ -213,6 +227,91 @@
this.$.alert.classList.remove('fade-out');
this.$.alert.classList.remove('hidden');
},
+ _isTextExpanded: function () {
+ this._expandText = !this._expandText;
+ if (this._expandText) {
+ this._showMore();
+ }
+ else {
+ this._showLess();
+ }
+ },
+ /**
+ * Checking to see if the combined message length of title and message exceed the max height of the parent div.
+ */
+ _checkMessageLength: function () {
+ var messageDiv = this.$.fullMessage,
+ messageTextTitle,
+ messageText;
+
+ // if the text fits, do nothing
+ if(this.type === "more" || messageDiv.scrollHeight <= messageDiv.offsetHeight){
+ return;
+ }
+
+ //Unhide button
+ this.toggleClass('visuallyhidden',false,this.$.showMoreButton);
+
+ //save original message and title as a var for expanding the message
+ //in IE10, we have to run checkMessageLength multiple times for all styles to load. We don't want to overwrite the original message.
+ this._messageTitleOriginal = this._messageTitleOriginal || this.messageTitle;
+ this._messageOriginal = this._messageOriginal || this.message;
+
+ //split message into an array
+ messageTextTitle = this.messageTitle.split(' ');
+ messageText = this.message.split(' ');
+
+ //Run while message is too long and truncate it.
+ while(messageDiv.scrollHeight > messageDiv.offsetHeight) {
+
+ //first truncate the message, then truncate the title
+ if(messageText.length > 0){
+ messageText.pop();
+ this.message = messageText.join(' ') + '...';
+ } else {
+ messageTextTitle.pop();
+ this.messageTitle = messageTextTitle.join(' ') + '...';
+ this.message = '';
+ }
+ }
+ //save short Message for shortening the message after it has been expanded
+ this.shortMessageTitle = this.messageTitle;
+ this.shortMessage = this.message;
+ },
+ /**
+ * run when 'show more' button is clicked to show full message
+ */
+ _showMore: function () {
+ this.messsageTruncatedHeight = this.$.fullMessage.offsetHeight;
+ //Safari draws from 0 therefore we need to create a min height to avoid jumping
+ this.$.fullMessage.style.minHeight = this.messsageTruncatedHeight + 'px';
+ this.$.fullMessage.style.height = this.messsageTruncatedHeight + 'px';
+ this.$.fullMessage.style.overflow = 'hidden';
+
+ this.toggleClass('collapse',false,this.$.fullMessage);
+ this.messageTitle = this._messageTitleOriginal;
+ this.message = this._messageOriginal;
+ this._showBtnText = 'Show Less';
+
+ this.$.fullMessage.style.height = this.$.message.offsetHeight + 'px';
+ },
+ /**
+ * run when 'show less' button is clicked to truncate message again
+ */
+ _showLess: function(){
+ this.$.fullMessage.style.height = this.messsageTruncatedHeight + 'px';
+ // Didnt include specfic brower transitionend events due to our brower support
+ this._showBtnText = 'Show More';
+ this.listen(this.$.fullMessage,'transitionend','_showLessAfterTransition');
+ },
+ /**
+ * helper function for _showLess, runs after css transition is completed
+ */
+ _showLessAfterTransition: function(){
+ this.toggleClass('collapse',true,this.$.fullMessage);
+ this._checkMessageLength();
+ this.unlisten(this.$.fullMessage,'transitionend','_showLessAfterTransition');
+ },
_action: function () {
if(this.action.indexOf('http') != -1) {
window.open(this.action);
@@ -226,7 +325,7 @@
} else if (action.indexOf('http') != -1) {
return 'Open';
} else {
- return ''; // future custom button actions
+ return ''; // future custom button actions
}
}
diff --git a/sass/px-alert-message-predix.scss b/sass/px-alert-message-predix.scss
index 0afd2248..6c4d1ffb 100644
--- a/sass/px-alert-message-predix.scss
+++ b/sass/px-alert-message-predix.scss
@@ -21,64 +21,42 @@ common/abstract rules go in px-alert-message-sketch.scss, not in this file.
// Settings
@import "px-colors-design/_settings.colors.scss";
-
@import 'px-alert-message-sketch.scss';
$alert-message-background: $gray3;
-.svg-triangle{
- margin: 0 auto;
- width: 100px;
- height: 100px;
-}
-
+//part of the icons
.svg-triangle polygon {
fill: $alert-red;
stroke: $white;
stroke-width: 1;
}
-
+.svg-triangle{
+ margin: 0 auto;
+ width: 100px;
+ height: 100px;
+}
.svg-canvas {
display: none;
}
-/** these should be more abstract than residing within this component */
-
-@keyframes fadein {
- from { opacity: 0; }
- to { opacity: 1; }
-}
-
-@keyframes fadeout {
- from {
- opacity: 1;
- max-height: 100px;
- min-height: 0px;
- }
- to {
- opacity: 0;
- max-height: 0px;
- min-height: 0px;
- padding-top: 0px;
- padding-bottom: 0px;
- }
+//Extend
+%icon {
+ color: $white;
+ text-align: center;
+ vertical-align: middle;
+ line-height: 30px;
+ font-weight: bold;
+ border: 1px solid $white;
}
// Component
.alert-message {
background-color: $alert-message-background;
opacity: 1;
- animation: fadein .5s;
- max-height: 100px;
- overflow: hidden;
- transition: max-height 1;
button, a {
outline: none;
}
- &.fade-out {
- animation: fadeout .5s;
- max-height: 0px;
- }
#icon {
&.custom {
::content img {
@@ -86,20 +64,15 @@ $alert-message-background: $gray3;
max-width: 100%;
}
}
- &.important {
- color: $white;
- text-align: center;
- vertical-align: middle;
- line-height: 30px;
- font-weight: bold;
- span {
-
- }
+ &.important,
+ %&.important {
+ border: none;
+ @extend %icon;
span:before {
content: '1';
position: absolute;
- top: 3px;
- left: 10px;
+ top: 4px;
+ left: 11px;
}
.svg-canvas {
display: block !important;
@@ -114,13 +87,8 @@ $alert-message-background: $gray3;
left: 2px;
margin-right: 5px;
background-color: $alert-orange;
- border: 1px solid $white;
- color: $white;
- text-align: center;
- vertical-align: middle;
- line-height: 30px;
- font-weight: bold;
transform: rotate(45deg);
+ @extend %icon;
span {
display: block;
position: relative;
@@ -134,40 +102,22 @@ $alert-message-background: $gray3;
}
&.error {
background-color: $alert-yellow;
- border: 1px solid $white;
- color: $white;
- text-align: center;
- vertical-align: middle;
- line-height: 30px;
- font-weight: bold;
+ @extend %icon;
span:before {
content: '3';
}
}
&.information {
background-color: $alert-blue;
- border: 1px solid $white;
border-radius: 40px;
- color: $white;
- text-align: center;
- vertical-align: middle;
- line-height: 30px;
- font-weight: bold;
+
+ @extend %icon;
span:before {
content: '4';
}
}
}
- .message {
- p.more {
- text-align: center;
- font-size: 1.4rem;
- margin-left: 20px;
- }
- span:first-child {
- font-weight: bold;
- }
- }
+
.action {
.dismiss {
color: $gray6;
diff --git a/sass/px-alert-message-sketch.scss b/sass/px-alert-message-sketch.scss
index 4d4187ba..9be2b86d 100644
--- a/sass/px-alert-message-sketch.scss
+++ b/sass/px-alert-message-sketch.scss
@@ -29,29 +29,80 @@ Predix branding rules go in px-alert-message-predix.scss, not in this file.
// Base
@import "px-flexbox-design/_base.flexbox.scss";
@import "px-viewport-design/_base.viewport.scss";
-@import "px-meta-buttons-design/_meta.buttons.scss";
+$inuit-enable-btn--bare: true;
+$inuit-enable-btn--bare-primary: true;
+@import "px-buttons-design/_objects.buttons.scss";
+$actionable: true;
+@import "px-actionable-text-icons/_objects.actionable.scss";
+
+/** these should be more abstract than residing within this component */
+
+@keyframes fadein {
+ from { opacity: 0; }
+ to { opacity: 1; }
+}
+
+@keyframes fadeout {
+ from {
+ opacity: 1;
+ max-height: $inuit-base-spacing-unit--small * 10;
+ min-height: 0px;
+ }
+ to {
+ opacity: 0;
+ max-height: 0px;
+ min-height: 0px;
+ padding-top: 0px;
+ padding-bottom: 0px;
+ }
+}
// Component
.alert-message {
- width: 400px;
- margin: 5px;
- padding: 10px;
- min-height: 50px;
+ width: $inuit-base-spacing-unit--small * 40;
+ margin: $inuit-base-spacing-unit--tiny;
+ padding: $inuit-base-spacing-unit--small;
+ min-height: $inuit-base-spacing-unit--small * 5;
+ animation: fadein .5s;
+ transition: max-height 1;
+ &.fade-out {
+ animation: fadeout .5s;
+ max-height: 0px;
+ }
.severity {
#icon {
position: relative;
- height: 30px;
- width: 30px;
+ height: 1.9rem;
+ width: 1.9rem;
+ //The square needs to be visually smaller
+ &.error {
+ height: 1.8rem;
+ width: 1.8rem;
+ }
}
}
.message {
- flex: 2 0px;
- margin-left: 10px;
- margin-right: 10px;
+ flex: 2;
+ margin-left: $inuit-base-spacing-unit--small;
+ margin-right: $inuit-base-spacing-unit--small;
+ transition: height 0.3s ease-in-out;
+ line-height: 1.14em;
+ font-size: 15px;
p {
padding: 0;
margin: 0;
}
+ p.more {
+ text-align: center;
+ font-size: 1.4rem;
+ margin-left: $inuit-base-spacing-unit--large;
+ }
+ &.collapse{
+ max-height: 3.7rem;
+ }
+ span:first-child {
+ font-weight: bold;
+ }
}
.action {
width: auto;
diff --git a/test/fixture.html b/test/fixture.html
index ecd2f871..577ad0ec 100644
--- a/test/fixture.html
+++ b/test/fixture.html
@@ -36,12 +36,14 @@