Skip to content

Instantly share code, notes, and snippets.

View danhollick's full-sized avatar

Daniel Hollick danhollick

View GitHub Profile
@danhollick
danhollick / code.js
Last active February 3, 2020 16:41
Send contrast info
function sendContrastInfo(contrast, foreground, backgound) {
figma.ui.postMessage({
type: 'selectionChange',
foreground,
background,
contrast,
})
}
@danhollick
danhollick / code.js
Last active February 2, 2020 12:52
Calling contrast
figma.on('selectionchange', () => {
if (figma.currentPage.selection.length > 1) {
const selection = figma.currentPage.selection.filter(
node => node.fills.length > 0 && node.fills[0].type === 'SOLID'
)
// filter out the first fills of each layer
const fills = selection.map(node => node.fills[0])
const contrast = calculateContrast(fills[0].color, fills[1].color)
console.log(contrast)
}
@danhollick
danhollick / code.js
Last active February 3, 2020 16:43
Mocking up contrast test
function calculateLuminance(color) {
//just return 1 for now
return 1
}
function calculateContrast(foreground, background) {
console.log(foreground, background)
const foregroundLuminance = calculateLuminance(foreground)
const backgroundLuminance = calculateLuminance(background)
return foregroundLuminance / backgroundLuminance
@danhollick
danhollick / code.js
Last active February 2, 2020 12:14
Logging selection change
figma.showUI(__html__)
figma.on('selectionchange', () => {
if (figma.currentPage.selection.length > 1) {
// find nodes with fills that are of type SOLID
const selection = figma.currentPage.selection.filter(
node => node.fills.length > 0 && node.fills[0].type === 'SOLID'
)
console.log(selection[0].fills)
} else {
var express = require('express')
var app = express()
const FigmaAPIKey = 'XXXX–XXXXXXXX–XXXX–XXXX-XXXX–XXXXXXXXXXXX'
const FigmaFileID = `SoMEGIbBeriSHHerE`
app.listen(3001, console.log("Holy shit, I'm a server and I am listening on port 3001"))
var express = require('express')
var app = express()
app.listen(3001, console.log("Holy shit, I'm a server and I am listening on port 3001"))
var containerStyle = {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
margin: 24,
height: '100vh',
}
var divStyle = {
margin: 24,
class App extends Component {
state = { images: [
{ name: '', url:'' }
]}
componentDidMount() {//1
fetch('/frames')//2
.then(res => res.json())//3
.then(data => this.setState({ images: data }))//4
.catch(error => console.log(error));
class App extends Component {
state = { images: [
{ name: '', url:'' }
]}
render() {
return (
<div className="App" >
{this.state.images.map( //1
(frame,i) =>
class App extends Component {
state = { images: [
{ name: '', url:'' }
]}
render() {
return (
);
}