Skip to content
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

Carry-over-token-descriptions-to-variable-descriptions #2330

Merged
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
5 changes: 5 additions & 0 deletions .changeset/dirty-otters-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tokens-studio/figma-plugin': patch
---

We now carry over token descriptions when creating variables
14 changes: 11 additions & 3 deletions src/app/components/EditTokenForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,17 @@ function EditTokenForm({ resolvedTokens }: Props) {
}, [internalEditToken, error, isValidColorToken, isValidDimensionToken]);

const hasNameThatExistsAlready = React.useMemo(
() => resolvedTokens
.filter((t) => t.internal__Parent === activeTokenSet)
.find((t) => t.name === internalEditToken?.name),
() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, can we just add a changeset for this?

const editToken = resolvedTokens
.filter((t) => t.internal__Parent === activeTokenSet)
.find((t) => t.name === internalEditToken?.name);

if (editToken) {
editToken.description = internalEditToken.description;
}

return editToken;
},
[internalEditToken, resolvedTokens, activeTokenSet],
);

Expand Down
2 changes: 2 additions & 0 deletions src/plugin/setValuesOnVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function setValuesOnVariable(
variable = figma.variables.createVariable(t.path, collection.id, variableType);
}
if (variable) {
variable.description = t.description ?? '';
switch (variableType) {
case 'BOOLEAN':
if (typeof t.value === 'string') {
Expand Down Expand Up @@ -70,6 +71,7 @@ export default function setValuesOnVariable(
} catch (e) {
console.error('Setting values on variable is failed', e);
}

return {
variableKeyMap,
referenceVariableCandidates,
Expand Down