UNPKG

@gechiui/components

Version:
50 lines (45 loc) 1.42 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { createElement } from "@gechiui/element"; /** * External dependencies */ // eslint-disable-next-line no-restricted-imports /** * GeChiUI dependencies */ import { isValidElement } from '@gechiui/element'; /** * Internal dependencies */ import { getValidChildren } from '../ui/utils/get-valid-children'; import { contextConnect, useContextSystem } from '../ui/context'; import { ZStackView, ZStackChildView } from './styles'; function ZStack(props, forwardedRef) { const { children, className, isLayered = true, isReversed = false, offset = 0, ...otherProps } = useContextSystem(props, 'ZStack'); const validChildren = getValidChildren(children); const childrenLastIndex = validChildren.length - 1; const clonedChildren = validChildren.map((child, index) => { const zIndex = isReversed ? childrenLastIndex - index : index; const offsetAmount = offset * index; const key = isValidElement(child) ? child.key : index; return createElement(ZStackChildView, { isLayered: isLayered, offsetAmount: offsetAmount, zIndex: zIndex, key: key }, child); }); return createElement(ZStackView, _extends({}, otherProps, { className: className, ref: forwardedRef }), clonedChildren); } export default contextConnect(ZStack, 'ZStack'); //# sourceMappingURL=component.js.map