Skip to content

Commit

Permalink
feat(utils): export preset utils
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Mar 29, 2021
1 parent d3ce18a commit 743a143
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
14 changes: 2 additions & 12 deletions presets.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { px, str, percOrPx } = require('./utils')

const tokens = {
space: [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64],
fontSize: ['3rem', '3rem', '2.2rem', '1.8rem', '1.4rem', '1rem', '0.875rem'],
Expand All @@ -19,18 +21,6 @@ const tokens = {

const breakpoints = ['400px', '800px', '1200px']

function px (v) {
return typeof v === 'number' ? v + 'px' : v
}

function str (v) {
return v + ''
}

function percOrPx (v) {
return typeof v === 'number' ? (v <= 1 ? v * 100 + '%' : v + 'px') : v
}

const shorthands = {
d: {
properties: ['display']
Expand Down
3 changes: 3 additions & 0 deletions utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function px(value: string | number): string;
export function str(value: string | number): string;
export function percentOrPixel(value: string | number): string;
17 changes: 17 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function px (v) {
return typeof v === 'number' ? v + 'px' : v
}

function str (v) {
return v + ''
}

function percOrPx (v) {
return typeof v === 'number' ? (v <= 1 ? v * 100 + '%' : v + 'px') : v
}

module.exports = {
px,
str,
percOrPx
}

0 comments on commit 743a143

Please sign in to comment.