From 459ecd4e8a0c0024a2776012129b4746b50722c3 Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Thu, 21 Jul 2022 01:41:58 +0200 Subject: [PATCH] popper and styling --- .../features/props-panel/props-panel.tsx | 14 +- .../features/style-panel/render-property.tsx | 7 +- .../components/combobox.stories.tsx | 64 +++---- .../design-system/components/combobox.tsx | 159 ++++++++++-------- apps/designer/package.json | 1 + yarn.lock | 109 ++++++++++++ 6 files changed, 240 insertions(+), 114 deletions(-) diff --git a/apps/designer/app/designer/features/props-panel/props-panel.tsx b/apps/designer/app/designer/features/props-panel/props-panel.tsx index 69c73c6e09..e472984038 100644 --- a/apps/designer/app/designer/features/props-panel/props-panel.tsx +++ b/apps/designer/app/designer/features/props-panel/props-panel.tsx @@ -54,23 +54,29 @@ const Property = ({ { + onItemSelect={({ value }) => { console.log(value); onChange(id, "prop", value); }} - disclosure={(props) => ( + disclosure={({ inputProps }) => ( )} + popperProps={{ + align: "start", + sideOffset: 5, + }} + // @todo should we use the side panel (width - x) or something? + listCss={{ width: 230 }} /> {isInvalidProp ? ( diff --git a/apps/designer/app/designer/features/style-panel/render-property.tsx b/apps/designer/app/designer/features/style-panel/render-property.tsx index 8688b15bee..ccbbf589aa 100644 --- a/apps/designer/app/designer/features/style-panel/render-property.tsx +++ b/apps/designer/app/designer/features/style-panel/render-property.tsx @@ -180,12 +180,7 @@ const ComboboxControl = ({ id={styleConfig.property} items={styleConfig.items} variant="ghost" - css={{ - // @todo drag&drop cursor to adjust numeric value - // const cursorUrl = data:image/svg+xml;base64,${btoa(svgCursor)} - //cursor: `url(${cursorUrl}), text`, - textAlign: "right", - }} + popperProps={{ align: "right", sideOffset: 5 }} state={value.type === "invalid" ? "invalid" : undefined} value={String(value.value)} onValueSelect={setValue} diff --git a/apps/designer/app/shared/design-system/components/combobox.stories.tsx b/apps/designer/app/shared/design-system/components/combobox.stories.tsx index b6ed6d5f02..8f3f1a5647 100644 --- a/apps/designer/app/shared/design-system/components/combobox.stories.tsx +++ b/apps/designer/app/shared/design-system/components/combobox.stories.tsx @@ -2,61 +2,65 @@ import { ComponentStory } from "@storybook/react"; import React from "react"; import { Combobox } from "~/shared/design-system"; import { TextField } from "./text-field"; +import { Flex } from "./flex"; +import { ChevronDownIcon } from "~/shared/icons"; +import { IconButton } from "./icon-button"; export default { component: Combobox, }; export const Simple: ComponentStory = () => { - const options = [ - { label: "Apple" }, - { label: "Banana" }, - { label: "Orange" }, - ]; - const [value, setValue] = React.useState(options[0]); + const items = [{ label: "Apple" }, { label: "Banana" }, { label: "Orange" }]; + const [value, setValue] = React.useState(items[0]); return ( ); }; export const CustomInput: ComponentStory = () => { - const options = [ + const items = [ { label: "Apple", value: "apple", disabled: true }, { label: "Banana", value: "banana" }, { label: "Orange", value: "orange" }, ]; - const [value, setValue] = React.useState(options[0]); + const [value, setValue] = React.useState(items[0]); return ( { - console.log(option); + onItemSelect={setValue} + onItemHighlight={(item) => { + console.log(item); }} - disclosure={(props) => ( - { - props.onKeyDown(event); - switch (event.key) { - case "Enter": { - console.log(props.value); - break; + disclosure={({ inputProps, toggleProps }) => ( + + { + inputProps?.onKeyDown(event); + switch (event.key) { + case "Enter": { + console.log(inputProps.value); + break; + } } - } - }} - onBlur={(event) => { - props.onBlur(event); - console.log(props.value); - }} - /> + }} + onBlur={(event) => { + inputProps?.onBlur(event); + console.log(inputProps.value); + }} + /> + + + + )} /> ); diff --git a/apps/designer/app/shared/design-system/components/combobox.tsx b/apps/designer/app/shared/design-system/components/combobox.tsx index aa243a1039..2603cdc004 100644 --- a/apps/designer/app/shared/design-system/components/combobox.tsx +++ b/apps/designer/app/shared/design-system/components/combobox.tsx @@ -1,52 +1,59 @@ +import { type ComponentProps, useState } from "react"; import { CheckIcon } from "@radix-ui/react-icons"; +import { Popper, PopperContent, PopperAnchor } from "@radix-ui/react-popper"; import { useCombobox } from "downshift"; import { matchSorter } from "match-sorter"; -import { type ComponentProps, useState } from "react"; -import { - Box, - Popover, - PopoverContent, - PopoverTrigger, - styled, -} from "~/shared/design-system"; -import { itemCss } from "~/shared/design-system/components/menu"; -import { panelStyles } from "~/shared/design-system/components/panel"; -import { ChevronDownIcon } from "~/shared/icons"; +import { styled, type CSS } from "../stitches.config"; +import { itemCss } from "./menu"; +import { panelStyles } from "./panel"; import { IconButton } from "./icon-button"; import { TextField } from "./text-field"; +import { Box } from "./box"; -type BaseOption = { label: string }; +type BaseItem = { label: string; disabled?: boolean }; -const getTextValue =