88 type StyleValue ,
99 type TupleValue ,
1010 type UnitValue ,
11+ type VarValue ,
1112} from "@webstudio-is/css-engine" ;
1213import {
1314 extractShadowProperties ,
@@ -20,8 +21,6 @@ import {
2021 Label ,
2122 Separator ,
2223 Text ,
23- TextArea ,
24- textVariants ,
2524 theme ,
2625 ToggleGroup ,
2726 ToggleGroupButton ,
@@ -36,7 +35,7 @@ import type { IntermediateStyleValue } from "../shared/css-value-input";
3635import { CssValueInputContainer } from "../shared/css-value-input" ;
3736import { toPascalCase } from "../shared/keyword-utils" ;
3837import type { StyleUpdateOptions } from "../shared/use-style-data" ;
39- import { parseCssFragment } from "./css-fragment" ;
38+ import { CssFragmentEditor , parseCssFragment } from "./css-fragment" ;
4039import { PropertyInlineLabel } from "../property-label" ;
4140import { styleConfigByName } from "./configs" ;
4241import { ColorPicker } from "./color-picker" ;
@@ -69,10 +68,11 @@ type ShadowContentProps = {
6968 index : number ;
7069 property : "boxShadow" | "textShadow" | "dropShadow" ;
7170 layer : StyleValue ;
71+ computedLayer ?: StyleValue ;
7272 propertyValue : string ;
7373 onEditLayer : (
7474 index : number ,
75- layers : LayersValue ,
75+ layers : LayersValue | VarValue ,
7676 options : StyleUpdateOptions
7777 ) => void ;
7878 hideCodeEditor ?: boolean ;
@@ -120,6 +120,7 @@ const shadowPropertySyntaxes = {
120120
121121export const ShadowContent = ( {
122122 layer,
123+ computedLayer,
123124 index,
124125 property,
125126 propertyValue,
@@ -133,10 +134,15 @@ export const ShadowContent = ({
133134 setIntermediateValue ( { type : "intermediate" , value : propertyValue } ) ;
134135 } , [ propertyValue ] ) ;
135136 const layerValues = useMemo < ExtractedShadowProperties > ( ( ) => {
136- return extractShadowProperties (
137- layer . type === "tuple" ? layer : { type : "tuple" , value : [ ] }
138- ) ;
139- } , [ layer ] ) ;
137+ let value : TupleValue = { type : "tuple" , value : [ ] } ;
138+ if ( layer . type === "tuple" ) {
139+ value = layer ;
140+ }
141+ if ( layer . type === "var" && computedLayer ?. type === "tuple" ) {
142+ value = computedLayer ;
143+ }
144+ return extractShadowProperties ( value ) ;
145+ } , [ layer , computedLayer ] ) ;
140146
141147 const { offsetX, offsetY, blur, spread, color, inset } = layerValues ;
142148 const colorControlProp = color ?? {
@@ -169,7 +175,7 @@ export const ShadowContent = ({
169175 const parsedValue = parsed . get (
170176 property === "dropShadow" ? "textShadow" : property
171177 ) ;
172- if ( parsedValue ?. type === "layers" ) {
178+ if ( parsedValue ?. type === "layers" || parsedValue ?. type === "var" ) {
173179 onEditLayer ( index , parsedValue , { isEphemeral : false } ) ;
174180 return ;
175181 }
@@ -213,6 +219,7 @@ export const ShadowContent = ({
213219 // outline-offset is a fake property for validating box-shadow's offsetX.
214220 property = "outlineOffset"
215221 styleSource = "local"
222+ disabled = { layer . type === "var" }
216223 value = { offsetX ?? { type : "unit" , value : 0 , unit : "px" } }
217224 setValue = { ( value , options ) =>
218225 handlePropertyChange ( { offsetX : value } , options )
@@ -236,6 +243,7 @@ export const ShadowContent = ({
236243 // outline-offset is a fake property for validating box-shadow's offsetY.
237244 property = "outlineOffset"
238245 styleSource = "local"
246+ disabled = { layer . type === "var" }
239247 value = { offsetY ?? { type : "unit" , value : 0 , unit : "px" } }
240248 setValue = { ( value , options ) =>
241249 handlePropertyChange ( { offsetY : value } , options )
@@ -259,6 +267,7 @@ export const ShadowContent = ({
259267 // border-top-width is a fake property for validating box-shadow's blur.
260268 property = "borderTopWidth"
261269 styleSource = "local"
270+ disabled = { layer . type === "var" }
262271 value = { blur ?? { type : "unit" , value : 0 , unit : "px" } }
263272 setValue = { ( value , options ) =>
264273 handlePropertyChange ( { blur : value } , options )
@@ -283,6 +292,7 @@ export const ShadowContent = ({
283292 // outline-offset is a fake property for validating box-shadow's spread.
284293 property = "outlineOffset"
285294 styleSource = "local"
295+ disabled = { layer . type === "var" }
286296 value = { spread ?? { type : "unit" , value : 0 , unit : "px" } }
287297 setValue = { ( value , options ) =>
288298 handlePropertyChange ( { spread : value } , options )
@@ -313,6 +323,7 @@ export const ShadowContent = ({
313323 />
314324 < ColorPicker
315325 property = "color"
326+ disabled = { layer . type === "var" }
316327 value = { colorControlProp }
317328 currentColor = { colorControlProp }
318329 getOptions = { ( ) =>
@@ -339,6 +350,7 @@ export const ShadowContent = ({
339350 />
340351 < ToggleGroup
341352 type = "single"
353+ disabled = { layer . type === "var" }
342354 value = { inset ?. value ?? "normal" }
343355 defaultValue = "inset"
344356 onValueChange = { ( value ) => {
@@ -396,14 +408,10 @@ export const ShadowContent = ({
396408 </ Tooltip >
397409 </ Flex >
398410 </ Label >
399- < TextArea
400- rows = { 3 }
401- name = "description"
411+ < CssFragmentEditor
412+ invalid = { intermediateValue ?. type === "invalid" }
413+ autoFocus = { layer . type === "var" }
402414 value = { intermediateValue ?. value ?? propertyValue ?? "" }
403- css = { { minHeight : theme . spacing [ 14 ] , ...textVariants . mono } }
404- color = {
405- intermediateValue ?. type === "invalid" ? "error" : undefined
406- }
407415 onChange = { handleChange }
408416 onBlur = { handleComplete }
409417 onKeyDown = { ( event ) => {
0 commit comments