Created
April 9, 2020 12:44
-
-
Save npretto/e9817b154a2085bb5b6b966f3a59c0fe to your computer and use it in GitHub Desktop.
get colors from figma and print them as ts code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // v this will probably change every figma deploy | |
| const styles = [...document.querySelectorAll('.style_icon--styleIcon--3-PzQ')] | |
| const colors = styles.map(style =>{ | |
| try { | |
| const name = style.attributes['data-tooltip-style-name'].value.split(" ")[2] | |
| const rgb = style.children[0].children[0].style.backgroundColor | |
| const color = "#"+rgb.split('(')[1].split(")")[0].split(",").map(str => parseInt(str,10)).map(component => component.toString(16)).map(c => c.length == 1 ? "0"+c : c).join("") | |
| return {name, color} | |
| }catch(ex){ | |
| console.log(ex) | |
| return false | |
| } | |
| }).filter(a => a) | |
| const correctNames = colors.map(({color,name}) => { | |
| // custom logic to rename colors | |
| const parts = name.split('-') | |
| return {color, name: `${parts[1].toUpperCase()}_${parts[2]}`} | |
| }) | |
| const tsCode = correctNames.map(({name, color}) => ` ${name} = '${color}',` ).join('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment