Skip to content

Commit

Permalink
feat(aside): add optional tooltip on header
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyen Lam committed Oct 15, 2021
1 parent 4ef1656 commit f7a30e0
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 8 deletions.
51 changes: 51 additions & 0 deletions docs/src/xhtml/components/asides/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,46 @@
<li>The new Aside will float the top of the z-index</li>
</ul>
</section>

<h3>Tooltip on aside header</h3>
<section>
<p>
A tooltip can be added to the aside header with the
<att>data-ts.tooltip</att> attribute. Set the value equal to the text to be
displayed in the tooltip.
</p>
<figure data-ts="DoxMarkup">
<script type="text/html">
<aside data-ts="Aside"
id="aside-with-tooltip"
data-ts.title="Aside Title with tooltip"
data-ts.tooltip="My Tooltip">
<div data-ts="Panel">
<p>Aside content.</p>
</div>
</aside>
</script>
</figure>
<p>
The tooltip can also be toggled via the API. Provide a string as the first
parameter to the function tooltip in order to change the contents of the tooltip.
</p>
<figure data-ts="DoxScript">
<script type="text/js">
ts.ui.get('#myAside', function(aside) {
aside.tooltip('tooltip');
});
</script>
</figure>
<p>
Run the script below to open the Aside with tooltip.
</p>
<figure data-ts="DoxScript">
<script type="runnable">
ts.ui.get('#aside-with-tooltip').open();
</script>
</figure>
</section>
</article>
</div>
</div>
Expand Down Expand Up @@ -413,5 +453,16 @@
</menu>
</div>
</aside>

<aside
data-ts="Aside"
id="aside-with-tooltip"
data-ts.title="Aside Title with tooltip"
data-ts.tooltip="My Tooltip"
>
<div data-ts="Panel">
<p>Aside content.</p>
</div>
</aside>
</body>
</html>
3 changes: 2 additions & 1 deletion src/runtime/edbml/scripts/ts.ui.HeaderBarSpirit.edbml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var id = (this.$instanceid + header.$instanceid);
var color = header.color;
var tooltip = header.tooltip;

<ul class="ts-headerbar-bars">
headerbar(header.headerbar);
Expand All @@ -13,7 +14,7 @@

function headerbar(model) {
<li data-ts="ToolBar" class="ts-headerbar-headerbar ${color}" id="${id}-headerbar" +
data-ts.model="?{model}" data-ts.visible="${header.$showHeaderBar(model)}"></li>
data-ts.model="?{model}" data-ts.tooltip="${tooltip}" data-ts.visible="${header.$showHeaderBar(model)}"></li>
}

function centerbar(model) {
Expand Down
15 changes: 10 additions & 5 deletions src/runtime/edbml/scripts/ts.ui.ToolBarSpirit.edbml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
toolbar.tabs,
toolbar.checkbox,
toolbar.$allactions(),
toolbar.pager
toolbar.pager,
toolbar.tooltip
);
rendercenter(id, toolbar.pager);
if(toolbar.search && toolbar.search.buttons.length) {
Expand All @@ -31,7 +32,7 @@
rendernormalbuttons(id, toolbar.$allbuttons());
}

function renderleft(title, icon, burger, back, forward, status, search, tabs, checkbox, actions, pager) {
function renderleft(title, icon, burger, back, forward, status, search, tabs, checkbox, actions, pager, tooltip) {
var hasnavi = back || forward;
var hastabs = !!tabs.getLength();
var hasactions = !!actions.length;
Expand Down Expand Up @@ -59,7 +60,7 @@
rendercheckbox(checkbox);
}
if(title || status) {
renderlabels(title, status, search, hasactions);
renderlabels(title, status, search, hasactions, tooltip);
}
actions.forEach(renderbutton);
}
Expand Down Expand Up @@ -204,12 +205,16 @@
}

