Skip to content

Commit 9525074

Browse files
committed
Add first pass of transform utilities
1 parent 3a85f56 commit 9525074

File tree

8 files changed

+151
-11
lines changed

8 files changed

+151
-11
lines changed

src/corePlugins.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ import whitespace from './plugins/whitespace'
6666
import wordBreak from './plugins/wordBreak'
6767
import width from './plugins/width'
6868
import zIndex from './plugins/zIndex'
69+
import transform from './plugins/transform'
70+
import transformOrigin from './plugins/transformOrigin'
71+
import scale from './plugins/scale'
72+
import rotate from './plugins/rotate'
73+
import translate from './plugins/translate'
6974

7075
import configurePlugins from './util/configurePlugins'
7176

@@ -139,5 +144,10 @@ export default function({ corePlugins: corePluginConfig }) {
139144
wordBreak,
140145
width,
141146
zIndex,
147+
transform,
148+
transformOrigin,
149+
scale,
150+
rotate,
151+
translate,
142152
})
143153
}

src/plugins/rotate.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import createUtilityPlugin from '../util/createUtilityPlugin'
2+
3+
export default function() {
4+
return createUtilityPlugin('rotate', 'rotate', '--transform-rotate')
5+
}

src/plugins/scale.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import createUtilityPlugin from '../util/createUtilityPlugin'
2+
3+
export default function() {
4+
return createUtilityPlugin('scale', 'scale', '--transform-scale')
5+
}

src/plugins/transform.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export default function() {
2+
return function({ addUtilities, variants }) {
3+
addUtilities(
4+
{
5+
'.transform': {
6+
transform: [
7+
'scale(var(--transform-scale, 1))',
8+
'rotate(var(--transform-rotate, 0))',
9+
'translateX(var(--transform-translate-x, 0))',
10+
'translateY(var(--transform-translate-y, 0))',
11+
].join(' '),
12+
},
13+
'.transform-none': { transform: 'none' },
14+
},
15+
variants('transform')
16+
)
17+
}
18+
}

src/plugins/transformOrigin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import createUtilityPlugin from '../util/createUtilityPlugin'
2+
3+
export default function() {
4+
return createUtilityPlugin('origin', 'transformOrigin')
5+
}

src/plugins/translate.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import createUtilityPlugin from '../util/createUtilityPlugin'
2+
3+
export default function() {
4+
return function(...args) {
5+
;[
6+
createUtilityPlugin(
7+
'translate-x',
8+
'translate',
9+
'--transform-translate-x'
10+
),
11+
createUtilityPlugin(
12+
'translate-y',
13+
'translate',
14+
'--transform-translate-y'
15+
),
16+
].forEach(f => f(...args))
17+
}
18+
}

src/util/createUtilityPlugin.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import fromPairs from 'lodash/fromPairs'
2+
import toPairs from 'lodash/toPairs'
3+
4+
function className(classPrefix, key) {
5+
if (key === 'default') {
6+
return classPrefix
7+
}
8+
9+
if (key.startsWith('-')) {
10+
return `-${classPrefix}${key}`
11+
}
12+
13+
return `${classPrefix}-${key}`
14+
}
15+
16+
export default function createUtilityPlugin(
17+
classPrefix,
18+
themeKey,
19+
property = themeKey
20+
) {
21+
return function({ e, addUtilities, variants, theme }) {
22+
return addUtilities(
23+
fromPairs(
24+
toPairs(theme(themeKey)).map(([key, value]) => {
25+
return [`.${e(className(classPrefix, key))}`, { [property]: value }]
26+
})
27+
),
28+
variants(themeKey)
29+
)
30+
}
31+
}

stubs/defaultConfig.stub.js

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,14 @@ module.exports = {
183183
'8': '8px',
184184
},
185185
boxShadow: {
186-
default: '0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)',
187-
md: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
188-
lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
189-
xl: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
186+
default:
187+
'0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)',
188+
md:
189+
'0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
190+
lg:
191+
'0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
192+
xl:
193+
'0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
190194
'2xl': '0 25px 50px -12px rgba(0, 0, 0, 0.25)',
191195
inner: 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)',
192196
outline: '0 0 0 3px rgba(66, 153, 225, 0.5)',
@@ -234,13 +238,7 @@ module.exports = {
234238
'"Segoe UI Symbol"',
235239
'"Noto Color Emoji"',
236240
],
237-
serif: [
238-
'Georgia',
239-
'Cambria',
240-
'"Times New Roman"',
241-
'Times',
242-
'serif',
243-
],
241+
serif: ['Georgia', 'Cambria', '"Times New Roman"', 'Times', 'serif'],
244242
mono: [
245243
'Menlo',
246244
'Monaco',
@@ -417,6 +415,51 @@ module.exports = {
417415
'40': '40',
418416
'50': '50',
419417
},
418+
transformOrigin: {
419+
center: 'center',
420+
top: 'top',
421+
'top-right': 'top right',
422+
right: 'right',
423+
'bottom-right': 'bottom right',
424+
bottom: 'bottom',
425+
'bottom-left': 'bottom left',
426+
left: 'left',
427+
'top-left': 'top left',
428+
},
429+
scale: {
430+
'0': '0',
431+
'10': '.1',
432+
'20': '.2',
433+
'30': '.3',
434+
'40': '.4',
435+
'50': '.5',
436+
'60': '.6',
437+
'70': '.7',
438+
'80': '.8',
439+
'90': '.9',
440+
'100': '1',
441+
'110': '1.1',
442+
'120': '1.2',
443+
'130': '1.3',
444+
'140': '1.4',
445+
'150': '1.5',
446+
'160': '1.6',
447+
'170': '1.7',
448+
'180': '1.8',
449+
'190': '1.9',
450+
'200': '2',
451+
},
452+
rotate: {
453+
'0': '0',
454+
'45': '45deg',
455+
'90': '90deg',
456+
'135': '135deg',
457+
'180': '180deg',
458+
'225': '225deg',
459+
'270': '270deg',
460+
'315': '315deg',
461+
},
462+
translate: theme => theme('spacing'),
420463
},
421464
variants: {
422465
accessibility: ['responsive', 'focus'],
@@ -485,6 +528,11 @@ module.exports = {
485528
width: ['responsive'],
486529
wordBreak: ['responsive'],
487530
zIndex: ['responsive'],
531+
transform: ['responsive'],
532+
transformOrigin: ['responsive'],
533+
scale: ['responsive', 'hover', 'focus'],
534+
rotate: ['responsive', 'hover', 'focus'],
535+
translate: ['responsive', 'hover', 'focus'],
488536
},
489537
corePlugins: {},
490538
plugins: [],

0 commit comments

Comments
 (0)