A React-inspired functional web components framework
Build modern web applications with familiar React-like syntax, powered by native Web Components
Dim is a lightweight framework that brings React's component model and hooks to native Web Components. Write familiar functional components with hooks while leveraging the power of web standards.
β οΈ Experimental: This framework is in early development and is not production-ready. It's provided for educational and experimental purposes.
- π― React-like DX - Familiar hooks API (
useState,useEffect,useMemo, etc.) - π§ Web Standards - Built on native Web Components and Shadow DOM
- π¨ Scoped Styling - CSS-in-JS with automatic style isolation
- π¦ Zero Dependencies - Pure JavaScript, no build step required
- π Lightweight - Minimal overhead on top of native APIs
- πΎ State Persistence - Built-in global state management with
useStore
import { html, css, define, useState, useStyle } from "@dim/core";
// Create a component
const Counter = (props, { useState, html, css, useStyle }) => {
const [count, setCount] = useState(0);
useStyle(css`
.counter {
padding: 2rem;
text-align: center;
}
button {
background: #029cfd;
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 4px;
cursor: pointer;
}
`);
return html`
<div class="counter">
<h2>Count: ${count}</h2>
<button @click="${() => setCount(count + 1)}">Increment</button>
</div>
`;
};
// Register as custom element
define({ tag: "my-counter", component: Counter });
// Use it
// <my-counter></my-counter>Dim provides React-like hooks for managing component logic:
const [value, setValue] = useState(initialValue);useEffect(() => {
// Effect logic
return () => {
// Cleanup
};
}, [dependencies]);useStyle(css`
.my-class {
color: blue;
}
`);useScope({
"child-component": ChildComponent,
});const expensive = useMemo(() => {
return computeExpensive(value);
}, [value]);const inputRef = useRef();
// Access via inputRef.currentconst {
user: [user, setUser],
} = useStore({
user: { name: "John" },
});const TodoList = (props, { useState, html, css, useStyle }) => {
const [todos, setTodos] = useState([]);
const [input, setInput] = useState("");
const addTodo = () => {
if (input.trim()) {
setTodos([
...todos,
{
id: Date.now(),
text: input,
done: false,
},
]);
setInput("");
}
};
return html`
<div>
<input
.value="${input}"
@input="${(e) => setInput(e.target.value)}"
@keydown="${(e) => e.key === "Enter" && addTodo()}"
/>
<button @click="${addTodo}">Add</button>
<ul>
${todos.map(
(todo) => html`
<li class="${todo.done ? "done" : ""}">
<input
type="checkbox"
.checked="${todo.done}"
@change="${() => toggleTodo(todo.id)}"
/>
${todo.text}
</li>
`
)}
</ul>
</div>
`;
};The framework includes comprehensive documentation through Storybook:
- Getting Started - Introduction and quick start guide
- Core Concepts - Deep dive into hooks and component architecture
- Tutorial - Step-by-step guide to building applications
- Examples - Real-world patterns and implementations
- API Reference - Detailed documentation for each hook
- State Management:
useState,useStore - Effects & Lifecycle:
useEffect,useRef - Performance:
useMemo - Styling:
useStyle - Composition:
useScope
Visit the live documentation for interactive examples and detailed guides.
# Clone the repository
git clone https://github.com/positive-intentions/dim.git
# Install dependencies
npm install
# Start Storybook dev server
npm run storybook
# Build for production
npm run builddim/
βββ src/
β βββ core/
β β βββ dim.ts # Main framework code
β β βββ mini-lit.js # Lit wrapper
β β βββ storage-manager.js
β βββ stories/
β βββ *.stories.js # Main documentation
β βββ hooks/ # Hook examples
β βββ advanced/ # Advanced patterns
β βββ tutorial/ # Step-by-step guides
βββ public/
βββ README.md
This project is licensed under the GNU General Public License v3.0 (GPL-3.0) - see the LICENSE file for details. This means you are free to use, modify, and distribute this software, but any derivative works must also be licensed under GPL-3.0.
- Inspired by React's component model and hooks
- Built on top of Lit for reactive Web Components
- Community feedback
Dim is brought to you by positive-intentions. Built with positivity.
