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
refactor, text control, search, etc
Sultan68b7b421714b
diff --git a/apps/designer/app/designer/features/inspector/inspector.tsx b/apps/designer/app/designer/features/inspector/inspector.tsxindex 0a0ad39e39..0412fa834f 100644--- a/apps/designer/app/designer/features/inspector/inspector.tsx+++ b/apps/designer/app/designer/features/inspector/inspector.tsx@@ -21,7 +21,7 @@ const contentStyle = {display: "flex",flexDirection: "column",overflow: "auto",- boxShadow: "0 -1px 0 $colors$panelOutline",+ // boxShadow: "0 -1px 0 $colors$panelOutline",};export const Inspector = ({ publish }: InspectorProps) => {diff --git a/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx b/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsxindex a3d6eea93c..4b23382581 100644--- a/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx@@ -3,15 +3,16 @@ import { ColorResult, RGBColor, SketchPicker } from "react-color";import {Box,Grid,- Flex,Popover,PopoverTrigger,PopoverContent,TextField,+ Tooltip,} from "@webstudio-is/design-system";-import { PropertyName } from "../../shared/property-name";+// import { PropertyName } from "../../shared/property-name";import { getFinalValue } from "../../shared/get-final-value";import type { ControlProps } from "../../style-sections";+import { StyleConfig } from "../../shared/configs";const stringifyRGBA = (color: RGBColor) => {const { r, g, b, a = 1 } = color;@@ -24,6 +25,7 @@ type ColorPickerProps = {onChangeComplete: (value: string) => void;value: string;id: string;+ styleConfig: StyleConfig;};const ColorPicker = ({@@ -31,6 +33,7 @@ const ColorPicker = ({onChange,onChangeComplete,id,+ styleConfig,}: ColorPickerProps) => {const [displayColorPicker, setDisplayColorPicker] = useState(false);// Color picker will use 0 as alpha value, which will force user to set alpha every time they have to change from transparent@@ -43,22 +46,41 @@ const ColorPicker = ({onOpenChange={setDisplayColorPicker}><PopoverTrigger asChild aria-label="Open color picker">- <Flex>- <Box+ <Grid+ css={{+ gridTemplateColumns: "repeat(4, 1fr)",+ gridTemplateRows: "repeat(1, 1fr)",+ }}+ >+ <Tooltip+ content={styleConfig.label}+ delayDuration={150}+ disableHoverableContent={true}+ >+ <Box+ css={{+ gridArea: "1 / 1 / 2 / 2",+ zIndex: 1,+ width: "calc($sizes$6 - 6px)",+ height: "calc($sizes$6 - 6px)",+ margin: 3,+ borderRadius: 2,+ background: value,+ }}+ />+ </Tooltip>+ <TextFieldcss={{- width: "$5",- height: "$5",- background: value,+ height: "$6",+ gridArea: "1 / 1 / -1 / -1",+ paddingLeft: "calc($sizes$6 + 6px)",}}- />- <TextFieldonChange={(e) => onChange(e.target.value)}onClick={() => setDisplayColorPicker((shown) => !shown)}- variant="ghost"value={value}id={id}/>- </Flex>+ </Grid></PopoverTrigger><PopoverContent>@@ -98,18 +120,19 @@ export const ColorControl = ({const setValue = setProperty(styleConfig.property);return (- <Grid columns={2} align="center" gapX="1">- <PropertyName property={styleConfig.property} label={styleConfig.label} />- <Flex align="center" css={{ gridColumn: "2/4" }} gap="1">- <ColorPicker- id={styleConfig.property}- value={String(value.value)}- onChange={(value) => {- setValue(value, { isEphemeral: true });- }}- onChangeComplete={setValue}- />- </Flex>+ <Grid columns={1} align="center" gapX="1">+ {/* <PropertyName property={styleConfig.property} label={styleConfig.label} /> */}+ {/* <Flex align="center" css={{ gridColumn: "4/4" }} gap="1"> */}+ <ColorPicker+ id={styleConfig.property}+ value={String(value.value)}+ styleConfig={styleConfig}+ onChange={(value) => {+ setValue(value, { isEphemeral: true });+ }}+ onChangeComplete={setValue}+ />+ {/* </Flex> */}</Grid>);};diff --git a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsxindex e70b9c71b3..4073e156ed 100644--- a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx@@ -1,8 +1,6 @@import { ChangeEvent } from "react";import {- Flex,Grid,- Combobox,IconButton,TextField,Tooltip,@@ -11,8 +9,7 @@ import { PropertyName } from "../../shared/property-name";import { getFinalValue } from "../../shared/get-final-value";import { useIsFromCurrentBreakpoint } from "../../shared/use-is-from-current-breakpoint";import { ControlProps } from "../../style-sections";-import { RowGapIcon, ColumnGapIcon } from "@webstudio-is/icons";-import { Unit } from "../../shared/unit";+import { iconConfigs } from "../../shared/configs";export const TextControl = ({currentStyle,@@ -33,96 +30,66 @@ export const TextControl = ({const setValue = setProperty(styleConfig.property);- // @todo abstract to a variant of the combobox component- // this whole switch block is a stop-gap measure, because i worked on flex-controls before the combobox update- // the combobox should be updated to supporting this rendered production- switch (styleConfig.property) {- case "rowGap":- case "columnGap": {- if (category == "layout") {- if (String(currentStyle.display?.value).includes("flex") !== true)- break;- const Icon =- styleConfig.property == "rowGap" ? RowGapIcon : ColumnGapIcon;- return (- <Grid- css={{- gridTemplateColumns: "repeat(4, 1fr)",- gridTemplateRows: "repeat(1, 1fr)",- }}- >- <Tooltip- content={styleConfig.label}- delayDuration={700}- disableHoverableContent={true}- >- <IconButton- variant="ghost"- size="1"- css={{- zIndex: 1,- gridArea: "1 / 1 / 2 / 2",- marginLeft: 2,- marginTop: 2,- borderRadius: 1,- height: "calc($sizes$5 - 4px)",- width: "calc($sizes$5 - 4px)",- "&:focus": {- boxShadow: "none",- },- ...(isCurrentBreakpoint && {- bc: "$colors$blue4",- "& svg *": {- fill: "$colors$blue11",- },- }),- }}- >- <Icon />- </IconButton>- </Tooltip>- <TextField- type="number"- value={value.value}- onChange={(event: ChangeEvent<HTMLInputElement>) =>- setValue(event.target.value + "px")- }- css={{- fontWeight: "500",- paddingLeft: "calc($5 + 6px)",- gridArea: "1 / 1 / -1 / -1",- cursor: "default",- }}- />- </Grid>- );+ const props = isNaN(parseFloat(String(value.value)))+ ? {+ type: "text",+ onChange: (event: ChangeEvent<HTMLInputElement>) => {},}- }- }-+ : {+ type: "number",+ onChange: (event: ChangeEvent<HTMLInputElement>) => {+ setValue(event.target.value + "px");+ },+ };+ console.log(value, styleConfig);+ const Icon = iconConfigs[styleConfig.property]?.normal || "noscript";return (- <Grid columns={2} align="center" gapX="1">- {/* @todo needs icon variant */}- <PropertyName property={styleConfig.property} label={styleConfig.label} />- <Flex align="center" css={{ gridColumn: "2/4" }} gap="1">- <Combobox- name={styleConfig.property}- label={styleConfig.property}- items={styleConfig.items}- value={{ label: String(value.value), name: value.type }}- // @todo new combobox doesn't include any of these event handlers- // state={value.type === "invalid" ? "invalid" : undefined}- // onValueSelect={setValue}- // onValueEnter={setValue}- // onItemEnter={(value: unknown) => {- // setValue(value as string, { isEphemeral: true });- // }}- // onItemLeave={() => {- // setValue(String(value.value), { isEphemeral: true });- // }}- />- <Unit value={value} />- </Flex>+ <Grid+ css={{+ gridTemplateColumns: "repeat(4, 1fr)",+ gridTemplateRows: "repeat(1, 1fr)",+ }}+ >+ <Tooltip+ content={styleConfig.label}+ delayDuration={700 / 4}+ disableHoverableContent={true}+ >+ <IconButton+ variant="ghost"+ size="1"+ css={{+ zIndex: 1,+ gridArea: "1 / 1 / 2 / 2",+ margin: 3,+ borderRadius: 2,+ height: "calc($sizes$6 - 6px)",+ width: "calc($sizes$6 - 6px)",+ "&:focus": {+ boxShadow: "none",+ },+ ...(isCurrentBreakpoint && {+ bc: "$colors$blue4",+ "& svg *": {+ fill: "$colors$blue11",+ },+ }),+ }}+ >+ <Icon />+ </IconButton>+ </Tooltip>+ <TextField+ {...props}+ value={value.value}+ css={{+ height: "$6",+ fontWeight: "500",+ paddingLeft: "calc($sizes$6 + 6px)",+ gridArea: "1 / 1 / -1 / -1",+ cursor: "default",+ }}+ /></Grid>);};diff --git a/apps/designer/app/designer/features/style-panel/search.tsx b/apps/designer/app/designer/features/style-panel/search.tsxindex a8fd31d040..abbc09782d 100644--- a/apps/designer/app/designer/features/style-panel/search.tsx+++ b/apps/designer/app/designer/features/style-panel/search.tsx@@ -1,16 +1,13 @@import { useState } from "react";import { css, IconButton, TextField } from "@webstudio-is/design-system";-import { Cross1Icon } from "@webstudio-is/icons";+import { Cross2Icon, MagnifyingGlassIcon } from "@webstudio-is/icons";+import { components } from "@webstudio-is/react-sdk";+import type { SelectedInstanceData } from "~/shared/canvas-components";const formStyle = css({position: "relative",});-const resetStyle = css({- position: "absolute",- right: 0,-});-type OnSearch = (search: string) => void;const useSearch = (onSearch: OnSearch): [string, OnSearch] => {@@ -26,9 +23,10 @@ const useSearch = (onSearch: OnSearch): [string, OnSearch] => {type SearchProps = {onSearch: OnSearch;+ selectedInstanceData: SelectedInstanceData;};-export const Search = ({ onSearch }: SearchProps) => {+export const Search = ({ onSearch, selectedInstanceData }: SearchProps) => {const [search, setSearch] = useSearch(onSearch);return (<form@@ -45,32 +43,38 @@ export const Search = ({ onSearch }: SearchProps) => {<TextFieldvalue={search}css={{- padding: "$2",- boxShadow: "0 0 0 1px $colors$slate7",+ fontSize: "$2",+ height: "$sizes$6",+ padding: "$3 calc($2 + $1)",+ border: "2px solid $colors$slate7",bc: "$colors$slate3",+ borderRadius: "$2",+ boxShadow: "none","&:focus": {bc: "$colors$slate1",- boxShadow: "0 0 0 2px $colors$blue10",+ borderWidth: 2,+ borderColor: "$colors$blue10",+ boxShadow: "none",},}}- placeholder="Search property or value"+ placeholder={components[selectedInstanceData.component].label}onChange={(event) => {const { value } = event.target;setSearch(value.toLowerCase());}}/><IconButton- disabled={search.length === 0}type="reset"aria-label="Reset search"- className={resetStyle()}css={{- // @todo: feels wrong to use transform for this, would setting width/height on the icon directly be a better approach?- transform: "scale(.75)",- "&:disabled path": { fill: "none" },+ color: "$slate9",+ position: "absolute",+ top: "50%",+ right: 0,+ transform: "translate(-25%,-50%)",}}>- <Cross1Icon />+ {search.length === 0 ? <MagnifyingGlassIcon /> : <Cross2Icon />}</IconButton></form>);diff --git a/apps/designer/app/designer/features/style-panel/shared/configs.ts b/apps/designer/app/designer/features/style-panel/shared/configs.tsindex 034d92abb7..9a3fd20971 100644--- a/apps/designer/app/designer/features/style-panel/shared/configs.ts+++ b/apps/designer/app/designer/features/style-panel/shared/configs.ts@@ -8,6 +8,7 @@ import {} from "@webstudio-is/react-sdk";import { humanizeString } from "~/shared/string-utils";import {+ IconRecords,AlignContentStartIcon,AlignContentEndIcon,AlignContentCenterIcon,@@ -34,7 +35,8 @@ import {JustifyItemsStartIcon,JustifyItemsEndIcon,JustifyItemsCenterIcon,- IconRecords,+ RowGapIcon,+ ColumnGapIcon,} from "@webstudio-is/icons";type BaseStyleConfig = {@@ -125,6 +127,7 @@ const createStyleConfigs = () => {export const styleConfigs: Array<StyleConfig> = createStyleConfigs();export const iconConfigs: IconRecords = {+ // layoutalignContent: {normal: AlignContentStartIcon,start: AlignContentStartIcon,@@ -169,4 +172,123 @@ export const iconConfigs: IconRecords = {end: JustifyItemsEndIcon,center: JustifyItemsCenterIcon,},+ rowGap: {+ normal: RowGapIcon,+ },+ columnGap: {+ normal: ColumnGapIcon,+ },+ // flex child+ flexShrink: {+ normal: ColumnGapIcon,+ },+ flexGrow: {+ normal: ColumnGapIcon,+ },+ flexBasis: {+ normal: ColumnGapIcon,+ },+ // grid child+ alignSelf: {+ normal: ColumnGapIcon,+ },+ order: {+ normal: ColumnGapIcon,+ },+ justifySelf: {+ normal: ColumnGapIcon,+ },+ // size+ width: {+ normal: ColumnGapIcon,+ },+ height: {+ normal: ColumnGapIcon,+ },+ minWidth: {+ normal: ColumnGapIcon,+ },+ minHeight: {+ normal: ColumnGapIcon,+ },+ maxWidth: {+ normal: ColumnGapIcon,+ },+ maxHeight: {+ normal: ColumnGapIcon,+ },+ overflow: {+ normal: ColumnGapIcon,+ },+ objectFit: {+ normal: ColumnGapIcon,+ },+ // position+ position: {+ normal: ColumnGapIcon,+ },+ float: {+ normal: ColumnGapIcon,+ },+ // typography+ fontFamily: {+ normal: ColumnGapIcon,+ },+ fontWeight: {+ normal: ColumnGapIcon,+ },+ fontSize: {+ normal: ColumnGapIcon,+ },+ lineHeight: {+ normal: ColumnGapIcon,+ },+ color: {+ normal: ColumnGapIcon,+ },+ textAlign: {+ normal: ColumnGapIcon,+ },+ fontStyle: {+ normal: ColumnGapIcon,+ },+ textDecorationColor: {+ normal: ColumnGapIcon,+ },+ textDecorationLine: {+ normal: ColumnGapIcon,+ },+ textDecorationStyle: {+ normal: ColumnGapIcon,+ },+ textIndent: {+ normal: ColumnGapIcon,+ },+ letterSpacing: {+ normal: ColumnGapIcon,+ },+ columnCount: {+ normal: ColumnGapIcon,+ },+ columnRuleStyle: {+ normal: ColumnGapIcon,+ },+ columnRuleWidth: {+ normal: ColumnGapIcon,+ },+ columnRuleColor: {+ normal: ColumnGapIcon,+ },+ textTransform: {+ normal: ColumnGapIcon,+ },+ direction: {+ normal: ColumnGapIcon,+ },+ whiteSpace: {+ normal: ColumnGapIcon,+ },+ textShadow: {+ normal: ColumnGapIcon,+ },};diff --git a/apps/designer/app/designer/features/style-panel/style-panel.tsx b/apps/designer/app/designer/features/style-panel/style-panel.tsxindex d8a4bfb79c..38cbf8372e 100644--- a/apps/designer/app/designer/features/style-panel/style-panel.tsx+++ b/apps/designer/app/designer/features/style-panel/style-panel.tsx@@ -57,11 +57,11 @@ export const StylePanel = ({return (<><Box css={{ overflow: "auto" }}>- <Box css={{ p: "$3 $3 $1 $3" }}>- <ComponentInfo selectedInstanceData={selectedInstanceData} />- </Box>- <Box css={{ p: "$2 $3 $1 $3" }}>- <Search onSearch={setSearch} />+ <Box css={{ px: "$3", paddingBottom: "$1" }}>+ <Search+ onSearch={setSearch}+ selectedInstanceData={selectedInstanceData}+ /></Box><StyleSettingssearch={search}diff --git a/apps/designer/app/designer/features/style-panel/style-sections.tsx b/apps/designer/app/designer/features/style-panel/style-sections.tsxindex 0ebc04cccb..33ad9805f2 100644--- a/apps/designer/app/designer/features/style-panel/style-sections.tsx+++ b/apps/designer/app/designer/features/style-panel/style-sections.tsx@@ -107,6 +107,20 @@ export const renderCategory = ({);};+export const shouldRenderCategory = ({+ currentStyle,+ category,+}: RenderCategoryProps) => {+ switch (category) {+ case "flexChild":+ return (currentStyle.display?.value as string)?.includes("flex");+ case "gridChild":+ return (currentStyle.display?.value as string)?.includes("grid");+ }++ return true;+};+const sections: {[key: string]: (props: RenderCategoryProps) => JSX.Element | null;} = {diff --git a/apps/designer/app/designer/features/style-panel/style-settings.tsx b/apps/designer/app/designer/features/style-panel/style-settings.tsxindex 5604e04aa2..6b41e1b70b 100644--- a/apps/designer/app/designer/features/style-panel/style-settings.tsx+++ b/apps/designer/app/designer/features/style-panel/style-settings.tsx@@ -8,7 +8,11 @@ import {import { type StyleConfig, styleConfigs } from "./shared/configs";import { CollapsibleSection } from "~/designer/shared/inspector";-import { renderProperty, renderCategory } from "./style-sections";+import {+ renderProperty,+ renderCategory,+ shouldRenderCategory,+} from "./style-sections";import { dependencies } from "./shared/dependencies";import { type InheritedStyle } from "./shared/get-inherited-style";import {@@ -130,25 +134,24 @@ export const StyleSettings = ({}if (styleConfigsByCategory.length === 0) continue;-- all.push(- <CollapsibleSection- isOpen={isSearchMode ? true : undefined}- label={categories[category].label}- key={category}- >- <>- {renderCategory({- setProperty,- createBatchUpdate,- currentStyle,- category,- styleConfigsByCategory,- moreStyleConfigsByCategory,- })}- </>- </CollapsibleSection>- );+ const categoryProps = {+ setProperty,+ createBatchUpdate,+ currentStyle,+ category,+ styleConfigsByCategory,+ moreStyleConfigsByCategory,+ };+ if (shouldRenderCategory(categoryProps))+ all.push(+ <CollapsibleSection+ isOpen={isSearchMode ? true : undefined}+ label={categories[category].label}+ key={category}+ >+ <>{renderCategory(categoryProps)}</>+ </CollapsibleSection>+ );}return <>{all}</>;};diff --git a/apps/designer/app/designer/shared/inspector/collapsible-section.tsx b/apps/designer/app/designer/shared/inspector/collapsible-section.tsxindex c451577704..d42f7164f0 100644--- a/apps/designer/app/designer/shared/inspector/collapsible-section.tsx+++ b/apps/designer/app/designer/shared/inspector/collapsible-section.tsx@@ -51,7 +51,6 @@ export const CollapsibleSection = ({px: "$3",color: "$hiContrast",cursor: "default",- ...(isOpenFinal && { paddingBottom: 0 }),}}><Text size="1" css={{ fontWeight: "500", flexGrow: 1 }}>@@ -73,6 +72,7 @@ export const CollapsibleSection = ({direction="column"css={{p: "$3",+ paddingTop: 0,"&:empty": {display: "none",},