// title (big text) or status message (with markdown)
function renderlabels(title, status, search, hasactions) {
function renderlabels(title, status, search, hasactions, tooltip) {
if(!search || !using(search)) {
if(title) {
@class = klass('ts-toolbar-title', null, !hasactions);
<li id="${id}-title" @class>
<label>${title}</label>
if(tooltip) {
<label data-ts="Tooltip" data-ts.title="${tooltip}" data-ts.offset="true">${title}</label>
} else {
<label>${title}</label>
}
</li>
} else {
@class = klass('ts-toolbar-status', null, !hasactions);
Expand Down
12 changes: 12 additions & 0 deletions src/runtime/js/ts.ui/bars/[email protected]/api/ts.ui.Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ ts.ui.Header = (function using(chained) {
}
}),

/** Set or get header tooltip with content from the parameter text.
* @param {string} [string]
* @returns {this|string}
*/
tooltip: chained(function(text) {
if (arguments.length) {
bar().tooltip(text);
} else {
return bar().tooltip();
}
}),

/**
* @TODO ts.ui.Header.localize
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ ts.ui.HeaderBarModel = (function using(ToolBarModel, SearchModel, chained) {
}
},

/**
* Setter and getter for header bar tooltip.
* @type {string}
*/
tooltip: {
getter: function() {
return this.headerbar.tooltip;
},
setter: function(tooltip) {
this.headerbar.tooltip = tooltip;
}
},

/**
* The buttons.
* @type {ts.ui.ButtonCollection}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ ts.ui.ToolBarModel = (function using(chained, ButtonModel, CheckBoxModel) {
*/
title: null,

/**
* Show tooltip.
* @type {string}
*/
tooltip: null,

/**
* Toolbar icon.
* @type {string}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ ts.ui.HeaderBarSpirit = (function using(chained) {
}
}),

/**
* Set or get header bar tooltip with content from the parameter text.
* @param {string} text
* @return {ts.ui.AsideSpirit|string}
*/
tooltip: chained(function(text) {
var model = this.model();
if (arguments.length) {
model.tooltip = text;
} else {
return model.tooltip;
}
}),

/**
* Get or set the icon image.
* @param {string} [string]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,27 @@ ts.ui.ToolBarSpirit = (function using(
})
),

/**
* Set or get toolbar tooltip with content from the parameter text.
* @param @optional {string|null} title
* @returns {string|ts.ui.ToolBarSpirit}
*/
tooltip: confirmed('(string|null)')(
chained(function(tooltip_text) {
var model = this.model();
if (arguments.length) {
tooltip_text = tooltip_text || '';
if (tooltip_text.trim().indexOf('{') !== 0) {
model.tooltip = tooltip_text;
this.event.add('click');
this.$hascontent();
}
} else {
return model.tooltip;
}
})
),

/**
* Get or set the search (getter will *create* the search).
* @param @optional {object|ts.ui.SearchModel} opt_json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ ts.ui.AsideModel = (function using(chained) {
*/
title: null,

/**
* Aside tooltip.
* @type {String}
*/
tooltip: null,

/**
* Aside Note.
* @type {String}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ ts.ui.TooltipSpirit = (function using(Client, CSSPlugin) {
*/
top: 0,

/**
* If tooltip position should be based on
* parent element(true) or the whole page(false).
* @type {boolean}
*/
offset: false,

/**
* Set id and add mosemove event.
*/
Expand All @@ -45,8 +52,15 @@ ts.ui.TooltipSpirit = (function using(Client, CSSPlugin) {
onevent: function(e) {
this.super.onevent(e);
if (e.type === 'mousemove') {
var x = e.pageX + parseInt(this.left);
var y = e.pageY + parseInt(this.top);
var x = parseInt(this.left);
var y = parseInt(this.top);
if (this.offset) {
x += e.offsetX;
y += e.offsetY;
} else {
x += e.pageX;
y += e.pageY;
}
this._pseudoStyle(x, y);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ ts.ui.SideShowSpirit = (function using(
}
}),

/**
* Set or get header tooltip with content from the parameter text.
* @param {string} text
* @return {ts.ui.AsideSpirit|string}
*/
tooltip: chained(function(text) {
var header = this._head();
if (arguments.length) {
header.tooltip(String(text));
} else {
return header.tooltip();
}
}),

/**
* Get or set the titlebar search model.
* @param {Object|ts.ui.SearchModel} search
Expand Down

0 comments on commit f7a30e0

Please sign in to comment.