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
add story for useList
Oleg Isonen2bde826c7fb5
diff --git a/packages/design-system/src/components/list.stories.tsx b/packages/design-system/src/components/list.stories.tsxindex 0149088511..4798d8e129 100644--- a/packages/design-system/src/components/list.stories.tsx+++ b/packages/design-system/src/components/list.stories.tsx@@ -1,19 +1,20 @@import type { ComponentStory } from "@storybook/react";import { CheckIcon, DotsHorizontalIcon } from "@webstudio-is/icons";-import { List, ListItem } from "./list";+import { useState } from "react";+import { List, ListItem, useList } from "./list";export default {component: List,};-export const Simple: ComponentStory<typeof List> = () => {+export const Declarative: ComponentStory<typeof List> = () => {return (<List><ListItem>Apple</ListItem><ListItem state="disabled">Banana</ListItem><ListItem state="selected">Orange</ListItem><ListItem prefix={<CheckIcon />} suffix={<DotsHorizontalIcon />}>- Orange+ Strawberry</ListItem><ListItemprefix={<CheckIcon />}@@ -21,8 +22,36 @@ export const Simple: ComponentStory<typeof List> = () => {currentstate="selected">- Orange+ Watermelon</ListItem></List>);};++export const WithHook: ComponentStory<typeof List> = () => {+ const items = ["Banana", "Orange", "Apple"];+ const [selectedIndex, setSelectedIndex] = useState(-1);+ const [currentIndex, setCurrentIndex] = useState(-1);+ const { getListProps, getItemProps } = useList({+ items,+ selectedIndex,+ currentIndex,+ onSelect: setSelectedIndex,+ onChangeCurrent: setCurrentIndex,+ });+ return (+ <List {...getListProps()}>+ {items.map((item, index) => {+ const itemProps = getItemProps({ index });+ return (+ <ListItem+ {...itemProps}+ prefix={itemProps.current ? <CheckIcon /> : undefined}+ >+ {item}+ </ListItem>+ );+ })}+ </List>+ );+};