Created
February 16, 2024 16:17
-
-
Save aerni/61a8d2feec8df2c2fed2e52f42ca7609 to your computer and use it in GitHub Desktop.
Stacks
This file contains hidden or 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
import Alpine from 'alpinejs' | |
import stack from './stack' | |
window.Alpine = Alpine | |
Alpine.plugin(stack) | |
Alpine.start() |
This file contains hidden or 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
export default function (Alpine) { | |
Alpine.directive('stack', (el, {}, { cleanup }) => { | |
let setStackSpaceCollapse = () => { | |
el.querySelectorAll('[class*="stack-space-collapse"]').forEach(el => { | |
el.setAttribute('data-stack-space-collapse', getComputedStyle(el).getPropertyValue('--stack-space-collapse') || 'false'); | |
}); | |
}; | |
setStackSpaceCollapse(); | |
window.addEventListener('resize', setStackSpaceCollapse); | |
cleanup(() => { | |
window.removeEventListener('resize', setStackSpaceCollapse) | |
}) | |
}) | |
} |
This file contains hidden or 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
plugin(function ({ addUtilities, matchUtilities, theme }) { | |
matchUtilities( | |
{ | |
'stack': (value) => ({ | |
'> *': { | |
'--stack-space': value, | |
}, | |
'> *:not(.no-space-y, .no-space-b) + *:not(.no-space-y, .no-space-t)': { | |
'margin-block-start': `var(--stack-item-space, var(--stack-space, ${theme('spacing.16')}))` | |
}, | |
}), | |
'stack-space': (value) => ({ | |
'--stack-item-space': value, | |
'&:is([class*="stack-"][class*="stack-space-"] > *)': { | |
'--stack-item-space': value, | |
}, | |
}), | |
}, | |
{ values: theme('spacing') } | |
); | |
addUtilities({ | |
'[class*="stack-"][class*="stack-space-"]': { | |
'& > *': { | |
'--stack-item-space': 'initial', | |
}, | |
}, | |
'.stack-space-inherit': { | |
'--stack-item-space': 'initial', | |
'&:is([class*="stack-"][class*="stack-space-"] > *)': { | |
'--stack-item-space': 'initial', | |
}, | |
}, | |
'[data-stack-space-collapse="true"] + [data-stack-space-collapse="true"]': { | |
'--stack-item-space': 0, | |
'&:is([class*="stack-"][class*="stack-space-"] > *)': { | |
'--stack-item-space': 0, | |
}, | |
}, | |
'.stack-space-collapse': { | |
'--stack-space-collapse': 'true', | |
}, | |
'.stack-space-block': { | |
'--stack-space-collapse': 'false', | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment