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.

create list component

Oleg Isonen2daf99cb01c7
diff --git a/packages/design-system/src/components/list.stories.tsx b/packages/design-system/src/components/list.stories.tsx
new file mode 100644
index 0000000000..1b3184f931
--- /dev/null
+++ b/packages/design-system/src/components/list.stories.tsx
@@ -0,0 +1,27 @@
+import type { ComponentStory } from "@storybook/react";
+import { CheckIcon, DotsHorizontalIcon } from "@webstudio-is/icons";
+import { List, ListItem } from "./list";
+
+export default {
+ component: List,
+};
+
+export const Simple: ComponentStory<typeof List> = () => {
+ return (
+ <List>
+ <ListItem>Apple</ListItem>
+ <ListItem state="disabled">Banana</ListItem>
+ <ListItem state="selected">Orange</ListItem>
+ <ListItem prefix={<CheckIcon />} suffix={<DotsHorizontalIcon />}>
+ Orange
+ </ListItem>
+ <ListItem
+ prefix={<CheckIcon />}
+ suffix={<DotsHorizontalIcon />}
+ state="selected"
+ >
+ Orange
+ </ListItem>
+ </List>
+ );
+};
diff --git a/packages/design-system/src/components/list.tsx b/packages/design-system/src/components/list.tsx
new file mode 100644
index 0000000000..4bf3c75e14
--- /dev/null
+++ b/packages/design-system/src/components/list.tsx
@@ -0,0 +1,65 @@
+import { ComponentProps, forwardRef } from "react";
+import { styled } from "../stitches.config";
+import { Flex } from "./flex";
+import { Text } from "./text";
+
+export const List = styled("ul", {
+ display: "flex",
+ flexDirection: "column",
+ margin: 0,
+ padding: 0,
+});
+
+const ListItemBase = styled("li", {
+ display: "grid",
+ gridTemplateColumns: "$4 1fr",
+ alignItems: "center",
+ justifyContent: "space-between",
+ height: "$5",
+ px: "$1",
+ listStyle: "none",
+ borderRadius: "$1",
+ outline: 0,
+ variants: {
+ state: {
+ disabled: {
+ pointerEvents: "none",
+ },
+ selected: {
+ boxShadow:
+ "0px 0px 0px 2px $colors$blue10, 0px 0px 0px 2px $colors$blue10",
+ },
+ },
+ },
+});
+
+export const ListItem = forwardRef<
+ HTMLLIElement,
+ Omit<ComponentProps<typeof ListItemBase>, "prefix" | "suffix"> & {
+ state?: "disabled" | "selected";
+ prefix?: JSX.Element;
+ suffix?: JSX.Element;
+ }
+>(({ children, prefix, suffix, state, ...props }, ref) => {
+ return (
+ <ListItemBase
+ {...props}
+ ref={ref}
+ state={state}
+ tabIndex={state === "disabled" ? -1 : 0}
+ >
+ {prefix}
+ <Flex css={{ gridColumn: 2 }} align="center">
+ <Text
+ variant="label"
+ truncate
+ color={state === "disabled" ? "hint" : "contrast"}
+ >
+ {children}
+ </Text>
+ {suffix}
+ </Flex>
+ </ListItemBase>
+ );
+});
+ListItem.displayName = "ListItem";