Getting started on the web
Camouflage for web is a set of Web Components, so it works in plain HTML and in any framework. Three steps are the same everywhere:
-
Install core and a skin:
npm install @srctool/camouflage-core @srctool/camouflage-skin-minimal. -
Define the elements and register the skin once, in your app's entry:
import "@srctool/camouflage-skin-minimal/register";import "@srctool/camouflage-core/define"; -
Put your components inside a provider:
<camo-provider skin="minimal" scheme="light"><camo-button text="Save"></camo-button></camo-provider>
Other skins are skin-material, skin-cupertino, skin-fluent and skin-carbon; charts are
@srctool/camouflage-charts (/define). Values that are not text (lists, objects) are element properties; things
that happen are DOM events (camo-*, plus the native click, input and change).
Plain HTML
The packages are ES modules that import each other by name, so a page needs a bundler (Vite is the least setup) or an
import map that resolves lit and the packages.
<!doctype html>
<camo-provider skin="minimal">
<camo-text-field label="Name"></camo-text-field>
<camo-button text="Save"></camo-button>
</camo-provider>
<script type="module">
import "@srctool/camouflage-skin-minimal/register";
import "@srctool/camouflage-core/define";
document.querySelector("camo-button").addEventListener("click", () => {
console.log(document.querySelector("camo-text-field").value);
});
</script>
React
React 19 sets properties and listens to custom events on custom elements. The typings are types only, so import them
with import type:
import type {} from "@srctool/camouflage-core/react";
import "@srctool/camouflage-skin-minimal/register";
import "@srctool/camouflage-core/define";
import { useState } from "react";
export function App() {
const [name, setName] = useState("");
return (
<camo-provider skin="minimal">
<camo-text-field label="Name" value={name} onInput={(e) => setName((e.target as HTMLInputElement).value)} />
<camo-button text="Save" onClick={() => console.log(name)} />
</camo-provider>
);
}
Vue
Tell the template compiler that camo- tags are custom elements, then add the typings:
// vite.config.js
import vue from "@vitejs/plugin-vue";
export default {
plugins: [vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.startsWith("camo-") } } })],
};
<script setup lang="ts">
import type {} from "@srctool/camouflage-core/vue";
import "@srctool/camouflage-skin-minimal/register";
import "@srctool/camouflage-core/define";
import { ref } from "vue";
const name = ref("");
</script>
<template>
<camo-provider skin="minimal">
<camo-text-field label="Name" :value="name" @input="name = $event.target.value" />
<camo-button text="Save" @click="console.log(name)" />
</camo-provider>
</template>
Svelte
Svelte passes properties and listens to events on custom elements as written:
<script>
import "@srctool/camouflage-skin-minimal/register";
import "@srctool/camouflage-core/define";
let name = $state("");
</script>
<camo-provider skin="minimal">
<camo-text-field label="Name" value={name} oninput={(e) => (name = e.target.value)}></camo-text-field>
<camo-button text="Save" onclick={() => console.log(name)}></camo-button>
</camo-provider>
Angular
Allow unknown elements in the component that uses them, and import the elements in main.ts:
import { Component, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
@Component({
selector: "app-form",
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<camo-provider skin="minimal">
<camo-text-field label="Name" [value]="name" (input)="name = $any($event.target).value"></camo-text-field>
<camo-button text="Save" (click)="save()"></camo-button>
</camo-provider>
`,
})
export class FormComponent {
name = "";
save() {
console.log(this.name);
}
}
The Svelte and Angular examples follow those frameworks' documented custom-element rules; they are not built in this repository's tests.
Server rendering
Render on the server with @lit-labs/ssr and load hydration support before the elements on the client:
// client entry
import "@lit-labs/ssr-client/lit-element-hydrate-support.js";
import "@srctool/camouflage-skin-minimal/register"; // skins first
import "@srctool/camouflage-core/define"; // elements last
The web repository has working plain Node and Next.js samples, and its server rendering page says what a server can and cannot draw.