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

Fix empty token group creation #3245

Merged
merged 8 commits into from
Jan 14, 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
5 changes: 5 additions & 0 deletions .changeset/tender-jokes-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tokens-studio/figma-plugin": patch
---

Fix ability to add a token with empty or nested empty token groups
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ function EditTokenForm({ resolvedTokens }: Props) {
[internalEditToken],
);

const hasEmptyGroups = React.useMemo(() => {
if (internalEditToken?.name) {
return internalEditToken.name.includes('..')
|| internalEditToken.name.startsWith('.')
|| internalEditToken.name.endsWith('.');
}
return false;
}, [internalEditToken]);

React.useEffect(() => {
if ((internalEditToken?.status !== EditTokenFormStatus.EDIT || nameWasChanged) && hasNameThatExistsAlready) {
setError(t('tokenNamesMustBeUnique', { ns: 'errors' }));
Expand All @@ -175,7 +184,10 @@ function EditTokenForm({ resolvedTokens }: Props) {
if ((internalEditToken?.status || nameWasChanged) && hasCurlyBraces) {
setError(t('tokenNamesCantContainCurlyBraces', { ns: 'errors' }));
}
}, [internalEditToken, hasNameThatExistsAlready, nameWasChanged, hasAnotherTokenThatStartsWithName]);
if ((internalEditToken?.status || nameWasChanged) && hasEmptyGroups) {
setError(t('tokenNamesCantContainEmptyGroups', { ns: 'errors' }));
}
}, [internalEditToken, hasNameThatExistsAlready, nameWasChanged, hasAnotherTokenThatStartsWithName, hasEmptyGroups]);

const handleChange = React.useCallback(
(property: string, value: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"cantCreateGroupThatSharesNameWithExistingToken": "Can't create a group that shares a name with an existing token",
"valueMustIncludePxOrRem": "Value must include either px or rem",
"tokenNamesCantStartWithDollar": "Can't start with a dollar ($) sign",
"tokenNamesCantContainCurlyBraces": "Can't contain braces '{}'"
"tokenNamesCantContainCurlyBraces": "Can't contain braces '{}'",
"tokenNamesCantContainEmptyGroups": "Token names cannot contain empty groups"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"cantCreateGroupThatSharesNameWithExistingToken": "No se puede crear un grupo que comparta un nombre con un token existente",
"valueMustIncludePxOrRem": "El valor debe incluir px o rem",
"tokenNamesCantStartWithDollar": "No puedo comenzar con un signo de dólar ($)",
"tokenNamesCantContainCurlyBraces": "No puede contener llaves '{}'"
"tokenNamesCantContainCurlyBraces": "No puede contener llaves '{}'",
"tokenNamesCantContainEmptyGroups": "Los nombres de los tokens no pueden contener grupos vacíos"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"cantCreateGroupThatSharesNameWithExistingToken": "Impossible de créer un groupe partageant un nom avec un jeton existant",
"valueMustIncludePxOrRem": "La valeur doit inclure px ou rem",
"tokenNamesCantStartWithDollar": "Je ne peux pas commencer par un signe dollar ($)",
"tokenNamesCantContainCurlyBraces": "Ne peut pas contenir d'accolades '{}'"
"tokenNamesCantContainCurlyBraces": "Ne peut pas contenir d'accolades '{}'",
"tokenNamesCantContainEmptyGroups": "Les noms de jetons ne peuvent pas contenir de groupes vides"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"cantCreateGroupThatSharesNameWithExistingToken": "ऐसा समूह नहीं बनाया जा सकता जो किसी मौजूदा टोकन के साथ नाम साझा करता हो",
"valueMustIncludePxOrRem": "मान में या तो px या rem शामिल होना चाहिए",
"tokenNamesCantStartWithDollar": "डॉलर ($) चिह्न से प्रारंभ नहीं किया जा सकता",
"tokenNamesCantContainCurlyBraces": "ब्रेसिज़ शामिल नहीं हो सकते '{}'"
"tokenNamesCantContainCurlyBraces": "ब्रेसिज़ शामिल नहीं हो सकते '{}'",
"tokenNamesCantContainEmptyGroups": "टोकन नामों में खाली समूह नहीं हो सकते"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"cantCreateGroupThatSharesNameWithExistingToken": "Kan geen groep maken die een naam deelt met een bestaand token",
"valueMustIncludePxOrRem": "De waarde moet px of rem bevatten",
"tokenNamesCantStartWithDollar": "Kan niet beginnen met een dollarteken ($).",
"tokenNamesCantContainCurlyBraces": "Mag geen accolades '{}' bevatten"
"tokenNamesCantContainCurlyBraces": "Mag geen accolades '{}' bevatten",
"tokenNamesCantContainEmptyGroups": "Tokennamen mogen geen lege groepen bevatten"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"cantCreateGroupThatSharesNameWithExistingToken": "无法创建与现有令Token享名称的组",
"valueMustIncludePxOrRem": "值必须包含 px 或 rem",
"tokenNamesCantStartWithDollar": "不能以美元 ($) 符号开头",
"tokenNamesCantContainCurlyBraces": "不能包含大括号“{}”"
"tokenNamesCantContainCurlyBraces": "不能包含大括号“{}”",
"tokenNamesCantContainEmptyGroups": "令牌名称不能包含空组"
}
Loading