Skip to content

Instantly share code, notes, and snippets.

@lnr0626
Last active June 7, 2021 22:27
Show Gist options
  • Select an option

  • Save lnr0626/433bb1e867112b7faf11a78b4c5116fb to your computer and use it in GitHub Desktop.

Select an option

Save lnr0626/433bb1e867112b7faf11a78b4c5116fb to your computer and use it in GitHub Desktop.
Tailwind plugin adding variants for phx loading events
const _ = require('lodash');
const plugin = require('tailwindcss/plugin');
module.exports = plugin(({ addVariant, theme, e }) => {
const events = theme('phxLive.events', []);
_.forEach(events, (event) => {
addVariant(`phx-${event}-loading`, ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `.${e(`phx-${event}-loading`)}.${e(`${event}-loading${separator}${className}`)}`;
})
});
addVariant(`phx-${event}-loading-group`, ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `.${e(`phx-${event}-loading`)} .${e(`${event}-loading${separator}${className}`)}`;
})
});
})
}, {
theme: {
phxLive: {
events: [
'click',
'change',
'submit',
'focus',
'blur',
'keydown',
'keyup'
]
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment