Skip to content

Commit

Permalink
Expandable button: added implementation and examples
Browse files Browse the repository at this point in the history
[Issue] Samsung#1336
[Problem] Expandable button: Card type - not implemented, no example
[Solution]
 - new example
 - extend styles for ui-content-area

Signed-off-by: Tomasz Lukawski <t.lukawski@samsung.com>
  • Loading branch information
TomaszLukawskiSam committed Jul 24, 2020
1 parent d12873b commit a0d197e
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ <h1>
Expand button on list
</a>
</li>
<li class="ui-li-anchor">
<a href="expandable-card.html">
Expand button on card
</a>
</li>
</ul>
</div>
<!-- /content -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>

<head>
<title>Expandable Card</title>
<meta content="width=device-width, user-scalable=no" name="viewport" />
<link href="../../lib/tau/mobile/theme/default/tau.css" rel="stylesheet" />
<link href="../../css/style.css" rel="stylesheet" />
<script data-build-remove="false" src="../../lib/tau/mobile/js/tau.js">
</script>
</head>

<body>
<div class="ui-page">
<div class="ui-header" data-position="fixed">
<div class="ui-appbar-left-icons-container">
<a href="#" class="ui-btn ui-btn-icon ui-btn-icon-back" data-style="flat" data-rel="back"></a>
</div>
<div class="ui-appbar-title-container">
<span class="ui-appbar-title">Expand button on card</span>
</div>
<div class="ui-appbar-action-buttons-container">
<button class="ui-btn ui-btn-icon ui-btn-icon-more" data-style="flat"></button>
</div>
</div>
<div class="ui-content">
<div class="ui-content-area">
<div class="ui-expandable">
<h2>
Subtitle 1
</h2>
<div class="app-content-example">
Contents area
</div>
</div>
</div>
<div class="ui-content-area">
<div class="ui-expandable" data-expander="button">
<h2>Subtitle 2
<button class="ui-btn ui-btn-icon" class="ui-expandable-toggle" data-icon="down" data-style="flat"></button>
</h2>
<div class="app-content-example">
Contents
</div>
<div class="ui-expandable-content app-content-example-expanded">
Contents area
</div>
</div>
</div>
</div>
</div>
</body>

</html>
31 changes: 26 additions & 5 deletions examples/mobile/UIComponents/css/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Header */
.btn-icon-back::after {
-webkit-mask-image: url(./images/core_icon_back.png);
-webkit-mask-image: url(./images/core_icon_back.png);
mask-image: url(./images/core_icon_back.png);
}

Expand Down Expand Up @@ -468,7 +468,7 @@
}

/**************************************
Slider
Slider
***************************************/
#slider-demo .ui-slider-vertical {
left: 50%;
Expand Down Expand Up @@ -624,14 +624,14 @@
}

/**************************************
text input with buttons
text input with buttons
***************************************/
#textinputwithbuttons-demo .ui-content {
top: 80px;
background: white;
}
/******************************************************
List Styles - sliders
List Styles - sliders
******************************************************/

#slider-description{
Expand Down Expand Up @@ -671,7 +671,7 @@
}

/******************************************************
Indexscrollbar with search floating button
Indexscrollbar with search floating button
******************************************************/

#indexscrollbarPage .ui-header.search-active h1 {
Expand Down Expand Up @@ -704,4 +704,25 @@
}
.sample-unit-lines p {
margin-bottom: 2px;
}

/* Expand button example */
.app-content-example {
height: 150px;
width: 100%;
background-color: #ddd;
display: flex;
text-align: center;
align-items: center;
justify-content: center;
margin-bottom: 15px;
}
.app-content-example-expanded {
height: 150px;
width: 100%;
background-color: #ddd;
display: flex;
text-align: center;
align-items: center;
justify-content: center;
}
4 changes: 4 additions & 0 deletions src/css/profile/mobile/common/core.less
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@
border-top-right-radius: 0;
mask-border-width: 0 26 * @px_base 26 * @px_base;
}

~ .ui-content-area {
margin-top: 16 * @px_base;
}
}

.ui-content-subheader {
Expand Down
22 changes: 9 additions & 13 deletions src/css/profile/mobile/common/expandable.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.ui-listview .ui-expandable {
.ui-listview .ui-expandable,
.ui-content-area .ui-expandable {
padding: 0 24 * @px_base;
user-select: none;
flex-direction: column;
Expand All @@ -13,10 +14,6 @@
margin: 0;
position: relative;

&:not(.ui-expandable-heading-collapsed) {
color: var(--primary-dark-color);
}

.ui-expandable-heading-toggle {
position: relative;
display: block;
Expand All @@ -25,10 +22,6 @@
outline: 0;
}

&:active {
color: @color_list_divider_text_expandable_press;
}

&::after {
content: "";
position: absolute;
Expand All @@ -45,9 +38,12 @@
transform: rotate(0);
}
}
&.ui-expandable-heading-active {
.ui-expandable-heading-toggle::after {
background-color: @color_expandable_heading_arrow_pressed;
.ui-btn {
&:after {
width: 32 * @px_base;
height: 32 * @px_base;
mask-size: 32 * @px_base;
background-color: var(--expander-color);
}
}
}
Expand All @@ -63,8 +59,8 @@
}

.ui-expandable-content {
display: block;
transition: all 330ms ease;
overflow: auto;
.ui-listview {
padding: 0;
margin-left: 18 * @px_base;
Expand Down
2 changes: 0 additions & 2 deletions src/css/profile/mobile/theme-changeable/theme.color.less
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
@color_list_sub_text_3_normal: var(--text-secondary-color); // #[color] sub text color

@color_list_divider_text: var(--text-secondary-color); // #[color] divider text color
@color_list_divider_text_expandable_press: var(--active); // #[color] divider text color

@color_list_divider_bg_press: var(--on-background); // #[color] divider background press color
@color_list_divider_text_press: var(--active); // #[color] divider text press color
Expand All @@ -59,7 +58,6 @@
// Expandable
//***************************************************************************
@color_expandable_heading_arrow: var(--on-background); // #[color] expandable arrow color
@color_expandable_heading_arrow_pressed: var(--active); // #[color] expandable arrow color pressed
@color_expandable_heading_arrow_dim: var(--control-background);

//***************************************************************************
Expand Down
58 changes: 34 additions & 24 deletions src/js/profile/mobile/widget/Expandable.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@
*/
this.options = {
collapsed: true,
heading: expandableSelectors.HEADING
heading: expandableSelectors.HEADING,
expander: "heading"
};

this._eventHandlers = {};
this._ui = {
expandableHeadingElement: null,
expandableHeadingContent: null
heading: null,
expandableHeadingContent: null,
expandButton: null
};

},
Expand Down Expand Up @@ -216,12 +218,18 @@
* @member ns.widget.mobile.Expandable
*/
uiExpandableHeadingToggle: "ui-expandable-heading-toggle",
/**
* Set active to expandable widget heading
* @style ui-expandable-heading-active
* @member ns.widget.mobile.Expandable,
*/
uiExpandableHeadingActive: "ui-expandable-heading-active",
/**
* Set active to expandable widget heading
* @style ui-expandable-heading-active
* @member ns.widget.mobile.Expandable
*/
uiExpandableHeadingActive: "ui-expandable-heading-active"
expandButton: "ui-expand-button"
};


Expand All @@ -240,9 +248,9 @@
function toggleExpandableHandler(self, element, event) {
var ui = self._ui,
elementClassList = element.classList,
heading = ui.expandableHeadingElement,
heading = ui.heading,
headingClassList = heading.classList,
content = ui.expandableContentElement,
content = ui.expandableContent,
contentClassList = content.classList,
isCollapse = event.type === "collapse";

Expand All @@ -268,7 +276,7 @@
}

function setHeadingActiveClassHandler(self, setClass) {
var headingClassList = self._ui.expandableHeadingElement.classList;
var headingClassList = self._ui.heading.classList;

if (setClass) {
headingClassList.add(classes.uiExpandableHeadingActive);
Expand All @@ -279,7 +287,7 @@

function toggleEventTypeHandler(self, event) {
var element = self.element,
heading = self._ui.expandableHeadingElement,
heading = self._ui.heading,
eventType = heading.classList.contains(classes.uiExpandableHeadingCollapsed) ? "expand" : "collapse";

eventUtil.trigger(element, eventType);
Expand Down Expand Up @@ -329,18 +337,19 @@
}
expandableHeading.classList.add(classes.uiExpandableHeading);

// Wrap all widget content
domUtils.wrapInHTML(element.childNodes, "<div class='" + classes.uiExpandableContent + "'></div>");
expandableContent = element.querySelector("." + classes.uiExpandableContent);
if (!expandableContent) {
// Wrap all widget content
domUtils.wrapInHTML(element.childNodes, "<div class='" + classes.uiExpandableContent + "'></div>");

// Move header out
element.insertBefore(expandableHeading, element.firstChild);

domUtils.wrapInHTML(expandableHeading.childNodes, "<a class='" + classes.uiExpandableHeadingToggle + "' tabindex='0'></a>");

expandableContent = expandableHeading.nextElementSibling;
// Move header out
element.insertBefore(expandableHeading, element.firstChild);
domUtils.wrapInHTML(expandableHeading.childNodes, "<a class='" + classes.uiExpandableHeadingToggle + "' tabindex='0'></a>");
expandableContent = expandableHeading.nextElementSibling;
}

ui.expandableHeadingElement = expandableHeading;
ui.expandableContentElement = expandableContent;
ui.heading = expandableHeading;
ui.expandableContent = expandableContent;

return element;
};
Expand All @@ -357,13 +366,14 @@
var self = this,
ui = self._ui;

ui.expandableHeadingElement = ui.expandableHeadingElement || selectors.getChildrenByClass(element, classes.uiExpandableHeading)[0];
ui.expandableContentElement = ui.expandableContentElement || selectors.getChildrenByClass(element, classes.uiExpandableContent)[0];
ui.heading = ui.heading || selectors.getChildrenByClass(element, classes.uiExpandableHeading)[0];
ui.expandableContent = ui.expandableContent || element.querySelector("." + classes.uiExpandableContent);
ui.expandButton = ui.expandButton || element.querySelector("." + classes.expandButton);

if (self.options.collapsed) {
element.classList.add(classes.uiExpandableCollapsed);
ui.expandableHeadingElement.classList.add(classes.uiExpandableHeadingCollapsed);
ui.expandableContentElement.classList.add(classes.uiExpandableContentCollapsed);
ui.heading.classList.add(classes.uiExpandableHeadingCollapsed);
ui.expandableContent.classList.add(classes.uiExpandableContentCollapsed);
}

return element;
Expand All @@ -379,7 +389,7 @@
Expandable.prototype._bindEvents = function (element) {
var self = this,
eventHandlers = self._eventHandlers,
heading = self._ui.expandableHeadingElement;
heading = self._ui.heading;

// Declare handlers with and assign them to local variables
eventHandlers.toggleExpandable = toggleExpandableHandler.bind(null, self, element);
Expand Down Expand Up @@ -450,7 +460,7 @@
Expandable.prototype._destroy = function () {
var self = this,
element = self.element,
heading = self._ui.expandableHeadingElement,
heading = self._ui.heading,
eventHandlers = self._eventHandlers,
parentNode = element.parentNode;

Expand Down

0 comments on commit a0d197e

Please sign in to comment.