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
Nested Input Button (#1650)
Ivan Starkovad574fefc295
diff --git a/apps/builder/app/builder/features/props-panel/props-panel.tsx b/apps/builder/app/builder/features/props-panel/props-panel.tsxindex 51f2c4c164..f296452038 100644--- a/apps/builder/app/builder/features/props-panel/props-panel.tsx+++ b/apps/builder/app/builder/features/props-panel/props-panel.tsx@@ -14,9 +14,8 @@ import {type CSS,ScrollArea,InputField,- NestedSelectButton,+ NestedInputButton,} from "@webstudio-is/design-system";-import { ChevronDownIcon } from "@webstudio-is/icons";import type { Publish } from "~/shared/pubsub";import { propsStore, useInstanceProps } from "~/shared/nano-states";import { CollapsibleSectionWithAddButton } from "~/builder/shared/collapsible-section";@@ -96,12 +95,7 @@ const PropsCombobox = ({autoFocus{...combobox.getInputProps()}placeholder="Property"- suffix={- <NestedSelectButton- {...combobox.getToggleButtonProps()}- icon={<ChevronDownIcon />}- />- }+ suffix={<NestedInputButton {...combobox.getToggleButtonProps()} />}/></ComboboxAnchor><ComboboxContent align="end" sideOffset={5}>diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsxindex cb4925c9fd..1eed08fb05 100644--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx@@ -8,12 +8,11 @@ import {ComboboxListbox,ComboboxListboxItem,numericScrubControl,- NestedSelectButton,+ NestedInputButton,NestedIconLabel,InputField,handleNumericInputArrowKeys,} from "@webstudio-is/design-system";-import { ChevronDownIcon } from "@webstudio-is/icons";import type {KeywordValue,StyleProperty,@@ -555,13 +554,11 @@ export const CssValueInput = ({));const keywordButtonElement = (- <NestedSelectButton+ <NestedInputButton{...getToggleButtonProps()}data-state={isOpen ? "open" : "closed"}tabIndex={-1}- >- <ChevronDownIcon />- </NestedSelectButton>+ />);const isUnitValue = unitSelectElement !== null;diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx b/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsxindex 625296184e..1e05a0fe75 100644--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx@@ -7,7 +7,7 @@ import {SelectViewport,SelectItem,SelectContent,- NestedSelectButton,+ NestedInputButton,nestedSelectButtonUnitless,} from "@webstudio-is/design-system";import { ChevronDownIcon, ChevronUpIcon } from "@webstudio-is/icons";@@ -111,11 +111,11 @@ const UnitSelect = ({open={open}><SelectPrimitive.SelectTrigger asChild>- <NestedSelectButton tabIndex={-1}>+ <NestedInputButton tabIndex={-1}><SelectPrimitive.Value>{value === "number" ? nestedSelectButtonUnitless : label}</SelectPrimitive.Value>- </NestedSelectButton>+ </NestedInputButton></SelectPrimitive.SelectTrigger><SelectPrimitive.Portal><SelectContentdiff --git a/packages/design-system/src/components/input-field.stories.tsx b/packages/design-system/src/components/input-field.stories.tsxindex fa47d86abb..188aaa2581 100644--- a/packages/design-system/src/components/input-field.stories.tsx+++ b/packages/design-system/src/components/input-field.stories.tsx@@ -2,7 +2,7 @@ import { GapVerticalIcon } from "@webstudio-is/icons";import { Flex } from "./flex";import { InputField, inputFieldColors } from "./input-field";import { NestedIconLabel } from "./nested-icon-label";-import { NestedSelectButton } from "./nested-select-button";+import { NestedInputButton } from "./nested-input-button";import { StorySection, StoryGrid } from "./storybook";export default {@@ -15,7 +15,7 @@ const prefix = (</NestedIconLabel>);-const suffix = <NestedSelectButton tabIndex={-1} />;+const suffix = <NestedInputButton tabIndex={-1} />;export const Demo = () => (<>@@ -47,7 +47,7 @@ export const Demo = () => (<GapVerticalIcon /></NestedIconLabel>}- suffix={<NestedSelectButton disabled />}+ suffix={<NestedInputButton disabled />}disabled/></StoryGrid>diff --git a/packages/design-system/src/components/nested-input-button.stories.tsx b/packages/design-system/src/components/nested-input-button.stories.tsxnew file mode 100644index 0000000000..baa8f505a2--- /dev/null+++ b/packages/design-system/src/components/nested-input-button.stories.tsx@@ -0,0 +1,48 @@+import { CopyIcon } from "@webstudio-is/icons";+import { NestedInputButton } from "./nested-input-button";+import { StoryGrid, StorySection } from "./storybook";++export default {+ title: "Library/Nested Select Button",+};++export const Demo = () => {+ return (+ <>+ <StorySection title="Text">+ <StoryGrid horizontal>+ <NestedInputButton>px</NestedInputButton>+ <NestedInputButton data-state="hover">px</NestedInputButton>+ <NestedInputButton data-state="open">px</NestedInputButton>+ <NestedInputButton disabled>px</NestedInputButton>+ </StoryGrid>+ </StorySection>+ <StorySection title="Chevron down icon">+ <StoryGrid horizontal>+ <NestedInputButton />+ <NestedInputButton data-state="hover" />+ <NestedInputButton data-state="open" />+ <NestedInputButton disabled />+ </StoryGrid>+ </StorySection>+ <StorySection title="Any Icon">+ <StoryGrid horizontal>+ <NestedInputButton>+ <CopyIcon />+ </NestedInputButton>+ <NestedInputButton data-state="hover">+ <CopyIcon />+ </NestedInputButton>+ <NestedInputButton data-state="open">+ <CopyIcon />+ </NestedInputButton>+ <NestedInputButton disabled>+ <CopyIcon />+ </NestedInputButton>+ </StoryGrid>+ </StorySection>+ </>+ );+};++Demo.storyName = "Nested Select Button";diff --git a/packages/design-system/src/components/nested-select-button.tsx b/packages/design-system/src/components/nested-input-button.tsxsimilarity index 69%rename from packages/design-system/src/components/nested-select-button.tsxrename to packages/design-system/src/components/nested-input-button.tsxindex bdd1fde7ee..7285ba3e70 100644--- a/packages/design-system/src/components/nested-select-button.tsx+++ b/packages/design-system/src/components/nested-input-button.tsx@@ -1,5 +1,5 @@/**- * Implementation of the "Nested Select Button" component from:+ * Implementation of the "Nested Input Button" component from:* https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=148-3113*/@@ -19,6 +19,7 @@ const style = css({borderRadius: theme.borderRadius[2],display: "inline-flex",alignItems: "center",+ justifyContent: "center",height: theme.spacing[11],whiteSpace: "pre", // to make nestedSelectButtonUnitless work as expected"&:not(:has(svg))": {@@ -37,21 +38,37 @@ const style = css({"&:disabled": {color: theme.colors.foregroundDisabled,},+ variants: {+ /**+ * ChevronDownIcon is the only case when we have svg inside the button and width is not equal to height+ */+ hasChildren: {+ true: {+ "&:where(:has(svg))": {+ width: theme.spacing[11],+ },+ },+ },+ },});-export const NestedSelectButton = forwardRef(+export const NestedInputButton = forwardRef(({css,className,- children = <ChevronDownIcon />,+ children,...props}: ComponentProps<"button"> & { css?: CSS },ref: Ref<HTMLButtonElement>) => (- <button className={style({ css, className })} {...props} ref={ref}>- {children}+ <button+ className={style({ css, className, hasChildren: children !== undefined })}+ {...props}+ ref={ref}+ >+ {children ?? <ChevronDownIcon />}</button>));-NestedSelectButton.displayName = "NestedSelectButton";+NestedInputButton.displayName = "NestedSelectButton";diff --git a/packages/design-system/src/components/nested-select-button.stories.tsx b/packages/design-system/src/components/nested-select-button.stories.tsxdeleted file mode 100644index deb1580c0f..0000000000--- a/packages/design-system/src/components/nested-select-button.stories.tsx+++ /dev/null@@ -1,31 +0,0 @@-import { NestedSelectButton } from "./nested-select-button";-import { StoryGrid, StorySection } from "./storybook";--export default {- title: "Library/Nested Select Button",-};--export const Demo = () => {- return (- <>- <StorySection title="Text">- <StoryGrid horizontal>- <NestedSelectButton>px</NestedSelectButton>- <NestedSelectButton data-state="hover">px</NestedSelectButton>- <NestedSelectButton data-state="open">px</NestedSelectButton>- <NestedSelectButton disabled>px</NestedSelectButton>- </StoryGrid>- </StorySection>- <StorySection title="Icon">- <StoryGrid horizontal>- <NestedSelectButton />- <NestedSelectButton data-state="hover" />- <NestedSelectButton data-state="open" />- <NestedSelectButton disabled />- </StoryGrid>- </StorySection>- </>- );-};--Demo.storyName = "Nested Select Button";diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.tsindex 16c24a8e51..a450604111 100644--- a/packages/design-system/src/index.ts+++ b/packages/design-system/src/index.ts@@ -36,7 +36,7 @@ export * from "./components/radio";export * from "./components/checkbox";export * from "./components/component-card";export * from "./components/input-field";-export * from "./components/nested-select-button";+export * from "./components/nested-input-button";// Not aligned