diff --git a/src/components/List/List.stories.tsx b/src/components/List/List.stories.tsx new file mode 100644 index 000000000000..dcfdb640fe3b --- /dev/null +++ b/src/components/List/List.stories.tsx @@ -0,0 +1,51 @@ +import React, { useState } from "react"; +import type { Meta, StoryObj } from "@storybook/react"; +import { userEvent, waitFor, within } from "@storybook/testing-library"; +import { expect } from "@storybook/jest"; + +import { List } from "./List"; +import { ListItem } from "./ListItem/ListItem"; + +const meta: Meta = { + component: List, +}; + +export default meta; + +export const Default: StoryObj = { + render: () => { + const [workingIndex, setWorkingIndex] = useState(1); + + return ( + <> + + = 1} index={1}> + Hello World + + = 2} index={2}> + Bonjour le monde + + = 3} index={3}> + 你好, 世界 + + +
+ + + ); + }, + play: async ({ canvasElement }) => { + const canvas = within(canvasElement.parentElement); + const button = canvas.getByText("Complete"); + + await expect(canvas.getAllByLabelText("complete")).toHaveLength(1); + + await userEvent.click(button); + + await waitFor(() => + expect(canvas.getAllByLabelText("complete")).toHaveLength(2) + ); + }, +}; diff --git a/src/components/List/List.styled.tsx b/src/components/List/List.styled.tsx new file mode 100644 index 000000000000..d75395a65467 --- /dev/null +++ b/src/components/List/List.styled.tsx @@ -0,0 +1,9 @@ +import { styled } from "@storybook/theming"; + +export const ListWrapper = styled.ul(() => ({ + display: "flex", + flexDirection: "column", + rowGap: 16, + padding: 0, + margin: 0, +})); diff --git a/src/components/List/List.tsx b/src/components/List/List.tsx new file mode 100644 index 000000000000..f443ec992f1b --- /dev/null +++ b/src/components/List/List.tsx @@ -0,0 +1,10 @@ +import React from "react"; +import { ListWrapper } from "./List.styled"; + +interface ListProps { + children: React.ReactNode; +} + +export const List = ({ children }: ListProps) => { + return {children}; +}; diff --git a/src/components/List/ListItem/ListItem.styled.tsx b/src/components/List/ListItem/ListItem.styled.tsx new file mode 100644 index 000000000000..98dd471ee30d --- /dev/null +++ b/src/components/List/ListItem/ListItem.styled.tsx @@ -0,0 +1,31 @@ +import { styled } from "@storybook/theming"; + +export const ListItemWrapper = styled.li(() => ({ + display: "flex", + alignItems: "flex-start", + columnGap: 12, +})); + +export const ListItemContentWrapper = styled.div(({ theme }) => ({ + fontFamily: theme.typography.fonts.base, + color: theme.color.darker, + fontSize: "13px", +})); + +export const ListItemIndexWrapper = styled.div<{ isCompleted: boolean }>( + ({ isCompleted, theme }) => ({ + display: "flex", + alignItems: "center", + justifyContent: "center", + border: !isCompleted && `1px solid ${theme.color.medium}`, + minWidth: 20, + width: 20, + height: 20, + borderRadius: "50%", + backgroundColor: isCompleted ? theme.color.green : "white", + fontFamily: theme.typography.fonts.base, + fontSize: 10, + fontWeight: 600, + color: theme.color.dark, + }) +); diff --git a/src/components/List/ListItem/ListItem.tsx b/src/components/List/ListItem/ListItem.tsx new file mode 100644 index 000000000000..16f4ceb34878 --- /dev/null +++ b/src/components/List/ListItem/ListItem.tsx @@ -0,0 +1,31 @@ +import React from "react"; +import { Icons } from "@storybook/components"; +import { + ListItemContentWrapper, + ListItemIndexWrapper, + ListItemWrapper, +} from "./ListItem.styled"; + +interface ListItemProps { + children: React.ReactNode; + index: number; + isCompleted?: boolean; +} + +export const ListItem = ({ children, index, isCompleted }: ListItemProps) => { + return ( + + + {isCompleted ? ( + + ) : ( + index + )} + + {children} + + ); +};