Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added marings and paddings #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @file index.js
*/
const plugin = require('tailwindcss/plugin')
const _ = require('lodash')
// const selectorParser = require('postcss-selector-parser')

/**
* getSizes
Expand All @@ -24,7 +22,6 @@ const getSizes = (totalSizes = 900, startingValue = 0) => {
)
// Merge the array of objects into a single one
const sizeObj = Object.assign.apply(Object, sizes)
// console.log('sizeObj', sizeObj)
return sizeObj
}

Expand All @@ -49,6 +46,15 @@ module.exports = plugin.withOptions(
(options && options.height && options.height.total) || 900,
(options && options.height && options.height.startingSize) || 0
)
const margins = getSizes(
(options && options.margin && options.margin.total) || 900,
(options && options.margin && options.margin.startingSize) || 0
)
const paddings = getSizes(
(options && options.padding && options.padding.total) || 900,
(options && options.padding && options.padding.startingSize) || 0
)

return {
theme: {
// fontSizes: {
Expand All @@ -59,6 +65,12 @@ module.exports = plugin.withOptions(
height: {
...heights,
},
margin: {
...margins,
},
padding: {
...paddings,
}
},
},
// variants: {
Expand Down
28 changes: 25 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const generatePluginCss = (config, pluginOptions = {}) => {
height: {},
},
variants: [],
corePlugins: ['width', 'height'],
corePlugins: ['width', 'height', 'margin', 'padding'],
plugins: [require('./index.js')(pluginOptions)],
},
config
Expand All @@ -41,8 +41,6 @@ const generatePluginCss = (config, pluginOptions = {}) => {
* Note: I can't figure out how to get around these. If display
* is not added above to corePlugins, nothing shows up
*/
const baseCss = `
`

expect.extend({
toMatchCss: cssMatcher,
Expand All @@ -60,6 +58,30 @@ test('Nine hundred heights are generated by default', () => {
})
})

test('Margin is working', () => {
return generatePluginCss(null, {}).then((css) => {
expect(css).toMatch(/(m-20px)/)
})
})

test('Margin top is working', () => {
return generatePluginCss(null, {}).then((css) => {
expect(css).toMatch(/(mt-20px)/)
})
})

test('Padding is working', () => {
return generatePluginCss(null, {}).then((css) => {
expect(css).toMatch(/(p-20px)/)
})
})

test('Padding top is working', () => {
return generatePluginCss(null, {}).then((css) => {
expect(css).toMatch(/(pt-20px)/)
})
})

// Note: If the results contain a backslash, add another to escape it.
test('A single width and height can be added', () => {
return generatePluginCss(
Expand Down