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 SectionTitle; Add utility for focusing using arrow keys (#1249)
Roman Pominovb4a6a67ada93
diff --git a/apps/builder/app/builder/features/props-panel/props-panel.tsx b/apps/builder/app/builder/features/props-panel/props-panel.tsxindex 53691e19d1..cf70c4dc06 100644--- a/apps/builder/app/builder/features/props-panel/props-panel.tsx+++ b/apps/builder/app/builder/features/props-panel/props-panel.tsx@@ -16,10 +16,10 @@ import {Text,CSS,} from "@webstudio-is/design-system";-import { ChevronDownIcon, PlusIcon } from "@webstudio-is/icons";+import { ChevronDownIcon } from "@webstudio-is/icons";import type { Publish } from "~/shared/pubsub";import { propsStore, useInstanceProps } from "~/shared/nano-states";-import { CollapsibleSection } from "~/builder/shared/inspector";+import { CollapsibleSectionWithAddButton } from "~/builder/shared/inspector";import {useStyleData,type SetProperty as SetCssProperty,@@ -89,6 +89,7 @@ const PropsCombobox = ({<div {...combobox.getComboboxProps()}><ComboboxAnchor><TextField+ autoFocus{...combobox.getInputProps()}placeholder="Property"suffix={@@ -198,6 +199,8 @@ export const PropsPanel = ({}) => {const [addingProp, setAddingProp] = useState(false);+ const hasAddedProps = logic.addedProps.length > 0 || addingProp;+return (<Box css={{ paddingTop: theme.spacing[3] }}><Row>@@ -225,48 +228,41 @@ export const PropsPanel = ({</Row><Separator />- <CollapsibleSection+ <CollapsibleSectionWithAddButtonlabel="Properties"- isOpenDefault- rightSlot={- <SmallIconButton- icon={<PlusIcon />}- onClick={(event) => {- // to prevent the section from collapsing/expanding- event.stopPropagation();- setAddingProp(true);- }}- />- }+ onAdd={() => setAddingProp(true)}+ hasItems={hasAddedProps}>- <Flex gap="2" direction="column">- {logic.addedProps.map(({ prop, propName, meta }) => (- <Property- key={propName}- propName={propName}- prop={prop}- meta={meta}- component={component}- onChange={(value) =>- logic.handleChange({ prop, propName }, value)- }- onDelete={() => logic.handleDelete({ prop, propName })}- onSoftDelete={() => prop && logic.handleSoftDelete(prop)}- setCssProperty={setCssProperty}- />- ))}+ {hasAddedProps && (+ <Flex gap="2" direction="column">+ {logic.addedProps.map(({ prop, propName, meta }) => (+ <Property+ key={propName}+ propName={propName}+ prop={prop}+ meta={meta}+ component={component}+ onChange={(value) =>+ logic.handleChange({ prop, propName }, value)+ }+ onDelete={() => logic.handleDelete({ prop, propName })}+ onSoftDelete={() => prop && logic.handleSoftDelete(prop)}+ setCssProperty={setCssProperty}+ />+ ))}- {addingProp && (- <AddPropertyForm- availableProps={logic.remainingProps}- onPropSelected={(propName) => {- setAddingProp(false);- logic.handleAdd(propName);- }}- />- )}- </Flex>- </CollapsibleSection>+ {addingProp && (+ <AddPropertyForm+ availableProps={logic.remainingProps}+ onPropSelected={(propName) => {+ setAddingProp(false);+ logic.handleAdd(propName);+ }}+ />+ )}+ </Flex>+ )}+ </CollapsibleSectionWithAddButton><Separator /></Box>);diff --git a/apps/builder/app/builder/features/sidebar-left/header.tsx b/apps/builder/app/builder/features/sidebar-left/header.tsxindex 6cfe1ca656..d70f47954f 100644--- a/apps/builder/app/builder/features/sidebar-left/header.tsx+++ b/apps/builder/app/builder/features/sidebar-left/header.tsx@@ -2,7 +2,7 @@ import {Button,Tooltip,Separator,- Title,+ PanelTitle,TitleSuffixSpacer,} from "@webstudio-is/design-system";import { CrossIcon } from "@webstudio-is/icons";@@ -15,7 +15,7 @@ type HeaderProps = {export const Header = ({ title, suffix }: HeaderProps) => {return (<>- <Title suffix={suffix}>{title}</Title>+ <PanelTitle suffix={suffix}>{title}</PanelTitle><Separator /></>);diff --git a/apps/builder/app/builder/shared/inspector/collapsible-section.tsx b/apps/builder/app/builder/shared/inspector/collapsible-section.tsxindex cdf7533b16..c042618692 100644--- a/apps/builder/app/builder/shared/inspector/collapsible-section.tsx+++ b/apps/builder/app/builder/shared/inspector/collapsible-section.tsx@@ -3,97 +3,154 @@ import { useStore } from "@nanostores/react";import {Box,Flex,- DeprecatedText2,Collapsible,+ SectionTitle,+ SectionTitleLabel,+ SectionTitleButton,} from "@webstudio-is/design-system";-import { ChevronLeftIcon, ChevronRightIcon } from "@webstudio-is/icons";import { theme } from "@webstudio-is/design-system";+import type { ComponentProps, ReactNode } from "react";+import { PlusIcon } from "@webstudio-is/icons";-type CollapsibleSectionProps = {+type UseOpenStateProps = {label: string;- children: JSX.Element;isOpenDefault?: boolean;isOpen?: boolean;- rightSlot?: JSX.Element;- fullWidth?: boolean;};const stateContainer = atom<{ [label: string]: boolean }>({});// Preserves the open/close state even when component gets unmounted-const useOpenState = (- label: string,- initialValue: boolean-): [boolean, (value: boolean) => void] => {+const useOpenState = ({+ label,+ isOpenDefault = true,+ isOpen: isOpenForced,+}: UseOpenStateProps): [boolean, (value: boolean) => void] => {const state = useStore(stateContainer);- const isOpen = label in state ? state[label] : initialValue;+ const isOpen = label in state ? state[label] : isOpenDefault;const setIsOpen = (isOpen: boolean) => {stateContainer.set({ ...state, [label]: isOpen });};- return [isOpen, setIsOpen];+ return [isOpenForced === undefined ? isOpen : isOpenForced, setIsOpen];+};++type BaseProps = {+ trigger?: ReactNode;+ children: ReactNode;+ fullWidth?: boolean;+ label: string;+ isOpen: boolean;+ onOpenChange: (value: boolean) => void;};-export const CollapsibleSection = ({+const CollapsibleSectionBase = ({label,+ trigger,children,- isOpenDefault = false,- isOpen,- rightSlot,fullWidth = false,-}: CollapsibleSectionProps) => {- const [isOpenByUser, setIsOpenByUser] = useOpenState(label, isOpenDefault);- const isOpenFinal = isOpen === undefined ? isOpenByUser : isOpen;+ isOpen,+ onOpenChange,+}: BaseProps) => (+ <Collapsible.Root open={isOpen} onOpenChange={onOpenChange}>+ <Box css={{ boxShadow: `0px 1px 0 ${theme.colors.panelOutline}` }}>+ <Collapsible.Trigger asChild>+ {trigger ?? (+ <SectionTitle>+ <SectionTitleLabel>{label}</SectionTitleLabel>+ </SectionTitle>+ )}+ </Collapsible.Trigger>++ <Collapsible.Content asChild>+ <Flex+ gap="3"+ direction="column"+ css={{+ pb: theme.spacing[9],+ px: fullWidth ? 0 : theme.spacing[9],+ paddingTop: 0,+ "&:empty": { display: "none" },+ }}+ >+ {children}+ </Flex>+ </Collapsible.Content>+ </Box>+ </Collapsible.Root>+);++type CollapsibleSectionProps = Omit<BaseProps, "isOpen" | "onOpenChange"> &+ UseOpenStateProps;++export const CollapsibleSection = (props: CollapsibleSectionProps) => {+ const { label, trigger, children, fullWidth } = props;+ const [isOpen, setIsOpen] = useOpenState(props);+ return (+ <CollapsibleSectionBase+ label={label}+ trigger={trigger}+ fullWidth={fullWidth}+ isOpen={isOpen}+ onOpenChange={setIsOpen}+ >+ {children}+ </CollapsibleSectionBase>+ );+};++export const CollapsibleSectionWithAddButton = ({+ onAdd,+ hasItems = true,+ ...props+}: Omit<CollapsibleSectionProps, "trigger"> & {+ onAdd: () => void;++ /**+ * If set to `true`, dots aren't shown,+ * but still affects how isOpen is treated and whether onAdd is called on open.+ */+ hasItems?: boolean | ComponentProps<typeof SectionTitle>["dots"];+}) => {+ const { label, children, fullWidth } = props;+ const [isOpen, setIsOpen] = useOpenState(props);++ const isEmpty =+ hasItems === false || (Array.isArray(hasItems) && hasItems.length === 0);++ // If it's open but empty, we want it to look as closed+ const isOpenFinal = isOpen && isEmpty === false;+return (- <Collapsible.Root open={isOpenFinal} onOpenChange={setIsOpenByUser}>- <Box- css={{- boxShadow: `0px 1px 0 ${theme.colors.panelOutline}`,- }}- >- <Collapsible.Trigger asChild>- <Flex- align="center"- gap="1"- justify="between"- css={{- py: theme.spacing[9],- px: theme.spacing[9],- color: theme.colors.hiContrast,- cursor: "default",- userSelect: "none",- }}- >- <DeprecatedText2 variant="label">{label}</DeprecatedText2>- <Flex- align="center"- justify="center"- css={{- marginRight: `-${theme.spacing[3]}`,- color: theme.colors.slate9,+ <CollapsibleSectionBase+ label={label}+ fullWidth={fullWidth}+ isOpen={isOpenFinal}+ onOpenChange={(nextIsOpen) => {+ setIsOpen(nextIsOpen);+ if (isEmpty) {+ onAdd?.();+ }+ }}+ trigger={+ <SectionTitle+ dots={Array.isArray(hasItems) ? hasItems : []}+ suffix={+ <SectionTitleButton+ prefix={<PlusIcon />}+ onClick={() => {+ if (isOpenFinal === false) {+ setIsOpen(true);+ }+ onAdd();}}- >- {rightSlot}- {isOpenFinal ? <ChevronLeftIcon /> : <ChevronRightIcon />}- </Flex>- </Flex>- </Collapsible.Trigger>- <Collapsible.Content asChild>- <Flex- gap="3"- direction="column"- css={{- pb: theme.spacing[9],- px: fullWidth ? 0 : theme.spacing[9],- paddingTop: 0,- "&:empty": {- display: "none",- },- }}- >- {children}- </Flex>- </Collapsible.Content>- </Box>- </Collapsible.Root>+ />+ }+ >+ <SectionTitleLabel>{props.label}</SectionTitleLabel>+ </SectionTitle>+ }+ >+ {children}+ </CollapsibleSectionBase>);};diff --git a/packages/design-system/package.json b/packages/design-system/package.jsonindex e0aa92ee26..76b41da14e 100644--- a/packages/design-system/package.json+++ b/packages/design-system/package.json@@ -65,6 +65,7 @@"@radix-ui/react-toolbar": "^1.0.2","@radix-ui/react-tooltip": "^1.0.0","@radix-ui/react-use-layout-effect": "^1.0.0",+ "@react-aria/focus": "^3.11.0","@react-aria/interactions": "^3.11.0","@react-aria/utils": "^3.13.3","@stitches/react": "^1.2.8",diff --git a/packages/design-system/src/components/dialog.tsx b/packages/design-system/src/components/dialog.tsxindex 1c8de5a63a..4a8c3b5e12 100644--- a/packages/design-system/src/components/dialog.tsx+++ b/packages/design-system/src/components/dialog.tsx@@ -1,7 +1,7 @@import React, { type ReactNode, type ComponentProps, type Ref } from "react";import * as Primitive from "@radix-ui/react-dialog";import { css, theme, keyframes, type CSS } from "../stitches.config";-import { Title } from "./title";+import { PanelTitle } from "./panel-title";import { floatingPanelStyle, CloseButton, TitleSlot } from "./floating-panel";export const Dialog = Primitive.Root;@@ -49,7 +49,7 @@ export const DialogTitle = ({closeLabel?: string;}) => (<TitleSlot>- <Title+ <PanelTitlesuffix={<Primitive.Close asChild><CloseButton aria-label={closeLabel} />@@ -57,7 +57,7 @@ export const DialogTitle = ({}><Primitive.Title className={titleStyle()}>{children}</Primitive.Title>- </Title>+ </PanelTitle></TitleSlot>);diff --git a/packages/design-system/src/components/floating-panel-popover.tsx b/packages/design-system/src/components/floating-panel-popover.tsxindex acb89eec3a..f38d219e75 100644--- a/packages/design-system/src/components/floating-panel-popover.tsx+++ b/packages/design-system/src/components/floating-panel-popover.tsx@@ -1,7 +1,7 @@import React, { type ComponentProps, type Ref, type ReactNode } from "react";import * as Primitive from "@radix-ui/react-popover";import { css, theme, type CSS } from "../stitches.config";-import { Title } from "./title";+import { PanelTitle } from "./panel-title";import { floatingPanelStyle, CloseButton, TitleSlot } from "./floating-panel";export const FloatingPanelPopover = Primitive.Root;@@ -46,7 +46,7 @@ export const FloatingPanelPopoverTitle = ({closeLabel?: string;}) => (<TitleSlot>- <Title+ <PanelTitlesuffix={<Primitive.Close asChild><CloseButton aria-label={closeLabel} />@@ -54,7 +54,7 @@ export const FloatingPanelPopoverTitle = ({}>{children}- </Title>+ </PanelTitle></TitleSlot>);diff --git a/packages/design-system/src/components/label.stories.tsx b/packages/design-system/src/components/label.stories.tsxindex 795c46c0cd..9a25b439f2 100644--- a/packages/design-system/src/components/label.stories.tsx+++ b/packages/design-system/src/components/label.stories.tsx@@ -31,6 +31,28 @@ const LabelStory: ComponentStory<typeof Label> = ({</StoryGrid></StorySection>+ <StorySection title="Section title">+ <StoryGrid horizontal>+ {colors.map((color) => (+ <Label key={color} color={color} sectionTitle>+ {color}+ </Label>+ ))}+ </StoryGrid>+ </StorySection>++ <StorySection title="Focused (initially)">+ <StoryGrid horizontal>+ <Label+ color="local"+ tabIndex={-1}+ ref={(element) => element?.focus()}+ >+ Local+ </Label>+ </StoryGrid>+ </StorySection>+<StorySection title="With checkbox"><input id="checkbox1" type="checkbox"></input><Label htmlFor="checkbox1">Label text</Label>diff --git a/packages/design-system/src/components/label.tsx b/packages/design-system/src/components/label.tsxindex 03e1a1bf26..d7179cb603 100644--- a/packages/design-system/src/components/label.tsx+++ b/packages/design-system/src/components/label.tsx@@ -10,15 +10,17 @@ import { styled, theme } from "../stitches.config";export const labelColors = ["default", "preset", "local", "remote"] as const;-const StyledLabel = styled("label", textVariants.labelsSentenceCase, {+const StyledLabel = styled("label", {boxSizing: "border-box",flexShrink: 0,py: theme.spacing[1],border: "1px solid transparent",borderRadius: theme.borderRadius[3],+ // https://github.com/webstudio-is/webstudio-builder/issues/1271#issuecomment-1478436340"&:focus-visible": {- outline: `2px solid ${theme.colors.blue10}`,+ outline: `2px solid ${theme.colors.borderFocus}`,+ outlineOffset: 1,},"&[aria-disabled=true]": {@@ -67,15 +69,21 @@ const StyledLabel = styled("label", textVariants.labelsSentenceCase, {flexGrow: 1,},},+ sectionTitle: {+ true: textVariants.titles,+ false: textVariants.labelsSentenceCase,+ },},defaultVariants: {color: "default",+ sectionTitle: false,},});type Props = ComponentProps<typeof StyledLabel> & {color?: (typeof labelColors)[number];+ sectionTitle?: boolean;disabled?: boolean;truncate?: boolean;children: ReactNode;diff --git a/packages/design-system/src/components/title.stories.tsx b/packages/design-system/src/components/panel-title.stories.tsxsimilarity index 65%rename from packages/design-system/src/components/title.stories.tsxrename to packages/design-system/src/components/panel-title.stories.tsxindex aa6a621391..28f8065bd8 100644--- a/packages/design-system/src/components/title.stories.tsx+++ b/packages/design-system/src/components/panel-title.stories.tsx@@ -1,21 +1,21 @@-import { Title, TitleSuffixSpacer } from "./title";+import { PanelTitle, TitleSuffixSpacer } from "./panel-title";import { Button } from "./button";import { CrossIcon, CopyIcon } from "@webstudio-is/icons";import { StoryGrid } from "./storybook";export default {- title: "Library/Title",+ title: "Library/Panel Title",};-const TitleStory = () => (+export const Demo = () => (<StoryGrid>- <Title>Without buttons</Title>+ <PanelTitle>Without buttons</PanelTitle>- <Title suffix={<Button prefix={<CrossIcon />} color="ghost" />}>+ <PanelTitle suffix={<Button prefix={<CrossIcon />} color="ghost" />}>One icon button- </Title>+ </PanelTitle>- <Title+ <PanelTitlesuffix={<><Button prefix={<CrossIcon />} color="ghost" />@@ -24,9 +24,9 @@ const TitleStory = () => (}>Many icon buttons- </Title>+ </PanelTitle>- <Title+ <PanelTitlesuffix={<><Button prefix={<CrossIcon />} color="ghost" />@@ -37,8 +37,7 @@ const TitleStory = () => (}>Icon and regular buttons- </Title>+ </PanelTitle></StoryGrid>);--export { TitleStory as Title };+Demo.storyName = "Panel Title";diff --git a/packages/design-system/src/components/title.tsx b/packages/design-system/src/components/panel-title.tsxsimilarity index 87%rename from packages/design-system/src/components/title.tsxrename to packages/design-system/src/components/panel-title.tsxindex 92f6547053..ed8257a951 100644--- a/packages/design-system/src/components/title.tsx+++ b/packages/design-system/src/components/panel-title.tsx@@ -1,6 +1,6 @@/**- * Implementation of the "Title" component from:- * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=2%3A12361+ * Implementation of the "Panel Title" component from:+ * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=2647-10046*/import { forwardRef, type ReactNode, type Ref } from "react";@@ -36,7 +36,7 @@ export const TitleSuffixSpacer = styled("div", {width: theme.spacing[5],});-export const Title = forwardRef(+export const PanelTitle = forwardRef(({ children, suffix, className, css }: TitleProps,ref: Ref<HTMLDivElement>@@ -47,4 +47,4 @@ export const Title = forwardRef(</Container>));-Title.displayName = "Title";+PanelTitle.displayName = "PanelTitle";diff --git a/packages/design-system/src/components/primitives/arrow-focus.tsx b/packages/design-system/src/components/primitives/arrow-focus.tsxnew file mode 100644index 0000000000..a8a48740db--- /dev/null+++ b/packages/design-system/src/components/primitives/arrow-focus.tsx@@ -0,0 +1,31 @@+import { FocusScope, useFocusManager } from "@react-aria/focus";+import type { KeyboardEvent } from "react";++type Render = (props: {+ handleKeyDown: (event: KeyboardEvent) => void;+ focusManager: ReturnType<typeof useFocusManager>;+}) => JSX.Element;++// Need this wrapper becuase we can't call useFocusManager+// in the same component that renders FocusScope+const ContextHelper = ({ render }: { render: Render }) => {+ const focusManager = useFocusManager();++ return render({+ handleKeyDown: (event: KeyboardEvent) => {+ if (event.key === "ArrowRight" || event.key === "ArrowDown") {+ focusManager.focusNext({ wrap: true });+ }+ if (event.key === "ArrowLeft" || event.key === "ArrowUp") {+ focusManager.focusPrevious({ wrap: true });+ }+ },+ focusManager,+ });+};++export const ArrowFocus = ({ render }: { render: Render }) => (+ <FocusScope>+ <ContextHelper render={render} />+ </FocusScope>+);diff --git a/packages/design-system/src/components/section-title.stories.tsx b/packages/design-system/src/components/section-title.stories.tsxnew file mode 100644index 0000000000..277dff802f--- /dev/null+++ b/packages/design-system/src/components/section-title.stories.tsx@@ -0,0 +1,111 @@+import {+ SectionTitle,+ SectionTitleLabel,+ SectionTitleButton,+} from "./section-title";+import { StoryGrid, StorySection } from "./storybook";+import type { ComponentProps } from "react";+import { PlusIcon } from "@webstudio-is/icons";++export default {+ title: "Library/Section Title",+};++const Wrap = ({ children }: { children: React.ReactNode }) => (+ <div style={{ width: 240, border: "dashed 3px #e3e3e3" }}>{children}</div>+);++const Variants = ({+ state,+}: {+ state: ComponentProps<typeof SectionTitle>["data-state"];+}) => (+ <>+ <Wrap>+ <SectionTitle data-state={state}>+ <SectionTitleLabel>Simplest</SectionTitleLabel>+ </SectionTitle>+ </Wrap>+ <Wrap>+ <SectionTitle+ suffix={<SectionTitleButton prefix={<PlusIcon />} />}+ data-state={state}+ >+ <SectionTitleLabel>With button</SectionTitleLabel>+ </SectionTitle>+ </Wrap>+ <Wrap>+ <SectionTitle+ dots={["local", "remote"]}+ suffix={<SectionTitleButton prefix={<PlusIcon />} />}+ data-state={state}+ >+ <SectionTitleLabel>With dots</SectionTitleLabel>+ </SectionTitle>+ </Wrap>+ <Wrap>+ <SectionTitle+ dots={["local"]}+ suffix={<SectionTitleButton prefix={<PlusIcon />} />}+ data-state={state}+ >+ <SectionTitleLabel+ color="local"+ onClick={() => null} // added to test focus of label+ >+ With label+ </SectionTitleLabel>+ </SectionTitle>+ </Wrap>+ <Wrap>+ <SectionTitle+ dots={["local", "remote"]}+ suffix={<SectionTitleButton prefix={<PlusIcon />} />}+ data-state={state}+ >+ <SectionTitleLabel>+ Some title so long that it cannot possibly fit+ </SectionTitleLabel>+ </SectionTitle>+ </Wrap>+ <Wrap>+ <SectionTitle data-state={state}>+ <SectionTitleLabel>+ Some title so long that it cannot possibly fit+ </SectionTitleLabel>+ </SectionTitle>+ </Wrap>+ </>+);++export const Demo = () => (+ <>+ <StorySection title="Focused (intially)">+ <StoryGrid>+ <Wrap>+ <SectionTitle+ dots={["local", "remote"]}+ suffix={<SectionTitleButton prefix={<PlusIcon />} />}+ autoFocus+ >+ <SectionTitleLabel>Title</SectionTitleLabel>+ </SectionTitle>+ </Wrap>+ </StoryGrid>+ </StorySection>++ <StorySection title="Closed">+ <StoryGrid>+ <Variants state="closed" />+ </StoryGrid>+ </StorySection>++ <StorySection title="Open">+ <StoryGrid>+ <Variants state="open" />+ </StoryGrid>+ </StorySection>+ </>+);++Demo.storyName = "Section Title";diff --git a/packages/design-system/src/components/section-title.tsx b/packages/design-system/src/components/section-title.tsxnew file mode 100644index 0000000000..fbb318538a--- /dev/null+++ b/packages/design-system/src/components/section-title.tsx@@ -0,0 +1,223 @@+/**+ * Implementation of the "Title (title of: section)" component from:+ * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=2%3A12361+ *+ * Designed to be used with Collapsible.Trigger+ */++import {+ forwardRef,+ type ReactNode,+ type Ref,+ type ComponentProps,+ createContext,+ useContext,+} from "react";+import { theme, css, type CSS } from "../stitches.config";+import { Button } from "./button";+import { cssVars } from "@webstudio-is/css-vars";+import { ArrowFocus } from "./primitives/arrow-focus";+import { Label } from "./label";++const buttonContentColor = cssVars.define("button-content-color");+const labelTextColor = cssVars.define("label-text-color");++const containerStyle = css({+ position: "relative",+ height: theme.spacing[15],+ [buttonContentColor]: theme.colors.foregroundSubtle,+ "&:hover, &:has(:focus-visible), &[data-state=open]": {+ [buttonContentColor]: theme.colors.foregroundIconMain,+ },+});++const titleButtonStyle = css({+ all: "unset", // reset <button>+ display: "flex",+ gap: theme.spacing[5],+ alignItems: "center",+ width: "100%",+ height: "100%",+ boxSizing: "border-box",+ paddingLeft: theme.spacing[9],+ paddingRight: theme.spacing[7],+ [labelTextColor]: theme.colors.foregroundSubtle,+ cursor: "pointer",+ "&:hover, &:focus-visible, &[data-state=open]": {+ [labelTextColor]: theme.colors.foregroundMain,+ },+ "&:focus-visible::before": {+ content: "''",+ position: "absolute",+ top: 0,+ bottom: 0,+ left: theme.spacing[2],+ right: theme.spacing[2],+ borderRadius: theme.borderRadius[4],+ border: `2px solid ${theme.colors.borderFocus}`,+ },+ variants: {+ // We assume that suffix is a <Button prefix={<Icon />} />+ // (hard to support arbitrary width suffixes here, hopefully we'll never need to)+ hasSuffix: { true: { paddingRight: theme.spacing[16] } },+ },+});++const suffixSlotStyle = css({+ position: "absolute",+ right: theme.spacing[6],+ top: theme.spacing[4],+});++const dotsSlotStyle = css({+ display: "flex",+});++const dotStyle = css({+ width: theme.spacing[4],+ height: theme.spacing[4],+ borderRadius: theme.borderRadius.round,+ marginRight: -2,+ variants: {+ color: {+ local: { backgroundColor: theme.colors.foregroundLocalFlexUi },+ remote: { backgroundColor: theme.colors.foregroundRemoteFlexUi },+ },+ },+});++const context = createContext<{ state: "open" | "closed" }>({+ state: "closed",+});++export const SectionTitle = forwardRef(+ (+ {+ dots,+ className,+ css,+ children,+ suffix,+ ...props+ }: ComponentProps<"button"> & {+ /** https://www.radix-ui.com/docs/primitives/components/collapsible#trigger */+ "data-state"?: "open" | "closed";+ dots?: Array<"local" | "remote">;+ css?: CSS;+ /** Primarily for <SectionTitleButton> */+ suffix?: ReactNode;+ },+ ref: Ref<HTMLButtonElement>+ ) => {+ const state = props["data-state"] ?? "closed";+ const finalDots = state === "open" ? [] : dots ?? [];++ return (+ <context.Provider value={{ state }}>+ <ArrowFocus+ render={({ handleKeyDown }) => (+ <div+ className={containerStyle({ className, css })}+ data-state={state}+ onKeyDown={handleKeyDown}+ >+ <button+ className={titleButtonStyle({+ hasSuffix: suffix !== undefined,+ })}+ data-state={state}+ ref={ref}+ {...props}+ >+ {children}+ {finalDots.length > 0 && (+ <div className={dotsSlotStyle()}>+ {finalDots.map((color) => (+ <div key={color} className={dotStyle({ color })} />+ ))}+ </div>+ )}+ </button>+ {suffix && <div className={suffixSlotStyle()}>{suffix}</div>}+ </div>+ )}+ />+ </context.Provider>+ );+ }+);+SectionTitle.displayName = "SectionTitle";++export const SectionTitleLabel = forwardRef(+ (+ {+ css,+ children,+ ...props+ }: Omit<ComponentProps<typeof Label>, "truncate" | "sectionTitle">,+ ref: Ref<HTMLLabelElement>+ ) => {+ const { state } = useContext(context);++ const commonCss = { flex: "0 1 auto" };++ // When section is closed Label basically turns into an innert text+ // https://github.com/webstudio-is/webstudio-builder/issues/1271#issuecomment-1478262629+ if (state === "closed") {+ return (+ <Label+ truncate+ sectionTitle+ color="default"+ css={{+ cursor: "inherit",+ color: cssVars.use(labelTextColor),+ ...commonCss,+ ...css,+ }}+ ref={ref}+ >+ {children}+ </Label>+ );+ }++ const hasAction = Object.keys(props).some((prop) => prop.startsWith("on"));++ return (+ <Label+ truncate+ sectionTitle+ tabIndex={hasAction ? -1 : undefined}+ {...props}+ css={{+ // if there's no action, use cursor of SectionTitle,+ // otherwise use cursor of Label+ cursor: hasAction ? undefined : "inherit",+ ...commonCss,+ ...css,+ }}+ ref={ref}+ >+ {children}+ </Label>+ );+ }+);+SectionTitleLabel.displayName = "SectionTitleLabel";++export const SectionTitleButton = forwardRef(+ (+ { css, ...props }: ComponentProps<typeof Button>,+ ref: Ref<HTMLButtonElement>+ ) => (+ <Button+ tabIndex={-1}+ color="ghost"+ {...props}+ css={{ color: cssVars.use(buttonContentColor), ...css }}+ ref={ref}+ />+ )+);+SectionTitleButton.displayName = "SectionTitleButton";diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.tsindex 7b9a0469e1..3eb6280bb5 100644--- a/packages/design-system/src/index.ts+++ b/packages/design-system/src/index.ts@@ -4,7 +4,8 @@ export * from "./components/storybook";// Aligned with Figmaexport * from "./components/text";-export * from "./components/title";+export * from "./components/panel-title";+export * from "./components/section-title";export * from "./components/separator";export * from "./components/button";export * from "./components/label";diff --git a/packages/icons/icons/plus.svg b/packages/icons/icons/plus.svgnew file mode 100644index 0000000000..e0712bf0a7--- /dev/null+++ b/packages/icons/icons/plus.svg@@ -0,0 +1,4 @@+<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">+<path fill-rule="evenodd" clip-rule="evenodd" d="M8 14C7.58579 14 7.25 13.6642 7.25 13.25L7.25 2.75C7.25 2.33579 7.58579 2 8 2C8.41421 2 8.75 2.33579 8.75 2.75L8.75 13.25C8.75 13.6642 8.41421 14 8 14Z"/>+<path fill-rule="evenodd" clip-rule="evenodd" d="M14 8C14 8.41421 13.6642 8.75 13.25 8.75H2.75C2.33579 8.75 2 8.41421 2 8C2 7.58579 2.33579 7.25 2.75 7.25H13.25C13.6642 7.25 14 7.58579 14 8Z"/>+</svg>diff --git a/packages/icons/src/__generated__/index.ts b/packages/icons/src/__generated__/index.tsindex 89196f7c95..6b482c900a 100644--- a/packages/icons/src/__generated__/index.ts+++ b/packages/icons/src/__generated__/index.ts@@ -43,6 +43,7 @@ export * from "./list-item";export * from "./list";export * from "./offline";export * from "./play";+export * from "./plus";export * from "./radio-checked";export * from "./radio-unchecked";export * from "./repeat-column";diff --git a/packages/icons/src/__generated__/plus.tsx b/packages/icons/src/__generated__/plus.tsxnew file mode 100644index 0000000000..bccad91fb7--- /dev/null+++ b/packages/icons/src/__generated__/plus.tsx@@ -0,0 +1,15 @@+// Generated from icons/plus.svg++import { forwardRef } from "react";+import type { IconProps } from "../types";++// prettier-ignore+export const PlusIcon = forwardRef<SVGSVGElement, IconProps>(+ ({ color = "currentColor", size = 16, ...props }, forwardedRef) => {+ return (+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width={size} height={size} fill={color} {...props} ref={forwardedRef}><path fillRule="evenodd" d="M8 14a.75.75 0 0 1-.75-.75V2.75a.75.75 0 0 1 1.5 0v10.5A.75.75 0 0 1 8 14Z" clipRule="evenodd" /><path fillRule="evenodd" d="M14 8a.75.75 0 0 1-.75.75H2.75a.75.75 0 0 1 0-1.5h10.5A.75.75 0 0 1 14 8Z" clipRule="evenodd" /></svg>+ );+ }+);++PlusIcon.displayName = "PlusIcon";diff --git a/packages/icons/src/legacy.ts b/packages/icons/src/legacy.tsindex e346e18bd8..b17c55048a 100644--- a/packages/icons/src/legacy.ts+++ b/packages/icons/src/legacy.ts@@ -3,7 +3,6 @@ export {FontBoldIcon,FontItalicIcon,Link2Icon,- PlusIcon,DotsHorizontalIcon,CheckIcon,RocketIcon,diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 9bd5ec6c2f..3a94390dc6 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -699,6 +699,9 @@ importers:'@radix-ui/react-use-layout-effect':specifier: ^1.0.0version: 1.0.0([email protected])+ '@react-aria/focus':+ specifier: ^3.11.0+ version: 3.11.0([email protected])'@react-aria/interactions':specifier: ^3.11.0version: 3.11.0([email protected])@@ -4720,7 +4723,7 @@ packages:react-refresh: 0.11.0schema-utils: 3.1.1source-map: 0.7.4- webpack: 5.75.0([email protected])+ webpack: 5.75.0dev: true/@prisma/[email protected]([email protected]):@@ -5630,6 +5633,19 @@ packages:'@babel/runtime': 7.20.13dev: false+ /@react-aria/[email protected]([email protected]):+ resolution: {integrity: sha512-yPuWs9bAR9CMfIwyOPm2oXLPF19gNkUqW+ozSPhWbLMTEa8Ma09eHW1br4xbN+4ONOm/dCJsIkxTNPUkiLdQoA==}+ peerDependencies:+ react: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0+ dependencies:+ '@react-aria/interactions': 3.14.0([email protected])+ '@react-aria/utils': 3.15.0([email protected])+ '@react-types/shared': 3.17.0([email protected])+ '@swc/helpers': 0.4.14+ clsx: 1.2.1+ react: 17.0.2+ dev: false+/@react-aria/[email protected]([email protected]):resolution: {integrity: sha512-ZjK4m8u6FlV7Q9/1h9P2Ii6j/NwKR3BmTeGeBQssS2i4dV2pJeOPePnGzVQQGG8FzGQ+TcNRvZPXKaU4AlnBjw==}peerDependencies:@@ -5641,6 +5657,17 @@ packages:react: 17.0.2dev: false+ /@react-aria/[email protected]([email protected]):+ resolution: {integrity: sha512-e1Tkr0UTuYFpV21PJrXy7jEY542Vl+C2Fo70oukZ1fN+wtfQkzodsTIzyepXb7kVMGmC34wDisMJUrksVkfY2w==}+ peerDependencies:+ react: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0+ dependencies:+ '@react-aria/utils': 3.15.0([email protected])+ '@react-types/shared': 3.17.0([email protected])+ '@swc/helpers': 0.4.14+ react: 17.0.2+ dev: false+/@react-aria/[email protected]([email protected]):resolution: {integrity: sha512-yNqUDuOVZIUGP81R87BJVi/ZUZp/nYOBXbPsRe7oltJOfErQZD+UezMpw4vM2KRz18cURffvmC8tJ6JTeyDtaQ==}peerDependencies:@@ -5650,6 +5677,15 @@ packages:react: 17.0.2dev: false+ /@react-aria/[email protected]([email protected]):+ resolution: {integrity: sha512-h0MJdSWOd1qObLnJ8mprU31wI8tmKFJMuwT22MpWq6psisOOZaga6Ml4u6Ee6M6duWWISjXvqO4Sb/J0PBA+nQ==}+ peerDependencies:+ react: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0+ dependencies:+ '@swc/helpers': 0.4.14+ react: 17.0.2+ dev: false+/@react-aria/[email protected]([email protected]):resolution: {integrity: sha512-wqjGNFX4TrXriUU1gvCaoqRhuckdoYogUWN0iyQRkTmzvb7H/NNzQzHou5ggWAdts/NzJUInwKarBWM9hCZZbg==}peerDependencies:@@ -5663,6 +5699,19 @@ packages:react: 17.0.2dev: false+ /@react-aria/[email protected]([email protected]):+ resolution: {integrity: sha512-aJZBG++iz1UwTW5gXFaHicKju4p0MPhAyBTcf2awHYWeTUUslDjJcEnNg7kjBYZBOrOSlA2rAt7/7C5CCURQPg==}+ peerDependencies:+ react: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0+ dependencies:+ '@react-aria/ssr': 3.5.0([email protected])+ '@react-stately/utils': 3.6.0([email protected])+ '@react-types/shared': 3.17.0([email protected])+ '@swc/helpers': 0.4.14+ clsx: 1.2.1+ react: 17.0.2+ dev: false+/@react-stately/[email protected]([email protected]):resolution: {integrity: sha512-INeQ5Er2Jm+db8Py4upKBtgfzp3UYgwXYmbU/XJn49Xw27ktuimH9e37qP3bgHaReb5L3g8IrGs38tJUpnGPHA==}peerDependencies:@@ -5672,6 +5721,15 @@ packages:react: 17.0.2dev: false+ /@react-stately/[email protected]([email protected]):+ resolution: {integrity: sha512-rptF7iUWDrquaYvBAS4QQhOBQyLBncDeHF03WnHXAxnuPJXNcr9cXJtjJPGCs036ZB8Q2hc9BGG5wNyMkF5v+Q==}+ peerDependencies:+ react: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0+ dependencies:+ '@swc/helpers': 0.4.14+ react: 17.0.2+ dev: false+/@react-types/[email protected]([email protected]):resolution: {integrity: sha512-yPPgVRWWanXqbdxFTgJmVwx0JlcnEK3dqkKDIbVk6mxAHvEESI9+oDnHvO8IMHqF+GbrTCzVtAs0zwhYI/uHJA==}peerDependencies:@@ -5680,6 +5738,14 @@ packages:react: 17.0.2dev: false+ /@react-types/[email protected]([email protected]):+ resolution: {integrity: sha512-1SNZ/RhVrrQ1e6yE0bPV7d5Sfp+Uv0dfUEhwF9MAu2v5msu7AMewnsiojKNA0QA6Ing1gpDLjHCxtayQfuxqcg==}+ peerDependencies:+ react: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0+ dependencies:+ react: 17.0.2+ dev: false+/@remix-run/[email protected](@cloudflare/[email protected]):resolution: {integrity: sha512-Xr7yhGlafY/JUTdBxVpMXJpBHgJsSwPGJ4tObol+s70monwNkIcRLKjt5+Aj8TjPR0NJ/I+sJbxFPHf65mTtRg==}engines: {node: '>=14'}@@ -6906,7 +6972,7 @@ packages:typescript: 4.9.5unfetch: 4.2.0util-deprecate: 1.0.2- webpack: 5.75.0([email protected])+ webpack: 5.75.0dev: true/@storybook/[email protected]([email protected])([email protected])([email protected])([email protected]):@@ -7161,7 +7227,7 @@ packages:react: 17.0.2react-dom: 17.0.2([email protected])typescript: 4.9.5- webpack: 5.75.0([email protected])+ webpack: 5.75.0transitivePeerDependencies:- '@storybook/mdx2-csf'- bluebird@@ -7367,7 +7433,7 @@ packages:react-docgen-typescript: 2.2.2([email protected])tslib: 2.5.0typescript: 4.9.5- webpack: 5.75.0([email protected])+ webpack: 5.75.0transitivePeerDependencies:- supports-colordev: true@@ -7835,6 +7901,12 @@ packages:tslib: 2.5.0dev: false+ /@swc/[email protected]:+ resolution: {integrity: sha512-4C7nX/dvpzB7za4Ql9K81xK3HPxCpHMgwTZVyf+9JQ6VUbn9jjZVN7/Nkdz/Ugzs2CSjqnL/UPXroiVBVHUWUw==}+ dependencies:+ tslib: 2.5.0+ dev: false+/@szmarczak/[email protected]:resolution: {integrity: sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==}engines: {node: '>=10'}