Created
August 13, 2021 11:43
-
-
Save zmitry/f7975c079e63ece0e8134dcd253bf0ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { CSSProperties, forwardRef } from "react"; | |
| import { ForwardRefComponent } from "@radix-ui/react-polymorphic"; | |
| import { css } from "libs/css"; | |
| const ZStackStyles = css({ | |
| "display": "grid", | |
| "justifyItems": "center", | |
| "placeItems": "center", | |
| "width": "fit-content", | |
| "> *": { | |
| gridArea: "1/1/1/1", | |
| zIndex: 1, | |
| }, | |
| }); | |
| type ZStackComponent = ForwardRefComponent< | |
| "div", | |
| { | |
| alignX?: CSSProperties["placeItems"]; | |
| alignY?: CSSProperties["alignItems"]; | |
| fullWidth?: boolean; | |
| } | |
| >; | |
| export const ZStack: ZStackComponent = forwardRef(function ZStack( | |
| { as: Comp = "div", className, alignX, alignY, fullWidth, style, ...props }, | |
| ref | |
| ) { | |
| return ( | |
| <Comp | |
| ref={ref} | |
| data-component={"ZStack"} | |
| style={{ | |
| ...style, | |
| width: fullWidth ? "100%" : undefined, | |
| alignItems: alignY, | |
| justifyItems: alignX, | |
| }} | |
| className={[ZStackStyles, className].join(" ")} | |
| {...props} | |
| /> | |
| ); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment