Skip to content

Commit

Permalink
Merge branch 'main' into buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
argyleink committed Jan 27, 2022
2 parents 375c0f9 + 49f137f commit 3df2642
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 188 deletions.
91 changes: 91 additions & 0 deletions build/props.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import fs from 'fs'

import Animations from '../src/props.animations.js'
import Sizes from '../src/props.sizes.js'
import * as OpenColors from '../src/props.colors.js'
import Fonts from '../src/props.fonts.js'
import Borders from '../src/props.borders.js'
import Aspects from '../src/props.aspects.js'
import Easings from '../src/props.easing.js'
import Gradients from '../src/props.gradients.js'
import Shadows from '../src/props.shadows.js'
import SVG from '../src/props.svg.js'
import Zindex from '../src/props.zindex.js'

import {buildPropsStylesheet} from './to-stylesheet.js'
import {toJSON} from './to-json.js'
import {toTokens} from './to-tokens.js'
import {toFigmaTokens} from './to-figmatokens.js'

const [,,prefix,useWhere] = process.argv
const selector = useWhere === 'true' ? ':where(html)' : 'html'

const mainbundle = {
'props.fonts.css': Fonts,
'props.sizes.css': Sizes,
'props.easing.css': Easings,
'props.zindex.css': Zindex,
'props.shadows.css': Shadows,
'props.aspects.css': Aspects,
'props.colors.css': OpenColors.default,
// 'props.svg.css': SVG,
'props.gradients.css': Gradients,
'props.animations.css': Animations,
'props.borders.css': Borders,
}

const individual_colors = {
'props.gray.css': OpenColors.Gray,
'props.red.css': OpenColors.Red,
'props.pink.css': OpenColors.Pink,
'props.grape.css': OpenColors.Grape,
'props.violet.css': OpenColors.Violet,
'props.indigo.css': OpenColors.Indigo,
'props.blue.css': OpenColors.Blue,
'props.cyan.css': OpenColors.Cyan,
'props.teal.css': OpenColors.Teal,
'props.green.css': OpenColors.Green,
'props.lime.css': OpenColors.Lime,
'props.yellow.css': OpenColors.Yellow,
'props.orange.css': OpenColors.Orange,
}

// gen design tokens
const jsonbundle = toJSON({
...Object.values(individual_colors)
.reduce((colors, color) =>
Object.assign(colors, color), {}),
...Sizes,
...Easings,
...Zindex,
...Aspects,
...Gradients,
...Borders,
})

const designtokens = toTokens(jsonbundle)
const JSONtokens = fs.createWriteStream('../open-props.tokens.json')
JSONtokens.end(JSON.stringify(Object.fromEntries(designtokens), null, 2))

// gen figma tokens
const figmatokens = toFigmaTokens(jsonbundle)
const FigmaTokens = fs.createWriteStream('../open-props.figma-tokens.json')
FigmaTokens.end(JSON.stringify(figmatokens, null, 2))

const figmatokensSYNC = { 'open-props': { ...figmatokens } }
const FigmaTokensSync = fs.createWriteStream('../open-props.figma-tokens.sync.json')
FigmaTokensSync.end(JSON.stringify(figmatokensSYNC, null, 2))

// gen prop variants
Object.entries({...mainbundle, ...individual_colors}).forEach(([filename, props]) => {
buildPropsStylesheet({filename, props}, {selector, prefix})
})

