Skip to content

Commit 4456f85

Browse files
committed
feat: add "Convert Position To Margin" command
1 parent 11b0479 commit 4456f85

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

apps/builder/app/builder/shared/commands.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,18 @@ export const deleteSelectedInstance = () => {
153153
});
154154
};
155155

156-
export const convertPositionToPadding = () => {
156+
export const convertPositionToProperty = (
157+
targetProperty: "padding" | "margin"
158+
) => {
157159
const batch = createBatchUpdate();
158160

159161
// Get the position properties we want to convert
160162
const positionProps = ["top", "right", "bottom", "left"] as const;
161-
const paddingProps = [
162-
"padding-top",
163-
"padding-right",
164-
"padding-bottom",
165-
"padding-left",
163+
const targetProps = [
164+
`${targetProperty}-top`,
165+
`${targetProperty}-right`,
166+
`${targetProperty}-bottom`,
167+
`${targetProperty}-left`,
166168
] as const;
167169

168170
// Get the current styles for the selected instance
@@ -206,12 +208,12 @@ export const convertPositionToPadding = () => {
206208
return;
207209
}
208210

209-
// Convert position to padding
211+
// Convert position to target property
210212
positionProps.forEach((prop, index) => {
211213
const value = positionValues.get(prop);
212214
if (value) {
213-
// Set the corresponding padding
214-
batch.setProperty(paddingProps[index])(value);
215+
// Set the corresponding target property
216+
batch.setProperty(targetProps[index])(value);
215217
// Delete the position property
216218
batch.deleteProperty(prop);
217219
}
@@ -556,7 +558,11 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
556558

557559
{
558560
name: "convertPositionToPadding",
559-
handler: convertPositionToPadding,
561+
handler: () => convertPositionToProperty("padding"),
562+
},
563+
{
564+
name: "convertPositionToMargin",
565+
handler: () => convertPositionToProperty("margin"),
560566
},
561567

562568
{

0 commit comments

Comments
 (0)