Skip to content

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.

better state logic

Oleg Isonen92bc014cf651
diff --git a/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx b/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx
index 8f8f8f030c..1d86ba75d1 100644
--- a/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx
+++ b/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx
@@ -17,7 +17,7 @@ import {
import { AssetUpload, PreviewAsset, useAssets } from "~/designer/shared/assets";
import { SYSTEM_FONTS } from "@webstudio-is/fonts";
import { DotsHorizontalIcon, MagnifyingGlassIcon } from "@webstudio-is/icons";
-import { useMemo } from "react";
+import { ComponentProps, forwardRef, Fragment, useMemo } from "react";
import { cssVars } from "@webstudio-is/css-vars";
const getItems = (
@@ -87,9 +87,16 @@ const Listbox = styled("ul", {
flexDirection: "column",
margin: 0,
padding: 0,
+ variants: {
+ isEmpty: {
+ true: {
+ display: "none",
+ },
+ },
+ },
});
-const ListboxItem = styled("li", {
+const ListboxItemBase = styled("li", {
display: "flex",
alignItems: "center",
justifyContent: "space-between",
@@ -97,7 +104,7 @@ const ListboxItem = styled("li", {
paddingLeft: "$4",
listStyle: "none",
borderRadius: "$1",
- "&:hover, &[aria-selected=true]": {
+ "&[data-highlighted], &[aria-selected=true]": {
boxShadow:
"inset 0px 0px 0px 1px $colors$blue10, 0px 0px 0px 1px $colors$blue10",
[vars.menuButtonVisibility]: "visible",
@@ -108,6 +115,24 @@ const ListboxItem = styled("li", {
},
});
+const ListboxItem = forwardRef<
+ HTMLLIElement,
+ ComponentProps<typeof ListboxItemBase> & {
+ highlighted: boolean;
+ disabled?: boolean;
+ }
+>(({ highlighted, disabled, ...props }, ref) => {
+ return (
+ <ListboxItemBase
+ {...props}
+ ref={ref}
+ {...(highlighted ? { ["data-highlighted"]: true } : {})}
+ {...(disabled ? { ["aria-disabled"]: true, disabled: true } : {})}
+ />
+ );
+});
+ListboxItem.displayName = "ListboxItem";
+
type FontsManagerProps = {
value: string;
onChange: (value: string) => void;
@@ -177,19 +202,14 @@ export const FontsManager = ({ value, onChange }: FontsManagerProps) => {
{items.map((item, index) => {
if (item.type === "separator") {
return (
- <>
+ <Fragment key={index}>
{index !== 0 && <Separator css={{ my: "$1" }} />}
- <ListboxItem
- {...getItemProps({ item, index })}
- key={index}
- aria-disabled
- disabled
- >
+ <ListboxItem {...getItemProps({ item, index })} disabled>
<Text variant="label" truncate>
{item.label}
</Text>
</ListboxItem>
- </>
+ </Fragment>
);
}
return (
diff --git a/packages/design-system/src/components/combobox.tsx b/packages/design-system/src/components/combobox.tsx
index 575344aa01..c81ee172c4 100644
--- a/packages/design-system/src/components/combobox.tsx
+++ b/packages/design-system/src/components/combobox.tsx
@@ -56,10 +56,9 @@ export const ListboxItemBase: ForwardRefRenderFunction<
disabled?: boolean;
selected?: boolean;
highlighted?: boolean;
- suffix?: JSX.Element;
}
> = (props, ref) => {
- const { disabled, selected, highlighted, children, suffix, ...rest } = props;
+ const { disabled, selected, highlighted, children, ...rest } = props;
return (
<ListboxItem
ref={ref}
@@ -71,7 +70,6 @@ export const ListboxItemBase: ForwardRefRenderFunction<
{selected && <CheckIcon />}
<Box css={{ gridColumn: 2 }}>{children}</Box>
</Grid>
- {suffix}
</ListboxItem>
);
};