@joe-truecode/components
v1.0.1
Published
Framework-agnostic UI components using TailwindCSS v4 and Alpine.js.
Maintainers
Readme
lit/mycomponents/README.md
MyComponents
A framework-agnostic UI component library built with TypeScript, TailwindCSS v4, and Alpine.js. This package is designed for maximum compatibility and ease of use in any modern frontend stack, including React, Vue, Laravel, and plain HTML.
Table of Contents
- Project Structure
- Getting Started
- Editing & Adding Features
- Building & Development
- Deploying & Publishing
- Consuming in Other Frameworks
- Troubleshooting
- References
Project Structure
mycomponents/
├── dist/ # Build output
├── src/
│ ├── index.ts # Entry point, exports components
│ ├── style.css # TailwindCSS entry
│ └── index.html # Demo HTML
├── package.json
├── postcss.config.js
├── tailwind.config.js
├── webpack.config.ts
├── tsconfig.json
└── README.mdGetting Started
Install dependencies:
npm installDevelopment mode (hot reload):
npm run devVisit http://localhost:3000 to see the demo.
Production build:
npm run build
Editing & Adding Features
Adding New Components
Create a new TypeScript file in
src/
Example:src/my-button.tsexport class MyButton extends HTMLElement { connectedCallback() { this.innerHTML = ` <button class="bg-green-500 text-white px-4 py-2 rounded" @click="alert('Clicked!')"> <slot>Click Me</slot> </button> `; window.Alpine && window.Alpine.initTree(this); } } if (!customElements.get('my-button')) { customElements.define('my-button', MyButton); }Export your component in
src/index.ts:export * from './my-button';Use Tailwind utility classes and Alpine.js directives as needed.
Using TailwindCSS & Alpine.js
- TailwindCSS:
Use utility classes directly in your component templates. - Alpine.js:
Usex-data,x-show,@click, etc. Alpine is globally available.
TypeScript Best Practices
- Use strict types for all custom elements.
- Use
declare globalfor extending thewindowobject if needed. - Always check if a custom element is already defined before registering.
Building & Development
- Development:
npm run dev(Webpack dev server, hot reload) - Production:
npm run build(Outputs todist/) - Type checking:
npm run typecheck
Deploying & Publishing
Login to npm (if not already):
npm loginPublish:
npm publish --access publicAfter publishing:
Your package can be installed via npm in any project.
Consuming in Other Frameworks
React
Install the package:
npm install mycomponentsImport the bundle in your entry file (e.g.,
index.tsx):import 'mycomponents/dist/bundle.js'; import 'mycomponents/dist/bundle.css'; // If you extract CSS separatelyUse the custom element in JSX:
<my-toggle></my-toggle>Note: For TypeScript, add a declaration for custom elements:
declare namespace JSX { interface IntrinsicElements { 'my-toggle': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>; } }
Vue
- Install and import as above.
- Use in templates:
<my-toggle></my-toggle>
Laravel & Blade
- Install via npm/yarn.
- Include the bundle in your Blade template:
<script src="{{ mix('node_modules/mycomponents/dist/bundle.js') }}"></script> <link rel="stylesheet" href="{{ mix('node_modules/mycomponents/dist/bundle.css') }}"> <my-toggle></my-toggle>
Plain HTML/JS
- Include the bundle via CDN or local build:
<script src="path/to/bundle.js"></script> <link rel="stylesheet" href="path/to/bundle.css"> <my-toggle></my-toggle>
Troubleshooting
- TailwindCSS not working?
Ensure you are using the correct PostCSS plugin:@tailwindcss/postcss. - Custom elements not rendering?
Make sure the bundle is loaded before using the elements. - TypeScript errors for custom elements in React?
Add a JSX namespace declaration as shown above. - Alpine.js not working?
Ensurewindow.Alpineis available andinitTreeis called in your component.
References
- TailwindCSS v4 Announcement
- Alpine.js Documentation
- Web Components Guide
- TypeScript Custom Elements
- PostCSS Plugin Migration
Happy hacking!
Feel free to open issues or PRs for improvements.
