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
import { useState, type ComponentProps, type ReactNode } from "react";
import { styled, theme } from "../stitches.config";
import {
InteractiveListArrowFocus,
InteractiveListItem,
__testing__,
} from "./interactive-list-item";
import { Label, labelColors } from "./label";
import { SmallToggleButton } from "./small-toggle-button";
import { EyeOpenIcon, EyeClosedIcon, MinusIcon } from "@webstudio-is/icons";
import { SmallIconButton } from "./small-icon-button";
import { StorySection, StoryGrid } from "./storybook";
export default {
component: InteractiveListItem,
title: "CSS Value List Item",
};
const { listItemAttributes } = __testing__;
const Thumbnail = styled("div", {
width: theme.spacing[10],
height: theme.spacing[10],
backgroundImage: "linear-gradient(yellow, red)",
});
const Panel = styled("div", {
width: theme.spacing[30],
});
const ListItem = (props: {
hidden: boolean;
labelColor: ComponentProps<typeof Label>["color"];
state: undefined | "open";
active: boolean;
focused: undefined | boolean;
label?: ReactNode;
index: number;
}) => {
const [pressed, onPressedChange] = useState(false);
return (
<InteractiveListItem
label={
<Label disabled={props.hidden} color={props.labelColor} truncate>
{props.label ?? "Image"}
</Label>
}
thumbnail={<Thumbnail />}
hidden={props.hidden}
draggable
state={props.state}
focused={props.focused}
active={props.active}
index={props.index}
id={String(props.index)}
buttons={
<>
<SmallToggleButton
pressed={pressed}
onPressedChange={onPressedChange}
variant="normal"
tabIndex={-1}
icon={pressed ? <EyeClosedIcon /> : <EyeOpenIcon />}
/>
<SmallIconButton
variant="destructive"
tabIndex={-1}
icon={<MinusIcon />}
/>
</>
}
{...listItemAttributes}
/>
);
};
export const InteractiveListItemExample = () => {
return (
<Panel>
<StorySection title="Overflows">
<StoryGrid>
<>
{labelColors.map((labelColor, index) => (
<ListItem
key={labelColor}
index={index}
hidden={false}
active={false}
labelColor={labelColor}
state={undefined}
focused={false}
label="Very long text, very long text"
/>
))}
</>
</StoryGrid>
</StorySection>
<StorySection title="Variants">
<StoryGrid>
<InteractiveListArrowFocus>
{labelColors.map((labelColor, index) => (
<ListItem
key={labelColor}
index={index}
hidden={false}
active={false}
labelColor={labelColor}
state={undefined}
focused={false}
/>
))}
{labelColors.map((labelColor) => (
<ListItem
key={labelColor}
index={-1}
hidden={true}
active={false}
labelColor={labelColor}
state={undefined}
focused={false}
/>
))}
{labelColors.map((labelColor, index) => (
<ListItem
key={labelColor}
index={index}
hidden={false}
active={false}
labelColor={labelColor}
state={"open"}
focused={false}
/>
))}
</InteractiveListArrowFocus>
</StoryGrid>
</StorySection>
<StorySection title="Active">
<StoryGrid>
<InteractiveListArrowFocus>
{labelColors.map((labelColor, index) => (
<ListItem
key={labelColor}
index={index}
hidden={false}
active={true}
labelColor={labelColor}
state={undefined}
focused={false}
/>
))}
{labelColors.map((labelColor, index) => (
<ListItem
key={labelColor}
index={index}
hidden={true}
active={true}
labelColor={labelColor}
state={undefined}
focused={false}
/>
))}
{labelColors.map((labelColor, index) => (
<ListItem
key={labelColor}
index={index}
hidden={false}
active={true}
labelColor={labelColor}
state={"open"}
focused={false}
/>
))}
</InteractiveListArrowFocus>
</StoryGrid>
</StorySection>
<StorySection title="No thumbnail">
<InteractiveListArrowFocus>
<InteractiveListItem
id="no-thumb-0"
index={0}
label={<Label>Text only item</Label>}
hidden={false}
buttons={
<SmallIconButton
variant="destructive"
tabIndex={-1}
icon={<MinusIcon />}
/>
}
{...listItemAttributes}
/>
<InteractiveListItem
id="no-thumb-1"
index={1}
label={<Label>Another text item</Label>}
hidden={false}
buttons={
<SmallIconButton
variant="destructive"
tabIndex={-1}
icon={<MinusIcon />}
/>
}
{...listItemAttributes}
/>
</InteractiveListArrowFocus>
</StorySection>
<StorySection title="Disabled state">
<InteractiveListArrowFocus>
<InteractiveListItem
id="disabled-0"
index={0}
label={<Label>Disabled item</Label>}
thumbnail={<Thumbnail />}
hidden={false}
disabled
{...listItemAttributes}
/>
<InteractiveListItem
id="disabled-1"
index={1}
label={<Label>Enabled item</Label>}
thumbnail={<Thumbnail />}
hidden={false}
{...listItemAttributes}
/>
</InteractiveListArrowFocus>
</StorySection>
<StorySection title="Arrow focus with drag item">
<InteractiveListArrowFocus dragItemId="drag-1">
{labelColors.map((labelColor, index) => (
<ListItem
key={labelColor}
index={index}
hidden={false}
active={index === 1}
labelColor={labelColor}
state={undefined}
focused={false}
/>
))}
</InteractiveListArrowFocus>
</StorySection>
</Panel>
);
};