Last active
June 7, 2021 22:27
-
-
Save lnr0626/433bb1e867112b7faf11a78b4c5116fb to your computer and use it in GitHub Desktop.
Tailwind plugin adding variants for phx loading events
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
| 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