Format everything uses 2 spaces instead of 4
This commit is contained in:
parent
94be330cde
commit
525146fb32
11 changed files with 99 additions and 107 deletions
|
|
@ -21,7 +21,7 @@ module.exports = function ({ colors, backgroundColors }) {
|
|||
|
||||
return _(backgroundColors).toPairs().map(([className, colorName]) => {
|
||||
return defineClass(`bg-${className}`, {
|
||||
backgroundColor: findColor(colors, colorName),
|
||||
backgroundColor: findColor(colors, colorName),
|
||||
})
|
||||
}).value()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const defineClass = require('../util/defineClass')
|
|||
module.exports = function ({ shadows }) {
|
||||
return _(shadows).toPairs().map(([className, shadow]) => {
|
||||
return defineClass(`shadow-${className}`, {
|
||||
boxShadow: shadow,
|
||||
boxShadow: shadow,
|
||||
})
|
||||
}).value()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,14 +7,10 @@ function buildMediaQuery(breakpoint) {
|
|||
}
|
||||
|
||||
return _(breakpoint).toPairs().map(([feature, value]) => {
|
||||
feature = _.get(
|
||||
{
|
||||
feature = _.get({
|
||||
min: 'min-width',
|
||||
max: 'max-width',
|
||||
},
|
||||
feature,
|
||||
feature
|
||||
)
|
||||
}, feature, feature)
|
||||
|
||||
return `(${feature}: ${value})`
|
||||
}).join(' and ')
|
||||
|
|
|
|||
|
|
@ -6,42 +6,40 @@ const flex = require('../generators/flex')
|
|||
const cloneNodes = require('../util/cloneNodes')
|
||||
|
||||
module.exports = function (options) {
|
||||
return function (css) {
|
||||
const rules = []
|
||||
return function (css) {
|
||||
const rules = []
|
||||
|
||||
css.walkAtRules(atRule => {
|
||||
if (atRule.name === 'responsive') {
|
||||
const nodes = atRule.nodes
|
||||
rules.push(...cloneNodes(nodes))
|
||||
css.insertBefore(atRule, nodes)
|
||||
atRule.remove()
|
||||
}
|
||||
if (atRule.name === 'tailwind' && atRule.params === 'utilities') {
|
||||
const utilities = _.flatten([
|
||||
backgroundColors(options),
|
||||
shadows(options),
|
||||
flex(),
|
||||
])
|
||||
rules.push(...cloneNodes(utilities))
|
||||
css.insertBefore(atRule, utilities)
|
||||
atRule.remove()
|
||||
}
|
||||
})
|
||||
css.walkAtRules(atRule => {
|
||||
if (atRule.name === 'responsive') {
|
||||
const nodes = atRule.nodes
|
||||
rules.push(...cloneNodes(nodes))
|
||||
css.insertBefore(atRule, nodes)
|
||||
atRule.remove()
|
||||
}
|
||||
if (atRule.name === 'tailwind' && atRule.params === 'utilities') {
|
||||
const utilities = _.flatten([
|
||||
backgroundColors(options),
|
||||
shadows(options),
|
||||
flex(),
|
||||
])
|
||||
rules.push(...cloneNodes(utilities))
|
||||
css.insertBefore(atRule, utilities)
|
||||
atRule.remove()
|
||||
}
|
||||
})
|
||||
|
||||
Object.keys(options.breakpoints).forEach(breakpoint => {
|
||||
const mediaQuery = postcss.atRule({
|
||||
name: 'media',
|
||||
params: `(--breakpoint-${breakpoint})`,
|
||||
})
|
||||
Object.keys(options.breakpoints).forEach(breakpoint => {
|
||||
const mediaQuery = postcss.atRule({
|
||||
name: 'media',
|
||||
params: `(--breakpoint-${breakpoint})`,
|
||||
})
|
||||
|
||||
mediaQuery.append(
|
||||
rules.map(rule => {
|
||||
const cloned = rule.clone()
|
||||
cloned.selector = `.${breakpoint}\\:${rule.selector.slice(1)}`
|
||||
return cloned
|
||||
})
|
||||
)
|
||||
css.append(mediaQuery)
|
||||
})
|
||||
}
|
||||
mediaQuery.append(rules.map(rule => {
|
||||
const cloned = rule.clone()
|
||||
cloned.selector = `.${breakpoint}\\:${rule.selector.slice(1)}`
|
||||
return cloned
|
||||
}))
|
||||
css.append(mediaQuery)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,29 +3,29 @@ const _ = require('lodash')
|
|||
const findMixin = require('../util/findMixin')
|
||||
|
||||
module.exports = function (options) {
|
||||
return function (css) {
|
||||
css.walkRules(rule => {
|
||||
rule.walkAtRules('apply', atRule => {
|
||||
const mixins = postcss.list.space(atRule.params)
|
||||
return function (css) {
|
||||
css.walkRules(rule => {
|
||||
rule.walkAtRules('apply', atRule => {
|
||||
const mixins = postcss.list.space(atRule.params)
|
||||
|
||||
const [customProperties, classes] = _.partition(mixins, mixin => {
|
||||
return _.startsWith(mixin, '--')
|
||||
})
|
||||
|
||||
const decls = _.flatMap(classes, mixin => {
|
||||
return findMixin(css, mixin, () => {
|
||||
throw atRule.error(`No ${mixin} class found.`)
|
||||
})
|
||||
})
|
||||
|
||||
rule.insertBefore(atRule, decls)
|
||||
|
||||
atRule.params = customProperties.join(' ')
|
||||
|
||||
if (_.isEmpty(customProperties)) {
|
||||
atRule.remove()
|
||||
}
|
||||
})
|
||||
const [customProperties, classes] = _.partition(mixins, mixin => {
|
||||
return _.startsWith(mixin, '--')
|
||||
})
|
||||
}
|
||||
|
||||
const decls = _.flatMap(classes, mixin => {
|
||||
return findMixin(css, mixin, () => {
|
||||
throw atRule.error(`No ${mixin} class found.`)
|
||||
})
|
||||
})
|
||||
|
||||
rule.insertBefore(atRule, decls)
|
||||
|
||||
atRule.params = customProperties.join(' ')
|
||||
|
||||
if (_.isEmpty(customProperties)) {
|
||||
atRule.remove()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const _ = require('lodash')
|
||||
|
||||
module.exports = function cloneNodes(nodes) {
|
||||
return _.map(nodes, node => node.clone())
|
||||
return _.map(nodes, node => node.clone())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,7 @@ module.exports = function defineClass(className, properties) {
|
|||
})
|
||||
})
|
||||
|
||||
return postcss
|
||||
.rule({
|
||||
selector: `.${_.kebabCase(className)}`,
|
||||
})
|
||||
.append(decls)
|
||||
return postcss.rule({
|
||||
selector: `.${_.kebabCase(className)}`,
|
||||
}).append(decls)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ const _ = require('lodash')
|
|||
const defineClass = require('./defineClass')
|
||||
|
||||
module.exports = function defineClasses(classes) {
|
||||
return _.map(classes, function(properties, className) {
|
||||
return defineClass(className, properties)
|
||||
})
|
||||
return _.map(classes, function(properties, className) {
|
||||
return defineClass(className, properties)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
const _ = require('lodash')
|
||||
|
||||
module.exports = function findMixin(css, mixin, onError) {
|
||||
const matches = []
|
||||
const matches = []
|
||||
|
||||
css.walkRules(rule => {
|
||||
if (rule.selector === mixin) {
|
||||
matches.push(rule)
|
||||
}
|
||||
})
|
||||
|
||||
if (_.isEmpty(matches) && _.isFunction(onError)) {
|
||||
onError()
|
||||
css.walkRules(rule => {
|
||||
if (rule.selector === mixin) {
|
||||
matches.push(rule)
|
||||
}
|
||||
})
|
||||
|
||||
return _.flatten(matches.map(match => match.clone().nodes))
|
||||
if (_.isEmpty(matches) && _.isFunction(onError)) {
|
||||
onError()
|
||||
}
|
||||
|
||||
return _.flatten(matches.map(match => match.clone().nodes))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,35 +4,35 @@ var _ = require('lodash')
|
|||
var defineClass = require('../src/util/defineClass')
|
||||
|
||||
var flexHelper = `.flex {
|
||||
display: flex
|
||||
display: flex
|
||||
}`
|
||||
|
||||
var inlineBlock = `.inline-block {
|
||||
display: inline-block
|
||||
display: inline-block
|
||||
}`
|
||||
|
||||
var inlineFlexHelper = `.inline-flex {
|
||||
display: inline-flex
|
||||
display: inline-flex
|
||||
}`
|
||||
|
||||
var backgroundColor = `.bg-1 {
|
||||
background-color: #bada55
|
||||
background-color: #bada55
|
||||
}`
|
||||
|
||||
/**
|
||||
* Tests
|
||||
*/
|
||||
it('creates a proper single-word class with rules', () => {
|
||||
let output = defineClass('flex', {display: 'flex'})
|
||||
expect(output.toString()).toEqual(flexHelper)
|
||||
let output = defineClass('flex', { display: 'flex' })
|
||||
expect(output.toString()).toEqual(flexHelper)
|
||||
})
|
||||
|
||||
it('generates a rule with a kebab-case selector', () => {
|
||||
let output = defineClass('inlineBlock', {display: 'inline-block'})
|
||||
expect(output.toString()).toEqual(inlineBlock)
|
||||
let output = defineClass('inlineBlock', { display: 'inline-block' })
|
||||
expect(output.toString()).toEqual(inlineBlock)
|
||||
})
|
||||
|
||||
it('generates a rule with a kebab-case property name', () => {
|
||||
let output = defineClass('bg-1', {backgroundColor: '#bada55'})
|
||||
expect(output.toString()).toEqual(backgroundColor)
|
||||
let output = defineClass('bg-1', { backgroundColor: '#bada55' })
|
||||
expect(output.toString()).toEqual(backgroundColor)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,28 +4,28 @@ var _ = require('lodash')
|
|||
var defineClasses = require('../src/util/defineClasses')
|
||||
|
||||
var config = {
|
||||
flex: {
|
||||
display: 'flex',
|
||||
},
|
||||
inlineFlex: {
|
||||
display: 'inline-flex',
|
||||
},
|
||||
flex: {
|
||||
display: 'flex',
|
||||
},
|
||||
inlineFlex: {
|
||||
display: 'inline-flex',
|
||||
},
|
||||
}
|
||||
|
||||
var flexHelper = `.flex {
|
||||
display: flex
|
||||
display: flex
|
||||
}`
|
||||
|
||||
var inlineFlexHelper = `.inline-flex {
|
||||
display: inline-flex
|
||||
display: inline-flex
|
||||
}`
|
||||
|
||||
/**
|
||||
* Tests
|
||||
*/
|
||||
it('it generates a set of helper classes from a config', () => {
|
||||
output = defineClasses(config)
|
||||
expect(output).toBeInstanceOf(Array)
|
||||
expect(output[0].toString()).toEqual(flexHelper)
|
||||
expect(output[1].toString()).toEqual(inlineFlexHelper)
|
||||
output = defineClasses(config)
|
||||
expect(output).toBeInstanceOf(Array)
|
||||
expect(output[0].toString()).toEqual(flexHelper)
|
||||
expect(output[1].toString()).toEqual(inlineFlexHelper)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue