forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tailwindlabs#423 from tailwindcss/container-options
Add center and padding options to container plugin
- Loading branch information
Showing
3 changed files
with
173 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import _ from 'lodash' | ||
import postcss from 'postcss' | ||
import processPlugins from '../src/util/processPlugins' | ||
import container from '../src/plugins/container' | ||
|
||
function css(nodes) { | ||
return postcss.root({ nodes }).toString() | ||
} | ||
|
||
function processPluginsWithValidConfig(config) { | ||
return processPlugins( | ||
_.defaultsDeep(config, { | ||
screens: { | ||
sm: '576px', | ||
md: '768px', | ||
lg: '992px', | ||
xl: '1200px', | ||
}, | ||
options: { | ||
prefix: '', | ||
important: false, | ||
separator: ':', | ||
}, | ||
}) | ||
) | ||
} | ||
|
||
test('options are not required', () => { | ||
const [components] = processPluginsWithValidConfig({ | ||
plugins: [container()], | ||
}) | ||
|
||
expect(css(components)).toMatchCss(` | ||
.container { width: 100% } | ||
@media (min-width: 576px) { | ||
.container { max-width: 576px } | ||
} | ||
@media (min-width: 768px) { | ||
.container { max-width: 768px } | ||
} | ||
@media (min-width: 992px) { | ||
.container { max-width: 992px } | ||
} | ||
@media (min-width: 1200px) { | ||
.container { max-width: 1200px } | ||
} | ||
`) | ||
}) | ||
|
||
test('screens can be specified explicitly', () => { | ||
const [components] = processPluginsWithValidConfig({ | ||
plugins: [ | ||
container({ | ||
screens: { | ||
sm: '400px', | ||
lg: '500px', | ||
}, | ||
}), | ||
], | ||
}) | ||
|
||
expect(css(components)).toMatchCss(` | ||
.container { width: 100% } | ||
@media (min-width: 400px) { | ||
.container { max-width: 400px } | ||
} | ||
@media (min-width: 500px) { | ||
.container { max-width: 500px } | ||
} | ||
`) | ||
}) | ||
|
||
test('the container can be centered by default', () => { | ||
const [components] = processPluginsWithValidConfig({ | ||
plugins: [ | ||
container({ | ||
center: true, | ||
}), | ||
], | ||
}) | ||
|
||
expect(css(components)).toMatchCss(` | ||
.container { | ||
width: 100%; | ||
margin-right: auto; | ||
margin-left: auto | ||
} | ||
@media (min-width: 576px) { | ||
.container { max-width: 576px } | ||
} | ||
@media (min-width: 768px) { | ||
.container { max-width: 768px } | ||
} | ||
@media (min-width: 992px) { | ||
.container { max-width: 992px } | ||
} | ||
@media (min-width: 1200px) { | ||
.container { max-width: 1200px } | ||
} | ||
`) | ||
}) | ||
|
||
test('horizontal padding can be included by default', () => { | ||
const [components] = processPluginsWithValidConfig({ | ||
plugins: [ | ||
container({ | ||
padding: '2rem', | ||
}), | ||
], | ||
}) | ||
|
||
expect(css(components)).toMatchCss(` | ||
.container { | ||
width: 100%; | ||
padding-right: 2rem; | ||
padding-left: 2rem | ||
} | ||
@media (min-width: 576px) { | ||
.container { max-width: 576px } | ||
} | ||
@media (min-width: 768px) { | ||
.container { max-width: 768px } | ||
} | ||
@media (min-width: 992px) { | ||
.container { max-width: 992px } | ||
} | ||
@media (min-width: 1200px) { | ||
.container { max-width: 1200px } | ||
} | ||
`) | ||
}) | ||
|
||
test('setting all options at once', () => { | ||
const [components] = processPluginsWithValidConfig({ | ||
plugins: [ | ||
container({ | ||
screens: { | ||
sm: '400px', | ||
lg: '500px', | ||
}, | ||
center: true, | ||
padding: '2rem', | ||
}), | ||
], | ||
}) | ||
|
||
expect(css(components)).toMatchCss(` | ||
.container { | ||
width: 100%; | ||
margin-right: auto; | ||
margin-left: auto; | ||
padding-right: 2rem; | ||
padding-left: 2rem | ||
} | ||
@media (min-width: 400px) { | ||
.container { max-width: 400px } | ||
} | ||
@media (min-width: 500px) { | ||
.container { max-width: 500px } | ||
} | ||
`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters