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
add api for prefix icon to text-control
Sultan9d7cd3ef0c42
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 b19305eac4..3adfb8e474 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@@ -3,13 +3,16 @@ import { getFinalValue } from "../../shared/get-final-value";import { ControlProps } from "../../style-sections";import { type StyleValue, toValue } from "@webstudio-is/react-sdk";import { useState } from "react";+import { PropertyIcon } from "../../shared/property-icon";+import { Box, Tooltip } from "@webstudio-is/design-system";export const TextControl = ({currentStyle,inheritedStyle,setProperty,styleConfig,-}: ControlProps) => {+ prefix,+}: ControlProps & { prefix?: JSX.Element }) => {const value = getFinalValue({currentStyle,inheritedStyle,@@ -19,34 +22,51 @@ export const TextControl = ({const setValue = setProperty(styleConfig.property);const [currentValue, setCurrentValue] = useState<StyleValue>();-return (- <CssValueInput- property={styleConfig.property}- value={currentValue ?? value}- keywords={styleConfig.items.map((item) => ({- type: "keyword",- value: item.name,- }))}- onChange={(styleValue) => {- setCurrentValue(styleValue);- setValue(toValue(styleValue), { isEphemeral: true });- }}- onItemHighlight={(styleValue) => {- const nextValue = styleValue ?? currentValue ?? value;- if (nextValue) {- setValue(toValue(nextValue), {- isEphemeral: true,- });- }- }}- onChangeComplete={(styleValue) => {- const prevValue = toValue(value);- const nextValue = toValue(styleValue);- if (prevValue === nextValue) return;- setCurrentValue(undefined);- setValue(toValue(styleValue));- }}- />+ <Tooltip+ content={styleConfig.label}+ delayDuration={600}+ disableHoverableContent={true}+ >+ <Box>+ <CssValueInput+ prefix={+ prefix && (+ <PropertyIcon+ property={styleConfig.property}+ label={styleConfig.label}+ >+ {prefix}+ </PropertyIcon>+ )+ }+ property={styleConfig.property}+ value={currentValue ?? value}+ keywords={styleConfig.items.map((item) => ({+ type: "keyword",+ value: item.name,+ }))}+ onChange={(styleValue) => {+ setCurrentValue(styleValue);+ setValue(toValue(styleValue), { isEphemeral: true });+ }}+ onItemHighlight={(styleValue) => {+ const nextValue = styleValue ?? currentValue ?? value;+ if (nextValue) {+ setValue(toValue(nextValue), {+ isEphemeral: true,+ });+ }+ }}+ onChangeComplete={(styleValue) => {+ const prevValue = toValue(value);+ const nextValue = toValue(styleValue);+ if (prevValue === nextValue) return;+ setCurrentValue(undefined);+ setValue(toValue(styleValue));+ }}+ />+ </Box>+ </Tooltip>);};diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsxindex 7529e48ee3..c777b3dd3a 100644--- a/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx+++ b/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx@@ -6,6 +6,7 @@ import { ShowMore } from "../../shared/show-more";import { renderProperty } from "../../style-sections";import { MenuControl, SelectControl, TextControl } from "../../controls";import { PropertyName } from "../../shared/property-name";+import { ColumnGapIcon, RowGapIcon } from "@webstudio-is/icons";const LayoutSectionFlex = ({currentStyle,@@ -106,7 +107,7 @@ const LayoutSectionFlex = ({>{columnGap?.styleConfig && (<Box css={{ gridArea: "columnGap" }}>- <TextControl {...columnGap} />+ <TextControl prefix={<ColumnGapIcon />} {...columnGap} /></Box>)}{rowGap?.styleConfig && columnGap?.styleConfig && (@@ -120,7 +121,7 @@ const LayoutSectionFlex = ({)}{rowGap?.styleConfig && (<Box css={{ gridArea: "rowGap" }}>- <TextControl {...rowGap} />+ <TextControl prefix={<RowGapIcon />} {...rowGap} /></Box>)}</Grid>diff --git a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsxindex 3f57594587..87cd1d6aaa 100644--- a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx+++ b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx@@ -84,7 +84,12 @@ const useScrub = ({value: StyleValue;onChange: (value: StyleValue) => void;onChangeComplete: (value: StyleValue) => void;-}): [React.MutableRefObject<HTMLInputElement | null>, boolean] => {+}): [+ React.MutableRefObject<HTMLInputElement | null>,+ React.MutableRefObject<HTMLInputElement | null>,+ boolean+] => {+ const scrubRef = useRef<HTMLElement | null>(null);const inputRef = useRef<HTMLInputElement | null>(null);const [isInputActive, setIsInputActive] = useState(false);const onChangeRef = useRef(onChange);@@ -101,10 +106,15 @@ const useScrub = ({// Since scrub is going to call onChange and onChangeComplete callbacks, it will result in a new value and potentially new callback refs.// We need this effect to ONLY run when type or unit changes, but not when callbacks or value.value changes.useEffect(() => {- if (type !== "unit" || unit === undefined || inputRef.current === null) {+ if (+ type !== "unit" ||+ unit === undefined ||+ inputRef.current === null ||+ scrubRef.current === null+ ) {return;}- const scrub = numericScrubControl(inputRef.current, {+ const scrub = numericScrubControl(scrubRef.current, {initialValue: valueRef.current.value,onValueInput(event) {onChangeRef.current({@@ -130,7 +140,7 @@ const useScrub = ({return scrub.disconnectedCallback;}, [type, unit]);- return [inputRef, isInputActive];+ return [scrubRef, inputRef, isInputActive];};const useHandleKeyDown =@@ -166,6 +176,7 @@ const useHandleKeyDown =};type CssValueInputProps = {+ prefix?: JSX.Element;property: StyleProperty;value?: StyleValue;keywords?: Array<KeywordValue>;@@ -207,6 +218,7 @@ type CssValueInputProps = {*/export const CssValueInput = ({+ prefix,property,value = unsetValue,keywords = [],@@ -249,7 +261,7 @@ export const CssValueInput = ({},});- const [inputRef, isInputActive] = useScrub({+ const [scrubRef, inputRef, isInputActive] = useScrub({value,onChange,onChangeComplete,@@ -295,6 +307,7 @@ export const CssValueInput = ({onBlur={handleOnBlur}onKeyDown={handleKeyDown}inputRef={inputRef}+ scrubRef={scrubRef}name={property}state={value.type === "invalid"@@ -303,6 +316,7 @@ export const CssValueInput = ({? "active": undefined}+ prefix={prefix}suffix={suffix}css={{ cursor: "default" }}/>diff --git a/apps/designer/app/designer/features/style-panel/shared/property-icon.tsx b/apps/designer/app/designer/features/style-panel/shared/property-icon.tsxnew file mode 100644index 0000000000..bf47a69cf0--- /dev/null+++ b/apps/designer/app/designer/features/style-panel/shared/property-icon.tsx@@ -0,0 +1,17 @@+import { TextFieldIconButton } from "@webstudio-is/design-system";+import { useIsFromCurrentBreakpoint } from "./use-is-from-current-breakpoint";+import type { PropertyProps } from "../style-sections";+import { forwardRef } from "react";++export const PropertyIcon = forwardRef<+ HTMLButtonElement,+ PropertyProps & { children: JSX.Element }+>(({ property, children }, forwardRef) => {+ const isCurrentBreakpoint = useIsFromCurrentBreakpoint(property);+ return (+ <TextFieldIconButton state={isCurrentBreakpoint ? "breakpoint" : undefined}>+ {children}+ </TextFieldIconButton>+ );+});+PropertyIcon.displayName = "PropertyIcon";diff --git a/apps/designer/app/designer/features/style-panel/shared/property-name.tsx b/apps/designer/app/designer/features/style-panel/shared/property-name.tsxindex ded7249bc1..f85eb51296 100644--- a/apps/designer/app/designer/features/style-panel/shared/property-name.tsx+++ b/apps/designer/app/designer/features/style-panel/shared/property-name.tsx@@ -1,13 +1,10 @@-import { Flex, Label, Tooltip, IconButton } from "@webstudio-is/design-system";+import { Flex, Label, Tooltip } from "@webstudio-is/design-system";import { useIsFromCurrentBreakpoint } from "./use-is-from-current-breakpoint";import { propertyNameColorForSelectedBreakpoint } from "./constants";import type { PropertyProps } from "../style-sections";-import { iconConfigs } from "./configs";-import { forwardRef, PointerEventHandler } from "react";export const PropertyName = ({ property, label, css }: PropertyProps) => {const isCurrentBreakpoint = useIsFromCurrentBreakpoint(property);-return (<Tooltip content={label} delayDuration={600} disableHoverableContent={true}><Flex@@ -42,37 +39,3 @@ export const PropertyName = ({ property, label, css }: PropertyProps) => {);};PropertyName.displayName = "PropertyName";--export const PropertyIcon = forwardRef<- HTMLButtonElement,- PropertyProps & { [key: `on${string}`]: PointerEventHandler }->(({ property, label, ...props }, forwardRef) => {- const isCurrentBreakpoint = useIsFromCurrentBreakpoint(property);- const IconType = iconConfigs[property]?.normal;- if (!IconType) return null;-- return (- <Tooltip content={label} delayDuration={600} disableHoverableContent={true}>- <IconButton- {...props}- ref={forwardRef}- size="1"- css={{- borderRadius: "$1",- border: "2px solid $colors$loContrast",- ...(isCurrentBreakpoint && {- bc: "$colors$blue4",- color: "$colors$blue11",- "&:hover,&:active,&:focus": {- bc: "$colors$blue4",- color: "$colors$blue11",- },- }),- }}- >- <IconType />- </IconButton>- </Tooltip>- );-});-PropertyIcon.displayName = "PropertyIcon";diff --git a/packages/design-system/src/components/text-field.tsx b/packages/design-system/src/components/text-field.tsxindex 6f6574903c..4107b62ffd 100644--- a/packages/design-system/src/components/text-field.tsx+++ b/packages/design-system/src/components/text-field.tsx@@ -55,6 +55,14 @@ export const TextFieldIconButton = styled(color: "white",},},+ breakpoint: {+ backgroundColor: "$blue4",+ color: "$blue11",+ "&:hover": {+ backgroundColor: "$blue4",+ color: "$blue11",+ },+ },},},},@@ -242,6 +250,7 @@ export type TextFieldProps = Pick<"variant" | "state" | "css"> &Omit<React.ComponentProps<"input">, "prefix" | "children"> & {+ scrubRef?: React.Ref<HTMLDivElement>;inputRef?: React.Ref<HTMLInputElement>;prefix?: React.ReactNode;suffix?: React.ReactNode;@@ -253,6 +262,7 @@ export const TextField = React.forwardRef<HTMLDivElement, TextFieldProps>(prefix,css,disabled,+ scrubRef,inputRef,state,variant: variantProp,@@ -297,7 +307,7 @@ export const TextField = React.forwardRef<HTMLDivElement, TextFieldProps>(<TextFieldBase{...focusWithinProps}aria-disabled={disabled}- ref={forwardedRef}+ ref={mergeRefs(forwardedRef, scrubRef ?? null)}state={state}variant={variant}css={css}