UNPKG

roko-date-picker

Version:
38 lines (37 loc) 1.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ShowComponent = void 0; const react_1 = __importDefault(require("react")); // Component for conditionally rendering based on `isTrue` const When = ({ isTrue, children }) => { return isTrue ? children : null; }; // Component for rendering an alternative if `When` is not rendered const Else = ({ children }) => { return children; }; // The main ShowComponent that decides which child to render const ShowComponent = ({ children }) => { let when = null; let otherwise = null; react_1.default.Children.forEach(children, (child) => { if (react_1.default.isValidElement(child)) { if (Object.prototype.hasOwnProperty.call(child.props, "isTrue")) { if (child.props.isTrue && !when) { when = child; } } else { otherwise = child; } } }); return when ?? otherwise; }; exports.ShowComponent = ShowComponent; // Attaching When and Else as static properties to ShowComponent ShowComponent.When = When; ShowComponent.Else = Else;