Skip to content

Commit 639d519

Browse files
committed
Bump 0.5.2
1 parent ffac070 commit 639d519

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

lib/utils.js

+19-28
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
66

7-
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8-
97
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
108

9+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
10+
1111
exports.position = position;
1212
exports.placement = placement;
13-
exports.opposite = opposite;
13+
exports.complete = complete;
1414
exports.intersection = intersection;
1515
exports.strip = strip;
1616
exports.amend = amend;
@@ -105,32 +105,23 @@ function placement(place, content, origin) {
105105
}
106106

107107
/**
108-
* Returns an opposite direction based on the given.
108+
* Completes missing directions in given direction(s).
109109
*
110-
* @param {string|Array} dir - 'top', 'right', 'bottom', or 'left'.
111-
* @return {string} an opposite direction.
112-
* @throw
110+
* @param {string|Array} dir - a direction or a list of directions.
111+
* @return {Array}
113112
*/
114-
function opposite(dir) {
115-
var place = dir;
116-
117-
// Alrays use first direction if Array is passed
118-
if ((typeof place === 'undefined' ? 'undefined' : _typeof(place)) === 'object' && typeof place.length === 'number' && 0 < place.length) {
119-
place = place[0];
120-
}
121-
122-
switch (place) {
123-
case 'top':
124-
return 'bottom';
125-
case 'bottom':
126-
return 'top';
127-
case 'right':
128-
return 'left';
129-
case 'left':
130-
return 'right';
113+
var DIRS = ['top', 'right', 'bottom', 'left'];
114+
function complete(dir) {
115+
if (typeof dir === 'string') {
116+
dir = [dir];
117+
} else {
118+
dir = [].concat(_toConsumableArray(dir));
131119
}
132120

133-
throw new Error('Unknown direction: "' + dir + '"');
121+
var missings = DIRS.filter(function (d) {
122+
return dir.indexOf(d) === -1;
123+
});
124+
return dir.concat(missings);
134125
}
135126

136127
/**
@@ -234,7 +225,7 @@ function overDirs(tip, el) {
234225
* Places and adjusts a tooltip.
235226
*
236227
* @param {Object} content - DOM element which contans a content.
237-
* @param {Object} props
228+
* @param {Object} props - props set from Tooltip component.
238229
* @return {Object} 'offset': style data to locate, 'place': final direction of the tooltip
239230
*/
240231
function adjust(content, props) {
@@ -249,8 +240,8 @@ function adjust(content, props) {
249240
return p.trim();
250241
});
251242
}
252-
if (auto && place.length === 1) {
253-
place.push(opposite(place));
243+
if (auto) {
244+
place = complete(place);
254245
}
255246

256247
var pos = undefined,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-tooltip",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"description": "A tooltip React component for Redux",
55
"main": "./lib/index.js",
66
"repository": {

0 commit comments

Comments
 (0)