UNPKG

@ffsm/compositor

Version:

A collection of declarative React utility components for simplified component composition, conditional rendering, and prop management - making React UI development more maintainable and expressive.

63 lines (62 loc) 2.52 kB
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; }; import { jsx as _jsx } from "react/jsx-runtime"; import { AsInstance } from './as-instance'; /** * A component that renders fallback content when the children are empty. * Useful for handling null, undefined, or falsy children in a declarative way. * * @param {PropsWithChildren<EmptyProps>} props - Component properties * @param {React.ReactNode} props.children - The primary content to render if not empty * @param {React.ReactNode} [props.fallback] - Content to display when children are empty * @param {boolean} [props.falsy] - When true, treats all falsy values (0, '', etc) as empty * @param {...unknown} props.rest - Additional props to pass to the rendered content * @returns {JSX.Element} Either the children or fallback content wrapped in AsInstance * * @example * // Basic usage with fallback * <Empty fallback={<NoDataMessage />}> * {userData} * </Empty> * * @example * // With falsy option to handle empty arrays or strings * <Empty fallback={<EmptyList />} falsy> * {items.length && <ItemsList items={items} />} * </Empty> * * @example * // Passing props to rendered content * <Empty fallback={<Placeholder />} className="content-box"> * {content} * </Empty> */ export function Empty(props) { var children = props.children, fallback = props.fallback, falsy = props.falsy, rest = __rest(props, ["children", "fallback", "falsy"]); if (typeof children === 'undefined' || children === false || (falsy && !children)) { return _jsx(AsInstance, __assign({}, rest, { children: fallback })); } return _jsx(AsInstance, __assign({}, rest, { children: children })); }