A UI library with CSS and vanilla JS that match the Figma UI for building plugins.
npm install figma-plugin-dsA lightweight UI library for creating Figma plugins.
* Contents
* Intro
* Getting started
* Roadmap
* Components
+ Button
+ Checkbox
+ Disclosure
+ Icon
+ Icon button
+ Input
+ Labels and sections
+ Onboarding tip
+ Radio button
+ Select menu
+ Switch
+ Textarea
+ Type
This package contains CSS and Javascript to closely match the look, feel and function of those found in Figma. It has been created without any frameworks (like React, Vue, etc.) and only leverages (native) javascript for components not possible without.
You can install this package as a dependecy on your own project: npm install figma-plugin-ds
Styles
To use the styles, you can use them via a link tag, or import them like a module using a CSS loader.
``HTML`
`Javascript`
//You could also inport the css via a CSS Loader in your JS environment (refer to syntax of whatever loader you are using)
import styles from 'figma-plugin-ds/dist/figma-plugin-ds.css'
To use the Select menu or Disclosure components, you will need to import the Javascript files as well. This package supports both standard IIFE (Immediately Invoked Function Expressions) and ES6 Modules. There are a number of ways to get started.
Scripts: IIFE hosted on CDN (quick and easy, I don't want to mess with npm packages)
`HTML`
Scripts: ES6 Modules
`Javascript`
import { selectMenu, disclosure } from 'figma-plugin-ds';
---
To use the button, use the following HTML markup. Each button has a destructive option. Teritary buttons are styled like hyperlinks.
`HTML
`
Modifiers
| Modifier class | Description |
|--------------------------------------|-------------------------------------------------------------------------------------------------|
| button--primary | Primary button |button--primary-destructive
| | Primary button with red destructive variant for actions such as deleting something |button--secondary
| | Secondary button with outline style |button--secondary-destructive
| | Secondary button with red destructive variant for actions such as deleting something |button--tertiary
| | Tertiary button with hyperlink style |button--tertiary-destructive
| | Tertiary button with red destructive variant for actions such as deleting something |
---
To use the checkbox, use the following HTML markup. Remember each checkbox should get a unique ID that is referenced in the label. This ensures the checkbox and the entire label are clickable.
`HTML
---
$3
To use a disclosure panel, you must use the following markup and also make sure you initialize the Javascript for the disclosure to work.
`HTML
Disclosure heading
Panel content here
`To initialize with Javascript:
`Javascript
//initialize all disclosure panels
disclosure.init();//uninitialize all disclosure panels
disclosure.destroy();
`Modifiers
| Modifier class | Description |
|------------------------|-------------------------------------------------------------------------------------------------|
|
disclosure--section | Add this class to the disclosure__label to style it like a heading |
| disclosure--expanded | Add this class to the disclosure__item to have it expanded on load |---
$3
To use the icon component, use the following markup. Apply the appropriate modifier class to select the item you wish to use, you can also add additional modifiers to change the color, or even spin the icon. You can also specify no icon name to use a text character as an icon (for example, like found in the width + height icon inputs in Figma)
`HTML
W
`Modifiers
| Modifier class | Description |
|--------------------|-------------------------------------------------------------------------------------------------|
|
icon--iconName* | Sepcify which icon to use. Ex: icon--adjust or icon--settings |
| icon--spin | Causes the icon to spin in an endless loop (for example: a loader used with icon--spinner) |
| icon--colorName* | Pass the name of any Figma color var to this prop. Ex: icon--blue or icon--black3 |_*Colors accepted: icon--blue, icon--purple, icon--purple4, icon--hot-pink, icon--green, icon--red, icon--yellow, icon--black, icon--black8, icon--black3, icon--white, icon--white8, icon--white4_
Icons
To use an icon, add one of the following modifier classes (see markup example above).
| Icon | Modifier class |
|----------------------------------------------------------------------------------------|---------------------------------------|
| !IconAdjust |
icon--adjust |
| !IconAlert | icon--alert |
| !IconAngle | icon--angle |
| !IconArrowLeftRight | icon--arrow-left-right |
| !IconUpDown | icon--updown |
| !IconAutoLayoutHorizontal | icon--auto-layout-horizontal |
| !IconAutoLayoutVertical | icon--auto-layout-vertical |
| !IconBack | icon--back |
| !IconBlendEmpty | icon--blend-empty |
| !IconBlend | icon--blend |
| !IconBreak | icon--break |
| !IconCaretDown | icon--caret-down |
| !IconCaretLeft | icon--caret-left |
| !IconCaretRight | icon--caret-right |
| !IconCaretUp | icon--caret-up |
| !IconCheck | icon--check |
| !IconClose | icon--close |
| !IconComponent | icon--component |
| !IconCornerRadius | icon--corner-radius |
| !IconCorners | icon--corners |
| !IconDistributeHorizontalSpacing | icon--distribute-horizontal-spacing |
| !IconDistributeVerticalSpacing | icon--distribute-vertical-spacing |
| !IconDraft | icon--draft |
| !IconEffects | icon--effects |
| !IconEllipses | icon--ellipses |
| !IconEyedropper | icon--eyedropper |
| !IconForward | icon--forward |
| !IconFrame | icon--frame |
| !IconGroup | icon--group |
| !IconHidden | icon--hidden |
| !IconHorizontalPadding | icon--horizontal-padding |
| !IconHyperlink | icon--hyperlink |
| !IconImage | icon--image |
| !IconInstance | icon--instance |
| !IconKey | icon--key |
| !IconLayoutAlignBottom | icon--layout-align-bottom |
| !IconAlignHorizontalCenters | icon--align-horizontal-centers |
| !IconAlignLeft | icon--align-left |
| !IconAlignRight | icon--align-right |
| !IconAlignTop | icon--align-top |
| !IconAlignVerticalCenters | icon--align-vertical-centers |
| !IconLayoutGridColumns | icon--layout-grid-columns |
| !IconLayoutGridRows | icon--layout-grid-rows |
| !IconLayoutGridUniform | icon--layout-grid-uniform |
| !IconLibrary | icon--library |
| !IconLinkBroken | icon--link-broken |
| !IconLinkConnected | icon--link-connected |
| !IconListDetailed | icon--list-detailed |
| !IconListTile | icon--list-tile |
| !IconList | icon--list |
| !IconLockOff | icon--lock-off |
| !IconLockOn | icon--lock-on |
| !IconMinus | icon--minus |
| !IconPlay | icon--play |
| !IconPlus | icon--plus |
| !IconRandom | icon--random |
| !IconRecent | icon--recent |
| !IconResizeToFit | icon--resize-to-fit |
| !IconResolveFilled | icon--resolve-filled |
| !IconResolve | icon--resolve |
| !IconReverse | icon--reverse |
| !IconSearchLarge | icon--search-large |
| !IconSearch | icon--search |
| !IconSettings | icon--settings |
| !IconShare | icon--share |
| !IconSmiley | icon--smiley |
| !IconSortAlphaAsc | icon--sort-alpha-asc |
| !IconSortAlphaDsc | icon--sort-alpha-dsc |
| !IconSortTopBottom | icon--sort-top-bottom |
| !IconSpacing | icon--spacing |
| !IconSpinner | icon--spinner |
| !IconStarOff | icon--star-off |
| !IconStarOn | icon--star-on |
| !IconStrokeWeight | icon--stroke-weight |
| !IconStyles | icon--styles |
| !IconSwap | icon--swap |
| !IconTheme | icon--theme |
| !IconTidyUpGrid | icon--tidy-up-grid |
| !IconTidyUpListHorizontal | icon--tidy-up-list-horizontal |
| !IconTidyUpListVertical | icon--tidy-up-list-vertical |
| !IconTimer | icon--timer |
| !IconTrash | icon--trash |
| !IconVerticalPadding | icon--vertical-padding |
| !IconVisible | icon--visible |
| !IconWarningLarge | icon--warning-large |
| !IconWarning | icon--warning |---
$3
The icon button is essentially a wrapper for the icon component. Refer to the icon component above for its usage.
`HTML
`---
$3
To use the input, use the following markup. You can also insert an icon into the input (see Icon component for usage).
`HTML
`Modifiers
| Modifier class | Description |
|---------------------|-------------------------------------------------------------------------------------------------|
|
input--with-icon* | Add this modifier class if you plan to include the icon component within the input |---
$3
To use a label or section, use the following markup.
`HTML
Label
Section title
`$3
To create an onboarding tip, use the following markup. The tip also makes use of the icon component (see Icon component for usage).
`HTML
Onboarding tip goes here.
`---
$3
To create an radio button, use the following markup. Remember each group of radio buttons must share the same name so that they are related to one another. Each button should have a unique id so that its label is associated with it and remains part of the clickable hit area.
`HTML
`---
$3
To create an select menu, use the following markup. The select menu also requires you to initalize it with Javascript. If your plugin requires you to add or remove items in the select menu, simply use Javascript to modify the select menu and the select will reinitialize.
The select menu will open and position the menu to the selected object. If there is no vertical room inside your plugin's iFrame, the position of the menu will be moved to ensure it fits inside the iframe. If you have a select menu with too many options to fit within the iFrame, the menu will scroll vertically.
`HTML
`To initialize with Javascript:
`Javascript
//initialize all select menus
selectMenu.init();//uninitialize all select menus
selectMenu.destroy();
`---
$3
To use the switch, use the following HTML markup. Remember each switch should get a unique ID that is referenced in the label. This ensures the switch and the entire label are clickable.
`HTML
`---
$3
To use the textarea, use the following HTML markup.
`HTML
`---
$3
To use the typography that is styled like it is in the Figma UI, use the following markup plus additional modifier classes to modify the size, weight, and letterspacing that is optimized for positive (dark text on light background) and negative (light text on dark background) applications.
`HTML
UI11, size: xsmall (default) weight: normal, positive
UI13, size: large, weight: bold, positive
UI12, size: large, weight: medium, negative
`Modifiers
| Modifier class | Description |
|--------------------|-----------------------------------------------------------------------------------------------------|
|
type--small | Font size 12px |
| type--large | Font size 13px |
| type--xlarge | Font size 14px |
| type--medium | Font weight medium |
| type--bold | Font weight bold |
| type--inverse` | Inversed (negative) application where light text is on dark background with increased letterspacing |_Defaults: Font size 11px, normal weight, positive application_