// gen index.css
const entry = fs.createWriteStream('../src/index.css')
entry.write(`@import 'props.media.css';
`)
Object.keys(mainbundle).forEach(filename => {
entry.write(`@import '${filename}';\n`)
})
entry.end()
39 changes: 39 additions & 0 deletions build/to-figmatokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export const toFigmaTokens = props => {
const figmatokens = {}

props.map(([key, token]) => {
let meta = {}

let isLength = key.includes('size') && !key.includes('border-size')
let isBorder = key.includes('border-size')
let isRadius = key.includes('radius')
let isShadow = key.includes('shadow')
let colors = ['gray','red','pink','grape','violet','indigo','blue','cyan','teal','green','lime','yellow','orange']
let isColor = colors.some(color => key.includes(color))

if (isLength) meta.type = 'sizing'
else if (isBorder) meta.type = 'borderWidth'
else if (isRadius) meta.type = 'borderRadius'
else if (isShadow) meta.type = 'boxShadow'
else if (isColor) meta.type = 'color'
else meta.type = 'other'

if (!(meta.type in figmatokens)) figmatokens[meta.type] = {}

if (isColor) {
let color = /--(.+?)-/.exec(key)[1]
if (!(color in figmatokens[meta.type])) figmatokens[meta.type][color] = {}
figmatokens[meta.type][color][key] = {
value: token,
...meta,
}
} else {
figmatokens[meta.type][key] = {
value: token,
...meta,
}
}
})

return figmatokens
}
6 changes: 6 additions & 0 deletions build/to-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const toJSON = props =>
Object.entries(props)
.reduce((bundle_entries, [key, val]) => {
bundle_entries.unshift([key,val])
return bundle_entries
}, [])
40 changes: 40 additions & 0 deletions build/to-stylesheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import fs from 'fs'

