-
-
Notifications
You must be signed in to change notification settings - Fork 225
Add alpine-ts example #2754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add alpine-ts example #2754
Conversation
|
@niLPotential is attempting to deploy a commit to the Chakra UI Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 Description
Add an example project using Zag as an Alpine.js plugin
⛳️ Current behavior (updates)
none
🚀 New behavior
This PR adds an example vite project simillar to the vanilla-ts example, with modifications around Alpine.js.
The
src/lib/
directory exports thenormalizeProps
function and anAlpineMachine
class.AlpineMachine
consumes the component machine and user props and returns a service.The
src/plugin.ts
file exports ancreateZagPlugin
function, which returns an Alpine.js plugin function corresponding to the given Zag component. It saves the connected api as data, initializes the machine, and reevaluates the api and re-binds the props on effect. Then one can use Zag component in html withx-component-name:part
directives, and$componentName
magic.The
pages/
directory contains examples in practice, with real time props manipulation like the website.💣 Is this a breaking change (Yes/No):
No
📝 Additional Information
Although I believe this implementation to work, there are some concerns.
Mainly that this might not be the most optimal way to extend Alpine.js.
My understanding of their inner apis is lacking, so there could be an improved version.
Also, I tried some manual testing, but bugs may still happen, especially in components not listed in the example.
I would not consider this stable or be ready as an official package.
Nonetheless, a half-baked example is better than none, so hopefully this is helpful.