@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
21 lines (19 loc) • 841 B
JavaScript
const require_utils_index = require('../../utils/index.cjs');
//#region src/components/for/for.tsx
/**
* `For` is a component used to loop over an array and render a component for each item.
*
* @see https://yamada-ui.com/docs/components/for
*/
const For = ({ children, each, fallback, filter, limit, offset = 0, reverse = false, sort }) => {
if (!each || !(0, require_utils_index.utils_exports.isArray)(each) || !each.length) return fallback || null;
const cloned = [...each];
const filtered = filter ? cloned.filter(filter) : cloned;
const sorted = sort ? filtered.sort(sort) : filtered;
const sliced = (reverse ? sorted.reverse() : sorted).slice(offset, limit ? offset + limit : void 0);
if (!sliced.length) return fallback || null;
return sliced.map(children);
};
//#endregion
exports.For = For;
//# sourceMappingURL=for.cjs.map