Skip to content

Commit

Permalink
fix: sellection change event
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-krakowski committed Apr 7, 2023
1 parent 5a5c0ab commit 41d43ed
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
35 changes: 25 additions & 10 deletions packages/status/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,17 @@ const changeStatus = ({ status, appearance }) => {
figma.notify('Please select a section or frame.');
return;
}
figma.currentPage.selection.forEach((el) => {
el.name = `${statusInfo[status].icon} ${el.name.replace(/^(🚧||) /, '')}`;
if (isSection(el) || isFrame(el)) {
el.fills = [{ type: 'SOLID', color: statusInfo[status].colorSchemes[appearance].color, opacity: 0.64 }];
}
else {
figma.notify('Please select a section or frame.');
}
});
if (status) {
figma.currentPage.selection.forEach((el) => {
el.name = `${statusInfo[status].icon} ${el.name.replace(/^(🚧||) /, '')}`;
if (isSection(el) || isFrame(el)) {
el.fills = [{ type: 'SOLID', color: statusInfo[status].colorSchemes[appearance].color, opacity: 0.64 }];
}
else {
figma.notify('Please select a section or frame.');
}
});
}
};
const archive = () => {
var _a;
Expand All @@ -168,6 +170,18 @@ const archive = () => {
el.name = `${el.name.replace(/^(🚧||) /, '')} | Archived on ${formattedDate}`;
el.y = isFinite(minY) ? minY - el.height - 400 : 0;
el.x = isFinite(x) ? x : 0;
if (isSection(el) || isFrame(el)) {
el.fills = [
{
type: 'SOLID',
color: {
b: 0.9490196108818054,
g: 0.9490196108818054,
r: 0.9490196108818054,
},
},
];
}
});
};
init();
Expand All @@ -189,13 +203,14 @@ const slugify = (str) => str
function startPluginWithParameters(parameters) {
const { workStatus } = parameters;
figma.currentPage.selection.forEach((el) => {
var _a;
const status = recognizeStatus(el);
const { backgrounds } = figma.currentPage;
const canvasBackground = rgbToHsl(backgrounds[0].type === 'SOLID' && backgrounds[0].color);
const appearance = canvasBackground.l > 40 ? 'light' : 'dark';
figma.ui.postMessage({ status, appearance });
changeStatus({
status: slugify(workStatus !== null && workStatus !== void 0 ? workStatus : status),
status: slugify((_a = workStatus !== null && workStatus !== void 0 ? workStatus : status) !== null && _a !== void 0 ? _a : ``),
appearance: 'light',
});
});
Expand Down
35 changes: 25 additions & 10 deletions packages/status/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,17 @@ const changeStatus = ({ status, appearance }: ChangeStatusPayload) => {
return
}

figma.currentPage.selection.forEach((el) => {
el.name = `${statusInfo[status].icon} ${el.name.replace(/^(🚧||) /, '')}`

if (isSection(el) || isFrame(el)) {
el.fills = [{ type: 'SOLID', color: statusInfo[status].colorSchemes[appearance].color, opacity: 0.64 }]
} else {
figma.notify('Please select a section or frame.')
}
})
if (status) {
figma.currentPage.selection.forEach((el) => {
el.name = `${statusInfo[status].icon} ${el.name.replace(/^(🚧||) /, '')}`

if (isSection(el) || isFrame(el)) {
el.fills = [{ type: 'SOLID', color: statusInfo[status].colorSchemes[appearance].color, opacity: 0.64 }]
} else {
figma.notify('Please select a section or frame.')
}
})
}
}

const archive = () => {
Expand All @@ -204,6 +206,19 @@ const archive = () => {
el.name = `${el.name.replace(/^(🚧||) /, '')} | Archived on ${formattedDate}`
el.y = isFinite(minY) ? minY - el.height - 400 : 0
el.x = isFinite(x) ? x : 0

if (isSection(el) || isFrame(el)) {
el.fills = [
{
type: 'SOLID',
color: {
b: 0.9490196108818054,
g: 0.9490196108818054,
r: 0.9490196108818054,
},
},
]
}
})
}

Expand Down Expand Up @@ -240,7 +255,7 @@ function startPluginWithParameters(parameters: PluginParameters) {
figma.ui.postMessage({ status, appearance })

changeStatus({
status: slugify(workStatus ?? status) as Status,
status: slugify(workStatus ?? status ?? ``) as Status,
appearance: 'light',
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/status/ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
<legend class="legend">Work status</legend>

<div class="input-wrapper">
<input type="radio" id="in-progress" name="type" value="in-progress" class="radio-input" checked="true" />
<input type="radio" id="in-progress" name="type" value="in-progress" class="radio-input" />
<label for="in-progress" class="label label--in-progress">In progress</label>
</div>
<div class="input-wrapper">
Expand Down

0 comments on commit 41d43ed

Please sign in to comment.