@figma-vars/hooks 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -15
- package/dist/figma-vars-hooks.js +559 -799
- package/dist/figma-vars-hooks.umd.cjs +3 -24
- package/dist/index.d.ts +936 -11
- package/package.json +17 -8
- package/dist/constants/index.d.ts +0 -3
- package/dist/contexts/FigmaTokenContext.d.ts +0 -49
- package/dist/hooks/useFigmaToken.d.ts +0 -17
- package/dist/hooks/useVariableCollections.d.ts +0 -26
- package/dist/hooks/useVariableModes.d.ts +0 -16
- package/dist/hooks/useVariables.d.ts +0 -25
- package/dist/mutations/bulkUpdateVariables.d.ts +0 -25
- package/dist/mutations/createVariable.d.ts +0 -26
- package/dist/mutations/deleteVariable.d.ts +0 -19
- package/dist/mutations/updateVariable.d.ts +0 -26
- package/dist/types/figma.d.ts +0 -111
- package/dist/types/hooks.d.ts +0 -12
- package/dist/types/index.d.ts +0 -3
- package/dist/types/mutations.d.ts +0 -114
- package/dist/utils/fetcher.d.ts +0 -13
- package/dist/utils/filterVariables.d.ts +0 -31
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,936 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
2
|
+
import { MutationResult as MutationResult_2 } from '..';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The payload for the `bulkUpdateVariables` function.
|
|
7
|
+
* Allows creating, updating, and deleting multiple variables, collections, and modes in one call.
|
|
8
|
+
* This corresponds to the `POST /v1/files/:file_key/variables` endpoint.
|
|
9
|
+
* Note: Figma has deprecated this complex endpoint in favor of simpler, more granular ones.
|
|
10
|
+
* This type is kept for legacy purposes but its usage is not recommended.
|
|
11
|
+
*
|
|
12
|
+
* @typedef {Object} BulkUpdatePayload
|
|
13
|
+
* @memberof Types
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
* @see {@link https://www.figma.com/developers/api#post-variables|Figma API - Bulk Update Variables}
|
|
16
|
+
* @property {VariableCollectionChange[]} [variableCollections] A list of changes to variable collections.
|
|
17
|
+
* @property {VariableModeChange[]} [variableModes] A list of changes to variable modes.
|
|
18
|
+
* @property {VariableChange[]} [variables] A list of changes to variables.
|
|
19
|
+
* @property {VariableModeValue[]} [variableModeValues] A list of changes to variable values in specific modes.
|
|
20
|
+
*/
|
|
21
|
+
export declare interface BulkUpdatePayload {
|
|
22
|
+
/** A list of changes to variable collections. */
|
|
23
|
+
variableCollections?: VariableCollectionChange[];
|
|
24
|
+
/** A list of changes to variable modes. */
|
|
25
|
+
variableModes?: VariableModeChange[];
|
|
26
|
+
/** A list of changes to variables. */
|
|
27
|
+
variables?: VariableChange[];
|
|
28
|
+
/** A list of changes to variable values in specific modes. */
|
|
29
|
+
variableModeValues?: VariableModeValue[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The response object returned by the `bulkUpdateVariables` function.
|
|
34
|
+
*
|
|
35
|
+
* @typedef {Object} BulkUpdateResponse
|
|
36
|
+
* @memberof Types
|
|
37
|
+
* @since 1.0.0
|
|
38
|
+
* @see {@link https://www.figma.com/developers/api#post-variables|Figma API - Bulk Update Variables}
|
|
39
|
+
* @property {boolean} error Whether an error occurred during the bulk update.
|
|
40
|
+
* @property {number} status The HTTP status code of the response.
|
|
41
|
+
* @property {string} [message] A message describing the result of the bulk update.
|
|
42
|
+
* @property {Object} [meta] Additional metadata about the bulk update.
|
|
43
|
+
* @property {Record<string, string>} [meta.tempIdToRealId] A mapping of temporary IDs to real IDs for created variables.
|
|
44
|
+
*/
|
|
45
|
+
export declare interface BulkUpdateResponse {
|
|
46
|
+
error: boolean;
|
|
47
|
+
status: number;
|
|
48
|
+
message?: string;
|
|
49
|
+
meta?: {
|
|
50
|
+
tempIdToRealId: Record<string, string>;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Represents a color in RGBA format.
|
|
56
|
+
*
|
|
57
|
+
* @typedef {Object} Color
|
|
58
|
+
* @memberof Types
|
|
59
|
+
* @since 1.0.0
|
|
60
|
+
* @see {@link https://www.figma.com/developers/api#color-object|Figma Color Object}
|
|
61
|
+
* @property {number} r The red channel value (0-1).
|
|
62
|
+
* @property {number} g The green channel value (0-1).
|
|
63
|
+
* @property {number} b The blue channel value (0-1).
|
|
64
|
+
* @property {number} a The alpha (opacity) channel value (0-1).
|
|
65
|
+
*/
|
|
66
|
+
export declare interface Color {
|
|
67
|
+
/** The red channel value (0-1). */
|
|
68
|
+
r: number;
|
|
69
|
+
/** The green channel value (0-1). */
|
|
70
|
+
g: number;
|
|
71
|
+
/** The blue channel value (0-1). */
|
|
72
|
+
b: number;
|
|
73
|
+
/** The alpha (opacity) channel value (0-1). */
|
|
74
|
+
a: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The payload for the `createVariable` function.
|
|
79
|
+
* Defines the properties for a new variable.
|
|
80
|
+
*
|
|
81
|
+
* @typedef {Object} CreateVariablePayload
|
|
82
|
+
* @memberof Types
|
|
83
|
+
* @since 1.0.0
|
|
84
|
+
* @see {@link https://www.figma.com/developers/api#post-variables|Figma API - Create Variable}
|
|
85
|
+
* @property {string} name The name of the new variable.
|
|
86
|
+
* @property {string} variableCollectionId The ID of the collection the new variable should be added to.
|
|
87
|
+
* @property {ResolvedType} resolvedType The underlying data type for the new variable.
|
|
88
|
+
* @property {string} [description] An optional description for the new variable.
|
|
89
|
+
* @property {boolean} [hiddenFromPublishing] Whether the new variable should be hidden when publishing. Defaults to `false`.
|
|
90
|
+
* @property {VariableScope[]} [scopes] The scopes in which this variable can be used.
|
|
91
|
+
* @property {Record<string, string>} [codeSyntax] Platform-specific code syntax for this variable.
|
|
92
|
+
* @property {Record<string, VariableValue>} [valuesByMode] Initial values for the variable by mode ID.
|
|
93
|
+
*/
|
|
94
|
+
export declare interface CreateVariablePayload {
|
|
95
|
+
/** The name of the new variable. */
|
|
96
|
+
name: string;
|
|
97
|
+
/** The ID of the collection the new variable should be added to. */
|
|
98
|
+
variableCollectionId: string;
|
|
99
|
+
/** The underlying data type for the new variable. */
|
|
100
|
+
resolvedType: ResolvedType;
|
|
101
|
+
/** An optional description for the new variable. */
|
|
102
|
+
description?: string;
|
|
103
|
+
/** Whether the new variable should be hidden when publishing. Defaults to `false`. */
|
|
104
|
+
hiddenFromPublishing?: boolean;
|
|
105
|
+
/** The scopes in which this variable can be used. */
|
|
106
|
+
scopes?: VariableScope[];
|
|
107
|
+
/** Platform-specific code syntax for this variable. */
|
|
108
|
+
codeSyntax?: Record<string, string>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Represents a collection of Figma variables, which can contain multiple modes.
|
|
113
|
+
*
|
|
114
|
+
* @typedef {Object} FigmaCollection
|
|
115
|
+
* @memberof Types
|
|
116
|
+
* @since 1.0.0
|
|
117
|
+
* @see {@link https://www.figma.com/developers/api#variable-collection-object|Figma Variable Collection Object}
|
|
118
|
+
* @property {string} id The unique identifier for the collection.
|
|
119
|
+
* @property {string} name The name of the collection (e.g., "Brand Colors").
|
|
120
|
+
* @property {VariableMode[]} modes An array of modes available in this collection.
|
|
121
|
+
* @property {string} defaultModeId The ID of the default mode for this collection.
|
|
122
|
+
* @property {string[]} variableIds An array of variable IDs that belong to this collection.
|
|
123
|
+
* @property {boolean} hiddenFromPublishing Whether the collection is hidden when publishing the library.
|
|
124
|
+
* @property {string} updatedAt The timestamp of the last update.
|
|
125
|
+
*/
|
|
126
|
+
export declare interface FigmaCollection {
|
|
127
|
+
/** The unique identifier for the collection. */
|
|
128
|
+
id: string;
|
|
129
|
+
/** The name of the collection (e.g., "Brand Colors"). */
|
|
130
|
+
name: string;
|
|
131
|
+
/** An array of modes available in this collection. */
|
|
132
|
+
modes: VariableMode[];
|
|
133
|
+
/** The ID of the default mode for this collection. */
|
|
134
|
+
defaultModeId: string;
|
|
135
|
+
/** An array of variable IDs that belong to this collection. */
|
|
136
|
+
variableIds: string[];
|
|
137
|
+
/** Whether the collection is hidden when publishing the library. */
|
|
138
|
+
hiddenFromPublishing: boolean;
|
|
139
|
+
/** The timestamp of the last update. */
|
|
140
|
+
updatedAt: string;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A generic error shape for failed Figma API requests.
|
|
145
|
+
*
|
|
146
|
+
* @typedef {Object} FigmaError
|
|
147
|
+
* @memberof Types
|
|
148
|
+
* @since 1.0.0
|
|
149
|
+
* @see {@link https://www.figma.com/developers/api#error-handling|Figma API Error Handling}
|
|
150
|
+
* @property {number} statusCode The HTTP status code of the error.
|
|
151
|
+
* @property {string} message The error message from the API.
|
|
152
|
+
*/
|
|
153
|
+
export declare interface FigmaError {
|
|
154
|
+
/** The HTTP status code of the error. */
|
|
155
|
+
statusCode: number;
|
|
156
|
+
/** The error message from the API. */
|
|
157
|
+
message: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/* Excluded from this release type: FigmaTokenContextType */
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Represents a single Figma variable.
|
|
164
|
+
*
|
|
165
|
+
* @typedef {Object} FigmaVariable
|
|
166
|
+
* @memberof Types
|
|
167
|
+
* @since 1.0.0
|
|
168
|
+
* @see {@link https://www.figma.com/developers/api#variable-object|Figma Variable Object}
|
|
169
|
+
* @property {string} id The unique identifier for the variable.
|
|
170
|
+
* @property {string} name The name of the variable.
|
|
171
|
+
* @property {string} variableCollectionId The ID of the collection this variable belongs to.
|
|
172
|
+
* @property {ResolvedType} resolvedType The underlying data type of the variable.
|
|
173
|
+
* @property {Record<string, VariableValue>} valuesByMode A map of mode IDs to the variable's value in that mode.
|
|
174
|
+
* @property {string} description The description of the variable, as set in Figma.
|
|
175
|
+
* @property {boolean} hiddenFromPublishing Whether the variable is hidden when publishing the library.
|
|
176
|
+
* @property {VariableScope[]} scopes The scopes in which this variable can be used.
|
|
177
|
+
* @property {Record<string, string>} codeSyntax Platform-specific code syntax for this variable (e.g., for Web, iOS, Android).
|
|
178
|
+
* @property {string} updatedAt The timestamp of the last update.
|
|
179
|
+
*/
|
|
180
|
+
export declare interface FigmaVariable {
|
|
181
|
+
/** The unique identifier for the variable. */
|
|
182
|
+
id: string;
|
|
183
|
+
/** The name of the variable. */
|
|
184
|
+
name: string;
|
|
185
|
+
/** The ID of the collection this variable belongs to. */
|
|
186
|
+
variableCollectionId: string;
|
|
187
|
+
/** The underlying data type of the variable. */
|
|
188
|
+
resolvedType: ResolvedType;
|
|
189
|
+
/** A map of mode IDs to the variable's value in that mode. */
|
|
190
|
+
valuesByMode: Record<string, VariableValue>;
|
|
191
|
+
/** The description of the variable, as set in Figma. */
|
|
192
|
+
description: string;
|
|
193
|
+
/** Whether the variable is hidden when publishing the library. */
|
|
194
|
+
hiddenFromPublishing: boolean;
|
|
195
|
+
/** The scopes in which this variable can be used. */
|
|
196
|
+
scopes: VariableScope[];
|
|
197
|
+
/** Platform-specific code syntax for this variable (e.g., for Web, iOS, Android). */
|
|
198
|
+
codeSyntax: Record<string, string>;
|
|
199
|
+
/** The timestamp of the last update. */
|
|
200
|
+
updatedAt: string;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Provides the Figma token and file key to all descendant hooks.
|
|
205
|
+
* This component should be placed at the root of your application or any component tree
|
|
206
|
+
* that needs to interact with the Figma Variables API.
|
|
207
|
+
*
|
|
208
|
+
* @function FigmaVarsProvider
|
|
209
|
+
* @memberof Providers
|
|
210
|
+
* @since 1.0.0
|
|
211
|
+
* @param {FigmaVarsProviderProps} props - The provider props
|
|
212
|
+
* @param {string} props.token - The Figma Personal Access Token
|
|
213
|
+
* @param {string} props.fileKey - The Figma file key from the file URL
|
|
214
|
+
* @param {React.ReactNode} props.children - The child components that will have access to the context
|
|
215
|
+
* @returns {JSX.Element} The provider component
|
|
216
|
+
* @see {@link https://www.figma.com/developers/api#authentication|Figma API Authentication}
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```tsx
|
|
220
|
+
* import { FigmaVarsProvider } from '@figma-vars/hooks';
|
|
221
|
+
*
|
|
222
|
+
* function App() {
|
|
223
|
+
* const token = process.env.REACT_APP_FIGMA_TOKEN;
|
|
224
|
+
* const fileKey = 'abc123def456'; // From Figma file URL
|
|
225
|
+
*
|
|
226
|
+
* return (
|
|
227
|
+
* <FigmaVarsProvider token={token} fileKey={fileKey}>
|
|
228
|
+
* <Dashboard />
|
|
229
|
+
* <VariableEditor />
|
|
230
|
+
* </FigmaVarsProvider>
|
|
231
|
+
* );
|
|
232
|
+
* }
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```tsx
|
|
237
|
+
* // With Next.js and environment variables
|
|
238
|
+
* import { FigmaVarsProvider } from '@figma-vars/hooks';
|
|
239
|
+
*
|
|
240
|
+
* export default function MyApp({ Component, pageProps }) {
|
|
241
|
+
* return (
|
|
242
|
+
* <FigmaVarsProvider
|
|
243
|
+
* token={process.env.NEXT_PUBLIC_FIGMA_TOKEN}
|
|
244
|
+
* fileKey={process.env.NEXT_PUBLIC_FIGMA_FILE_KEY}
|
|
245
|
+
* >
|
|
246
|
+
* <Component {...pageProps} />
|
|
247
|
+
* </FigmaVarsProvider>
|
|
248
|
+
* );
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
export declare const FigmaVarsProvider: ({ children, token, fileKey, }: FigmaVarsProviderProps) => JSX_2.Element;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Props for the `FigmaVarsProvider` component.
|
|
256
|
+
*
|
|
257
|
+
* @typedef {Object} FigmaVarsProviderProps
|
|
258
|
+
* @memberof Types
|
|
259
|
+
* @since 1.0.0
|
|
260
|
+
* @property {ReactNode} children The child components that will have access to the context.
|
|
261
|
+
* @property {string | null} token The Figma Personal Access Token for API authentication.
|
|
262
|
+
* @property {string | null} fileKey The Figma file key extracted from the file URL.
|
|
263
|
+
*/
|
|
264
|
+
export declare interface FigmaVarsProviderProps {
|
|
265
|
+
/** The child components that will have access to the context. */
|
|
266
|
+
children: ReactNode;
|
|
267
|
+
/**
|
|
268
|
+
* Your Figma Personal Access Token.
|
|
269
|
+
* @see https://www.figma.com/developers/api#authentication
|
|
270
|
+
*/
|
|
271
|
+
token: string | null;
|
|
272
|
+
/**
|
|
273
|
+
* The unique identifier of the Figma file you want to access.
|
|
274
|
+
* You can get this from the file's URL.
|
|
275
|
+
*/
|
|
276
|
+
fileKey: string | null;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Filters an array of Figma variables based on specified criteria.
|
|
281
|
+
* This utility can filter by variable type, a partial name match, or both.
|
|
282
|
+
*
|
|
283
|
+
* @function filterVariables
|
|
284
|
+
* @memberof Utils
|
|
285
|
+
* @since 1.0.0
|
|
286
|
+
* @param {FigmaVariable[]} variables The array of `FigmaVariable` objects to filter.
|
|
287
|
+
* @param {Object} criteria An object specifying the filter criteria.
|
|
288
|
+
* @param {ResolvedType} [criteria.resolvedType] The variable type (e.g., 'COLOR', 'FLOAT') to filter by.
|
|
289
|
+
* @param {string} [criteria.name] A string to search for within the variable names (case-sensitive).
|
|
290
|
+
* @returns {FigmaVariable[]} A new array containing only the variables that match the criteria.
|
|
291
|
+
* @see {@link https://www.figma.com/developers/api#variable-object|Figma Variable Object}
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* import { filterVariables } from 'utils/filterVariables';
|
|
296
|
+
*
|
|
297
|
+
* const allVariables = [
|
|
298
|
+
* { name: 'primary-color', resolvedType: 'COLOR', id: '1:1', ... },
|
|
299
|
+
* { name: 'font-size-large', resolvedType: 'FLOAT', id: '1:2', ... },
|
|
300
|
+
* { name: 'secondary-color', resolvedType: 'COLOR', id: '1:3', ... }
|
|
301
|
+
* ];
|
|
302
|
+
*
|
|
303
|
+
* // Filter by type
|
|
304
|
+
* const colorVariables = filterVariables(allVariables, {
|
|
305
|
+
* resolvedType: 'COLOR'
|
|
306
|
+
* });
|
|
307
|
+
* // Returns: [primary-color, secondary-color]
|
|
308
|
+
*
|
|
309
|
+
* // Filter by name (partial match)
|
|
310
|
+
* const fontVariables = filterVariables(allVariables, {
|
|
311
|
+
* name: 'font'
|
|
312
|
+
* });
|
|
313
|
+
* // Returns: [font-size-large]
|
|
314
|
+
*
|
|
315
|
+
* // Filter by both type and name
|
|
316
|
+
* const primaryColors = filterVariables(allVariables, {
|
|
317
|
+
* resolvedType: 'COLOR',
|
|
318
|
+
* name: 'primary'
|
|
319
|
+
* });
|
|
320
|
+
* // Returns: [primary-color]
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```typescript
|
|
325
|
+
* // Use with the useVariables hook
|
|
326
|
+
* import { useVariables, filterVariables } from 'utils';
|
|
327
|
+
*
|
|
328
|
+
* function ColorVariablesList() {
|
|
329
|
+
* const { variables } = useVariables();
|
|
330
|
+
*
|
|
331
|
+
* const colorVariables = filterVariables(variables, {
|
|
332
|
+
* resolvedType: 'COLOR'
|
|
333
|
+
* });
|
|
334
|
+
*
|
|
335
|
+
* return (
|
|
336
|
+
* <ul>
|
|
337
|
+
* {colorVariables.map(variable => (
|
|
338
|
+
* <li key={variable.id}>{variable.name}</li>
|
|
339
|
+
* ))}
|
|
340
|
+
* </ul>
|
|
341
|
+
* );
|
|
342
|
+
* }
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
export declare function filterVariables(variables: FigmaVariable[], criteria: {
|
|
346
|
+
resolvedType?: ResolvedType;
|
|
347
|
+
name?: string;
|
|
348
|
+
}): FigmaVariable[];
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* The structure of the successful response from the Figma API's `/v1/files/{file_key}/variables/local` endpoint.
|
|
352
|
+
*
|
|
353
|
+
* @typedef {Object} LocalVariablesResponse
|
|
354
|
+
* @memberof Types
|
|
355
|
+
* @since 1.0.0
|
|
356
|
+
* @see {@link https://www.figma.com/developers/api#variables-endpoint|Figma Variables Endpoint}
|
|
357
|
+
* @property {Object} meta Contains the metadata about the variables and collections.
|
|
358
|
+
* @property {Record<string, FigmaCollection>} meta.variableCollections A map of collection IDs to `FigmaCollection` objects.
|
|
359
|
+
* @property {Record<string, FigmaVariable>} meta.variables A map of variable IDs to `FigmaVariable` objects.
|
|
360
|
+
*/
|
|
361
|
+
export declare interface LocalVariablesResponse {
|
|
362
|
+
/** Contains the metadata about the variables and collections. */
|
|
363
|
+
meta: {
|
|
364
|
+
/** A map of collection IDs to `FigmaCollection` objects. */
|
|
365
|
+
variableCollections: Record<string, FigmaCollection>;
|
|
366
|
+
/** A map of variable IDs to `FigmaVariable` objects. */
|
|
367
|
+
variables: Record<string, FigmaVariable>;
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* The result object returned by the `useMutation` hook.
|
|
373
|
+
* @template TData The type of data returned by the mutation.
|
|
374
|
+
* @template TPayload The type of the payload passed to the mutate function.
|
|
375
|
+
*
|
|
376
|
+
* @typedef {Object} MutationResult
|
|
377
|
+
* @memberof Types
|
|
378
|
+
* @since 1.0.0
|
|
379
|
+
* @property {(payload: TPayload) => Promise<TData | undefined>} mutate A function to trigger the mutation.
|
|
380
|
+
* @property {'idle' | 'loading' | 'success' | 'error'} status The current status of the mutation.
|
|
381
|
+
* @property {TData | null} data The data returned by the mutation, or null if the mutation has not completed.
|
|
382
|
+
* @property {Error | null} error The error returned by the mutation, or null if the mutation was successful.
|
|
383
|
+
* @property {boolean} isLoading Whether the mutation is currently loading.
|
|
384
|
+
* @property {boolean} isSuccess Whether the mutation was successful.
|
|
385
|
+
* @property {boolean} isError Whether the mutation resulted in an error.
|
|
386
|
+
*/
|
|
387
|
+
export declare interface MutationResult<TData, TPayload> {
|
|
388
|
+
mutate: (payload: TPayload) => Promise<TData | undefined>;
|
|
389
|
+
status: 'idle' | 'loading' | 'success' | 'error';
|
|
390
|
+
data: TData | null;
|
|
391
|
+
error: Error | null;
|
|
392
|
+
isLoading: boolean;
|
|
393
|
+
isSuccess: boolean;
|
|
394
|
+
isError: boolean;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Represents the state of a mutation operation.
|
|
399
|
+
* @template TData The type of data returned by the mutation.
|
|
400
|
+
* @template TError The type of error returned by the mutation.
|
|
401
|
+
*
|
|
402
|
+
* @typedef {Object} MutationState
|
|
403
|
+
* @memberof Types
|
|
404
|
+
* @since 1.0.0
|
|
405
|
+
* @property {'idle' | 'loading' | 'success' | 'error'} status The current status of the mutation.
|
|
406
|
+
* @property {TData | null} data The data returned by the mutation, or null if the mutation has not completed.
|
|
407
|
+
* @property {Error | null} error The error returned by the mutation, or null if the mutation was successful.
|
|
408
|
+
*/
|
|
409
|
+
export declare interface MutationState<TData> {
|
|
410
|
+
status: 'idle' | 'loading' | 'success' | 'error';
|
|
411
|
+
data: TData | null;
|
|
412
|
+
error: Error | null;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* @fileoverview TypeScript type definitions for the Figma Variables REST API.
|
|
417
|
+
* These types match the official Figma API specification for variables, collections, and modes.
|
|
418
|
+
* @see {@link https://www.figma.com/developers/api#variables|Figma Variables API Documentation}
|
|
419
|
+
* @since 1.0.0
|
|
420
|
+
*/
|
|
421
|
+
/**
|
|
422
|
+
* The resolved type of a Figma variable.
|
|
423
|
+
* Determines what kind of value the variable can hold.
|
|
424
|
+
*
|
|
425
|
+
* @typedef {string} ResolvedType
|
|
426
|
+
* @memberof Types
|
|
427
|
+
* @since 1.0.0
|
|
428
|
+
* @see {@link https://www.figma.com/developers/api#variable-object|Figma Variable Object}
|
|
429
|
+
*/
|
|
430
|
+
export declare type ResolvedType = 'BOOLEAN' | 'FLOAT' | 'STRING' | 'COLOR';
|
|
431
|
+
|
|
432
|
+
declare type UpdateVariableArgs = {
|
|
433
|
+
variableId: string;
|
|
434
|
+
payload: UpdateVariablePayload;
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* The payload for the `updateVariable` function.
|
|
439
|
+
* All properties are optional.
|
|
440
|
+
*
|
|
441
|
+
* @typedef {Object} UpdateVariablePayload
|
|
442
|
+
* @memberof Types
|
|
443
|
+
* @since 1.0.0
|
|
444
|
+
* @see {@link https://www.figma.com/developers/api#patch-variables|Figma API - Update Variable}
|
|
445
|
+
* @property {string} [name] The new name for the variable.
|
|
446
|
+
* @property {string} [description] The new description for the variable.
|
|
447
|
+
* @property {boolean} [hiddenFromPublishing] The new hidden status for the variable.
|
|
448
|
+
* @property {VariableScope[]} [scopes] The new scopes for the variable.
|
|
449
|
+
* @property {Record<string, string>} [codeSyntax] The new code syntax for the variable.
|
|
450
|
+
* @property {Record<string, VariableValue>} [valuesByMode] New values for the variable by mode ID.
|
|
451
|
+
*/
|
|
452
|
+
export declare interface UpdateVariablePayload {
|
|
453
|
+
/** The new name for the variable. */
|
|
454
|
+
name?: string;
|
|
455
|
+
/** The new description for the variable. */
|
|
456
|
+
description?: string;
|
|
457
|
+
/** The new hidden status for the variable. */
|
|
458
|
+
hiddenFromPublishing?: boolean;
|
|
459
|
+
/** The new scopes for the variable. */
|
|
460
|
+
scopes?: VariableScope[];
|
|
461
|
+
/** The new code syntax for the variable. */
|
|
462
|
+
codeSyntax?: Record<string, string>;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Updates multiple variables in the Figma file in a single request.
|
|
467
|
+
*
|
|
468
|
+
* This hook provides a stateful API to perform a bulk update, returning the mutation's
|
|
469
|
+
* current state including `isLoading`, `isSuccess`, and `isError`.
|
|
470
|
+
*
|
|
471
|
+
* @function useBulkUpdateVariables
|
|
472
|
+
* @memberof Hooks
|
|
473
|
+
* @since 1.0.0
|
|
474
|
+
* @returns {MutationResult<any, BulkUpdatePayload>} The mutation object with state and trigger function.
|
|
475
|
+
* @see {@link https://www.figma.com/developers/api#post-variables|Figma Variables API - Bulk Update Variables}
|
|
476
|
+
* @see {@link useMutation} - The underlying mutation hook
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* ```tsx
|
|
480
|
+
* import { useBulkUpdateVariables } from '@figma-vars/hooks';
|
|
481
|
+
*
|
|
482
|
+
* function BulkVariableEditor() {
|
|
483
|
+
* const { mutate, isLoading, isSuccess, error } = useBulkUpdateVariables();
|
|
484
|
+
*
|
|
485
|
+
* const handleBulkUpdate = () => {
|
|
486
|
+
* mutate({
|
|
487
|
+
* variableIds: ['VariableID:123:456', 'VariableID:123:457'],
|
|
488
|
+
* variableCollectionId: 'VariableCollectionId:123:456',
|
|
489
|
+
* updates: {
|
|
490
|
+
* 'VariableID:123:456': {
|
|
491
|
+
* name: 'Primary Color Updated',
|
|
492
|
+
* description: 'Updated primary brand color'
|
|
493
|
+
* },
|
|
494
|
+
* 'VariableID:123:457': {
|
|
495
|
+
* name: 'Secondary Color Updated',
|
|
496
|
+
* description: 'Updated secondary brand color'
|
|
497
|
+
* }
|
|
498
|
+
* }
|
|
499
|
+
* });
|
|
500
|
+
* };
|
|
501
|
+
*
|
|
502
|
+
* if (isLoading) return <div>Updating variables...</div>;
|
|
503
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
504
|
+
* if (isSuccess) return <div>Variables updated successfully!</div>;
|
|
505
|
+
*
|
|
506
|
+
* return <button onClick={handleBulkUpdate}>Update All Variables</button>;
|
|
507
|
+
* }
|
|
508
|
+
* ```
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```tsx
|
|
512
|
+
* // Bulk update color variables with new values
|
|
513
|
+
* const { mutate } = useBulkUpdateVariables();
|
|
514
|
+
*
|
|
515
|
+
* mutate({
|
|
516
|
+
* variableIds: ['VariableID:123:456', 'VariableID:123:457'],
|
|
517
|
+
* variableCollectionId: 'VariableCollectionId:123:456',
|
|
518
|
+
* updates: {
|
|
519
|
+
* 'VariableID:123:456': {
|
|
520
|
+
* valuesByMode: {
|
|
521
|
+
* '42:0': { r: 0.2, g: 0.4, b: 0.8, a: 1 }
|
|
522
|
+
* }
|
|
523
|
+
* },
|
|
524
|
+
* 'VariableID:123:457': {
|
|
525
|
+
* valuesByMode: {
|
|
526
|
+
* '42:0': { r: 0.8, g: 0.4, b: 0.2, a: 1 }
|
|
527
|
+
* }
|
|
528
|
+
* }
|
|
529
|
+
* }
|
|
530
|
+
* });
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
533
|
+
export declare const useBulkUpdateVariables: () => MutationResult_2<any, BulkUpdatePayload>;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Creates a new variable in the Figma file.
|
|
537
|
+
*
|
|
538
|
+
* This hook provides a stateful API to create a new variable, returning the mutation's
|
|
539
|
+
* current state including `isLoading`, `isSuccess`, `isError`, and the created data.
|
|
540
|
+
*
|
|
541
|
+
* @function useCreateVariable
|
|
542
|
+
* @memberof Hooks
|
|
543
|
+
* @since 1.0.0
|
|
544
|
+
* @returns {MutationResult<any, CreateVariablePayload>} The mutation object with state and trigger function.
|
|
545
|
+
* @see {@link https://www.figma.com/developers/api#post-variables|Figma Variables API - Create Variable}
|
|
546
|
+
* @see {@link useMutation} - The underlying mutation hook
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```tsx
|
|
550
|
+
* import { useCreateVariable } from '@figma-vars/hooks';
|
|
551
|
+
*
|
|
552
|
+
* function VariableCreator() {
|
|
553
|
+
* const { mutate, isLoading, isSuccess, error, data } = useCreateVariable();
|
|
554
|
+
*
|
|
555
|
+
* const handleCreate = () => {
|
|
556
|
+
* mutate({
|
|
557
|
+
* name: 'Primary Color',
|
|
558
|
+
* variableCollectionId: 'VariableCollectionId:123:456',
|
|
559
|
+
* resolvedType: 'COLOR',
|
|
560
|
+
* valuesByMode: {
|
|
561
|
+
* '42:0': { r: 0.2, g: 0.4, b: 0.8, a: 1 }
|
|
562
|
+
* }
|
|
563
|
+
* });
|
|
564
|
+
* };
|
|
565
|
+
*
|
|
566
|
+
* if (isLoading) return <div>Creating variable...</div>;
|
|
567
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
568
|
+
* if (isSuccess) return <div>Variable created: {data?.name}</div>;
|
|
569
|
+
*
|
|
570
|
+
* return <button onClick={handleCreate}>Create Variable</button>;
|
|
571
|
+
* }
|
|
572
|
+
* ```
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```tsx
|
|
576
|
+
* // Create a string variable
|
|
577
|
+
* const { mutate } = useCreateVariable();
|
|
578
|
+
*
|
|
579
|
+
* mutate({
|
|
580
|
+
* name: 'Button Text',
|
|
581
|
+
* variableCollectionId: 'VariableCollectionId:123:456',
|
|
582
|
+
* resolvedType: 'STRING',
|
|
583
|
+
* description: 'Default button text content',
|
|
584
|
+
* valuesByMode: {
|
|
585
|
+
* '42:0': 'Click me'
|
|
586
|
+
* },
|
|
587
|
+
* scopes: ['TEXT_CONTENT']
|
|
588
|
+
* });
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
export declare const useCreateVariable: () => MutationResult_2<any, CreateVariablePayload>;
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Deletes a variable from the Figma file by its ID.
|
|
595
|
+
*
|
|
596
|
+
* This hook provides a stateful API to delete a variable, returning the mutation's
|
|
597
|
+
* current state including `isLoading`, `isSuccess`, and `isError`.
|
|
598
|
+
*
|
|
599
|
+
* @function useDeleteVariable
|
|
600
|
+
* @memberof Hooks
|
|
601
|
+
* @since 1.0.0
|
|
602
|
+
* @returns {MutationResult<void, string>} The mutation object with state and trigger function.
|
|
603
|
+
* @see {@link https://www.figma.com/developers/api#delete-variables|Figma Variables API - Delete Variable}
|
|
604
|
+
* @see {@link useMutation} - The underlying mutation hook
|
|
605
|
+
*
|
|
606
|
+
* @example
|
|
607
|
+
* ```tsx
|
|
608
|
+
* import { useDeleteVariable } from './useDeleteVariable';
|
|
609
|
+
*
|
|
610
|
+
* function VariableDeleter({ variableId }) {
|
|
611
|
+
* const { mutate, isLoading, isSuccess, error } = useDeleteVariable();
|
|
612
|
+
*
|
|
613
|
+
* const handleDelete = () => {
|
|
614
|
+
* if (confirm('Are you sure you want to delete this variable?')) {
|
|
615
|
+
* mutate(variableId);
|
|
616
|
+
* }
|
|
617
|
+
* };
|
|
618
|
+
*
|
|
619
|
+
* if (isLoading) return <div>Deleting variable...</div>;
|
|
620
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
621
|
+
* if (isSuccess) return <div>Variable deleted successfully!</div>;
|
|
622
|
+
*
|
|
623
|
+
* return <button onClick={handleDelete}>Delete Variable</button>;
|
|
624
|
+
* }
|
|
625
|
+
* ```
|
|
626
|
+
*
|
|
627
|
+
* @example
|
|
628
|
+
* ```tsx
|
|
629
|
+
* // Delete a variable by ID
|
|
630
|
+
* const { mutate, isLoading } = useDeleteVariable();
|
|
631
|
+
*
|
|
632
|
+
* const deleteVariable = (id: string) => {
|
|
633
|
+
* mutate(id); // Pass the variable ID directly
|
|
634
|
+
* };
|
|
635
|
+
*
|
|
636
|
+
* // Usage
|
|
637
|
+
* deleteVariable('VariableID:123:456');
|
|
638
|
+
* ```
|
|
639
|
+
*/
|
|
640
|
+
export declare const useDeleteVariable: () => MutationResult_2<any, string>;
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Retrieves the Figma API token from the FigmaVarsProvider.
|
|
644
|
+
* This hook must be used within a component wrapped by FigmaVarsProvider.
|
|
645
|
+
*
|
|
646
|
+
* @function useFigmaToken
|
|
647
|
+
* @memberof Hooks
|
|
648
|
+
* @since 1.0.0
|
|
649
|
+
* @returns {string | null} The Figma Personal Access Token, or `null` if it has not been provided.
|
|
650
|
+
* @see {@link https://www.figma.com/developers/api#authentication|Figma API Authentication}
|
|
651
|
+
* @see {@link FigmaVarsProvider} - The provider component that supplies the token
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
* ```tsx
|
|
655
|
+
* import { useFigmaToken } from './useFigmaToken';
|
|
656
|
+
*
|
|
657
|
+
* function CustomAPIComponent() {
|
|
658
|
+
* const figmaToken = useFigmaToken();
|
|
659
|
+
*
|
|
660
|
+
* const makeCustomAPICall = async () => {
|
|
661
|
+
* if (!figmaToken) {
|
|
662
|
+
* console.error('No Figma token available');
|
|
663
|
+
* return;
|
|
664
|
+
* }
|
|
665
|
+
*
|
|
666
|
+
* // Use token for custom API calls
|
|
667
|
+
* const response = await fetch('https://api.figma.com/v1/me', {
|
|
668
|
+
* headers: {
|
|
669
|
+
* 'X-FIGMA-TOKEN': figmaToken
|
|
670
|
+
* }
|
|
671
|
+
* });
|
|
672
|
+
* };
|
|
673
|
+
*
|
|
674
|
+
* return (
|
|
675
|
+
* <div>
|
|
676
|
+
* {figmaToken ? 'Token available' : 'No token provided'}
|
|
677
|
+
* </div>
|
|
678
|
+
* );
|
|
679
|
+
* }
|
|
680
|
+
* ```
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* ```tsx
|
|
684
|
+
* // Check token availability before making API calls
|
|
685
|
+
* const MyComponent = () => {
|
|
686
|
+
* const figmaToken = useFigmaToken();
|
|
687
|
+
*
|
|
688
|
+
* if (!figmaToken) {
|
|
689
|
+
* return <div>Please provide a Figma token</div>;
|
|
690
|
+
* }
|
|
691
|
+
*
|
|
692
|
+
* return <div>Ready to interact with Figma API</div>;
|
|
693
|
+
* };
|
|
694
|
+
* ```
|
|
695
|
+
*/
|
|
696
|
+
export declare const useFigmaToken: () => string | null;
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Updates an existing Figma variable.
|
|
700
|
+
*
|
|
701
|
+
* This hook provides a stateful API to update a variable, returning the mutation's
|
|
702
|
+
* current state including `isLoading`, `isSuccess`, `isError`, and the updated data.
|
|
703
|
+
*
|
|
704
|
+
* @function useUpdateVariable
|
|
705
|
+
* @memberof Hooks
|
|
706
|
+
* @since 1.0.0
|
|
707
|
+
* @returns {MutationResult<any, UpdateVariableArgs>} The mutation object with state and trigger function.
|
|
708
|
+
* @see {@link https://www.figma.com/developers/api#put-variables|Figma Variables API - Update Variable}
|
|
709
|
+
* @see {@link useMutation} - The underlying mutation hook
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* ```tsx
|
|
713
|
+
* import { useUpdateVariable } from '@figma-vars/hooks';
|
|
714
|
+
*
|
|
715
|
+
* function VariableEditor() {
|
|
716
|
+
* const { mutate, isLoading, isSuccess, error } = useUpdateVariable();
|
|
717
|
+
*
|
|
718
|
+
* const handleUpdate = () => {
|
|
719
|
+
* mutate({
|
|
720
|
+
* variableId: 'VariableID:123:456',
|
|
721
|
+
* payload: {
|
|
722
|
+
* name: 'Updated Variable Name',
|
|
723
|
+
* description: 'Updated description'
|
|
724
|
+
* }
|
|
725
|
+
* });
|
|
726
|
+
* };
|
|
727
|
+
*
|
|
728
|
+
* if (isLoading) return <div>Updating variable...</div>;
|
|
729
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
730
|
+
* if (isSuccess) return <div>Variable updated successfully!</div>;
|
|
731
|
+
*
|
|
732
|
+
* return <button onClick={handleUpdate}>Update Variable</button>;
|
|
733
|
+
* }
|
|
734
|
+
* ```
|
|
735
|
+
*
|
|
736
|
+
* @example
|
|
737
|
+
* ```tsx
|
|
738
|
+
* // Update variable with new values
|
|
739
|
+
* const { mutate } = useUpdateVariable();
|
|
740
|
+
*
|
|
741
|
+
* mutate({
|
|
742
|
+
* variableId: 'VariableID:123:456',
|
|
743
|
+
* payload: {
|
|
744
|
+
* name: 'Primary Color',
|
|
745
|
+
* description: 'Main brand color',
|
|
746
|
+
* valuesByMode: {
|
|
747
|
+
* '42:0': { r: 0.2, g: 0.4, b: 0.8, a: 1 }
|
|
748
|
+
* }
|
|
749
|
+
* }
|
|
750
|
+
* });
|
|
751
|
+
* ```
|
|
752
|
+
*/
|
|
753
|
+
export declare const useUpdateVariable: () => MutationResult_2<unknown, UpdateVariableArgs>;
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* A memoized selector hook to access variable collections from the data fetched by `useVariables`.
|
|
757
|
+
*
|
|
758
|
+
* This hook is a lightweight, performant way to get only collection data. It avoids
|
|
759
|
+
* unnecessary re-renders in components that only care about collections, as it will only
|
|
760
|
+
* update when the collection data itself changes.
|
|
761
|
+
*
|
|
762
|
+
* @returns {{collections: FigmaCollection[], collectionsById: Record<string, FigmaCollection>}} An object containing the collections in different formats.
|
|
763
|
+
*
|
|
764
|
+
* @example
|
|
765
|
+
* ```tsx
|
|
766
|
+
* const { collectionsById } = useVariableCollections();
|
|
767
|
+
* const collection = collectionsById['VariableCollectionId:123:456'];
|
|
768
|
+
*
|
|
769
|
+
* if (!collection) return <div>Collection not found.</div>;
|
|
770
|
+
*
|
|
771
|
+
* return <div>{collection.name}</div>
|
|
772
|
+
* ```
|
|
773
|
+
*/
|
|
774
|
+
export declare const useVariableCollections: () => {
|
|
775
|
+
collections: FigmaCollection[];
|
|
776
|
+
collectionsById: Record<string, FigmaCollection>;
|
|
777
|
+
};
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* A memoized selector hook to access and process variable modes from the data fetched by `useVariables`.
|
|
781
|
+
*
|
|
782
|
+
* This hook is a lightweight, performant way to get only mode data. It avoids
|
|
783
|
+
* unnecessary re-renders in components that only care about modes, as it will only
|
|
784
|
+
* update when the mode data itself changes. It provides modes in several useful formats.
|
|
785
|
+
*
|
|
786
|
+
* @returns {UseVariableModesResult} An object containing the modes in different formats.
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
789
|
+
* ```tsx
|
|
790
|
+
* const { modesById, modesByCollectionId } = useVariableModes();
|
|
791
|
+
* const lightMode = modesById['42:0'];
|
|
792
|
+
* const collectionModes = modesByCollectionId['VariableCollectionId:123:456'];
|
|
793
|
+
*
|
|
794
|
+
* if (!lightMode) return <div>Mode not found.</div>;
|
|
795
|
+
*
|
|
796
|
+
* return <div>Mode: {lightMode.name}</div>
|
|
797
|
+
* ```
|
|
798
|
+
*/
|
|
799
|
+
export declare const useVariableModes: () => UseVariableModesResult;
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* The return type for the `useVariableModes` hook.
|
|
803
|
+
* Provides multiple ways to access and organize variable modes from Figma collections.
|
|
804
|
+
*
|
|
805
|
+
* @typedef {Object} UseVariableModesResult
|
|
806
|
+
* @memberof Types
|
|
807
|
+
* @since 1.0.0
|
|
808
|
+
* @see {@link useVariableModes} - The hook that returns this type
|
|
809
|
+
* @property {VariableMode[]} modes A flat array of all modes across all collections.
|
|
810
|
+
* @property {Record<string, VariableMode[]>} modesByCollectionId A map of collection IDs to an array of modes belonging to that collection.
|
|
811
|
+
* @property {Record<string, VariableMode>} modesById A map of mode IDs to the corresponding mode object for quick lookups.
|
|
812
|
+
*/
|
|
813
|
+
export declare interface UseVariableModesResult {
|
|
814
|
+
/** A flat array of all modes across all collections. */
|
|
815
|
+
modes: VariableMode[];
|
|
816
|
+
/** A map of collection IDs to an array of modes belonging to that collection. */
|
|
817
|
+
modesByCollectionId: Record<string, VariableMode[]>;
|
|
818
|
+
/** A map of mode IDs to the corresponding mode object for quick lookups. */
|
|
819
|
+
modesById: Record<string, VariableMode>;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Fetches all local variables, collections, and modes for the file specified in the `FigmaVarsProvider`.
|
|
824
|
+
* This is the primary data-fetching hook and serves as the foundation for other hooks like `useVariableCollections` and `useVariableModes`.
|
|
825
|
+
*
|
|
826
|
+
* "Local variables" are all variables and collections defined in the current file.
|
|
827
|
+
*
|
|
828
|
+
* It uses `swr` for efficient data fetching, caching, and revalidation.
|
|
829
|
+
*
|
|
830
|
+
* @returns {{data: LocalVariablesResponse | undefined, isLoading: boolean, isValidating: boolean, error: Error | undefined}} The response from `useSWR` for the local variables endpoint.
|
|
831
|
+
* @see {@link https://www.figma.com/developers/api#get-local-variables-v1|Figma Variables API Documentation}
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
* ```tsx
|
|
835
|
+
* const { data, isLoading, error } = useVariables();
|
|
836
|
+
*
|
|
837
|
+
* if (isLoading) return <div>Loading variables...</div>;
|
|
838
|
+
* if (error) return <div>Error fetching variables: {error.message}</div>;
|
|
839
|
+
*
|
|
840
|
+
* const collections = data ? Object.values(data.meta.variableCollections) : [];
|
|
841
|
+
* console.log(collections);
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
844
|
+
export declare const useVariables: () => {
|
|
845
|
+
data: LocalVariablesResponse | undefined;
|
|
846
|
+
isLoading: boolean;
|
|
847
|
+
isValidating: boolean;
|
|
848
|
+
error: any;
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
/* Excluded from this release type: VariableAction */
|
|
852
|
+
|
|
853
|
+
/**
|
|
854
|
+
* Represents an alias to another Figma variable.
|
|
855
|
+
* This is used when a variable's value is set to reference another variable.
|
|
856
|
+
*
|
|
857
|
+
* @typedef {Object} VariableAlias
|
|
858
|
+
* @memberof Types
|
|
859
|
+
* @since 1.0.0
|
|
860
|
+
* @see {@link https://www.figma.com/developers/api#variable-object|Figma Variable Object}
|
|
861
|
+
* @property {string} type The type of the value, indicating it's a variable alias.
|
|
862
|
+
* @property {string} id The ID of the variable being referenced.
|
|
863
|
+
*/
|
|
864
|
+
export declare interface VariableAlias {
|
|
865
|
+
/** The type of the value, indicating it's a variable alias. */
|
|
866
|
+
type: 'VARIABLE_ALIAS';
|
|
867
|
+
/** The ID of the variable being referenced. */
|
|
868
|
+
id: string;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/* Excluded from this release type: VariableChange */
|
|
872
|
+
|
|
873
|
+
/* Excluded from this release type: VariableCollectionChange */
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Represents a single mode within a variable collection.
|
|
877
|
+
*
|
|
878
|
+
* @typedef {Object} VariableMode
|
|
879
|
+
* @memberof Types
|
|
880
|
+
* @since 1.0.0
|
|
881
|
+
* @see {@link https://www.figma.com/developers/api#variable-collection-object|Figma Variable Collection Object}
|
|
882
|
+
* @property {string} modeId The unique identifier for the mode.
|
|
883
|
+
* @property {string} name The name of the mode (e.g., "Light", "Dark").
|
|
884
|
+
*/
|
|
885
|
+
export declare interface VariableMode {
|
|
886
|
+
/** The unique identifier for the mode. */
|
|
887
|
+
modeId: string;
|
|
888
|
+
/** The name of the mode (e.g., "Light", "Dark"). */
|
|
889
|
+
name: string;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/* Excluded from this release type: VariableModeChange */
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* A change to a variable's value in a specific mode in a bulk update.
|
|
896
|
+
*
|
|
897
|
+
* @typedef {Object} VariableModeValue
|
|
898
|
+
* @memberof Types
|
|
899
|
+
* @since 1.0.0
|
|
900
|
+
* @see {@link https://www.figma.com/developers/api#patch-variables|Figma API - Update Variable Value}
|
|
901
|
+
* @property {string} variableId The ID of the variable to update.
|
|
902
|
+
* @property {string} modeId The ID of the mode to update.
|
|
903
|
+
* @property {VariableValue} value The new value for the variable in this mode.
|
|
904
|
+
*/
|
|
905
|
+
export declare interface VariableModeValue {
|
|
906
|
+
/** The ID of the variable to update. */
|
|
907
|
+
variableId: string;
|
|
908
|
+
/** The ID of the mode to update. */
|
|
909
|
+
modeId: string;
|
|
910
|
+
/** The new value for the variable in this mode. */
|
|
911
|
+
value: VariableValue;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* The scopes where a Figma variable can be applied.
|
|
916
|
+
* `ALL_SCOPES` is a general-purpose scope. Other values restrict the variable to specific properties.
|
|
917
|
+
*
|
|
918
|
+
* @typedef {string} VariableScope
|
|
919
|
+
* @memberof Types
|
|
920
|
+
* @since 1.0.0
|
|
921
|
+
* @see {@link https://www.figma.com/developers/api#variable-object|Figma Variable Object}
|
|
922
|
+
*/
|
|
923
|
+
export declare type VariableScope = 'ALL_SCOPES' | 'TEXT_CONTENT' | 'CORNER_RADIUS' | 'WIDTH_HEIGHT' | 'GAP' | 'STROKE_FLOAT' | 'OPACITY' | 'EFFECT_FLOAT' | 'FONT_WEIGHT' | 'FONT_SIZE' | 'LINE_HEIGHT' | 'LETTER_SPACING' | 'PARAGRAPH_SPACING' | 'PARAGRAPH_INDENT' | 'FONT_FAMILY' | 'FONT_STYLE' | 'FONT_VARIATIONS' | 'ALL_FILLS' | 'FRAME_FILL' | 'SHAPE_FILL' | 'TEXT_FILL' | 'STROKE_COLOR' | 'EFFECT_COLOR';
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* The possible value types for a variable in a specific mode.
|
|
927
|
+
* It can be a primitive value, a color object, or an alias to another variable.
|
|
928
|
+
*
|
|
929
|
+
* @typedef {(string|boolean|number|Color|VariableAlias)} VariableValue
|
|
930
|
+
* @memberof Types
|
|
931
|
+
* @since 1.0.0
|
|
932
|
+
* @see {@link https://www.figma.com/developers/api#variable-object|Figma Variable Object}
|
|
933
|
+
*/
|
|
934
|
+
export declare type VariableValue = string | boolean | number | Color | VariableAlias;
|
|
935
|
+
|
|
936
|
+
export { }
|