diff --git a/docs/user-guide/design-systems/design-tokens.njk b/docs/user-guide/design-systems/design-tokens.njk index 15373b1241..878cfb4230 100644 --- a/docs/user-guide/design-systems/design-tokens.njk +++ b/docs/user-guide/design-systems/design-tokens.njk @@ -42,20 +42,74 @@ desc: Learn how to create, manage and apply Penpot Design Tokens using W3C DTCG
If the value of the referenced token changes, this will also change the value of the tokens where it is referenced.
References to existing tokens are case sensitive.
-Token types with numerical values also accept mathematical equations. If, for example, you create a spacing.small token with the value of 2, and you then want to create a spacing.medium token that is twice as large, you could do so by writing {spacing.small} * 2 in its value. As a result, spacing.medium would have a value of 4.
Say you have a spacing.scale token with a value of 2. You could also use this token in the equation to calculate the value of spacing.medium by writing {spacing.small} * {spacing.scale} in its value.
Token types with numerical values accept mathematical equations to calculate their values. This allows you to create dynamic relationships between tokens and build flexible design systems.
+For example, if you create a spacing.small token with the value of 2, and you want to create a spacing.medium token that is twice as large, you can write {spacing.small} * 2 in its value. As a result, spacing.medium would have a value of 4.
You can also reference other tokens in your equations. Say you have a spacing.scale token with a value of 2. You could use this token in the equation to calculate the value of spacing.medium by writing {spacing.small} * {spacing.scale} in its value.
Mathematical equations can be performed using:
+ +Mathematical equations can be performed using these basic operators:
+ for addition.- for subtraction.* for multiplication./ for division.+ for addition- for subtraction* for multiplication/ for division% for modulo (remainder)^ for exponentiationIn addition to basic operators, you can use various math functions in your token values:
+abs(x) - absolute valueceil(x) - round up to nearest integerfloor(x) - round down to nearest integerround(x) - round to nearest integermax(x, y, ...) - maximum valuemin(x, y, ...) - minimum valuesqrt(x) - square rootpow(x, y) - x raised to the power of ylog(x) - natural logarithmexp(x) - e raised to the power of xsin(x) - sinecos(x) - cosinetan(x) - tangentasin(x) - arcsineacos(x) - arccosineatan(x) - arctangentatan2(y, x) - arctangent of y/xWhen writing math equations in token values, keep these guidelines in mind:
+8 * 8 and (8 * 8) both resolve to 64.8 * 8 instead of 8*8.{token.name}.{spacing.base} * 1.5.Here are some common use cases for math in token values:
+ +When using multipliers that result in decimals, you can use the round() function to get whole numbers. For example, if sizing.sm has a value of 2:
round({sizing.sm} * 1.33)
+This calculates 2 * 1.33 = 2.66, which rounds to 3.
You can convert unitless numbers to percentages. For example, a Number token called lineHeights.heading.relaxed with a value of 1.5 can be written in a Line Height token as:
+{lineHeights.heading.relaxed} * 100%
+This calculates a resolved value of 150%.
+ +Use max() or min() to ensure values stay within bounds. For example:
max({spacing.base}, 8)
+This ensures the spacing is at least 8, even if the base token is smaller.
+Tokens can be edited by right-clicking the token and selecting Edit token. This will allow you to change the tokens name, value and description. Once the changes are made, click Save.