Home

Awesome

Figma Plugin DS Svelte

WORK IN PROGRESS—This is a Svelte version of the Figma Plugin DS specifically for use in creating Figma Plugins. I decided to create this because Svelte seems like a great lightweight approach well suited for creating Figma plugins, and also improves the developer experience when compared to my vanilla JS Figma Plugin DS due to simplified markup.

You can also get started with Figsvelte, a boilerplate for Figma plugins that already has this library setup as a dependency.

Installation

To install into your own Svelte project. npm i -D figma-plugin-ds-svelte

To use

//import the global css which includes Figma color, spacing, and type vars
//also includes a basic set of utility classes
import { GlobalCSS } from 'figma-plugin-ds-svelte';

//import the desired components
import { Button, Input, SelectMenu } from 'figma-plugin-ds-svelte';

Components

All components can accept class props to add global or utility classes to each component


Button

import { Button } from 'figma-plugin-ds-svelte';
<Button on:click={funcName}>Label</Button>
<Button on:click={funcName} variant="secondary">Label</Button>
<Button on:click={funcName} variant="secondary" destructive>Label</Button>
<Button on:click={funcName} disabled>Label</Button>

Props

PropTypeOptions/notes
on:clickFuncAssign a function to execute on click. Ex: on:click={funcName}
variantStringDefault: "primary", Options: "secondary", "tertiary"
disabledBooleanDefault: false
destructiveBooleanDefault: false

Checkbox

import { Checkbox } from 'figma-plugin-ds-svelte';
<Checkbox>Label</Checkbox>
<Checkbox checked>Label</Checkbox>
<Checkbox disabled>Label</Checkbox>

Props

PropTypeOptions/notes
on:changeFuncFuntion to execute on change. Ex: on:change={funcName}
valueBooleanDefault: false;
checkedBooleanDefault: false; You can bind the value when checked to a var. bind:checked={varName}
disabledBooleanDefault: false

Disclosure

import { Disclosure, DisclosureItem } from 'figma-plugin-ds-svelte';
<Disclosure>
  <DisclosureItem title="Item 1" open>Content here</DisclosureItem>
  <DisclosureItem title="Item 2">Content here</DisclosureItem>
  <DisclosureItem title="Item 3">Content here</DisclosureItem>
</Disclosure>

Props

PropTypeOptions/notes
titleStringTitle of disclosure item
openBooleanDefault: false; Only one disclosure item can be opened at once
sectionBooleanDefault: false; Bold section header for disclosure title

Icon

//You need to import the icon component + whatever icons you want to use,
//pass the names of your icon modules to the iconName prop in the Icon component
import { Icon, IconName } from 'figma-plugin-ds-svelte';

//You can also import your own svg icon (32x32) and pass it to the icon component
import SvgName from './src/directory/image.svg';

//Example
import { Icon, IconVisible, IconSpinner } from 'figma-plugin-ds-svelte';
<Icon iconName={IconVisible} color="black"/>
<Icon iconName={IconSpinner} color="blue" spin/>
<Icon iconText="W" color="blue"/>

Props

PropTypeOptions/notes
iconNameVarPass an imported SVG to this prop. iconName={IconImport}
iconTextStringPass a text character to use instead of an icon. Ex: width and height inputs iconText="W"
colorStringPass the name of any Figma color var to this prop. color="blue"
spinBooleanDefault: false; This will rotate the icon in an endless loop.

Icons

