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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Component card (#1275)
Oleg Isonen51f3230b8422
diff --git a/packages/design-system/src/components/component-card.stories.tsx b/packages/design-system/src/components/component-card.stories.tsxnew file mode 100644index 0000000000..b1f665b185--- /dev/null+++ b/packages/design-system/src/components/component-card.stories.tsx@@ -0,0 +1,58 @@+import { BoxIcon } from "@webstudio-is/icons";+import { StoryGrid, StorySection } from "./storybook";+import { ComponentCard } from "./component-card";++export default {+ title: "Library/Component Card",+};++export const Demo = () => {+ return (+ <>+ <StorySection title="States">+ <StoryGrid horizontal>+ <ComponentCard icon={<BoxIcon />} label="Box" tabIndex={1} />+ <ComponentCard+ icon={<BoxIcon />}+ label="Box"+ state="hover"+ tabIndex={1}+ />+ <ComponentCard+ icon={<BoxIcon />}+ label="Box"+ state="focus"+ tabIndex={1}+ />+ <ComponentCard+ icon={<BoxIcon />}+ label="Box"+ state="disabled"+ tabIndex={1}+ />+ </StoryGrid>+ </StorySection>+ <StorySection title="Labels">+ <StoryGrid horizontal>+ <ComponentCard icon={<BoxIcon />} label="Single" tabIndex={1} />+ <ComponentCard+ icon={<BoxIcon />}+ label="Too many words too many"+ tabIndex={1}+ />+ <ComponentCard+ icon={<BoxIcon />}+ label="Manylongwordstotruncate Manylongwordstotruncate"+ tabIndex={1}+ />+ <ComponentCard+ icon={<BoxIcon />}+ label="Truncatedlongword"+ tabIndex={1}+ />+ </StoryGrid>+ </StorySection>+ </>+ );+};+Demo.storyName = "Component Card";diff --git a/packages/design-system/src/components/component-card.tsx b/packages/design-system/src/components/component-card.tsxnew file mode 100644index 0000000000..52201c1ed8--- /dev/null+++ b/packages/design-system/src/components/component-card.tsx@@ -0,0 +1,85 @@+/**+ * Implementation of the "Component Card" component from:+ * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=2608-8921+ */++import { forwardRef, type ElementRef, ComponentProps } from "react";+import { textVariants } from "../";+import { css, theme } from "../stitches.config";++const cardStyle = css({+ display: "flex",+ flexDirection: "column",+ alignItems: "center",+ textAlign: "center",+ px: theme.spacing[3],+ width: theme.spacing[19],+ height: theme.spacing[19],+ border: `1px solid`,+ borderColor: theme.colors.borderMain,+ borderRadius: theme.borderRadius[2],+ userSelect: "none",+ color: theme.colors.foregroundIconMain,+ cursor: "grab",+ background: theme.colors.backgroundPanel,+ "&:hover, &[data-state=hover]": {+ background: theme.colors.backgroundHover,+ },+ "&[data-state=disabled]": {+ background: theme.colors.backgroundPanel,+ color: theme.colors.foregroundDisabled,+ },+ "&:focus-visible, &[data-state=focus]": {+ outline: `2px solid ${theme.colors.borderFocus}`,+ outlineOffset: "-2px",+ },+ "& svg": {+ flexGrow: 0,+ marginTop: theme.spacing[7],+ width: 22,+ height: 22,+ },+});++const textContainerStyle = css({+ display: "flex",+ flexDirection: "column",+ justifyContent: "center",+ flexGrow: 1,+ width: "100%",+});++const textStyle = css(textVariants.small, {+ display: "-webkit-box",+ WebkitLineClamp: 2,+ WebkitBoxOrient: "vertical",+ overflow: "hidden",+ textOverflow: "ellipsis",+});++type ComponentCardProps = {+ label: string;+ icon: JSX.Element;+ state?: "hover" | "disabled" | "focus";+} & ComponentProps<"div">;++export const ComponentCard = forwardRef<ElementRef<"div">, ComponentCardProps>(+ ({ icon, label, className, state, ...props }, ref) => {+ return (+ <div+ className={cardStyle({ className })}+ ref={ref}+ data-state={state}+ {...props}+ >+ {icon}++ <div className={textContainerStyle()}>+ <div className={textStyle()}>{label}</div>+ </div>+ </div>+ );+ }+);++ComponentCard.displayName = "ComponentCard";