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
create List component, rename disclousure to renderTextField
Oleg Isonen3f8f09cf02a5
diff --git a/apps/designer/app/designer/features/props-panel/props-panel.tsx b/apps/designer/app/designer/features/props-panel/props-panel.tsxindex 3cd90b950f..2b7e8cbbe9 100644--- a/apps/designer/app/designer/features/props-panel/props-panel.tsx+++ b/apps/designer/app/designer/features/props-panel/props-panel.tsx@@ -57,7 +57,7 @@ const Property = ({onItemSelect={(value) => {onChange(id, "prop", value);}}- disclosure={({ inputProps, toggleProps }) => (+ renderTextField={({ inputProps, toggleProps }) => (<ComboboxTextFieldtoggleProps={toggleProps}inputProps={{diff --git a/apps/designer/app/designer/features/style-panel/render-property.tsx b/apps/designer/app/designer/features/style-panel/render-property.tsxindex bc4d57e630..37b3e645b0 100644--- a/apps/designer/app/designer/features/style-panel/render-property.tsx+++ b/apps/designer/app/designer/features/style-panel/render-property.tsx@@ -202,7 +202,7 @@ const ComboboxControl = ({}setValue(item.name, { isEphemeral: true });}}- disclosure={({ inputProps, toggleProps, highlightedItem }) => (+ renderTextField={({ inputProps, toggleProps, highlightedItem }) => (<ComboboxTextFieldtoggleProps={toggleProps}inputProps={{diff --git a/apps/designer/app/shared/design-system/components/combobox.stories.tsx b/apps/designer/app/shared/design-system/components/combobox.stories.tsxindex bd48ed0072..b55a30a339 100644--- a/apps/designer/app/shared/design-system/components/combobox.stories.tsx+++ b/apps/designer/app/shared/design-system/components/combobox.stories.tsx@@ -37,7 +37,7 @@ export const CustomInput: ComponentStory<typeof Combobox> = () => {onItemHighlight={(item) => {action("Highlight")(item);}}- disclosure={({ inputProps, toggleProps }) => (+ renderTextField={({ inputProps, toggleProps }) => (<ComboboxTextFieldtoggleProps={toggleProps}inputProps={{diff --git a/apps/designer/app/shared/design-system/components/combobox.tsx b/apps/designer/app/shared/design-system/components/combobox.tsxindex 6e8ee4ca28..b9f6a0a55f 100644--- a/apps/designer/app/shared/design-system/components/combobox.tsx+++ b/apps/designer/app/shared/design-system/components/combobox.tsx@@ -7,7 +7,7 @@ import {} from "react";import { CheckIcon, ChevronDownIcon } from "~/shared/icons";import { Popper, PopperContent, PopperAnchor } from "@radix-ui/react-popper";-import { useCombobox } from "downshift";+import { useCombobox, type UseComboboxGetItemPropsOptions } from "downshift";import { matchSorter } from "match-sorter";import { styled } from "../stitches.config";import { IconButton } from "./icon-button";@@ -21,19 +21,6 @@ type Label = string;type BaseItem = { label: Label; disabled?: boolean } | Label;-const Listbox = styled("ul", panelStyles, {- padding: 0,- margin: 0,- overflow: "auto",- // @todo need some non-hardcoded value- maxHeight: 400,- minWidth: 230,-});-const ListboxItem = styled("li", itemCss, {- padding: 0,- margin: 0,-});-type ComboboxTextFieldProps<Item> = {inputProps: ComponentProps<typeof TextField>;toggleProps: ComponentProps<typeof IconButton>;@@ -65,6 +52,66 @@ export const ComboboxTextField = forwardRef(ComboboxTextFieldBase);ComboboxTextField.displayName = "ComboboxTextField";+const Listbox = styled("ul", panelStyles, {+ padding: 0,+ margin: 0,+ overflow: "auto",+ // @todo need some non-hardcoded value+ maxHeight: 400,+ minWidth: 230,+});++const ListboxItem = styled("li", itemCss, {+ padding: 0,+ margin: 0,+});++type ListProps<Item> = {+ containerProps: ComponentProps<typeof Listbox>;+ items: Array<Item>;+ getItemProps: (+ options: UseComboboxGetItemPropsOptions<Item>+ ) => ComponentProps<typeof ListboxItem>;+ highlightedIndex: number;+ selectedItem: Item | null;+ itemToString: (item: Item | null) => string;+};++const List = <Item extends BaseItem>({+ containerProps,+ items,+ getItemProps,+ highlightedIndex,+ selectedItem,+ itemToString,+}: ListProps<Item>) => {+ return (+ <Listbox {...containerProps}>+ {items.map((item, index) => {+ const itemProps: Record<string, unknown> = getItemProps({+ item,+ index,+ key: index,+ ...(typeof item === "object" && item.disabled+ ? { "data-disabled": true, disabled: true }+ : {}),+ ...(highlightedIndex === index ? { "data-found": true } : {}),+ });++ return (+ // eslint-disable-next-line react/jsx-key+ <ListboxItem {...itemProps}>+ <Grid align="center" css={{ gridTemplateColumns: "$4 1fr" }}>+ {selectedItem === item && <CheckIcon />}+ <Box css={{ gridColumn: 2 }}>{itemToString(item)}</Box>+ </Grid>+ </ListboxItem>+ );+ })}+ </Listbox>+ );+};+type ComboboxProps<Item> = {name: string;items: Array<Item>;@@ -72,7 +119,10 @@ type ComboboxProps<Item> = {onItemSelect?: (value: Item) => void;onItemHighlight?: (value?: Item) => void;itemToString?: (item: Item | null) => string;- disclosure?: (props: ComponentProps<typeof ComboboxTextField>) => JSX.Element;+ renderTextField?: (+ props: ComponentProps<typeof ComboboxTextField>+ ) => JSX.Element;+ renderList?: (props: ListProps<Item>) => JSX.Element;// @todo should we spread those props flat?contentProps?: ComponentProps<typeof PopperContent>;};@@ -86,7 +136,8 @@ export const Combobox = <Item extends BaseItem>({item !== null && "label" in item ? item.label : item ?? "",onItemSelect,onItemHighlight,- disclosure = (props) => <ComboboxTextField {...props} />,+ renderTextField = (props) => <ComboboxTextField {...props} />,+ renderList = (props) => <List {...props} />,}: ComboboxProps<Item>) => {const [foundItems, setFoundItems] = useState(items);const {@@ -141,36 +192,17 @@ export const Combobox = <Item extends BaseItem>({<Popper><Box {...comboboxProps}><PopperAnchor asChild>- {disclosure({ inputProps, toggleProps, highlightedItem })}+ {renderTextField({ inputProps, toggleProps, highlightedItem })}</PopperAnchor><PopperContent {...contentProps} style={{ zIndex: 1 }}>- <Listbox {...menuProps}>- {isOpen &&- foundItems.map((item, index) => {- const itemProps: Record<string, unknown> = getItemProps({- item,- index,- key: index,- ...(typeof item === "object" && item.disabled- ? { "data-disabled": true, disabled: true }- : {}),- ...(highlightedIndex === index ? { "data-found": true } : {}),- });-- return (- // eslint-disable-next-line react/jsx-key- <ListboxItem {...itemProps}>- <Grid- align="center"- css={{ gridTemplateColumns: "20px 1fr" }}- >- {selectedItem === item && <CheckIcon />}- <Box css={{ gridColumn: 2 }}>{itemToString(item)}</Box>- </Grid>- </ListboxItem>- );- })}- </Listbox>+ {renderList({+ containerProps: menuProps,+ items: isOpen ? foundItems : [],+ getItemProps,+ highlightedIndex,+ selectedItem,+ itemToString,+ })}</PopperContent></Box></Popper>