alter-ui Framework
alter-ui is a lightweight UI framework that converts a simple syntax into frontend elements.
🚀 Features
- Supports Tables, Buttons, Inputs, Modals, Dropdowns, Cards, Lists, and Images
- Handles event listeners like
onClick
- Implements two-way data binding
- Reactive state management
- Custom components
- Custom directives
- Built-in API fetching
- Virtual DOM for optimized rendering
- Client-side routing
- Nested components
- Custom events
- Built-in animations
- Global styles
- Dynamic data fetching
- Component-based architecture
📦 Installation
You can install alter-ui via NPM:
npm install alter-ui
Or include the script in your HTML file:
<script src="https://cdn.jsdelivr.net/npm/alter-ui"></script>
🛠 Usage
Setting Up Your Project
-
Create a new project directory:
mkdir my-alter-ui-project
cd my-alter-ui-project
-
Initialize a new NPM project:
npm init -y
-
Install alter-ui:
npm install alter-ui
Creating Your First Component
-
Create an HTML file:
<!DOCTYPE html>
<html>
<head>
<script defer src="node_modules/alter-ui/src/miniUI.js"></script>
<script defer src="script.js"></script>
</head>
<body>
<h1>alter-ui Framework Demo</h1>
<div id="app"></div>
</body>
</html>
-
Create a JavaScript file:
document.addEventListener("DOMContentLoaded", () => {
const ui = new MiniUI("app");
ui.registerComponent('button', {
template: `<button>{{ text }}</button>`,
onMount: () => console.log('Button Mounted!'),
onDestroy: () => console.log('Button Destroyed!')
});
ui.registerComponent('user-card', {
template: `
<div class="card">
<h3>{{ name }}</h3>
<p>Age: {{ age }}</p>
</div>
`,
onMount: () => console.log('User Card Mounted!'),
onDestroy: () => console.log('User Card Destroyed!')
});
ui.setGlobalStyles({
'.card': {
'border': '1px solid #ddd',
'padding': '10px',
'margin': '10px',
'border-radius': '5px',
'box-shadow': '2px 2px 5px rgba(0,0,0,0.1)'
},
'.fadeIn': {
'animation': 'fadeIn 1s ease-in-out'
},
'@keyframes fadeIn': {
'from': { 'opacity': 0 },
'to': { 'opacity': 1 }
}
});
ui.registerRoute('/', `
Table:
row=3, column=3, border=1px solid black
Button:
text=Click Me, color=blue, onclick=Hello World!
Link:
text=Go to About, to=about
Card:
title=Welcome, content=This is a card with nested components., ui-animate=fadeIn
List:
items={{items}}
UserCard:
name=John Doe, age=30
`);
ui.registerRoute('about', `
Input:
placeholder=Type your name, model=username
Link:
text=Go Back, to=/
`);
ui.loadRoute();
ui.root.addEventListener('Hello World!', () => {
alert('Button was clicked!');
});
ui.fetchData('https://jsonplaceholder.typicode.com/todos', 'items');
});
Running Your Project
-
Start a local server:
You can use any local server to serve your HTML file. For example, using http-server:
npm install -g http-server
http-server
-
Open your browser:
Navigate to http://localhost:8080 (or the port specified by your local server) to see your alter-ui project in action.
📄 License
This project is licensed under the MIT License.