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#992 from AlexVipond/prefixNegativeMod…
…ifiers_for_boxShadow_and_letterSpacing_and_lineHeight Support negative prefix syntax for boxShadow and letterSpacing
- Loading branch information
Showing
7 changed files
with
195 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,63 @@ | ||
import _ from 'lodash' | ||
import escapeClassName from '../../src/util/escapeClassName' | ||
import plugin from '../../src/plugins/boxShadow' | ||
|
||
test('box shadow can use default keyword and negative prefix syntax', () => { | ||
const addedUtilities = [] | ||
|
||
const config = { | ||
theme: { | ||
boxShadow: { | ||
default: '0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)', | ||
md: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)', | ||
'-': 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)', | ||
'-md': '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)', | ||
}, | ||
}, | ||
variants: { | ||
boxShadow: ['responsive'], | ||
}, | ||
} | ||
|
||
const getConfigValue = (path, defaultValue) => _.get(config, path, defaultValue) | ||
const pluginApi = { | ||
config: getConfigValue, | ||
e: escapeClassName, | ||
theme: (path, defaultValue) => getConfigValue(`theme.${path}`, defaultValue), | ||
variants: (path, defaultValue) => { | ||
if (_.isArray(config.variants)) { | ||
return config.variants | ||
} | ||
|
||
return getConfigValue(`variants.${path}`, defaultValue) | ||
}, | ||
addUtilities(utilities, variants) { | ||
addedUtilities.push({ | ||
utilities, | ||
variants, | ||
}) | ||
}, | ||
} | ||
|
||
plugin()(pluginApi) | ||
|
||
expect(addedUtilities).toEqual([ | ||
{ | ||
utilities: { | ||
'.shadow': { | ||
'box-shadow': '0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)', | ||
}, | ||
'.shadow-md': { | ||
'box-shadow': '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)', | ||
}, | ||
'.-shadow': { | ||
'box-shadow': 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)', | ||
}, | ||
'.-shadow-md': { | ||
'box-shadow': '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)', | ||
}, | ||
}, | ||
variants: ['responsive'], | ||
}, | ||
]) | ||
}) |
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,51 @@ | ||
import _ from 'lodash' | ||
import escapeClassName from '../../src/util/escapeClassName' | ||
import plugin from '../../src/plugins/letterSpacing' | ||
|
||
test('letter spacing can use negative prefix syntax', () => { | ||
const addedUtilities = [] | ||
|
||
const config = { | ||
theme: { | ||
letterSpacing: { | ||
'-1': '-0.025em', | ||
'1': '0.025em', | ||
}, | ||
}, | ||
variants: { | ||
letterSpacing: ['responsive'], | ||
}, | ||
} | ||
|
||
const getConfigValue = (path, defaultValue) => _.get(config, path, defaultValue) | ||
const pluginApi = { | ||
config: getConfigValue, | ||
e: escapeClassName, | ||
theme: (path, defaultValue) => getConfigValue(`theme.${path}`, defaultValue), | ||
variants: (path, defaultValue) => { | ||
if (_.isArray(config.variants)) { | ||
return config.variants | ||
} | ||
|
||
return getConfigValue(`variants.${path}`, defaultValue) | ||
}, | ||
addUtilities(utilities, variants) { | ||
addedUtilities.push({ | ||
utilities, | ||
variants, | ||
}) | ||
}, | ||
} | ||
|
||
plugin()(pluginApi) | ||
|
||
expect(addedUtilities).toEqual([ | ||
{ | ||
utilities: { | ||
'.-tracking-1': { 'letter-spacing': '-0.025em' }, | ||
'.tracking-1': { 'letter-spacing': '0.025em' }, | ||
}, | ||
variants: ['responsive'], | ||
}, | ||
]) | ||
}) |
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,55 @@ | ||
import _ from 'lodash' | ||
import escapeClassName from '../../src/util/escapeClassName' | ||
import plugin from '../../src/plugins/zIndex' | ||
|
||
test('z index can use negative prefix syntax', () => { | ||
const addedUtilities = [] | ||
|
||
const config = { | ||
theme: { | ||
zIndex: { | ||
'-20': '-20', | ||
'-10': '-10', | ||
'10': '10', | ||
'20': '20', | ||
}, | ||
}, | ||
variants: { | ||
zIndex: ['responsive'], | ||
}, | ||
} | ||
|
||
const getConfigValue = (path, defaultValue) => _.get(config, path, defaultValue) | ||
const pluginApi = { | ||
config: getConfigValue, | ||
e: escapeClassName, | ||
theme: (path, defaultValue) => getConfigValue(`theme.${path}`, defaultValue), | ||
variants: (path, defaultValue) => { | ||
if (_.isArray(config.variants)) { | ||
return config.variants | ||
} | ||
|
||
return getConfigValue(`variants.${path}`, defaultValue) | ||
}, | ||
addUtilities(utilities, variants) { | ||
addedUtilities.push({ | ||
utilities, | ||
variants, | ||
}) | ||
}, | ||
} | ||
|
||
plugin()(pluginApi) | ||
|
||
expect(addedUtilities).toEqual([ | ||
{ | ||
utilities: { | ||
'.-z-20': { 'z-index': '-20' }, | ||
'.-z-10': { 'z-index': '-10' }, | ||
'.z-10': { 'z-index': '10' }, | ||
'.z-20': { 'z-index': '20' }, | ||
}, | ||
variants: ['responsive'], | ||
}, | ||
]) | ||
}) |
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,13 @@ | ||
import prefixNegativeModifiers from '../src/util/prefixNegativeModifiers' | ||
|
||
test('it does not prefix classes using standard syntax', () => { | ||
expect(prefixNegativeModifiers('base', 'modifier')).toEqual('base-modifier') | ||
}) | ||
|
||
test('it prefixes classes using negative syntax', () => { | ||
expect(prefixNegativeModifiers('base', '-modifier')).toEqual('-base-modifier') | ||
}) | ||
|
||
test('it prefixes classes and omits suffix using default negative syntax', () => { | ||
expect(prefixNegativeModifiers('base', '-')).toEqual('-base') | ||
}) |
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
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import _ from 'lodash' | ||
|
||
export default function prefixNegativeModifiers(base, modifier) { | ||
return _.startsWith(modifier, '-') ? `-${base}-${modifier.slice(1)}` : `${base}-${modifier}` | ||
if (modifier === '-') { | ||
return `-${base}` | ||
} else if (_.startsWith(modifier, '-')) { | ||
return `-${base}-${modifier.slice(1)}` | ||
} else { | ||
return `${base}-${modifier}` | ||
} | ||
} |