-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (44 loc) · 1.54 KB
/
index.js
File metadata and controls
49 lines (44 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const plugin = require('tailwindcss/plugin');
module.exports = plugin.withOptions(
({
className = 'debug-screens',
prefix = 'screen: ',
position = 'bottom, left',
} = {}) => {
return function({ addComponents, theme }) {
/**
* Workaround to get the screens.
* https://github.com/tailwindlabs/tailwindcss/issues/16130
*/
const allScreens = theme('screens') || {};
const enabledScreenNames = Object.keys(allScreens['__CSS_VALUES__'] || {});
const screens = Object.fromEntries(enabledScreenNames.map((name) => [name, allScreens[name]]));
const positions = position.split(',').map(position => position.trim());
const positionY = ['top', 'bottom'].includes(positions[0]) ? positions[0] : 'bottom';
const positionX = ['left', 'right'].includes(positions[1]) ? positions[1] : 'left';
const mediaQueries = {};
Object.entries(screens).forEach(([name, size]) => {
mediaQueries[`@media (min-width: ${size})`] = {
content: `'${prefix}${name}'`,
}
});
addComponents({
[`.${className}::before`]: {
position: 'fixed',
zIndex: '2147483647',
[positionY]: '0',
[positionX]: '0',
padding: '.3333333em .5em',
fontSize: '12px',
lineHeight: '1',
fontFamily: 'sans-serif',
backgroundColor: '#000',
color: '#fff',
boxShadow: '0 0 0 1px #fff',
content: `'${prefix}_'`,
...mediaQueries,
},
});
};
},
);