forked from jorenvanhee/tailwindcss-debug-screens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (39 loc) · 1.43 KB
/
index.js
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
module.exports = function ({ addComponents, theme }) {
const containers = theme('containers', {}); // Get container breakpoints from the Tailwind theme
const userStyles = theme('debugContainers.style', {}); // Allow user-defined styles
const prefix = theme('debugContainers.prefix', 'container: '); // Label prefix
const selector = theme('debugContainers.selector', '[class*="@container"]'); // Target elements with `@container`
const components = {
// Make all `@container` elements `relative` for debug label positioning
[selector]: {
position: 'relative',
},
// Base styles for the debug label
[`${selector}::before`]: Object.assign(
{
position: 'absolute',
top: '0',
left: '0',
padding: '.3333333em .5em',
fontSize: '12px',
lineHeight: '1',
fontFamily: 'sans-serif',
backgroundColor: '#000',
color: '#fff',
boxShadow: '0 0 0 1px #fff',
zIndex: '2147483647',
content: `'${prefix}_'`, // Placeholder content, updated via container queries
},
userStyles
),
};
// Add container-specific rules using `@container`
Object.entries(containers).forEach(([container, size]) => {
components[`@container (min-width: ${size})`] = {
[`${selector}::before`]: {
content: `'${prefix}${container} (${size})'`, // Dynamic label for container
},
};
});
addComponents(components);
};