IconVar
IconAdjustIconAdjust
IconAlertIconAlert
IconAngleIconAngle
IconArrowLeftRightIconArrowLeftRight
IconUpDownIconUpDown
IconAutoLayoutHorizontalIconAutoLayoutHorizontal
IconAutoLayoutVerticalIconAutoLayoutVertical
IconBackIconBack
IconBlendEmptyIconBlendEmpty
IconBlendIconBlend
IconBreakIconBreak
IconCaretDownIconCaretDown
IconCaretLeftIconCaretLeft
IconCaretRightIconCaretRight
IconCaretUpIconCaretUp
IconCheckIconCheck
IconCloseIconClose
IconComponentIconComponent
IconCornerRadiusIconCornerRadius
IconCornersIconCorners
IconDistributeHorizontalSpacingIconDistributeHorizontalSpacing
IconDistributeVerticalSpacingIconDistributeVerticalSpacing
IconDraftIconDraft
IconEffectsIconEffects
IconEllipsesIconEllipses
IconEyedropperIconEyedropper
IconForwardIconForward
IconFrameIconFrame
IconGroupIconGroup
IconHiddenIconHidden
IconHorizontalPaddingIconHorizontalPadding
IconHyperlinkIconHyperlink
IconImageIconImage
IconInstanceIconInstance
IconKeyIconKey
IconLayoutAlignBottomIconLayoutAlignBottom
IconAlignHorizontalCentersIconAlignHorizontalCenters
IconAlignLeftIconAlignLeft
IconAlignRightIconAlignRight
IconAlignTopIconAlignTop
IconAlignVerticalCentersIconAlignVerticalCenters
IconLayoutGridColumnsIconLayoutGridColumns
IconLayoutGridRowsIconLayoutGridRows
IconLayoutGridUniformIconLayoutGridUniform
IconLibraryIconLibrary
IconLinkBrokenIconLinkBroken
IconLinkConnectedIconLinkConnected
IconListDetailedIconListDetailed
IconListTileIconListTile
IconListIconList
IconLockOffIconLockOff
IconLockOnIconLockOn
IconMinusIconMinus
IconPlayIconPlay
IconPlusIconPlus
IconRandomIconRandom
IconRecentIconRecent
IconResizeToFitIconResizeToFit
IconResolveFilledIconResolveFilled
IconResolveIconResolve
IconReverseIconReverse
IconSearchLargeIconSearchLarge
IconSearchIconSearch
IconSettingsIconSettings
IconShareIconShare
IconSmileyIconSmiley
IconSortAlphaAscIconSortAlphaAsc
IconSortAlphaDscIconSortAlphaDsc
IconSortTopBottomIconSortTopBottom
IconSpacingIconSpacing
IconSpinnerIconSpinner
IconStarOffIconStarOff
IconStarOnIconStarOn
IconStrokeWeightIconStrokeWeight
IconStylesIconStyles
IconSwapIconSwap
IconThemeIconTheme
IconTidyUpGridIconTidyUpGrid
IconTidyUpListHorizontalIconTidyUpListHorizontal
IconTidyUpListVerticalIconTidyUpListVertical
IconTimerIconTimer
IconTrashIconTrash
IconVerticalPaddingIconVerticalPadding
IconVisibleIconVisible
IconWarningLargeIconWarningLarge
IconWarningIconWarning

Icon button

//use this component as you would an Icon, it accepts the same props (except color)
import { IconButton } from 'figma-plugin-ds-svelte';
<IconButton on:click={funcName} iconName={IconVisible}/>
<IconButton on:click={funcName} iconName={IconVisible} selected/>
<IconButton on:click={funcName} iconText="@"/>

Props

PropTypeOptions/notes
on:clickFuncAssign a function to execute on click. Ex: on:click={funcName}
selectedBooleanDefault: false
iconNameStringSee Icon component for usage.
IconTextStringSee Icon component for usage.
spinBooleanSee Icon component for usage.

Input

import { Input } from 'figma-plugin-ds-svelte';

//var to define and store value
var inputValue = 'Default value'; 
<Input bind:value={inputValue}/>
<Input bind:value={inputValue} disabled/>
<Input placeholder="Enter some info..."/>

<!-- You can also pass Icon props to use the icon component inside the input -->
<Input iconName={IconName} />
<Input iconName={IconSpinner} spin placeholder="Fetching data..." />

<!-- Force borders on the input -->
<Input value="Value" borders/>

Props

