Skip to content

Instantly share code, notes, and snippets.

View souporserious's full-sized avatar

Travis Arnold souporserious

View GitHub Profile
const attributesToObjectString = (attributes) =>
Object.entries(attributes)
.filter(([key]) => key !== 'xmlns')
.map(([key, value]) => {
if ((key === 'fill' || key === 'stroke') && value !== 'none') {
return `${key}: 'currentColor'`;
}
return `${key}: '${value}'`;
})
.join(', ');
@souporserious
souporserious / rewrite-storybooks.js
Created July 26, 2021 20:57
Rewrites Storybook MDX to a README MDX file
import glob from 'fast-glob';
import fs from 'fs';
import path from 'path';
import frontmatter from 'remark-frontmatter';
import mdx from 'remark-mdx';
import markdown from 'remark-parse';
import stringify from 'remark-stringify';
import { unified } from 'unified';
// https://unifiedjs.com/explore/package/remark-mdx/
@souporserious
souporserious / plugin.js
Created July 22, 2021 22:11
Update Figma styles to match their alias
function findLocalPaintStyle(name) {
return figma
.getLocalPaintStyles()
.find((paintStyle) => paintStyle.name === name)
}
function updateLocalAliasPaintStyles() {
figma.getLocalPaintStyles().forEach((paintStyle) => {
const alias = paintStyle.description
@souporserious
souporserious / in.jsx
Created July 9, 2021 20:01
Example JSXUI breakpoints
export default function App() {
return (
<Stack
axis="x"
width="container.medium"
spaceX={{ 'breakpoints.large': 'xlarge' }}
spaceYStart="40px"
spaceYEnd="80px"
>
<Text>Hello World</Text>
@souporserious
souporserious / Input.tsx
Created July 9, 2021 03:03
Example JSXUI Input component
type InputProps = Pick<TextFieldProps, 'value' | 'onValueChange'>
function Input({ value, onValueChange }: InputProps) {
const id = useId()
return (
<Stack
paddingX="16px"
paddingY="8px"
stroke={{
@souporserious
souporserious / babel.config.js
Created July 7, 2021 06:12
Example of web and native visitors in JSXUI.
module.exports = {
plugins: [
['@jsxui/babel-plugin', {
visitor: process.env.PLATFORM === 'native' ? require('./native') : require('./web')
}]
]
}
@souporserious
souporserious / babel.config.js
Last active July 4, 2021 18:11
JSXUI Compiler Components
const components = [
{
name: 'Text',
as: 'span',
props: {
color: ['primary', 'secondary'],
},
transforms: {
color: (value, theme) => theme.colors[value]
}
@souporserious
souporserious / open-editor.js
Created July 1, 2021 19:36
Open VS Code editor using NextJS API routes
import { exec } from 'child_process';
import path from 'path';
export default function handler(request, response) {
exec(
`code --goto "${path.resolve(process.cwd(), 'pages/_app.page.tsx')}:30:11"`,
(err) => {
if (err) {
console.log(err);
}
@souporserious
souporserious / args.js
Created June 25, 2021 05:26
Parse Node args using Object.fromEntries.
const args = Object.fromEntries(
process.argv.slice(2).map((arg) => {
const [key, value] = arg.split('=')
return [key.slice(2), value]
})
)
// input: --port=3000 --out=dist
// output: { port: '3000', out: 'dist' }
@souporserious
souporserious / rename.js
Last active May 24, 2021 17:40
Rename files using Node.js
const fs = require('fs');
const glob = require('glob');
glob('src/**/index.tsx', {}, (globError, files) => {
if (globError) {
console.error(`Error Globbing: ${globError}`);
}
files.forEach((filePath) => {
fs.rename(filePath, filePath.replace('.tsx', '.ts'), (renameError) => {
if (renameError) {