Skip to content

Instantly share code, notes, and snippets.

View rogie's full-sized avatar

Rogie King rogie

View GitHub Profile
/* Dropdown */
class FigDropdown extends HTMLElement {
constructor() {
super()
this.type = "select"
}
connectedCallback() {
this.trigger = this.querySelector('[slot=trigger]')
if (this.trigger) {
async function buildSFSymbolIcons(){
const sfSymbolNames = "square.and.arrow.up,square.and.arrow.up.fill,square.and.arrow.up.circle,square.and.arrow.up.circle.fill,square.and.arrow.up.badge.clock,square.and.arrow.up.badge.clock.fill,square.and.arrow.up.trianglebadge.exclamationmark,square.and.arrow.down,square.and.arrow.down.fill,square.and.arrow.up.on.square,square.and.arrow.up.on.square.fill,square.and.arrow.down.on.square,square.and.arrow.down.on.square.fill,rectangle.portrait.and.arrow.right,rectangle.portrait.and.arrow.right.fill,rectangle.portrait.and.arrow.forward,rectangle.portrait.and.arrow.forward.fill,pencil,pencil.circle,pencil.circle.fill,pencil.slash,pencil.line,eraser,eraser.fill,eraser.line.dashed,eraser.line.dashed.fill,square.and.pencil,square.and.pencil.circle,square.and.pencil.circle.fill,rectangle.and.pencil.and.ellipsis,scribble,scribble.variable,pencil.and.scribble,highlighter,pencil.and.outline,pencil.tip,pencil.tip.crop.circle,pencil.tip.crop.circle.fill,pencil.tip.crop.circle.ba
@rogie
rogie / code.ts
Last active August 31, 2023 04:22
Embedding video on Figma Canvas
let errorCreatingVideo = false
let video, paint
// Figma's pro (and higher plans) allow for embedding videos. There is no native code for a Figma plugin to be able
// to test what plan a user is on. So, this code attempts to create the video. If it can't, then it will notify the user
// of the error (I would imagine this error also will fire if the video is too large).
try {
video = await figma.createVideoAsync(args.webm)
paint = {
videoHash: video.hash,
// SAVING some settings on a layer (code.ts/figma scene)
// Namespace
const dataNamespace = 'stipple-settings'
// get a node
let layer = figma.currentPage.selection[0]
// options to save in json format
let options = {
// creating the client
// https://supabase.com/docs/reference/javascript/initializing
import { createClient } from '@supabase/supabase-js';
import clientStorage from './FigmaClientStorage';
const supabase = createClient(
<URL>,
<PUBLIC_ANON_KEY>,
{
@rogie
rogie / figma-select-nodes
Last active June 21, 2022 13:49
Selects all nodes with a specific name within a selection
let nodesToSelect = []
figma.currentPage.selection.forEach(node => {
// Change "Icon Right" to the node name you want to select
node.findAll(node => node.name == "Icon Right").forEach(node => nodesToSelect.push(node))
})
figma.currentPage.selection = nodesToSelect
@rogie
rogie / download-exportAsync.js
Last active May 24, 2022 14:19
Figma Plugin API: Download exportAsync
/* code.ts (scene) */
node.exportAsync({
format: "PNG",
constraint: {
type: "WIDTH",
value: 1000
}
}).then(imageData => {
// Send the image data to the plugin window
@rogie
rogie / gist:c88a80b8c911ea2e6cc57af45969cb07
Last active September 12, 2021 23:40
Insert Components from Figma published team library
async function insertAllComponentsFromFile(){
// Uses the Web api..more here https://www.figma.com/developers/api#files-endpoints
// Ideally, you don't hit this api every time the plugin runs, but maybe use figma.clientStorage
// to store the keys for a set amount of time, then refresh on expiration
let result = await fetch('https://api.figma.com/v1/files/08U6xAT28gUfHkx2l2kUhc', {
method: 'GET',
headers: {
'X-Figma-Token': '236259-788a3c64-e9b2-4ca2-851b-193954b2ad6d'