PropTypeOptions/notes
on:changeFuncFuntion to execute on change. Ex: on:change={funcName}
valueStringValue that will get populated by user or specify predefined value. You can also bind this to a variable.
placeholderStringPlaceholder text.
bordersBooleanDefault: false; Force a border on the input field.
disabledBooleanDefault: false
iconNameVarSee Icon component for usage.
iconTextStringSee Icon component for usage.
spinBooleanSee Icon component for usage.

Labels and sections

import { Label, SectionHeader } from 'figma-plugin-ds-svelte';
<Label>Label name</Label>
<Section>Section name</Section>

Onboarding tip

import { OnboardingTip } from 'figma-plugin-ds-svelte';
<OnboardingTip iconName={IconStyles}>
  Tip text goes here
</OnboardingTip>

Props

PropTypeOptions/notes
iconNameVarSee Icon component for usage.
iconTextStringSee Icon component for usage.
spinBooleanSee Icon component for usage.

Radio button

import { Radio } from 'figma-plugin-ds-svelte';

//use bind:group, with a var to create a radio group and store the value of selected item
//set value if this var to same value as radio item to set initial selection
var radioValue;
<Radio bind:group={radioValue} value="a">Label</Radio>
<Radio bind:group={radioValue} value="b">Label</Radio>

Props

PropTypeOptions/notes
on:changeFuncFuntion to execute on change. Ex: on:change={funcName}
groupVarPass name of var to store selected item from radio group.
valueStringValue of radio item.
disabledBooleanDefault: false

Select menu

import { SelectMenu } from 'figma-plugin-ds-svelte';

//You will need to pass and bind an array of menu items to this
//Note: it is up to you to sort this array however you want
let menuItemArray = [
  { 'value': 'item1', 'label': 'Menu item 1', 'group': null, 'selected': false },
  { 'value': 'item2', 'label': 'Menu item 2 ', 'group': null, 'selected': false }
];

//use bind:value, with a var bind the data of the selected item
var selectedItem;
<SelectMenu bind:menuItems={menuItemArray} bind:value={selectedItem}/>
<SelectMenu bind:menuItems={menuItemArray} bind:value={selectedItem} showGroupLabels/>
<SelectMenu bind:menuItems={menuItemArray} bind:value={selectedItem} iconName={IconBlend}/>
<SelectMenu bind:menuItems={menuItemArray} bind:value={selectedItem} disabled/>

Props

PropTypeOptions/notes
on:changeFuncFunction to execute on change. Ex: on:change={funcName}
menuItemsVarPass in array of menu item objects. See example above for format. If you want to use option groups, update the group keys to a string.
valueVarBind the value of the selected item to a var. Ex: bind:value={selectedItem}
placeholderStringOverride default placeholder text with a string when there is no item selected.
showGroupLabelsBooleanDefault: false; If you are using option groups, this will show the group labels.
disabledBooleanDefault: false
macOSBlinkBooleanDefault: false; Easter egg, old school Mac OS triple blink on select.
iconNameVarSee Icon component for usage.
iconTextStringSee Icon component for usage.

Switch

import { Switch } from 'figma-plugin-ds-svelte';

//use bind:group, with a var to create a radio group and store the value of selected item
//set value if this var to same value as radio item to set initial selection
var switchValue;
<Switch value="value" bind:checked={switchValue}>Label</Switch>

Props

PropTypeOptions/notes
on:changeFuncFuntion to execute on change. Ex: on:change={funcName}
valueBooleanDefault: false;
checkedBooleanDefault: false; You can bind the value when checked to a var. bind:checked={varName}
disabledBooleanDefault: false

Textarea

import { Textarea } from 'figma-plugin-ds-svelte';
<Textarea placeholder="Enter some text"></Textarea>

Props

PropTypeOptions/notes
on:changeFuncFunction to execute on change. Ex: on:change={funcName}
valueStringValue of textarea. Can bind to a variable. Ex: bind:value={someVar}
placeholderStringOverride default placeholder text with a string.
rowsIntDefault: 2; Number of rows (height) to display.
disabledBooleanDefault: false

Type

import { Type } from 'figma-plugin-ds-svelte';
<Type size="large" weight="bold">Content here</Type>

Props

