Figma Variable Export
Introduction
Section titled “Introduction”The “Figma to Slint” plugin bridges the gap between Figma designs and Slint user interfaces. It provides two primary functionalities:
- Object Inspection: Allows developers to select any object on the Figma canvas and view its properties (like dimensions, colors, fonts, etc.)formatted as a Slint code snippet. This is useful for quickly translating visual design elements into Slint code. When paired with the variable export, this inserts variables into the code, if they are used in the figma file.
- Variable Export: Enables the export of design tokens (variables for colors, numbers, strings, and booleans) defined in Figma directly into
.slint
files. This feature supports Figma’s modes, allowing for themeable designs (e.g., light and dark modes) and generates the necessary Slint structs, enums, and global instances to use these tokens seamlessly in your Slint application.
Setting up the Figma Inspector
Section titled “Setting up the Figma Inspector”First of all, find and enable the “Figma to Slint” plugin in the Figma Plugin Manager. The inspector currently has 2 functions. One is to inspect individual Figma objects for their properties, and the other is to export the variables defined in Figma so they are useable in Slint directly.
Key Features of Variable Export
Section titled “Key Features of Variable Export”-
Type Conversion:
The plugin maps Figma variable types to their corresponding Slint types as follows:
Figma Variable Type Slint Type Color brush
Float length
String string
Boolean bool
-
Mode Support: For a figma file where Mode
MyCollection
has modeslight
anddark
, the exporter will create a Slintenum
for mode selection (e.g.,MyCollectionMode { light, dark }
). The file also contains aScheme
struct (MyCollection-Scheme
) representing the structure of variables. AScheme-Mode
struct (MyCollection-Scheme-Mode
) holds instances of theScheme
for each mode. And finally a global instance (my_collection
) which contains:mode
: An instance ofScheme-Mode
holding the resolved values for each mode.current-mode
: Anin-out
property using the modeenum
to control the active mode.current-scheme
: Anout
property dynamically selecting the correct scheme instance based oncurrent-mode
.current
: Anout
property mirroring theScheme
structure, providing direct access to the values of thecurrent-scheme
.
-
Alias Resolution: Follows variable aliases (references) to find the underlying concrete value or target variable path.
-
Hierarchy Generation: Interprets
/
in Figma likecolors/background/primary
to generate nested Slint structs so the corresponding variables are nested for dot notation in Slint, thus the above example turns intocolors.background.primary
-
Circular Reference Handling: Detects dependency cycles between variables. If a cycle is detected within the same collection, it attempts to break the loop using the target’s concrete value. Otherwise, or if the loop break fails, it resolves with a default value and logs a warning. Collections involved in cycles force a single-file export.
-
Name Sanitization: Cleans up collection, variable, and mode names to be valid Slint identifiers (e.g., converting spaces and special characters to underscores, handling leading digits).
-
Export Options:
- Separate Files: Exports each Figma collection into its own
.slint
file. Automatically generates necessaryimport
statements between files if cross-collection references exist (unless a cycle forces single-file mode). - Single File: Combines all collections into a single
design-tokens.slint
file. This is also the fallback if dependency cycles are detected.
- Separate Files: Exports each Figma collection into its own
-
README Generation: Creates a
README.md
file alongside the export, summarizing exported collections, renamed variables, detected circular references, and warnings.
-
Inspector:
- Bring up the plugin UI and select any object you’d like to inspect.
- Bring up the plugin UI and select any object you’d like to inspect.
-
Variables:
- To see and export variables, check the “Use Figma Variables” checkbox in the plugin UI.
- Now when selecting objects to inspect you should see variable names instead of resolved values (if they are assigned)
- To see and export variables, check the “Use Figma Variables” checkbox in the plugin UI.
-
Export: Click the “Export” button and choose:
Separate Files Per Collection…
: Recommended for organization if no recursive references exist. Creates<collection_name>.slint
files.Single Design-Tokens File…
: Createsdesign-tokens.slint
. Necessary if any self references exist.
-
Integrate:
- Place the generated
.slint
file(s) in your Slint project.
- Place the generated
Design-Token File Structure
Section titled “Design-Token File Structure”-
Import
// If separate files:import { Colors } from "colors.slint";import { Spacing } from "spacing.slint";slint// If single file:import { Colors, Spacing } from "design-tokens.slint";slint -
Use variables
// Use the tokens:MyComponent := Rectangle {background: Colors.current.background.primary; // Access via .current for mode switchingheight: Spacing.medium; // Access directly if single-mode or not mode-dependent}slint -
Mode Switching: (For multi-mode collections) Modify the
current-mode
property of the imported global:// Example: In your main component's logicinit => {// Set initial modeColors.current-mode = ColorsMode.dark;}// Or in response to a user action:clicked => {Colors.current-mode = (Colors.current-mode == ColorsMode.light) ? ColorsMode.dark : ColorsMode.light;}slint- All properties accessed via
<collection_name>.current.*
will automatically update.
- All properties accessed via
Naming Conventions & Sanitization
Section titled “Naming Conventions & Sanitization”-
Hierarchy: Figma uses
/
in variable names (e.g.,radius/small
,font/body/weight
). The export will use these to create nested Slint structs for code completion clarity. -
Sanitization: Collection names, variable names (path segments), and mode names are automatically sanitized:
- Spaces and invalid characters (
&
,+
,:
,-
, etc.) are typically converted to-
for collection/struct names and_
for property/enum names. - Leading/trailing invalid characters are removed.
- Names starting with a digit are prefixed with
_
orm_
. - Any variable named exactly
mode
at the root of a collection is renamed tomode-var
in the Slint output to avoid conflicts with the generated schememode
property.
Example
Section titled “Example”Variable
Color & Shade (only #hex values)
in a collection namedColor Primitives
would get turned intocolor-primitives.color_and_shade_only_hex_values
- Spaces and invalid characters (
© 2025 SixtyFPS GmbH