UNPKG

@arpitbhalla/rneui-base-dev

Version:
75 lines (74 loc) 4 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.ListItemAccordion = void 0; var react_1 = __importDefault(require("react")); var react_native_1 = require("react-native"); var ListItem_1 = require("./ListItem"); var ListItem_Content_1 = require("./ListItem.Content"); var Icon_1 = require("../Icon"); var helpers_1 = require("../helpers"); var ListItemAccordion = function (_a) { var children = _a.children, _b = _a.isExpanded, isExpanded = _b === void 0 ? false : _b, _c = _a.icon, icon = _c === void 0 ? react_1.default.createElement(Icon_1.Icon, { name: 'chevron-down', type: "material-community" }) : _c, expandIcon = _a.expandIcon, content = _a.content, _d = _a.leftRotate, leftRotate = _d === void 0 ? false : _d, noRotation = _a.noRotation, noIcon = _a.noIcon, _e = _a.animation, animation = _e === void 0 ? { duration: 350, type: 'timing', } : _e, rest = __rest(_a, ["children", "isExpanded", "icon", "expandIcon", "content", "leftRotate", "noRotation", "noIcon", "animation"]); var transition = react_1.default.useRef(new react_native_1.Animated.Value(0)); var startAnimation = react_1.default.useCallback(function () { if (typeof animation !== 'boolean') { react_native_1.Animated[animation.type || 'timing'](transition.current, { toValue: Number(isExpanded), useNativeDriver: true, duration: animation.duration || 350, }).start(); } }, [isExpanded, animation]); react_1.default.useEffect(function () { startAnimation(); }, [isExpanded, startAnimation]); var iconAnimation = react_1.default.useMemo(function () { return ({ transform: [ { rotate: noRotation ? '0deg' : transition.current.interpolate({ inputRange: [0, 1], outputRange: ['0deg', leftRotate ? '180deg' : '-180deg'], }), }, ], }); }, [leftRotate, noRotation]); return (react_1.default.createElement(react_1.default.Fragment, null, react_1.default.createElement(ListItem_1.ListItemBase, __assign({}, rest), react_1.default.isValidElement(content) ? content : react_1.default.createElement(ListItem_Content_1.ListItemContent, null), !noIcon && (react_1.default.createElement(react_native_1.Animated.View, { testID: "RNE__ListItem__Accordion__Icon", style: iconAnimation }, (0, helpers_1.renderNode)(Icon_1.Icon, isExpanded ? expandIcon !== null && expandIcon !== void 0 ? expandIcon : icon : icon)))), isExpanded && (react_1.default.createElement(react_native_1.Animated.View, { testID: "RNE__ListItem__Accordion__Children", style: { opacity: transition.current, } }, children)))); }; exports.ListItemAccordion = ListItemAccordion; exports.ListItemAccordion.displayName = 'ListItem.Accordion';