react-native-navigation-drilldown
Version:
Drilldown screens to use with react-navigation
82 lines • 3.98 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var react_native_1 = require("react-native");
var react_native_portal_1 = require("react-native-portal");
var DrilldownList_1 = require("./DrilldownList");
var Handle_1 = require("./Handle");
var icons_1 = require("./icons");
var types_1 = require("./types");
var styles = react_native_1.StyleSheet.create({
container: {
alignSelf: 'stretch',
},
});
var getTitle = function (noSelectionTitle) { return function (selection) {
if (!selection || Array.isArray(selection) && selection.length === 0) {
return noSelectionTitle;
}
else if (Array.isArray(selection)) {
return selection.length > 1 ? selection[0].name + " (+ " + (selection.length - 1) + " more)" : selection[0].name;
}
return selection.name;
}; };
var getIcon = function (noSelectionIcon) { return function (selection) {
if (!selection || Array.isArray(selection) && selection.length === 0) {
return noSelectionIcon;
}
else if (Array.isArray(selection)) {
return selection[0].icon;
}
return selection.icon;
}; };
var Drilldown = (function (_super) {
__extends(Drilldown, _super);
function Drilldown() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.onHandlePress = function () {
var _a = _this.props, multi = _a.multi, name = _a.name, navigate = _a.navigate, _b = _a.routeName, routeName = _b === void 0 ? types_1.DEFAULT_ROUTE_NAME : _b;
navigate({ routeName: routeName, params: { rootPortalName: name, multi: multi } });
};
return _this;
}
Drilldown.prototype.render = function () {
var _a = this.props, name = _a.name, icon = _a.icon, label = _a.label, handle = _a.handle, handleProps = _a.handleProps, style = _a.style, disabled = _a.disabled, listProps = __rest(_a, ["name", "icon", "label", "handle", "handleProps", "style", "disabled"]);
var _b = listProps.value, value = _b === void 0 ? null : _b;
var handlePropsObj = (typeof handleProps === 'function') ? handleProps(value) : handleProps;
var HandleComponent = handle || Handle_1.Handle;
var handleIcon = typeof icon === 'function' ? icon(value) : getIcon(icon)(value);
var handleLabel = typeof label === 'function' ? label(value) : getTitle(label)(value);
return (<react_native_1.View style={[styles.container, style]}>
<HandleComponent disabled={disabled} rightIcon={icons_1.ARROW_RIGHT} {...handlePropsObj} leftIcon={handleIcon} title={handleLabel} onPress={this.onHandlePress}/>
<react_native_portal_1.BlackPortal name={"drilldownPortal_" + name}>
<DrilldownList_1.default {...listProps} rootOptions={listProps.options}/>
</react_native_portal_1.BlackPortal>
</react_native_1.View>);
};
Drilldown.defaultProps = {
value: null,
};
return Drilldown;
}(React.PureComponent));
exports.Drilldown = Drilldown;
//# sourceMappingURL=Drilldown.js.map