PropTypeOptions/notes
sizeStringDefault: "small"; Also accepts "xsmall","large", "xlarge"
weightStringDefault: "normal"; Also accepts "medium","bold"
colorStringDefault: "black8"; Pass the name of any Figma color var to this prop. color="blue", Default color is white when inverse is true and no value specified
inverseBooleanDefault: false; Optimizes letter-spacing for light on dark applications.

Tokens

Color

NameVarTypeNotes
blue--blueAccentEx: primary button, hyperlinks, focus/selected states
purple--purpleAccentEx: components/instances
hot-pink--hot-pinkAccentEx: smart selection handles
green--greenAccentEx: Toolbar selections
red--redAccentEx: Error
yellow--yellowAccentEx: Caution/warning
black--blackBasic foregroundEx: active states
black8--black8Basic foreground80% black, ex: most common black used in UI text and icons
black8-opaque--black8-opaqueBasic foregroundOpaque version of black8
black3--black3Basic foreground30% black, ex: lower priority messages, disabled states
black3-opaque--black3-opaqueBasic foregroundOpaque version of black3
white--whiteBasic foregroundUsed in same way as black8, but on dark backgrounds
white8--white8Basic foregroundRarely used, only in toolbar
white4--white4Basic foregroundUsed in same way as black3, Ex: option group headers in menus
white--whiteBasic background(Duplicate) White is also the most common background color
grey--greyBasic backgroundUsed behind controls in active state
silver--silverBasic backgroundEx: horizontal separators, default canvas background
hud--hudBasic backgroundEx: background for menus
toolbar--toolbarBasic backgroundEx: background for the toolbar
black1--black1SpecialEx: input placeholder underline, textarea border
blue3--blue3SpecialEx: text range selection in inputs
purple4--purple4SpecialEx: disabled components/instances
hover-fill--hover-fillSpecialHover state for items without borders, ex: icon button
selection-a--selection-aSpecialSelected cells, ex: selected top level layer
selection-b--selection-bSpecialSelected cells, ex: selected child layers
white2--white2SpecialEx: menu separators

Type

PropertyVarValueNotes
font-family--font-stack'Inter', sans-serifDefault font everywhere
font-size--font-size-xsmall11pxMost common font size
font-size--font-size-small12pxUsed in menus
font-size--font-size-large13pxRarely used in editor
font-size--font-size-xlarge14pxRarely used in editor
font-weight--font-weight-normal400
font-weight--font-weight-medium500
font-weight--font-weight-bold600
line-height--font-line-height16pxFor use with xsmall and small font sizes
line-height--font-line-height-large24pxFor use with large and xlarge font sizes
letter-spacing--font-letter-spacing-pos-xsmall.005emOptimized letter spacing for xsmall text on light background
letter-spacing--font-letter-spacing-neg-xsmall.01emOptimized letter spacing for xsmall text on dark background
letter-spacing--font-letter-spacing-pos-small0Optimized letter spacing for small text on light background
letter-spacing--font-letter-spacing-neg-small.005emOptimized letter spacing for small text on dark background
letter-spacing--font-letter-spacing-pos-large-.0025emOptimized letter spacing for large text on light background
letter-spacing--font-letter-spacing-neg-large.0025emOptimized letter spacing for large text on dark background
letter-spacing--font-letter-spacing-pos-xlarge-.001emOptimized letter spacing for xlarge text on light background
letter-spacing--font-letter-spacing-neg-xlarge-.001emOptimized letter spacing for xlarge text on dark background

Border Radius

VarValueNotes
--border-radius-small2pxEx: menus, input borders, icon button
--border-radius-med5pxEx: visual bell, toasts
--border-radius-large6pxEx: buttons

Shadows

VarNotes
--shadow-hudEx: menus, tooltips, toasts
--shadow-floating-window:Ex: modal, dialog

Sizes

VarValue
--size-xxxsmall4px
--size-xxsmall8px
--size-xsmall16px
--size-small24px
--size-medium32px
--size-large40px
--size-xlarge48px
--size-xxlarge64px
--size-huge80px