Socket
Socket
Sign inDemoInstall

@figma-export/output-components-as-svgr

Package Overview
Dependencies
88
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @figma-export/output-components-as-svgr

Outputter for @figma-export that exports components as React components using svgr


Version published
Weekly downloads
2.9K
increased by38.19%
Maintainers
1
Install size
11.9 MB
Created
Weekly downloads
 

Readme

Source

@figma-export/output-components-as-svgr

Outputter for @figma-export that exports components as React components.

With this outputter you can export all Figma components as React components into the specified output folder.

This is a sample of the output from this Figma file:

$ tree output/

# output
# ├── icons
# │   ├── FigmaArrow.jsx
# │   ├── FigmaExport.jsx
# │   ├── FigmaLogo.jsx
# │   └── index.js
# └── unit-test
#     ├── figma
#     │   ├── logo
#     │   │   ├── Main.jsx
#     │   │   ├── MainBright.jsx
#     │   │   └── index.js
#     │   ├── Logo.jsx
#     │   └── index.js
#     ├── FigmaDefaultLogo.jsx
#     └── index.js

Tip: A figma component named icon/eye will be exported as Eye.jsx inside the icon folder. Another index.js file will be created inside the icon folder and this will export directly the Eye component.

.figmaexportrc.js

You can easily add this outputter to your .figmaexportrc.js:

module.exports = {
    commands: [
        ['components', {
            fileId: 'fzYhvQpqwhZDUImRz431Qo',
            onlyFromPages: ['icons', 'unit-test'],
            outputters: [
                require('@figma-export/output-components-as-svgr')({
                    output: './output'
                })
            ]
        }],
    ]
}

output is mandatory.

getDirname, getComponentName, getComponentFilename, getFileExtension, getExportTemplate and getSvgrConfig are optional.

const path = require('path');
const { pascalCase } = require('@figma-export/utils');

...

require('@figma-export/output-components-as-svgr')({
    output: './output',
    getDirname: (options) => `${options.pageName}${path.sep}${options.dirname}`,
    getComponentName: (options) => `${pascalCase(options.basename)}`,
    getComponentFilename = (options): string => `${getComponentName(options)}`,
    getFileExtension: (options) => '.jsx',
    getSvgrConfig: (options) => ({}),
    getExportTemplate = (options): string => {
        const reactComponentName = getComponentName(options);
        const reactComponentFilename = `${getComponentFilename(options)}${getFileExtension(options)}`;
        return `export { default as ${reactComponentName} } from './${reactComponentFilename}';`;
    },
})

defaults may change, please refer to ./src/index.ts

getComponentFilename if not set, it will use the same value for getComponentName.

getSvgrConfig is a function that returns the SVGR configuration object.

:warning: @svgr/plugin-jsx

Starting from v7 they removed plugin-jsx from the core so you'll need to install it manually.

npm install --save-dev @svgr/plugin-jsx
// .figmaexportrc.js

...

outputters: [
  require('@figma-export/output-components-as-svgr')({
    output: './output/svgr',
    getSvgrConfig: () => ({
      plugins: ['@svgr/plugin-jsx']
    })
  })
]

...

Install

Using npm:

npm install --save-dev @figma-export/output-components-as-svgr

or using yarn:

yarn add @figma-export/output-components-as-svgr --dev

Keywords

FAQs

Last updated on 25 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc