Support unquoted lists as default theme function values

This commit is contained in:
Adam Wathan 2019-03-12 21:20:31 -04:00
parent 72697fd580
commit 525d03b7dc
2 changed files with 23 additions and 2 deletions

View file

@ -88,3 +88,24 @@ test('quotes are preserved around default values', () => {
expect(result.warnings().length).toBe(0)
})
})
test('an unquoted list is valid as a default value', () => {
const input = `
.heading { font-family: theme('fonts.sans', Helvetica, Arial, sans-serif); }
`
const output = `
.heading { font-family: Helvetica, Arial, sans-serif; }
`
return run(input, {
theme: {
fonts: {
serif: 'Constantia',
},
},
}).then(result => {
expect(result.css).toEqual(output)
expect(result.warnings().length).toBe(0)
})
})

View file

@ -4,8 +4,8 @@ import functions from 'postcss-functions'
export default function(config) {
return functions({
functions: {
theme: (path, defaultValue) => {
return _.get(config.theme, _.trim(path, `'"`), defaultValue)
theme: (path, ...defaultValue) => {
return _.get(config.theme, _.trim(path, `'"`), defaultValue.join(', '))
},
},
})