export const buildPropsStylesheet = ({filename,props}, {selector,prefix}) => {
const file = fs.createWriteStream("../src/" + filename)

let appendedMeta = ''

if (filename.includes('shadows'))
file.write(`@import 'props.media.css';\n\n`)

file.write(`${selector} {\n`)

Object.entries(props).forEach(([prop, val]) => {
if (prop.includes('-@'))
return

if (prefix)
prop = `--${prefix}-` + prop.slice(2)

if (prop.includes('animation')) {
let keyframes = props[`${prop}-@`]
appendedMeta += keyframes
}

file.write(` ${prop}: ${val};\n`)
})

if (filename.includes('shadows')) {
appendedMeta += `
@media (--OSdark) {
:where(html) {
--shadow-strength: 25%;
--shadow-color: 220 40% 2%;
}
}`
}

file.write('}\n')
file.end(appendedMeta)
}
18 changes: 18 additions & 0 deletions build/to-tokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const toTokens = props =>
props.map(([key, token]) => {
let meta = {}

let isLength = key.includes('size')
let isEasing = key.includes('ease')
let colors = ['gray','red','pink','grape','violet','indigo','blue','cyan','teal','green','lime','yellow','orange']
let isColor = colors.some(color => key.includes(color))

if (isLength) meta.type = 'dimension'
else if (isEasing) meta.type = 'cubic-bezier'
else if (isColor) meta.type = 'color'

return [key, {
value: token,
...meta,
}]
})
2 changes: 0 additions & 2 deletions docsite/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,12 @@ section.hero {
@media (--md-n-above) { font-size: var(--font-size-fluid-3) }

& > * {
--op-gradient-direction: to right;
background: var(--gradient-1) fixed;
background-size: 13ch 50%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;

@nest [data-theme="dark"] & {
--op-gradient-direction: to bottom right;
background: var(--gradient-4) fixed;
background-size: 12ch 7ch;
-webkit-background-clip: text;
Expand Down
15 changes: 11 additions & 4 deletions docsite/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ <h1><span>CSS</span> <span>variables.</span></h1>
</li>
</ul>
<small>
v1.1.3
v1.2.1
<span class="license">
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16">
<path fill-rule="evenodd" d="M8.75.75a.75.75 0 00-1.5 0V2h-.984c-.305 0-.604.08-.869.23l-1.288.737A.25.25 0 013.984 3H1.75a.75.75 0 000 1.5h.428L.066 9.192a.75.75 0 00.154.838l.53-.53-.53.53v.001l.002.002.002.002.006.006.016.015.045.04a3.514 3.514 0 00.686.45A4.492 4.492 0 003 11c.88 0 1.556-.22 2.023-.454a3.515 3.515 0 00.686-.45l.045-.04.016-.015.006-.006.002-.002.001-.002L5.25 9.5l.53.53a.75.75 0 00.154-.838L3.822 4.5h.162c.305 0 .604-.08.869-.23l1.289-.737a.25.25 0 01.124-.033h.984V13h-2.5a.75.75 0 000 1.5h6.5a.75.75 0 000-1.5h-2.5V3.5h.984a.25.25 0 01.124.033l1.29.736c.264.152.563.231.868.231h.162l-2.112 4.692a.75.75 0 00.154.838l.53-.53-.53.53v.001l.002.002.002.002.006.006.016.015.045.04a3.517 3.517 0 00.686.45A4.492 4.492 0 0013 11c.88 0 1.556-.22 2.023-.454a3.512 3.512 0 00.686-.45l.045-.04.01-.01.006-.005.006-.006.002-.002.001-.002-.529-.531.53.53a.75.75 0 00.154-.838L13.823 4.5h.427a.75.75 0 000-1.5h-2.234a.25.25 0 01-.124-.033l-1.29-.736A1.75 1.75 0 009.735 2H8.75V.75zM1.695 9.227c.285.135.718.273 1.305.273s1.02-.138 1.305-.273L3 6.327l-1.305 2.9zm10 0c.285.135.718.273 1.305.273s1.02-.138 1.305-.273L13 6.327l-1.305 2.9z"></path>
Expand Down Expand Up @@ -1331,11 +1331,9 @@ <h5>The Props</h5>
<h5>Hero Header Sample</h5>
<pre class="language-css"><code>
header {
--op-gradient-direction: to top left;
background-image: var(--gradient-5);

@media (--OSdark) {
--op-gradient-direction: to bottom right;
background-image: var(--gradient-15);
}
}
Expand Down Expand Up @@ -2575,7 +2573,16 @@ <h5>Usage Sample</h5>
<section id="media-queries">
<header class="just-for-gap">
<h2>Media Queries</h2>
<p>Currently one step ahead of <a href="https://drafts.csswg.org/mediaqueries-5/#at-ruledef-custom-media">the CSS spec</a>, Open Props offers named media queries with the <code>@custom-media</code> syntax. Available only with <a href="https://github.com/postcss/postcss-custom-media">this PostCSS plugin</a>, for now 😈</p>
<div class="block-wrap">
<p>Currently one step ahead of <a href="https://drafts.csswg.org/mediaqueries-5/#at-ruledef-custom-media">the CSS spec</a>, Open Props offers named media queries with the <code>@custom-media</code> syntax. Available only with <a href="https://github.com/postcss/postcss-custom-media">this PostCSS plugin</a>, for now 😈</p>

<blockquote class="icon-quote indigo">
<svg viewBox="0 0 24 24">
<path d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" />
</svg>
<span>Media query widths also available as custom properties. Use like <code class="language-css">var(--size-sm)</code></span>
</blockquote>
</div>
<div class="media-query-chart">
<div>
<svg height="24" width="24">
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "open-props",
"author": "Adam Argyle",
"license": "MIT",
"version": "1.1.5",
"version": "1.2.2",
"repository": {
"type": "git",
"url": "https://github.com/argyleink/open-props"
Expand Down Expand Up @@ -68,9 +68,9 @@
"bundle": "concurrently npm:lib:*",
"bundle:pre-edit": "json -I -f package.json -e \"this.unpkg=''\"",
"bundle:post-edit": "json -I -f package.json -e \"this.unpkg='open-props.min.css'\"",
"gen:op": "cd src && node _create-props.js '' true",
"gen:nowhere": "cd src && node _create-props.js '' false",
"gen:prefixed": "cd src && node _create-props.js 'op'",
"gen:op": "cd build && node props.js '' true",
"gen:nowhere": "cd build && node props.js '' false",
"gen:prefixed": "cd build && node props.js 'op'",
"lib:js": "npm run bundle:pre-edit && microbundle --no-sourcemap && npm run bundle:post-edit",
"lib:all": "postcss src/index.css -o open-props.min.css",
"lib:normalize": "postcss src/extra/normalize.css -o normalize.min.css",
Expand Down
Loading

0 comments on commit 3df2642

Please sign in to comment.