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.
Upgrading? See MIGRATION.md for breaking API changes (
useStore, object attributes,useFS, crypto format).
useState, useEffect, useMemo, etc.)useStoreimport { 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:
useState - Local State Managementconst [value, setValue] = useState(initialValue);
useEffect - Side EffectsuseEffect(() => {
// Effect logic
return () => {
// Cleanup
};
}, [dependencies]);
useStyle - Scoped CSSuseStyle(css`
.my-class {
color: blue;
}
`);
useScope - Component CompositionuseScope({
"child-component": ChildComponent,
});
useMemo - Memoized Valuesconst expensive = useMemo(() => {
return computeExpensive(value);
}, [value]);
useRef - DOM Referencesconst inputRef = useRef();
// Access via inputRef.current
useStore - Global Stateconst {
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:
useState, useStoreuseEffect, useRefuseMemouseStyleuseScopeVisit 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 build
dim/
βββ 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.
Dim is brought to you by positive-intentions. Built with positivity.
35 commits
JavaScript
97.8%
TypeScript
1.2%
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.
Upgrading? See MIGRATION.md for breaking API changes (
useStore, object attributes,useFS, crypto format).
useState, useEffect, useMemo, etc.)useStoreimport { 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:
useState - Local State Managementconst [value, setValue] = useState(initialValue);
useEffect - Side EffectsuseEffect(() => {
// Effect logic
return () => {
// Cleanup
};
}, [dependencies]);
useStyle - Scoped CSSuseStyle(css`
.my-class {
color: blue;
}
`);
useScope - Component CompositionuseScope({
"child-component": ChildComponent,
});
useMemo - Memoized Valuesconst expensive = useMemo(() => {
return computeExpensive(value);
}, [value]);
useRef - DOM Referencesconst inputRef = useRef();
// Access via inputRef.current
useStore - Global Stateconst {
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:
useState, useStoreuseEffect, useRefuseMemouseStyleuseScopeVisit 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 build
dim/
βββ 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.
Dim is brought to you by positive-intentions. Built with positivity.
35 commits
JavaScript
97.8%
TypeScript
1.2%