diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx index 0d41127d9c..c12bba814a 100644 --- a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx +++ b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx @@ -1,3 +1,4 @@ +import { colord } from "colord"; import { useEffect, useMemo, useRef, useState, type ReactNode } from "react"; import { computed } from "nanostores"; import { matchSorter } from "match-sorter"; @@ -22,6 +23,7 @@ import { import { useStore } from "@nanostores/react"; import { hyphenateProperty, + toValue, type StyleProperty, } from "@webstudio-is/css-engine"; import { @@ -39,6 +41,7 @@ import { import { getDots } from "../../shared/style-section"; import { PropertyInfo } from "../../property-label"; import { sections } from "../sections"; +import { ColorPopover } from "../../shared/color-picker"; // Only here to keep the same section module interface export const properties = []; @@ -229,6 +232,7 @@ const AdvancedPropertyValue = ({ inputRef.current?.focus(); } }, [autoFocus]); + const isColor = colord(toValue(styleDecl.usedValue)).isValid(); return ( { + const options = { isEphemeral: true, listed: true }; + if (styleValue) { + setProperty(property)(styleValue, options); + } else { + deleteProperty(property, options); + } + }} + onChangeComplete={(styleValue) => { + setProperty(property)(styleValue); + }} + /> + ) + } property={property} styleSource={styleDecl.source.name} keywords={[ diff --git a/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx b/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx index b5ce3a7ab0..dd1bfa3ae8 100644 --- a/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx +++ b/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx @@ -176,25 +176,21 @@ type ColorPickerProps = { disabled?: boolean; }; -export const ColorPicker = ({ +export const ColorPopover = ({ + size, value, - currentColor, - keywords, - property, - disabled, onChange, onChangeComplete, - onAbort, -}: ColorPickerProps) => { +}: { + size?: 1 | 2; + value: StyleValue; + onChange: (value: undefined | StyleValue) => void; + onChangeComplete: (value: StyleValue) => void; +}) => { const [displayColorPicker, setDisplayColorPicker] = useState(false); const { enableCanvasPointerEvents, disableCanvasPointerEvents } = useDisableCanvasPointerEvents(); - const [intermediateValue, setIntermediateValue] = useState< - StyleValue | IntermediateStyleValue - >(); - const currentValue = intermediateValue ?? value; - const handleOpenChange = (open: boolean) => { setDisplayColorPicker(open); if (open) { @@ -209,7 +205,7 @@ export const ColorPicker = ({ enableCanvasPointerEvents(); }; - const prefix = ( + return ( setDisplayColorPicker((shown) => !shown)} > @@ -230,7 +227,36 @@ export const ColorPicker = ({ }} > + + + ); +}; + +export const ColorPicker = ({ + value, + currentColor, + keywords, + property, + disabled, + onChange, + onChangeComplete, + onAbort, +}: ColorPickerProps) => { + const [intermediateValue, setIntermediateValue] = useState< + StyleValue | IntermediateStyleValue + >(); + + return ( + { setIntermediateValue(styleValue); if (styleValue) { @@ -244,15 +270,7 @@ export const ColorPicker = ({ onChangeComplete(value); }} /> - - - ); - - return ( - { }; }; +const colorThumbSize = "--color-thumb-size"; + const thumbStyle = css({ display: "block", - width: theme.spacing[10], - height: theme.spacing[10], + width: `var(${colorThumbSize}, 20px)`, + height: `var(${colorThumbSize}, 20px)`, backgroundBlendMode: "difference", borderRadius: theme.borderRadius[2], borderWidth: 0, borderStyle: "solid", }); -export const ColorThumb = forwardRef< - ElementRef<"button">, - Omit, "color"> & { color?: RgbaColor; css?: CSS } ->(({ color = transparentColor, css, ...rest }, ref) => { - const background = - color === undefined || color.a < 1 - ? // Chessboard pattern 5x5 - `repeating-conic-gradient(rgba(0,0,0,0.22) 0% 25%, transparent 0% 50%) 0% 33.33% / 40% 40%, ${colord(color).toRgbString()}` - : colord(color).toRgbString(); - const borderColor = calcBorderColor(color); +type Props = Omit, "color"> & { + color?: RgbaColor; + css?: CSS; + size?: 1 | 2; +}; - return ( -