Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

1.5 KB
Raw Blame
import {
  Flex,
  theme,
  Box,
  Grid,
  styled,
  css,
  Slot,
  type SlotProps,
  cssVar,
  declareCssVar,
} from "@webstudio-is/design-system";
import { forwardRef, type ComponentProps } from "react";

const borderColorVar = declareCssVar("--dashboard-card-border-color");

const cardStyle = css({
  position: "relative",
  isolation: "isolate",
  display: "flex",
  padding: 0,
  height: "100%",
  flexDirection: "column",
  alignItems: "center",
  flexShrink: 0,
  outline: "none",
  "&:focus-within, &[aria-selected=true]": {
    [borderColorVar]: cssVar("--border-focus"),
  },
});

type CardProps = ComponentProps<"div"> & {
  asChild?: boolean;
} & SlotProps;

export const Card = forwardRef<HTMLDivElement, CardProps>(
  ({ asChild, ...props }, ref) => {
    const Component = asChild ? Slot : Box;
    return <Component {...props} className={cardStyle()} ref={ref} />;
  }
);
Card.displayName = "Card";

export const CardContent = styled(Grid, {
  position: "relative",
  overflow: "hidden",
  width: "100%",
  aspectRatio: "1.91/1",
  borderRadius: theme.borderRadius[5],
  "&::after": {
    content: '""',
    position: "absolute",
    inset: 0,
    border: `1px solid ${cssVar(borderColorVar, "transparent")}`,
    borderRadius: theme.borderRadius[5],
    pointerEvents: "none",
  },
});

export const CardFooter = styled(Flex, {
  justifyContent: "space-between",
  flexShrink: 0,
  alignSelf: "stretch",
  flexGap: theme.spacing[3],
  background: cssVar("--background-primary"),
  height: theme.spacing[17],
  paddingBlock: theme.panel.paddingBlock,
});