Skip to content

Instantly share code, notes, and snippets.

@zmitry
Created August 13, 2021 11:43
Show Gist options
  • Select an option

  • Save zmitry/f7975c079e63ece0e8134dcd253bf0ac to your computer and use it in GitHub Desktop.

Select an option

Save zmitry/f7975c079e63ece0e8134dcd253bf0ac to your computer and use it in GitHub Desktop.
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