Skip to content

Commit 9a19553

Browse files
felixtrzmeta-codesync[bot]
authored andcommitted
docs(ui): document color scheme configuration, dark mode styling, and kit bundle optimization
Summary: document color scheme configuration, dark mode styling, and kit bundle optimization Reviewed By: zjm-meta Differential Revision: D87293886 Privacy Context Container: L1334777 fbshipit-source-id: ac853c2c029a20c69badc6fa5e2b96e4e2187235
1 parent 242cb3a commit 9a19553

1 file changed

Lines changed: 141 additions & 15 deletions

File tree

docs/guides/10-spatial-ui-uikitml.md

Lines changed: 141 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,14 @@ IWSDK includes a Vite plugin that compiles UIKitML files:
5959
```typescript
6060
// vite.config.js
6161
import { defineConfig } from 'vite';
62-
import { uikitml } from '@iwsdk/vite-plugin-uikitml';
62+
import { compileUIKit } from '@iwsdk/vite-plugin-uikitml';
6363

6464
export default defineConfig({
6565
plugins: [
66-
uikitml({
67-
// File extensions to process
68-
include: ['**/*.uikitml'],
69-
70-
// Hot reload during development
71-
hotReload: true,
66+
compileUIKit({
67+
sourceDir: 'ui', // Directory containing .uikitml files
68+
outputDir: 'public/ui', // Where compiled .json files are written
69+
verbose: true, // Enable build logging
7270
}),
7371
],
7472
});
@@ -109,22 +107,149 @@ export class PanelSystem extends createSystem({
109107
}) {}
110108
```
111109

112-
### Adding Component Kits to Your Spatial User Interface
110+
### Component Kits
111+
112+
Component kits provide pre-built UI components like buttons, panels, inputs, and icons. IWSDK supports multiple kits that can be combined in your application.
113+
114+
#### Available Component Kits
115+
116+
- **`@pmndrs/uikit-horizon`** - Reality Labs design system (buttons, panels, inputs)
117+
- **`@pmndrs/uikit-lucide`** - Icon library with 1000+ icons
118+
- **`@pmndrs/uikit-default`** - Default kit based on shadcn design system
119+
120+
#### Basic Kit Configuration
121+
122+
Configure kits in the `spatialUI` feature when creating your world:
123+
124+
```typescript
125+
import * as horizonKit from '@pmndrs/uikit-horizon';
126+
127+
World.create(document.getElementById('scene-container'), {
128+
features: {
129+
spatialUI: {
130+
kits: [horizonKit]
131+
},
132+
},
133+
});
134+
```
135+
136+
#### Combining Multiple Kits
137+
138+
You can use components from multiple kits by passing them as an array:
139+
140+
```typescript
141+
import * as horizonKit from '@pmndrs/uikit-horizon';
142+
import * as defaultKit from '@pmndrs/uikit-default';
143+
144+
World.create(document.getElementById('scene-container'), {
145+
features: {
146+
spatialUI: {
147+
kits: [horizonKit, defaultKit]
148+
},
149+
},
150+
});
151+
```
152+
153+
#### Optimizing Bundle Size with Selective Imports
113154

114-
If you'd like to use a different or additional component kit for your uikitml file, you can configure the kits in the `spatialUI` feature list when creating a `World`:
155+
For large icon libraries like `@pmndrs/uikit-lucide` (which contains over 1000 icons), importing the entire package can significantly increase your bundle size. Instead, import only the icons you need:
115156

116157
```typescript
117-
import * as horizonKit from "@pmndrs/uikit-horizon";
158+
import * as horizonKit from '@pmndrs/uikit-horizon';
159+
import { LogInIcon, RectangleGogglesIcon, SettingsIcon } from '@pmndrs/uikit-lucide';
118160

119-
World.create(document.getElementById("scene-container"), {
120-
...
161+
World.create(document.getElementById('scene-container'), {
121162
features: {
122-
...
123-
spatialUI: { kits: [horizonKit] },
163+
spatialUI: {
164+
kits: [
165+
horizonKit,
166+
{ LogInIcon, RectangleGogglesIcon, SettingsIcon } // Only these icons
167+
]
168+
},
124169
},
125-
})
170+
});
126171
```
127172

173+
This technique works with any kit component - just import what you need and pass it as an object in the kits array.
174+
175+
## Color Scheme & Theming
176+
177+
UIKitML supports automatic light and dark mode theming that can follow system preferences or be explicitly set.
178+
179+
### Configuring Color Scheme
180+
181+
Set the preferred color scheme when creating your world:
182+
183+
```typescript
184+
import { ColorSchemeType } from '@iwsdk/core';
185+
186+
World.create(document.getElementById('scene-container'), {
187+
features: {
188+
spatialUI: {
189+
preferredColorScheme: ColorSchemeType.Dark, // Force dark mode
190+
},
191+
},
192+
});
193+
```
194+
195+
**Available color schemes:**
196+
197+
- `ColorSchemeType.System` - Automatically follows browser/OS preference (default)
198+
- `ColorSchemeType.Light` - Force light mode
199+
- `ColorSchemeType.Dark` - Force dark mode
200+
201+
### Changing Color Scheme at Runtime
202+
203+
You can dynamically change the color scheme after initialization:
204+
205+
```typescript
206+
const world = await World.create(container, { /* ... */ });
207+
const panelSystem = world.getSystem(PanelUISystem);
208+
209+
// Switch to light mode
210+
panelSystem.config.preferredColorScheme.value = ColorSchemeType.Light;
211+
212+
// Switch to dark mode
213+
panelSystem.config.preferredColorScheme.value = ColorSchemeType.Dark;
214+
215+
// Follow system preference
216+
panelSystem.config.preferredColorScheme.value = ColorSchemeType.System;
217+
```
218+
219+
### Dark Mode Styling
220+
221+
Use the `:dark` pseudo-selector to define styles that apply only in dark mode:
222+
223+
```html
224+
<style>
225+
.heading {
226+
color: #272727; /* Light mode color */
227+
font-size: 24px;
228+
font-weight: 700;
229+
}
230+
231+
.heading:dark {
232+
color: rgba(255, 255, 255, 0.9); /* Dark mode color */
233+
}
234+
235+
.panel {
236+
background-color: #ffffff;
237+
border: 1px solid #e0e0e0;
238+
}
239+
240+
.panel:dark {
241+
background-color: #1a1a1a;
242+
border: 1px solid #333333;
243+
}
244+
</style>
245+
246+
<Panel class="panel">
247+
<span class="heading">Hello, Immersive Web!</span>
248+
</Panel>
249+
```
250+
251+
The UI automatically updates when the color scheme changes, with no additional code needed.
252+
128253
## Overview of Properties and Features Available for Building Spatial User Interfaces
129254

130255
When authoring a User Interface with IWSDK, developers can use almost all the features they know and love from HTML.
@@ -259,6 +384,7 @@ Define reusable styles with full pseudo-selector support using the `<style>` tag
259384
**Supported selectors:**
260385

261386
- **States:** `:hover`, `:active`, `:focus`
387+
- **Theme:** `:dark` - Applies styles in dark mode
262388
- **Responsive:** `:sm`, `:md`, `:lg`, `:xl`, `:2xl`
263389

264390
### ID-Based Styling

0 commit comments

Comments
 (0)