UNPKG

@arpitbhalla/rneui-base-dev

Version:
71 lines (70 loc) 3.9 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; 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 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TabItem = void 0; var color_1 = __importDefault(require("color")); var react_1 = __importDefault(require("react")); var react_native_1 = require("react-native"); var Button_1 = require("../Button"); var helpers_1 = require("../helpers"); var TabItem = function (_a) { var _b, _c; var active = _a.active, _d = _a.theme, theme = _d === void 0 ? helpers_1.defaultTheme : _d, _parentProps = _a._parentProps, _e = _a.titleStyle, titleStyle = _e === void 0 ? _parentProps.titleStyle : _e, _f = _a.containerStyle, containerStyle = _f === void 0 ? _parentProps.containerStyle : _f, _g = _a.buttonStyle, buttonStyle = _g === void 0 ? _parentProps.buttonStyle : _g, _h = _a.iconPosition, iconPosition = _h === void 0 ? _parentProps.iconPosition || 'top' : _h, _j = _a.dense, dense = _j === void 0 ? _parentProps.dense : _j, iconContainerStyle = _a.iconContainerStyle, variant = _a.variant, title = _a.title, icon = _a.icon, rest = __rest(_a, ["active", "theme", "_parentProps", "titleStyle", "containerStyle", "buttonStyle", "iconPosition", "dense", "iconContainerStyle", "variant", "title", "icon"]); var activeProp = react_1.default.useCallback(function (prop) { return (typeof prop === 'function' ? prop(active) : prop); }, [active]); return (react_1.default.createElement(Button_1.Button, __assign({ accessibilityRole: "tab", accessibilityState: { selected: active }, accessibilityValue: typeof title === 'string' ? { text: title } : undefined, buttonStyle: [styles.buttonStyle, activeProp(buttonStyle)], titleStyle: [ !dense && styles.titleStyle, { color: variant === 'primary' ? 'white' : (_b = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _b === void 0 ? void 0 : _b.secondary, paddingVertical: !dense && !icon ? 8 : 2, }, activeProp(titleStyle), ], containerStyle: [ styles.containerStyle, variant === 'primary' && { backgroundColor: active ? (0, color_1.default)((_c = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _c === void 0 ? void 0 : _c.primary).darken(0.05).rgb().toString() : 'transparent', }, activeProp(containerStyle), ], iconContainerStyle: activeProp(iconContainerStyle), icon: activeProp(icon), iconPosition: iconPosition, title: title }, rest))); }; exports.TabItem = TabItem; var styles = react_native_1.StyleSheet.create({ buttonStyle: { borderRadius: 0, backgroundColor: 'transparent', }, titleStyle: { paddingHorizontal: 16, paddingVertical: 8, }, containerStyle: { flex: 1, borderRadius: 0, }, }); exports.TabItem.displayName = 'Tab.Item';