@figma-vars/hooks 1.0.3

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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +133 -0
  3. package/package.json +69 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Mark Learst
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the β€œSoftware”), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED β€œAS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # figma-vars-hooks
2
+
3
+ A modern, type-safe React hooks & utilities library for the [Figma Variables API](https://www.figma.com/developers/api#variables). Fetch, update, and sync design tokens between Figma and your app, Storybook, or design system dashboard.
4
+
5
+ ---
6
+
7
+ ## πŸš€ Features
8
+
9
+ - **React 19+ hooks** for fetching and updating Figma variables, collections, and modes
10
+ - **Mutation utilities** for creating, updating, and deleting variables
11
+ - **TypeScript-first**: strict, ergonomic types for all API surfaces
12
+ - **Storybook/Next.js ready** for live token dashboards
13
+ - **Experimental/advanced hooks** for power users
14
+
15
+ ---
16
+
17
+ ## πŸ“¦ Install
18
+
19
+ ```bash
20
+ npm install figma-vars-hooks
21
+ # or
22
+ yarn add figma-vars-hooks
23
+ # or
24
+ pnpm add figma-vars-hooks
25
+ ```
26
+
27
+ > **Peer dependency:** React 19+
28
+
29
+ ---
30
+
31
+ ## πŸ› οΈ Setup: Figma API Token
32
+
33
+ Set your Figma Personal Access Token as an environment variable in your app (Vite example):
34
+
35
+ ```env
36
+ VITE_FIGMA_TOKEN=your-figma-token-here
37
+ ```
38
+
39
+ ---
40
+
41
+ ## ⚑ Quick Start Example
42
+
43
+ ```tsx
44
+ import { useVariables } from 'figma-vars-hooks'
45
+
46
+ export function TokenList({ fileKey }: { fileKey: string }) {
47
+ const { variables, loading, error, refresh } = useVariables(fileKey)
48
+
49
+ if (loading) return <div>Loading…</div>
50
+ if (error) return <div>Error: {error.message}</div>
51
+
52
+ return (
53
+ <ul>
54
+ {variables?.map((v) => (
55
+ <li key={v.id}>
56
+ {v.name}: {v.value}
57
+ </li>
58
+ ))}
59
+ <button onClick={refresh}>Refresh</button>
60
+ </ul>
61
+ )
62
+ }
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 🧩 API Reference
68
+
69
+ ### Core Hooks
70
+
71
+ - `useFigmaToken()` – Get the current Figma API token
72
+ - `useVariables(fileKey, options?)` – Fetch variables for a Figma file (with polling/refresh)
73
+ - `useVariableCollections(fileKey)` – Fetch variable collections for a file
74
+ - `useVariableModes(collectionId)` – Fetch variable modes for a collection
75
+
76
+ ### Mutations
77
+
78
+ - `createVariable(fileKey, variableData)` – Create a new variable
79
+ - `updateVariable(fileKey, variableId, newData)` – Update a variable
80
+ - `deleteVariable(fileKey, variableId)` – Delete a variable
81
+ - `updateVariableValues(variableId, values)` – Update variable values across modes
82
+
83
+ ### Utilities
84
+
85
+ - `filterVariables(variables, { type?, name? })` – Filter variables by type/name
86
+ - `VariablesCache` – Simple in-memory cache for variable lists
87
+ - `fetchHelpers`, `authHelpers` – Internal helpers (advanced)
88
+
89
+ ### Types
90
+
91
+ All types are exported from `figma-vars-hooks/types` (see `src/types/`).
92
+
93
+ ---
94
+
95
+ ## πŸ§ͺ Experimental/Advanced Hooks
96
+
97
+ - `useVariableAliases` – Manage local variable aliases (not in Figma API)
98
+ - `useVariableBindings` – Bind variables to UI components (not in Figma API)
99
+ - `usePublishVars`, `useSync` – Placeholders for future publish/sync features
100
+
101
+ > These are opt-in and may changeβ€”see `src/experimental/` for details.
102
+
103
+ ---
104
+
105
+ ## πŸ“š Storybook & Next.js Integration
106
+
107
+ Use these hooks in your Storybook stories or Next.js pages to build live design token dashboards. Example:
108
+
109
+ ```tsx
110
+ // In a Storybook story
111
+ import { useVariables } from 'figma-vars-hooks'
112
+
113
+ export const TokensStory = () => {
114
+ const { variables } = useVariables('YOUR_FILE_KEY')
115
+ return <pre>{JSON.stringify(variables, null, 2)}</pre>
116
+ }
117
+ ```
118
+
119
+ ---
120
+
121
+ ## πŸ“ Contributing
122
+
123
+ PRs and issues welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
124
+
125
+ ## πŸ“„ License
126
+
127
+ MIT
128
+
129
+ ---
130
+
131
+ ## πŸ™ Credits
132
+
133
+ Built by Mark Learst and contributors. Inspired by the Figma community and the need for seamless design token workflows.
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@figma-vars/hooks",
3
+ "version": "1.0.3",
4
+ "description": "Typed React hooks for managing Figma Variables, modes, tokens, and bindings via API.",
5
+ "author": "Mark Learst",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.mjs",
10
+ "types": "dist/index.d.ts",
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "keywords": [
15
+ "figma",
16
+ "figma variables",
17
+ "figma tokens",
18
+ "react",
19
+ "react hooks",
20
+ "design tokens",
21
+ "theme",
22
+ "storybook",
23
+ "vite",
24
+ "typescript",
25
+ "design system"
26
+ ],
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/marklearst/figma-vars-hooks"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/marklearst/figma-vars-hooks/issues"
33
+ },
34
+ "homepage": "https://github.com/marklearst/figma-vars-hooks#readme",
35
+ "engines": {
36
+ "node": ">=18.0.0"
37
+ },
38
+ "peerDependencies": {
39
+ "react": ">=19.0.0",
40
+ "react-dom": ">=19.0.0"
41
+ },
42
+ "sideEffects": false,
43
+ "exports": {
44
+ ".": {
45
+ "import": "./dist/index.mjs",
46
+ "require": "./dist/index.js",
47
+ "types": "./dist/index.d.ts"
48
+ }
49
+ },
50
+ "funding": {
51
+ "type": "github",
52
+ "url": "https://github.com/sponsors/marklearst"
53
+ },
54
+ "devDependencies": {
55
+ "@types/react": "^19.1.8",
56
+ "@types/react-dom": "^19.1.6",
57
+ "react": "^19.1.0",
58
+ "react-dom": "^19.1.0",
59
+ "typescript": "~5.8.3",
60
+ "vite": "^6.3.5",
61
+ "vite-plugin-dts": "^4.5.4",
62
+ "vite-tsconfig-paths": "^5.1.4"
63
+ },
64
+ "scripts": {
65
+ "dev": "vite",
66
+ "build": "tsc && vite build",
67
+ "preview": "vite preview"
68
+ }
69
+ }