File tree Expand file tree Collapse file tree 8 files changed +217
-0
lines changed
packages/create-figma-plugin/plugin-templates/ui Expand file tree Collapse file tree 8 files changed +217
-0
lines changed Original file line number Diff line number Diff line change 1+ .DS_Store
2+ * .log
3+ * .css.d.ts
4+ build /
5+ node_modules /
6+ manifest.json
Original file line number Diff line number Diff line change 1+ {
2+ "json.schemas" : [
3+ {
4+ "fileMatch" : [
5+ " package.json"
6+ ],
7+ "url" : " https://yuanqing.github.io/create-figma-plugin/figma-plugin.json"
8+ }
9+ ]
10+ }
Original file line number Diff line number Diff line change 1+ # {{name}}
2+
3+ {{#description}}
4+ > {{description}}
5+
6+ {{/description}}
7+ ## Development guide
8+
9+ * This plugin is built with [ Create Figma Plugin] ( https://yuanqing.github.io/create-figma-plugin/ ) .*
10+
11+ ### Pre-requisites
12+
13+ - [ Node.js] ( https://nodejs.org ) – v14
14+ - [ Figma desktop app] ( https://figma.com/downloads/ )
15+
16+ ### Build the plugin
17+
18+ To build the plugin:
19+
20+ ```
21+ $ npm run build
22+ ```
23+
24+ This will generate a [ ` manifest.json ` ] ( https://figma.com/plugin-docs/manifest/ ) file and a ` build/ ` directory containing a JavaScript bundle for the plugin.
25+
26+ To watch for code changes and rebuild the plugin automatically:
27+
28+ ```
29+ $ npm run watch
30+ ```
31+
32+ ### Install the plugin
33+
34+ In the Figma desktop app:
35+
36+ 1 . Open a Figma document.
37+ 2 . Go to ` Plugins ` → ` Development ` → ` New Plugin… ` .
38+ 3 . Click the ` Click to choose a manifest.json file ` box, and select the ` manifest.json ` file that was generated.
39+
40+ ### Debugging
41+
42+ Use ` console.log ` statements to inspect values in your code.
43+
44+ To open the developer console in the Figma desktop app, go to ` Plugins ` → ` Development ` → ` Open Console ` .
45+
46+ ## See also
47+
48+ - [ Create Figma Plugin docs] ( https://yuanqing.github.io/create-figma-plugin/ )
49+ - [ Storybook] ( https://yuanqing.github.io/create-figma-plugin/ui/ )
50+ - [ Figma plugin API docs] ( https://figma.com/plugin-docs/api/ )
51+ - [ ` figma/plugin-samples ` ] ( https://github.com/figma/plugin-samples )
52+ - [ ` yuanqing/figma-plugins ` ] ( https://github.com/yuanqing/figma-plugins )
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " {{{name}}}" ,
3+ {{#version }}
4+ "version" : " {{{version}}}" ,
5+ {{/version }}
6+ {{#description }}
7+ "description" : " {{{description}}}" ,
8+ {{/description }}
9+ "keywords" : [
10+ " create-figma-plugin" ,
11+ " figma" ,
12+ " figma-plugin"
13+ ],
14+ {{#license }}
15+ "license" : " {{{license}}}" ,
16+ {{/license }}
17+ {{#author }}
18+ "author" : " {{{author}}}" ,
19+ {{/author }}
20+ {{#repositoryUrl }}
21+ "repository" : " {{{repositoryUrl}}}" ,
22+ {{/repositoryUrl }}
23+ "dependencies" : {
24+ "@create-figma-plugin/ui" : " ^{{{versions.ui}}}" ,
25+ "@create-figma-plugin/utilities" : " ^{{{versions.utilities}}}" ,
26+ "preact" : " ^10"
27+ },
28+ "devDependencies" : {
29+ "@create-figma-plugin/build" : " ^{{{versions.build}}}" ,
30+ "@create-figma-plugin/tsconfig" : " ^{{{versions.tsconfig}}}" ,
31+ "@figma/plugin-typings" : " ^1" ,
32+ "typescript" : " ^4"
33+ },
34+ "scripts" : {
35+ "build" : " build-figma-plugin --typecheck --minify" ,
36+ "watch" : " build-figma-plugin --typecheck --watch"
37+ },
38+ "figma-plugin" : {
39+ "id" : " {{{name}}}" ,
40+ {{#displayName }}
41+ "name" : " {{{displayName}}}" ,
42+ {{/displayName }}
43+ "main" : " src/main.ts" ,
44+ "ui" : " src/ui.tsx"
45+ }
46+ }
Original file line number Diff line number Diff line change 1+ import { once , showUI } from '@create-figma-plugin/utilities'
2+
3+ import { CloseHandler , CreateRectanglesHandler } from './types'
4+
5+ export default function ( ) {
6+ once < CreateRectanglesHandler > ( 'CREATE_RECTANGLES' , function ( count : number ) {
7+ const nodes : Array < SceneNode > = [ ]
8+ for ( let i = 0 ; i < count ; i ++ ) {
9+ const rect = figma . createRectangle ( )
10+ rect . x = i * 150
11+ rect . fills = [
12+ {
13+ color : { b : 0 , g : 0.5 , r : 1 } ,
14+ type : 'SOLID'
15+ }
16+ ]
17+ figma . currentPage . appendChild ( rect )
18+ nodes . push ( rect )
19+ }
20+ figma . currentPage . selection = nodes
21+ figma . viewport . scrollAndZoomIntoView ( nodes )
22+ figma . closePlugin ( )
23+ } )
24+ once < CloseHandler > ( 'CLOSE' , function ( ) {
25+ figma . closePlugin ( )
26+ } )
27+ showUI ( {
28+ height : 137 ,
29+ width : 240
30+ } )
31+ }
Original file line number Diff line number Diff line change 1+ import { EventHandler } from '@create-figma-plugin/utilities'
2+
3+ export interface CreateRectanglesHandler extends EventHandler {
4+ name : 'CREATE_RECTANGLES'
5+ handler : ( count : number ) => void
6+ }
7+
8+ export interface CloseHandler extends EventHandler {
9+ name : 'CLOSE'
10+ handler : ( ) => void
11+ }
Original file line number Diff line number Diff line change 1+ import {
2+ Button ,
3+ Columns ,
4+ Container ,
5+ render ,
6+ Text ,
7+ TextboxNumeric ,
8+ VerticalSpace
9+ } from '@create-figma-plugin/ui'
10+ import { emit } from '@create-figma-plugin/utilities'
11+ import { h } from 'preact'
12+ import { useCallback , useState } from 'preact/hooks'
13+
14+ import { CloseHandler , CreateRectanglesHandler } from './types'
15+
16+ function Plugin ( ) {
17+ const [ count , setCount ] = useState < number | null > ( 5 )
18+ const [ countString , setCountString ] = useState ( '5' )
19+ const handleCreateRectanglesClick = useCallback (
20+ function ( ) {
21+ if ( count !== null ) {
22+ emit < CreateRectanglesHandler > ( 'CREATE_RECTANGLES' , count )
23+ }
24+ } ,
25+ [ count ]
26+ )
27+ const handleCloseClick = useCallback ( function ( ) {
28+ emit < CloseHandler > ( 'CLOSE' )
29+ } , [ ] )
30+ return (
31+ < Container >
32+ < VerticalSpace space = "large" />
33+ < Text muted > Count</ Text >
34+ < VerticalSpace space = "small" />
35+ < TextboxNumeric
36+ onNumericValueInput = { setCount }
37+ onValueInput = { setCountString }
38+ value = { countString }
39+ />
40+ < VerticalSpace space = "extraLarge" />
41+ < Columns space = "extraSmall" >
42+ < Button fullWidth onClick = { handleCreateRectanglesClick } >
43+ Create
44+ </ Button >
45+ < Button fullWidth onClick = { handleCloseClick } secondary >
46+ Close
47+ </ Button >
48+ </ Columns >
49+ < VerticalSpace space = "small" />
50+ </ Container >
51+ )
52+ }
53+
54+ export default render ( Plugin )
Original file line number Diff line number Diff line change 1+ {
2+ "extends" : " @create-figma-plugin/tsconfig" ,
3+ "compilerOptions" : {
4+ "typeRoots" : [" node_modules/@figma" , " node_modules/@types" ]
5+ },
6+ "include" : [" src/**/*.ts" , " src/**/*.tsx" ]
7+ }
You can’t perform that action at this time.
0 commit comments