Skip to content

refactor: rename callbacks in css input container #5014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ export const PositionControl = ({
styleSource={styleDecl.source.name}
getOptions={() => keywords}
value={value.value[0]}
setValue={setValueX}
deleteProperty={deleteProperty}
onUpdate={setValueX}
onDelete={(options) => deleteProperty(property, options)}
/>
<PropertyInlineLabel
label="Top"
Expand All @@ -125,8 +125,8 @@ export const PositionControl = ({
styleSource={styleDecl.source.name}
getOptions={() => keywords}
value={value.value[1]}
setValue={setValueY}
deleteProperty={deleteProperty}
onUpdate={setValueY}
onDelete={(options) => deleteProperty(property, options)}
/>
</Grid>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export const BackgroundPosition = ({ index }: { index: number }) => {
{ type: "keyword", value: "right" },
]}
value={xValue}
setValue={(value, options) => {
onUpdate={(value, options) => {
setRepeatedStyleItem(backgroundPositionX, index, value, options);
}}
deleteProperty={() => {
onDelete={() => {
if (xValue) {
setRepeatedStyleItem(backgroundPositionX, index, xValue);
}
Expand All @@ -102,10 +102,10 @@ export const BackgroundPosition = ({ index }: { index: number }) => {
{ type: "keyword", value: "bottom" },
]}
value={yValue}
setValue={(value, options) => {
onUpdate={(value, options) => {
setRepeatedStyleItem(backgroundPositionY, index, value, options);
}}
deleteProperty={() => {
onDelete={() => {
if (yValue) {
setRepeatedStyleItem(backgroundPositionY, index, yValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ export const BackgroundSize = ({ index }: { index: number }) => {
styleSource="default"
getOptions={() => customSizeOptions}
value={customSizeValue.value[0]}
setValue={setValueX}
deleteProperty={() => {}}
onUpdate={setValueX}
onDelete={() => {}}
/>

<CssValueInputContainer
Expand All @@ -152,8 +152,8 @@ export const BackgroundSize = ({ index }: { index: number }) => {
styleSource="default"
getOptions={() => customSizeOptions}
value={customSizeValue.value[1]}
setValue={setValueY}
deleteProperty={() => {}}
onUpdate={setValueY}
onDelete={() => {}}
/>
</Grid>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ export const BorderProperty = ({
...$availableUnitVariables.get(),
]}
value={value}
setValue={(newValue, options) => {
onUpdate={(newValue, options) => {
const batch = createBatchUpdate();
for (const property of borderProperties) {
batch.setProperty(property)(newValue);
}
batch.publish(options);
}}
deleteProperty={(_property, options) => {
onDelete={(options) => {
const batch = createBatchUpdate();
for (const property of borderProperties) {
batch.deleteProperty(property);
Expand Down Expand Up @@ -127,8 +127,10 @@ export const BorderProperty = ({
}))
}
value={styleDecl.cascadedValue}
setValue={setProperty(styleDecl.property)}
deleteProperty={deleteProperty}
onUpdate={setProperty(styleDecl.property)}
onDelete={(options) =>
deleteProperty(styleDecl.property, options)
}
/>
))}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ export const TransformAndPerspectiveOrigin = ({
getOptions={() => xOriginKeywords}
styleSource="local"
property={fakePropertyX}
deleteProperty={() => {}}
setValue={(value, options) =>
onDelete={() => {}}
onUpdate={(value, options) =>
handleValueChange(0, value, options)
}
/>
Expand All @@ -214,8 +214,8 @@ export const TransformAndPerspectiveOrigin = ({
getOptions={() => yOriginKeywords}
styleSource="local"
property={fakePropertyY}
deleteProperty={() => {}}
setValue={(value, options) =>
onDelete={() => {}}
onUpdate={(value, options) =>
handleValueChange(1, value, options)
}
/>
Expand All @@ -235,8 +235,8 @@ export const TransformAndPerspectiveOrigin = ({
value={origin.z}
styleSource="local"
property={fakePropertyZ}
deleteProperty={() => {}}
setValue={(value, options) =>
onDelete={() => {}}
onUpdate={(value, options) =>
handleValueChange(2, value, options)
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ export const RotatePanelContent = () => {
property="rotate"
getOptions={() => $availableUnitVariables.get()}
value={rotateX}
setValue={(value, options) =>
onUpdate={(value, options) =>
updateTransformFunction(styleDecl, "rotateX", value, options)
}
deleteProperty={() => {}}
onDelete={() => {}}
/>
</Grid>
<Grid
Expand All @@ -73,10 +73,10 @@ export const RotatePanelContent = () => {
property="rotate"
getOptions={() => $availableUnitVariables.get()}
value={rotateY}
setValue={(value, options) =>
onUpdate={(value, options) =>
updateTransformFunction(styleDecl, "rotateY", value, options)
}
deleteProperty={() => {}}
onDelete={() => {}}
/>
</Grid>
<Grid
Expand All @@ -93,10 +93,10 @@ export const RotatePanelContent = () => {
property="rotate"
getOptions={() => $availableUnitVariables.get()}
value={rotateZ}
setValue={(value, options) =>
onUpdate={(value, options) =>
updateTransformFunction(styleDecl, "rotateZ", value, options)
}
deleteProperty={() => {}}
onDelete={() => {}}
/>
</Grid>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ export const SkewPanelContent = () => {
styleSource="local"
property={fakeProperty}
value={skewX}
setValue={(value, options) =>
onUpdate={(value, options) =>
updateTransformFunction(styleDecl, "skewX", value, options)
}
deleteProperty={() => {}}
onDelete={() => {}}
/>
</Grid>
<Grid
Expand All @@ -69,10 +69,10 @@ export const SkewPanelContent = () => {
styleSource="local"
property={fakeProperty}
value={skewY}
setValue={(value, options) =>
onUpdate={(value, options) =>
updateTransformFunction(styleDecl, "skewY", value, options)
}
deleteProperty={() => {}}
onDelete={() => {}}
/>
</Grid>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export const TranslatePanelContent = () => {
property={property}
getOptions={() => $availableUnitVariables.get()}
value={translateX}
setValue={(newValue, options) => setAxis(0, newValue, options)}
deleteProperty={(property, options) =>
onUpdate={(newValue, options) => setAxis(0, newValue, options)}
onDelete={(options) =>
setProperty(property)(styleDecl.cascadedValue, options)
}
/>
Expand All @@ -83,8 +83,8 @@ export const TranslatePanelContent = () => {
property={property}
getOptions={() => $availableUnitVariables.get()}
value={translateY}
setValue={(newValue, options) => setAxis(1, newValue, options)}
deleteProperty={(property, options) =>
onUpdate={(newValue, options) => setAxis(1, newValue, options)}
onDelete={(options) =>
setProperty(property)(styleDecl.cascadedValue, options)
}
/>
Expand All @@ -103,8 +103,8 @@ export const TranslatePanelContent = () => {
property={property}
getOptions={() => $availableUnitVariables.get()}
value={translateZ}
setValue={(newValue, options) => setAxis(2, newValue, options)}
deleteProperty={(property, options) =>
onUpdate={(newValue, options) => setAxis(2, newValue, options)}
onDelete={(options) =>
setProperty(property)(styleDecl.cascadedValue, options)
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export const TransitionContent = ({ index }: { index: number }) => {
styleSource="local"
getOptions={() => $availableUnitVariables.get()}
value={duration ?? propertiesData["transition-duration"].initial}
deleteProperty={() => {}}
setValue={(value, options) => {
onDelete={() => {}}
onUpdate={(value, options) => {
if (value === undefined) {
return;
}
Expand All @@ -170,8 +170,8 @@ export const TransitionContent = ({ index }: { index: number }) => {
styleSource="local"
getOptions={() => $availableUnitVariables.get()}
value={delay ?? propertiesData["transition-delay"].initial}
deleteProperty={() => {}}
setValue={(value, options) => {
onDelete={() => {}}
onUpdate={(value, options) => {
if (value === undefined) {
return;
}
Expand Down Expand Up @@ -207,8 +207,8 @@ export const TransitionContent = ({ index }: { index: number }) => {
timingFunction ??
propertiesData["transition-timing-function"].initial
}
deleteProperty={() => {}}
setValue={(value, options) => {
onDelete={() => {}}
onUpdate={(value, options) => {
if (value === undefined) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { type ComponentProps, useState } from "react";
import type { StyleValue } from "@webstudio-is/css-engine";
import { CssValueInput, type IntermediateStyleValue } from "./css-value-input";
import type { DeleteProperty, SetValue } from "../use-style-data";
import type { StyleUpdateOptions } from "../use-style-data";

type CssValueInputContainerProps = {
setValue: SetValue;
deleteProperty: DeleteProperty;
} & Omit<
type CssValueInputContainerProps = Omit<
ComponentProps<typeof CssValueInput>,
| "onChange"
| "onHighlight"
| "onReset"
| "onAbort"
| "intermediateValue"
| "onChangeComplete"
| "setProperty"
> & {
onChangeComplete?: ComponentProps<typeof CssValueInput>["onChangeComplete"];
onReset?: ComponentProps<typeof CssValueInput>["onReset"];
};
onUpdate: (style: StyleValue, options?: StyleUpdateOptions) => void;
onDelete: (options?: StyleUpdateOptions) => void;
onChangeComplete?: ComponentProps<typeof CssValueInput>["onChangeComplete"];
onReset?: ComponentProps<typeof CssValueInput>["onReset"];
};

export const CssValueInputContainer = ({
property,
setValue,
deleteProperty,
onUpdate,
onDelete,
onChangeComplete,
onReset,
...props
Expand All @@ -40,32 +40,32 @@ export const CssValueInputContainer = ({
setIntermediateValue(styleValue);

if (styleValue === undefined) {
deleteProperty(property, { isEphemeral: true });
onDelete({ isEphemeral: true });
return;
}

if (styleValue.type !== "intermediate") {
setValue(styleValue, { isEphemeral: true });
onUpdate(styleValue, { isEphemeral: true });
}
}}
onHighlight={(styleValue) => {
if (styleValue !== undefined) {
setValue(styleValue, { isEphemeral: true });
onUpdate(styleValue, { isEphemeral: true });
} else {
deleteProperty(property, { isEphemeral: true });
onDelete({ isEphemeral: true });
}
}}
onChangeComplete={(event) => {
setValue(event.value);
onUpdate(event.value);
setIntermediateValue(undefined);
onChangeComplete?.(event);
}}
onAbort={() => {
deleteProperty(property, { isEphemeral: true });
onDelete({ isEphemeral: true });
}}
onReset={() => {
setIntermediateValue(undefined);
deleteProperty(property);
onDelete();
onReset?.();
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ export const FilterSectionContent = ({
unit: "px",
}
}
setValue={handleFilterFunctionValueChange}
deleteProperty={() => {}}
onUpdate={handleFilterFunctionValueChange}
onDelete={() => {}}
/>
</Grid>
) : undefined}
Expand Down
Loading